EncryptedID::decrypt()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 14
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\XML\saml;
6
7
use InvalidArgumentException;
8
use SimpleSAML\SAML2\XML\EncryptedElementTrait;
9
use SimpleSAML\XML\DOMDocumentFactory;
10
use SimpleSAML\XML\SchemaValidatableElementInterface;
11
use SimpleSAML\XML\SchemaValidatableElementTrait;
12
use SimpleSAML\XML\SerializableElementInterface;
13
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface;
14
use SimpleSAML\XMLSecurity\XML\EncryptedElementInterface;
15
16
use function implode;
17
18
/**
19
 * Class representing an encrypted identifier.
20
 *
21
 * @package simplesamlphp/saml2
22
 */
23
class EncryptedID extends AbstractSamlElement implements
24
    EncryptedElementInterface,
25
    IdentifierInterface,
26
    SchemaValidatableElementInterface
27
{
28
    use EncryptedElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\SAML2\XML\EncryptedElementTrait requires some properties which are not provided by SimpleSAML\SAML2\XML\saml\EncryptedID: $localName, $namespaceURI
Loading history...
29
    use SchemaValidatableElementTrait;
30
31
32
    /**
33
     * @inheritDoc
34
     *
35
     * @return \SimpleSAML\XML\SerializableElementInterface
36
     * @throws \InvalidArgumentException
37
     */
38
    public function decrypt(EncryptionAlgorithmInterface $decryptor): SerializableElementInterface
39
    {
40
        $xml = DOMDocumentFactory::fromString($this->decryptData($decryptor))->documentElement;
41
42
        $id = implode(':', [$xml->namespaceURI, $xml->localName]);
43
        switch ($id) {
44
            case NameID::NS . ':NameID':
45
                return NameID::fromXML($xml);
46
            case AbstractBaseID::NS . ':BaseID':
47
                return AbstractBaseID::fromXML($xml);
48
            default:
49
                // Fall thru
50
        }
51
        throw new InvalidArgumentException('Unknown or unsupported encrypted identifier.');
52
    }
53
}
54