Passed
Push — master ( a3fda0...7c0590 )
by Tim
14:58 queued 13:28
created

NewEncryptedID   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 3
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
    public const string NS = C::NS_SAMLP;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting '=' on line 33 at column 24
Loading history...
34
35
    public const string NS_PREFIX = 'samlp';
36
37
    public const string SCHEMA = 'resources/schemas/saml-schema-protocol-2.0.xsd';
38
39
40
    /**
41
     * @inheritDoc
42
     *
43
     * @return \SimpleSAML\XML\SerializableElementInterface
44
     */
45
    public function decrypt(EncryptionAlgorithmInterface $decryptor): SerializableElementInterface
46
    {
47
        $xml = DOMDocumentFactory::fromString($this->decryptData($decryptor))->documentElement;
48
49
        $id = implode(':', [$xml->namespaceURI, $xml->localName]);
50
        switch ($id) {
51
            case NameID::NS . ':NameID':
52
                return NameID::fromXML($xml);
53
            case AbstractBaseID::NS . ':BaseID':
54
                return AbstractBaseID::fromXML($xml);
55
            default:
56
                // Fall thru
57
        }
58
        throw new InvalidArgumentException('Unknown or unsupported encrypted identifier.');
59
    }
60
}
61