Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
KeyDescriptor.php 1.89 KiB
<?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.