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\XML\DOMDocumentFactory;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XML\DOMDocumentFactory was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use SimpleSAML\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XML\SerializableElementInterface;
12
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface;
13
14
use function implode;
15
16
/**
17
 * Class representing an encrypted identifier.
18
 *
19
 * @package simplesamlphp/saml2
20
 */
21
final class EncryptedID extends AbstractEncryptedElement implements
22
    IdentifierInterface,
23
    SchemaValidatableElementInterface
24
{
25
    use SchemaValidatableElementTrait;
26
27
28
    /**
29
     * @inheritDoc
30
     *
31
     * @return \SimpleSAML\XML\SerializableElementInterface
32
     * @throws \InvalidArgumentException
33
     */
34
    public function decrypt(EncryptionAlgorithmInterface $decryptor): SerializableElementInterface
35
    {
36
        $xml = DOMDocumentFactory::fromString($this->decryptData($decryptor))->documentElement;
37
38
        $id = implode(':', [$xml->namespaceURI, $xml->localName]);
39
        switch ($id) {
40
            case NameID::NS . ':NameID':
41
                return NameID::fromXML($xml);
42
            case AbstractBaseID::NS . ':BaseID':
43
                return AbstractBaseID::fromXML($xml);
44
            default:
45
                // Fall thru
46
        }
47
        throw new InvalidArgumentException('Unknown or unsupported encrypted identifier.');
48
    }
49
}
50