|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace SimpleSAML\SAML2\XML\saml; |
|
6
|
|
|
|
|
7
|
|
|
use DOMElement; |
|
8
|
|
|
use InvalidArgumentException; |
|
9
|
|
|
use SimpleSAML\Assert\Assert; |
|
10
|
|
|
use SimpleSAML\SAML2\Compat\ContainerSingleton; |
|
11
|
|
|
use SimpleSAML\SAML2\Constants as C; |
|
12
|
|
|
use SimpleSAML\SAML2\XML\EncryptedElementTrait; |
|
13
|
|
|
use SimpleSAML\XML\DOMDocumentFactory; |
|
14
|
|
|
use SimpleSAML\XML\Exception\SchemaViolationException; |
|
15
|
|
|
use SimpleSAML\XML\ElementInterface; |
|
16
|
|
|
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface; |
|
17
|
|
|
use SimpleSAML\XMLSecurity\XML\EncryptedElementInterface; |
|
18
|
|
|
|
|
19
|
|
|
use function implode; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Class representing an encrypted identifier. |
|
23
|
|
|
* |
|
24
|
|
|
* @package simplesamlphp/saml2 |
|
25
|
|
|
*/ |
|
26
|
|
|
class EncryptedID extends AbstractSamlElement implements EncryptedElementInterface, IdentifierInterface |
|
27
|
|
|
{ |
|
28
|
|
|
use EncryptedElementTrait; |
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @inheritDoc |
|
33
|
|
|
* |
|
34
|
|
|
* @return \SimpleSAML\XML\ElementInterface |
|
35
|
|
|
* @throws \InvalidArgumentException |
|
36
|
|
|
*/ |
|
37
|
|
|
public function decrypt(EncryptionAlgorithmInterface $decryptor): ElementInterface |
|
38
|
|
|
{ |
|
39
|
|
|
$xml = DOMDocumentFactory::fromString($this->decryptData($decryptor))->documentElement; |
|
40
|
|
|
|
|
41
|
|
|
$id = implode(':', [$xml->namespaceURI, $xml->localName]); |
|
42
|
|
|
switch ($id) { |
|
43
|
|
|
case NameID::NS . ':NameID': |
|
44
|
|
|
return NameID::fromXML($xml); |
|
45
|
|
|
case AbstractBaseID::NS . ':BaseID': |
|
46
|
|
|
return AbstractBaseID::fromXML($xml); |
|
47
|
|
|
default: |
|
48
|
|
|
// Fall thru |
|
49
|
|
|
} |
|
50
|
|
|
throw new InvalidArgumentException('Unknown or unsupported encrypted identifier.'); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|