PrivateKey   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getPassphrase() 0 3 2
A create() 0 8 2
A getKeyAsString() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML2\Certificate;
6
7
class PrivateKey extends Key
8
{
9
    /**
10
     * @param string $keyContents
11
     * @param string|null $passphrase
12
     * @throws \SimpleSAML\SAML2\Exception\InvalidArgumentException
13
     * @return \SimpleSAML\SAML2\Certificate\PrivateKey
14
     */
15
    public static function create(string $keyContents, ?string $passphrase = null): PrivateKey
16
    {
17
        $keyData = ['PEM' => $keyContents, self::USAGE_ENCRYPTION => true];
18
        if ($passphrase) {
19
            $keyData['passphrase'] = $passphrase;
20
        }
21
22
        return new self($keyData);
23
    }
24
25
26
    /**
27
     * @return string
28
     */
29
    public function getKeyAsString(): string
30
    {
31
        return $this->keyData['PEM'];
32
    }
33
34
35
    /**
36
     * @return string|null
37
     */
38
    public function getPassphrase(): ?string
39
    {
40
        return isset($this->keyData['passphrase']) ? $this->keyData['passphrase'] : null;
41
    }
42
}
43