1 | <?php |
||
18 | class NameConstraintsExtension extends Extension |
||
19 | { |
||
20 | /** |
||
21 | * Permitted subtrees. |
||
22 | * |
||
23 | * @var null|GeneralSubtrees |
||
24 | */ |
||
25 | protected $_permitted; |
||
26 | |||
27 | /** |
||
28 | * Excluded subtrees. |
||
29 | * |
||
30 | * @var null|GeneralSubtrees |
||
31 | */ |
||
32 | protected $_excluded; |
||
33 | |||
34 | /** |
||
35 | * Constructor. |
||
36 | * |
||
37 | * @param bool $critical |
||
38 | * @param GeneralSubtrees $permitted |
||
39 | * @param GeneralSubtrees $excluded |
||
40 | */ |
||
41 | 12 | public function __construct(bool $critical, ?GeneralSubtrees $permitted = null, |
|
42 | ?GeneralSubtrees $excluded = null) |
||
43 | { |
||
44 | 12 | parent::__construct(self::OID_NAME_CONSTRAINTS, $critical); |
|
45 | 12 | $this->_permitted = $permitted; |
|
46 | 12 | $this->_excluded = $excluded; |
|
47 | 12 | } |
|
48 | |||
49 | /** |
||
50 | * Whether permitted subtrees are present. |
||
51 | * |
||
52 | * @return bool |
||
53 | */ |
||
54 | 10 | public function hasPermittedSubtrees(): bool |
|
57 | 10 | } |
|
58 | 10 | ||
59 | 10 | /** |
|
60 | 9 | * Get permitted subtrees. |
|
61 | 9 | * |
|
62 | 9 | * @throws \LogicException If not set |
|
63 | 9 | * |
|
64 | * @return GeneralSubtrees |
||
65 | 10 | */ |
|
66 | 1 | public function permittedSubtrees(): GeneralSubtrees |
|
67 | 1 | { |
|
68 | 1 | if (!$this->hasPermittedSubtrees()) { |
|
69 | 1 | throw new \LogicException('No permitted subtrees.'); |
|
70 | } |
||
71 | 10 | return $this->_permitted; |
|
72 | } |
||
73 | |||
74 | /** |
||
75 | * Whether excluded subtrees are present. |
||
76 | * |
||
77 | * @return bool |
||
78 | */ |
||
79 | 3 | public function hasExcludedSubtrees(): bool |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * Get excluded subtrees. |
||
86 | * |
||
87 | * @throws \LogicException If not set |
||
88 | * |
||
89 | * @return GeneralSubtrees |
||
90 | 3 | */ |
|
91 | public function excludedSubtrees(): GeneralSubtrees |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | protected static function _fromDER(string $data, bool $critical): Extension |
||
103 | 2 | { |
|
104 | $seq = UnspecifiedType::fromDER($data)->asSequence(); |
||
105 | 2 | $permitted = null; |
|
106 | $excluded = null; |
||
107 | if ($seq->hasTagged(0)) { |
||
108 | $permitted = GeneralSubtrees::fromASN1( |
||
109 | $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
||
110 | } |
||
111 | if ($seq->hasTagged(1)) { |
||
112 | $excluded = GeneralSubtrees::fromASN1( |
||
113 | $seq->getTagged(1)->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
||
114 | 2 | } |
|
115 | return new self($critical, $permitted, $excluded); |
||
116 | 2 | } |
|
117 | 1 | ||
118 | /** |
||
119 | 1 | * {@inheritdoc} |
|
120 | */ |
||
121 | protected function _valueASN1(): Element |
||
131 | 16 | } |
|
132 | } |
||
133 |