Passed
Push — master ( ff3228...e5a9b6 )
by Tim
14:22
created

EncryptedID::getEncryptionBackend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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;
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
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