PrivateKey::getPassphrase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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