Passed
Pull Request — master (#225)
by Jaime Pérez
02:23
created

EncryptedID   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 17
c 3
b 1
f 0
dl 0
loc 33
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A decrypt() 0 19 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SAML2\XML\saml;
6
7
use RobRichards\XMLSecLibs\XMLSecurityKey;
8
use SAML2\Compat\ContainerSingleton;
9
use SAML2\Constants;
10
use SAML2\XML\EncryptedElementInterface;
11
use SAML2\XML\EncryptedElementTrait;
12
use SAML2\Exception\InvalidArgumentException;
13
use SAML2\Utils;
14
use SAML2\XML\AbstractXMLElement;
15
16
/**
17
 * Class representing an encrypted identifier.
18
 *
19
 * @package simplesamlphp/saml2
20
 */
21
class EncryptedID extends AbstractSamlElement implements EncryptedElementInterface
22
{
23
    use EncryptedElementTrait;
1 ignored issue
show
introduced by
The trait SAML2\XML\EncryptedElementTrait requires some properties which are not provided by SAML2\XML\saml\EncryptedID: $localName, $namespaceURI
Loading history...
24
25
26
    /**
27
     * @inheritDoc
28
     *
29
     * @return IdentifierInterface
30
     * @throws \Exception
31
     *
32
     * @psalm-suppress MismatchingDocblockReturnType
33
     * @psalm-suppress ImplementedReturnTypeMismatch
34
     */
35
    public function decrypt(XMLSecurityKey $key, array $blacklist = []): AbstractXMLElement
36
    {
37
        $xml = Utils::decryptElement($this->encryptedData->toXML(), $key, $blacklist);
38
        $id = implode(':', [$xml->namespaceURI, $xml->localName]);
39
        switch ($id) {
40
            case NameID::NS . ':NameID':
41
                return NameID::fromXML($xml);
42
            case Issuer::NS . 'Issuer':
43
                return Issuer::fromXML($xml);
44
            case BaseID::NS . ':BaseID':
45
                $xsiType = $xml->getAttributeNS(Constants::NS_XSI, 'type');
46
                $container = ContainerSingleton::getInstance();
47
                $handler = $container->getIdentifierHandler($xsiType);
48
                if ($handler !== null) {
49
                    return $handler::fromXML($xml);
50
                }
51
                return BaseID::fromXML($xml);
52
        }
53
        throw new InvalidArgumentException('Unknown or unsupported encrypted identifier.');
54
    }
55
}
56