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

KeyTransportAlgorithmFactory::getAlgorithm()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\Alg\KeyTransport;
6
7
use SimpleSAML\XMLSecurity\Alg\AbstractAlgorithmFactory;
8
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface;
9
use SimpleSAML\XMLSecurity\Constants;
10
use SimpleSAML\XMLSecurity\Key\AbstractKey;
11
12
/**
13
 * Factory class to create and configure key transport algorithms.
14
 */
15
class KeyTransportAlgorithmFactory extends AbstractAlgorithmFactory
16
{
17
    /**
18
     * A cache of algorithm implementations indexed by algorithm ID.
19
     *
20
     * @var string[]
21
     */
22
    protected static array $cache = [];
23
24
    /**
25
     * Whether the factory has been initialized or not.
26
     *
27
     * @var bool
28
     */
29
    protected static bool $initialized = false;
30
31
    /**
32
     * An array of blacklisted algorithms.
33
     *
34
     * Defaults to RSA 1.5.
35
     *
36
     * @var string[]
37
     */
38
    protected array $blacklist = [
39
        Constants::KEY_TRANSPORT_RSA_1_5,
40
    ];
41
42
43
    /**
44
     * Build a factory that creates key transport algorithms.
45
     *
46
     * @param array|null $blacklist A list of algorithms forbidden for their use.
47
     */
48
    public function __construct(array $blacklist = null)
49
    {
50
        parent::__construct($blacklist, [RSA::class]);
51
    }
52
53
    /**
54
     * @inheritDoc
55
     */
56
    protected static function getExpectedParent(): string
57
    {
58
        return EncryptionAlgorithmInterface::class;
59
    }
60
61
62
    /**
63
     * Get a new object implementing the given key transport algorithm.
64
     *
65
     * @param string $algId The identifier of the algorithm desired.
66
     * @param \SimpleSAML\XMLSecurity\Key\AbstractKey $key The key to use with the given algorithm.
67
     *
68
     * @return \SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface An object implementing the given
69
     * algorithm.
70
     *
71
     * @throws \SimpleSAML\XMLSecurity\Exception\InvalidArgumentException If an error occurs, e.g. the given algorithm
72
     * is blacklisted, unknown or the given key is not suitable for it.
73
     */
74
    public function getAlgorithm(string $algId, AbstractKey $key): EncryptionAlgorithmInterface
75
    {
76
        return parent::getAlgorithm($algId, $key);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::getAlgorithm($algId, $key) returns the type SimpleSAML\XMLSecurity\Alg\AlgorithmInterface which includes types incompatible with the type-hinted return SimpleSAML\XMLSecurity\A...ptionAlgorithmInterface.
Loading history...
77
    }
78
}