diff options
author | Olav Morken <olav.morken@uninett.no> | 2010-04-21 12:56:08 +0000 |
---|---|---|
committer | Olav Morken <olav.morken@uninett.no> | 2010-04-21 12:56:08 +0000 |
commit | d970a850e835bd106bb3920d93bcb09f3a45756d (patch) | |
tree | ebb0e124ef0d34b08ab26e2decfe35fddce548cd /lib/SAML2/XML/md/KeyDescriptor.php | |
parent | ce9c4077c5ea8898eb2480c7c251c27418bf9e53 (diff) | |
download | simplesamlphp-d970a850e835bd106bb3920d93bcb09f3a45756d.zip simplesamlphp-d970a850e835bd106bb3920d93bcb09f3a45756d.tar.gz simplesamlphp-d970a850e835bd106bb3920d93bcb09f3a45756d.tar.bz2 |
SAML2: Metadata XML classes.
git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2261 44740490-163a-0410-bde0-09ae8108e29a
Diffstat (limited to 'lib/SAML2/XML/md/KeyDescriptor.php')
-rw-r--r-- | lib/SAML2/XML/md/KeyDescriptor.php | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/SAML2/XML/md/KeyDescriptor.php b/lib/SAML2/XML/md/KeyDescriptor.php new file mode 100644 index 0000000..aeaffe9 --- /dev/null +++ b/lib/SAML2/XML/md/KeyDescriptor.php @@ -0,0 +1,97 @@ +<?php + +/** + * Class representing a KeyDescriptor element. + * + * @package simpleSAMLphp + * @version $Id$ + */ +class SAML2_XML_md_KeyDescriptor { + + /** + * What this key can be used for. + * + * 'encryption', 'signing' or NULL. + * + * @var string|NULL + */ + public $use; + + + /** + * The KeyInfo for this key. + * + * @var SAML2_XML_ds_KeyInfo + */ + public $KeyInfo; + + + /** + * Supported EncryptionMethods. + * + * Array of SAML2_XML_Chunk objects. + * + * @var array + */ + public $EncryptionMethod = array(); + + + /** + * Initialize an KeyDescriptor. + * + * @param DOMElement|NULL $xml The XML element we should load. + */ + public function __construct(DOMElement $xml = NULL) { + + if ($xml === NULL) { + return; + } + + if ($xml->hasAttribute('use')) { + $this->use = $xml->getAttribute('use'); + } + + $keyInfo = SAML2_Utils::xpQuery($xml, './ds:KeyInfo'); + if (count($keyInfo) > 1) { + throw new Exception('More than one ds:KeyInfo in the KeyDescriptor.'); + } elseif (empty($keyInfo)) { + throw new Exception('No ds:KeyInfo in the KeyDescriptor.'); + } + $this->KeyInfo = new SAML2_XML_ds_KeyInfo($keyInfo[0]); + + foreach (SAML2_Utils::xpQuery($xml, './saml_metadata:EncryptionMethod') as $em) { + $this->EncryptionMethod[] = new SAML2_XML_Chunk($em); + } + + } + + + /** + * Convert this KeyDescriptor to XML. + * + * @param DOMElement $parent The element we should append this KeyDescriptor to. + */ + public function toXML(DOMElement $parent) { + assert('is_null($this->use) || is_string($this->use)'); + assert('$this->KeyInfo instanceof SAML2_XML_ds_KeyInfo'); + assert('is_array($this->EncryptionMethod)'); + + $doc = $parent->ownerDocument; + + $e = $doc->createElementNS(SAML2_Const::NS_MD, 'md:KeyDescriptor'); + $parent->appendChild($e); + + if (isset($this->use)) { + $e->setAttribute('use', $this->use); + } + + $this->KeyInfo->toXML($e); + + foreach ($this->EncryptionMethod as $em) { + $em->toXML($e); + } + + return $e; + } + +} |