1 | <?php |
||
16 | class KeyUsageExtension extends Extension |
||
17 | { |
||
18 | const DIGITAL_SIGNATURE = 0x100; |
||
19 | const NON_REPUDIATION = 0x080; |
||
20 | const KEY_ENCIPHERMENT = 0x040; |
||
21 | const DATA_ENCIPHERMENT = 0x020; |
||
22 | const KEY_AGREEMENT = 0x010; |
||
23 | const KEY_CERT_SIGN = 0x008; |
||
24 | const CRL_SIGN = 0x004; |
||
25 | const ENCIPHER_ONLY = 0x002; |
||
26 | const DECIPHER_ONLY = 0x001; |
||
27 | |||
28 | /** |
||
29 | * Key usage flags. |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $_keyUsage; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param bool $critical |
||
39 | * @param int $keyUsage |
||
40 | */ |
||
41 | 20 | public function __construct(bool $critical, int $keyUsage) |
|
42 | { |
||
43 | 20 | parent::__construct(self::OID_KEY_USAGE, $critical); |
|
44 | 20 | $this->_keyUsage = $keyUsage; |
|
45 | 20 | } |
|
46 | |||
47 | /** |
||
48 | * Check whether digitalSignature flag is set. |
||
49 | * |
||
50 | * @return bool |
||
51 | */ |
||
52 | 16 | public function isDigitalSignature(): bool |
|
55 | 16 | } |
|
56 | 16 | ||
57 | /** |
||
58 | * Check whether nonRepudiation/contentCommitment flag is set. |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | public function isNonRepudiation(): bool |
||
63 | { |
||
64 | 4 | return $this->_flagSet(self::NON_REPUDIATION); |
|
65 | } |
||
66 | 4 | ||
67 | /** |
||
68 | * Check whether keyEncipherment flag is set. |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | public function isKeyEncipherment(): bool |
||
73 | { |
||
74 | 2 | return $this->_flagSet(self::KEY_ENCIPHERMENT); |
|
75 | } |
||
76 | 2 | ||
77 | /** |
||
78 | * Check whether dataEncipherment flag is set. |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | public function isDataEncipherment(): bool |
||
83 | { |
||
84 | 3 | return $this->_flagSet(self::DATA_ENCIPHERMENT); |
|
85 | } |
||
86 | 3 | ||
87 | /** |
||
88 | * Check whether keyAgreement flag is set. |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | public function isKeyAgreement(): bool |
||
93 | { |
||
94 | 2 | return $this->_flagSet(self::KEY_AGREEMENT); |
|
95 | } |
||
96 | 2 | ||
97 | /** |
||
98 | * Check whether keyCertSign flag is set. |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | public function isKeyCertSign(): bool |
||
103 | { |
||
104 | 2 | return $this->_flagSet(self::KEY_CERT_SIGN); |
|
105 | } |
||
106 | 2 | ||
107 | /** |
||
108 | * Check whether cRLSign flag is set. |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | public function isCRLSign(): bool |
||
113 | { |
||
114 | 23 | return $this->_flagSet(self::CRL_SIGN); |
|
115 | } |
||
116 | 23 | ||
117 | /** |
||
118 | * Check whether encipherOnly flag is set. |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function isEncipherOnly(): bool |
||
123 | { |
||
124 | 2 | return $this->_flagSet(self::ENCIPHER_ONLY); |
|
125 | } |
||
126 | 2 | ||
127 | /** |
||
128 | * Check whether decipherOnly flag is set. |
||
129 | * |
||
130 | * @return bool |
||
131 | */ |
||
132 | public function isDecipherOnly(): bool |
||
133 | { |
||
134 | 2 | return $this->_flagSet(self::DECIPHER_ONLY); |
|
135 | } |
||
136 | 2 | ||
137 | /** |
||
138 | * Check whether given flag is set. |
||
139 | * |
||
140 | * @param int $flag |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | 2 | protected function _flagSet(int $flag): bool |
|
147 | } |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | protected static function _fromDER(string $data, bool $critical): Extension |
||
153 | { |
||
154 | return new self($critical, |
||
155 | 31 | Flags::fromBitString( |
|
156 | UnspecifiedType::fromDER($data)->asBitString(), 9)->intNumber()); |
||
157 | 31 | } |
|
158 | |||
159 | /** |
||
160 | * {@inheritdoc} |
||
161 | */ |
||
162 | protected function _valueASN1(): Element |
||
166 | } |
||
167 | } |
||
168 |