Passed
Push — master ( 8c6c02...c19f8b )
by Tim
02:50
created

NewEncryptedID::decrypt()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 14
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\samlp;
6
7
use InvalidArgumentException;
8
use SimpleSAML\SAML2\Constants as C;
9
use SimpleSAML\SAML2\XML\saml\AbstractBaseID;
10
use SimpleSAML\SAML2\XML\saml\AbstractEncryptedElement;
11
use SimpleSAML\SAML2\XML\saml\IdentifierInterface;
12
use SimpleSAML\SAML2\XML\saml\NameID;
13
use SimpleSAML\XML\DOMDocumentFactory;
14
use SimpleSAML\XML\SchemaValidatableElementInterface;
15
use SimpleSAML\XML\SchemaValidatableElementTrait;
16
use SimpleSAML\XML\SerializableElementInterface;
17
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface;
18
19
use function implode;
20
21
/**
22
 * Class representing an encrypted identifier.
23
 *
24
 * @package simplesamlphp/saml2
25
 */
26
final class NewEncryptedID extends AbstractEncryptedElement implements
27
    IdentifierInterface,
28
    SchemaValidatableElementInterface
29
{
30
    use SchemaValidatableElementTrait;
31
32
33
    /** @var string */
34
    public const NS = C::NS_SAMLP;
35
36
    /** @var string */
37
    public const NS_PREFIX = 'samlp';
38
39
    /** @var string */
40
    public const SCHEMA = 'resources/schemas/saml-schema-protocol-2.0.xsd';
41
42
43
    /**
44
     * @inheritDoc
45
     *
46
     * @return \SimpleSAML\XML\SerializableElementInterface
47
     */
48
    public function decrypt(EncryptionAlgorithmInterface $decryptor): SerializableElementInterface
49
    {
50
        $xml = DOMDocumentFactory::fromString($this->decryptData($decryptor))->documentElement;
51
52
        $id = implode(':', [$xml->namespaceURI, $xml->localName]);
53
        switch ($id) {
54
            case NameID::NS . ':NameID':
55
                return NameID::fromXML($xml);
56
            case AbstractBaseID::NS . ':BaseID':
57
                return AbstractBaseID::fromXML($xml);
58
            default:
59
                // Fall thru
60
        }
61
        throw new InvalidArgumentException('Unknown or unsupported encrypted identifier.');
62
    }
63
}
64