PrivateKey::getPassPhrase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
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\Configuration;
6
7
use SimpleSAML\Assert\Assert;
8
9
/**
10
 * Configuration of a private key.
11
 */
12
class PrivateKey extends ArrayAdapter
13
{
14
    /** @var string */
15
    public const NAME_NEW = 'new';
16
17
    /** @var string */
18
    public const NAME_DEFAULT = 'default';
19
20
21
    /**
22
     * Constructor for PrivateKey.
23
     *
24
     * @param string $filePathOrContents
25
     * @param string $name
26
     * @param string $passphrase
27
     * @param bool $isFile
28
     */
29
    public function __construct(
30
        private string $filePathOrContents,
31
        private string $name,
32
        private string $passphrase = '',
33
        private bool $isFile = true,
34
    ) {
35
    }
36
37
38
    /**
39
     * @return string
40
     *
41
     * @throws \SimpleSAML\Assert\AssertionFailedException if assertions are false
42
     */
43
    public function getFilePath(): string
44
    {
45
        Assert::true($this->isFile(), 'No path provided.');
46
47
        return $this->filePathOrContents;
48
    }
49
50
51
    /**
52
     * @return bool
53
     */
54
    public function hasPassPhrase(): bool
55
    {
56
        return !empty($this->passphrase);
57
    }
58
59
60
    /**
61
     * @return string
62
     */
63
    public function getPassPhrase(): string
64
    {
65
        return $this->passphrase;
66
    }
67
68
69
    /**
70
     * @return string
71
     */
72
    public function getName(): string
73
    {
74
        return $this->name;
75
    }
76
77
78
    /**
79
     * @return string
80
     *
81
     * @throws \SimpleSAML\Assert\AssertionFailedException if assertions are false
82
     */
83
    public function getContents(): string
84
    {
85
        Assert::false($this->isFile(), 'No contents provided.');
86
87
        return $this->filePathOrContents;
88
    }
89
90
91
    /**
92
     * @return bool
93
     */
94
    public function isFile(): bool
95
    {
96
        return $this->isFile;
97
    }
98
}
99