1 | <?php |
||
16 | class ReasonFlags |
||
17 | { |
||
18 | // const UNUSED = 0x100; |
||
19 | const KEY_COMPROMISE = 0x080; |
||
20 | const CA_COMPROMISE = 0x040; |
||
21 | const AFFILIATION_CHANGED = 0x020; |
||
22 | const SUPERSEDED = 0x010; |
||
23 | const CESSATION_OF_OPERATION = 0x008; |
||
24 | const CERTIFICATE_HOLD = 0x004; |
||
25 | const PRIVILEGE_WITHDRAWN = 0x002; |
||
26 | const AA_COMPROMISE = 0x001; |
||
27 | |||
28 | /** |
||
29 | * Flags. |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $_flags; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param int $flags |
||
39 | */ |
||
40 | 15 | public function __construct(int $flags) |
|
41 | { |
||
42 | 15 | $this->_flags = $flags; |
|
43 | 15 | } |
|
44 | |||
45 | /** |
||
46 | * Initialize from ASN.1. |
||
47 | * |
||
48 | * @param BitString $bs |
||
49 | * |
||
50 | * @return self |
||
51 | */ |
||
52 | 12 | public static function fromASN1(BitString $bs): self |
|
53 | { |
||
54 | 12 | return new self(Flags::fromBitString($bs, 9)->intNumber()); |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * Check whether keyCompromise flag is set. |
||
59 | * |
||
60 | * @return bool |
||
61 | */ |
||
62 | 3 | public function isKeyCompromise(): bool |
|
63 | { |
||
64 | 3 | return $this->_flagSet(self::KEY_COMPROMISE); |
|
65 | } |
||
66 | |||
67 | /** |
||
68 | * Check whether cACompromise flag is set. |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 3 | public function isCACompromise(): bool |
|
73 | { |
||
74 | 3 | return $this->_flagSet(self::CA_COMPROMISE); |
|
75 | } |
||
76 | |||
77 | /** |
||
78 | * Check whether affiliationChanged flag is set. |
||
79 | * |
||
80 | * @return bool |
||
81 | */ |
||
82 | 3 | public function isAffiliationChanged(): bool |
|
83 | { |
||
84 | 3 | return $this->_flagSet(self::AFFILIATION_CHANGED); |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Check whether superseded flag is set. |
||
89 | * |
||
90 | * @return bool |
||
91 | */ |
||
92 | 3 | public function isSuperseded(): bool |
|
93 | { |
||
94 | 3 | return $this->_flagSet(self::SUPERSEDED); |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Check whether cessationOfOperation flag is set. |
||
99 | * |
||
100 | * @return bool |
||
101 | */ |
||
102 | 3 | public function isCessationOfOperation(): bool |
|
105 | } |
||
106 | |||
107 | /** |
||
108 | * Check whether certificateHold flag is set. |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 3 | public function isCertificateHold(): bool |
|
113 | { |
||
114 | 3 | return $this->_flagSet(self::CERTIFICATE_HOLD); |
|
115 | } |
||
116 | |||
117 | /** |
||
118 | * Check whether privilegeWithdrawn flag is set. |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | 4 | public function isPrivilegeWithdrawn(): bool |
|
123 | { |
||
124 | 4 | return $this->_flagSet(self::PRIVILEGE_WITHDRAWN); |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * Check whether aACompromise flag is set. |
||
129 | * |
||
130 | * @return bool |
||
131 | */ |
||
132 | 3 | public function isAACompromise(): bool |
|
135 | } |
||
136 | |||
137 | /** |
||
138 | * Generate ASN.1 element. |
||
139 | * |
||
140 | * @return BitString |
||
141 | */ |
||
142 | 18 | public function toASN1(): BitString |
|
143 | { |
||
144 | 18 | $flags = new Flags($this->_flags, 9); |
|
145 | 18 | return $flags->bitString()->withoutTrailingZeroes(); |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * Check whether given flag is set. |
||
150 | * |
||
151 | * @param int $flag |
||
152 | * |
||
153 | * @return bool |
||
154 | */ |
||
155 | 11 | protected function _flagSet(int $flag): bool |
|
158 | } |
||
159 | } |
||
160 |