BeSimpleSoap/src/BeSimple/SoapCommon/WsSecurityKey.php

116 lines
2.5 KiB
PHP
Raw Normal View History

2011-11-01 11:12:07 +01:00
<?php
/*
* This file is part of BeSimpleSoapCommon.
*
* (c) Christian Kerl <christian-kerl@web.de>
* (c) Francis Besset <francis.besset@gmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace BeSimple\SoapCommon;
use ass\XmlSecurity\Key as XmlSecurityKey;
/**
* This class represents a security key for WS-Security (WSS).
*
* @author Andreas Schamberger <mail@andreass.net>
*/
class WsSecurityKey
{
/**
* Private key.
*
* @var \ass\XmlSecurity\Key
*/
protected $privateKey = null;
/**
* Public key.
*
* @var \ass\XmlSecurity\Key
*/
protected $publicKey = null;
/**
* Add private key.
*
* @param string $encryptionType Encryption type
* @param string $key Private key
* @param boolean $keyIsFile Given key parameter is path to key file
* @param string $passphrase Passphrase for key
2011-12-17 16:25:49 +01:00
*
2011-11-01 11:12:07 +01:00
* @return void
*/
public function addPrivateKey($encryptionType, $key = null, $keyIsFile = true, $passphrase = null)
{
$this->privateKey = XmlSecurityKey::factory($encryptionType, $key, $keyIsFile, XmlSecurityKey::TYPE_PRIVATE, $passphrase);
}
/**
* Add public key.
*
* @param string $encryptionType Encryption type
* @param string $key Public key
* @param boolean $keyIsFile Given key parameter is path to key file
2011-12-17 16:25:49 +01:00
*
2011-11-01 11:12:07 +01:00
* @return void
*/
public function addPublicKey($encryptionType, $key = null, $keyIsFile = true)
{
$this->publicKey = XmlSecurityKey::factory($encryptionType, $key, $keyIsFile, XmlSecurityKey::TYPE_PUBLIC);
}
/**
* Get private key.
*
* @return \ass\XmlSecurity\Key
*/
public function getPrivateKey()
{
return $this->privateKey;
}
/**
* Get public key.
*
* @return \ass\XmlSecurity\Key
*/
public function getPublicKey()
{
return $this->publicKey;
}
/**
* Has private and public key?
*
* @return boolean
*/
public function hasKeys()
{
2011-12-04 17:29:50 +01:00
return null !== $this->privateKey && null !== $this->publicKey;
2011-11-01 11:12:07 +01:00
}
/**
* Has private key?
*
* @return boolean
*/
public function hasPrivateKey()
{
2011-12-04 17:29:50 +01:00
return null !== $this->privateKey;
2011-11-01 11:12:07 +01:00
}
/**
* Has public key?
*
* @return boolean
*/
public function hasPublicKey()
{
2011-12-04 17:29:50 +01:00
return null !== $this->publicKey;
2011-11-01 11:12:07 +01:00
}
}