Passed
Pull Request — master (#363)
by Tim
02:37
created

AbstractProvider   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getSignatureAlgorithm() 0 3 1
A getEntityId() 0 3 1
A getIDPList() 0 3 1
A getEncryptionKey() 0 3 1
A getValidatingKeys() 0 3 1
A getSigningKey() 0 3 1
A __construct() 0 19 1
A getDecryptionKeys() 0 3 1
A getPreSharedKey() 0 3 1
A getPreSharedKeyAlgorithm() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Metadata;
6
7
use SimpleSAML\Assert\Assert;
8
use SimpleSAML\XMLSecurity\Constants as C;
9
use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey};
10
11
use function array_keys;
12
13
/**
14
 * Class holding common configuration for SAML2 entities.
15
 *
16
 * @package simplesamlphp/saml2
17
 */
18
abstract class AbstractProvider
19
{
20
    /**
21
     */
22
    protected function __construct(
23
        protected string $entityId,
24
        protected string $signatureAlgorithm,
25
        protected array $validatingKeys,
26
        protected ?PrivateKey $signingKey,
27
        protected ?PublicKey $encryptionKey,
28
        protected array $decryptionKeys,
29
        protected ?SymmetricKey $preSharedKey,
30
        protected string $preSharedKeyAlgorithm,
31
        protected array $IDPList,
32
    ) {
33
        Assert::validURI($entityId);
34
        Assert::validURI($signatureAlgorithm);
35
        Assert::oneOf($signatureAlgorithm, array_keys(C::$RSA_DIGESTS));
36
        Assert::allIsInstanceOf($decryptionKeys, PrivateKey::class);
37
        Assert::allIsInstanceOf($validatingKeys, PublicKey::class);
38
        Assert::allValidURI($IDPList);
39
        Assert::nullOrValidURI($preSharedKeyAlgorithm);
40
        Assert::oneOf($preSharedKeyAlgorithm, array_keys(C::$BLOCK_CIPHER_ALGORITHMS));
41
    }
42
43
44
    /**
45
     * Retrieve the signature slgorithm to be used for signing messages.
46
     */
47
    public function getSignatureAlgorithm(): string
48
    {
49
        return $this->signatureAlgorithm;
50
    }
51
52
53
    /**
54
     * Get the private key to use for signing messages.
55
     *
56
     * @return \SimpleSAML\XMLSecurity\Key\PrivateKey|null
57
     */
58
    public function getSigningKey(): ?PrivateKey
59
    {
60
        return $this->signingKey;
61
    }
62
63
64
    /**
65
     * Get the validating keys to verify a message signature with.
66
     *
67
     * @return array<\SimpleSAML\XMLSecurity\Key\PublicKey>
68
     */
69
    public function getValidatingKeys(): array
70
    {
71
        return $this->validatingKeys;
72
    }
73
74
75
    /**
76
     * Get the public key to use for encrypting messages.
77
     *
78
     * @return \SimpleSAML\XMLSecurity\Key\PublicKey|null
79
     */
80
    public function getEncryptionKey(): ?PublicKey
81
    {
82
        return $this->encryptionKey;
83
    }
84
85
86
    /**
87
     * Get the symmetric key to use for encrypting/decrypting messages.
88
     *
89
     * @return \SimpleSAML\XMLSecurity\Key\SymmetricKey|null
90
     */
91
    public function getPreSharedKey(): ?SymmetricKey
92
    {
93
        return $this->preSharedKey;
94
    }
95
96
97
    /**
98
     * Get the symmetric encrypting/decrypting algorithm to use.
99
     *
100
     * @return string|null
101
     */
102
    public function getPreSharedKeyAlgorithm(): ?string
103
    {
104
        return $this->preSharedKeyAlgorithm;
105
    }
106
107
108
    /**
109
     * Get the decryption keys to decrypt the assertion with.
110
     *
111
     * @return array<\SimpleSAML\XMLSecurity\Key\PrivateKey>
112
     */
113
    public function getDecryptionKeys(): array
114
    {
115
        return $this->decryptionKeys;
116
    }
117
118
119
    /**
120
     * Retrieve the configured entity ID for this entity
121
     */
122
    public function getEntityId(): string
123
    {
124
        return $this->entityId;
125
    }
126
127
128
    /**
129
     * Retrieve the configured IDPList for this entity.
130
     *
131
     * @return string[]
132
     */
133
    public function getIDPList(): array
134
    {
135
        return $this->IDPList;
136
    }
137
}
138