@@ -13,16 +13,16 @@ |
||
13 | 13 | */ |
14 | 14 | class FreshestCRLExtension extends CRLDistributionPointsExtension |
15 | 15 | { |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param bool $critical |
|
20 | - * @param DistributionPoint ...$distribution_points |
|
21 | - */ |
|
22 | - public function __construct(bool $critical, |
|
23 | - DistributionPoint ...$distribution_points) |
|
24 | - { |
|
25 | - Extension::__construct(self::OID_FRESHEST_CRL, $critical); |
|
26 | - $this->_distributionPoints = $distribution_points; |
|
27 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param bool $critical |
|
20 | + * @param DistributionPoint ...$distribution_points |
|
21 | + */ |
|
22 | + public function __construct(bool $critical, |
|
23 | + DistributionPoint ...$distribution_points) |
|
24 | + { |
|
25 | + Extension::__construct(self::OID_FRESHEST_CRL, $critical); |
|
26 | + $this->_distributionPoints = $distribution_points; |
|
27 | + } |
|
28 | 28 | } |
@@ -16,134 +16,134 @@ |
||
16 | 16 | */ |
17 | 17 | class CertificatePoliciesExtension extends Extension implements \Countable, \IteratorAggregate |
18 | 18 | { |
19 | - /** |
|
20 | - * Policy information terms. |
|
21 | - * |
|
22 | - * @var PolicyInformation[] |
|
23 | - */ |
|
24 | - protected $_policies; |
|
19 | + /** |
|
20 | + * Policy information terms. |
|
21 | + * |
|
22 | + * @var PolicyInformation[] |
|
23 | + */ |
|
24 | + protected $_policies; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructor. |
|
28 | - * |
|
29 | - * @param bool $critical |
|
30 | - * @param PolicyInformation ...$policies |
|
31 | - */ |
|
32 | - public function __construct(bool $critical, PolicyInformation ...$policies) |
|
33 | - { |
|
34 | - parent::__construct(Extension::OID_CERTIFICATE_POLICIES, $critical); |
|
35 | - $this->_policies = []; |
|
36 | - foreach ($policies as $policy) { |
|
37 | - $this->_policies[$policy->oid()] = $policy; |
|
38 | - } |
|
39 | - } |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + * |
|
29 | + * @param bool $critical |
|
30 | + * @param PolicyInformation ...$policies |
|
31 | + */ |
|
32 | + public function __construct(bool $critical, PolicyInformation ...$policies) |
|
33 | + { |
|
34 | + parent::__construct(Extension::OID_CERTIFICATE_POLICIES, $critical); |
|
35 | + $this->_policies = []; |
|
36 | + foreach ($policies as $policy) { |
|
37 | + $this->_policies[$policy->oid()] = $policy; |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Check whether policy information by OID is present. |
|
43 | - * |
|
44 | - * @param string $oid |
|
45 | - * |
|
46 | - * @return bool |
|
47 | - */ |
|
48 | - public function has(string $oid): bool |
|
49 | - { |
|
50 | - return isset($this->_policies[$oid]); |
|
51 | - } |
|
41 | + /** |
|
42 | + * Check whether policy information by OID is present. |
|
43 | + * |
|
44 | + * @param string $oid |
|
45 | + * |
|
46 | + * @return bool |
|
47 | + */ |
|
48 | + public function has(string $oid): bool |
|
49 | + { |
|
50 | + return isset($this->_policies[$oid]); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get policy information by OID. |
|
55 | - * |
|
56 | - * @param string $oid |
|
57 | - * |
|
58 | - * @throws \LogicException If not set |
|
59 | - * |
|
60 | - * @return PolicyInformation |
|
61 | - */ |
|
62 | - public function get(string $oid): PolicyInformation |
|
63 | - { |
|
64 | - if (!$this->has($oid)) { |
|
65 | - throw new \LogicException("Not certificate policy by OID {$oid}."); |
|
66 | - } |
|
67 | - return $this->_policies[$oid]; |
|
68 | - } |
|
53 | + /** |
|
54 | + * Get policy information by OID. |
|
55 | + * |
|
56 | + * @param string $oid |
|
57 | + * |
|
58 | + * @throws \LogicException If not set |
|
59 | + * |
|
60 | + * @return PolicyInformation |
|
61 | + */ |
|
62 | + public function get(string $oid): PolicyInformation |
|
63 | + { |
|
64 | + if (!$this->has($oid)) { |
|
65 | + throw new \LogicException("Not certificate policy by OID {$oid}."); |
|
66 | + } |
|
67 | + return $this->_policies[$oid]; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Check whether anyPolicy is present. |
|
72 | - * |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function hasAnyPolicy(): bool |
|
76 | - { |
|
77 | - return $this->has(PolicyInformation::OID_ANY_POLICY); |
|
78 | - } |
|
70 | + /** |
|
71 | + * Check whether anyPolicy is present. |
|
72 | + * |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function hasAnyPolicy(): bool |
|
76 | + { |
|
77 | + return $this->has(PolicyInformation::OID_ANY_POLICY); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get anyPolicy information. |
|
82 | - * |
|
83 | - * @throws \LogicException if anyPolicy is not present |
|
84 | - * |
|
85 | - * @return PolicyInformation |
|
86 | - */ |
|
87 | - public function anyPolicy(): PolicyInformation |
|
88 | - { |
|
89 | - if (!$this->hasAnyPolicy()) { |
|
90 | - throw new \LogicException('No anyPolicy.'); |
|
91 | - } |
|
92 | - return $this->get(PolicyInformation::OID_ANY_POLICY); |
|
93 | - } |
|
80 | + /** |
|
81 | + * Get anyPolicy information. |
|
82 | + * |
|
83 | + * @throws \LogicException if anyPolicy is not present |
|
84 | + * |
|
85 | + * @return PolicyInformation |
|
86 | + */ |
|
87 | + public function anyPolicy(): PolicyInformation |
|
88 | + { |
|
89 | + if (!$this->hasAnyPolicy()) { |
|
90 | + throw new \LogicException('No anyPolicy.'); |
|
91 | + } |
|
92 | + return $this->get(PolicyInformation::OID_ANY_POLICY); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Get the number of policies. |
|
97 | - * |
|
98 | - * @see \Countable::count() |
|
99 | - * |
|
100 | - * @return int |
|
101 | - */ |
|
102 | - public function count(): int |
|
103 | - { |
|
104 | - return count($this->_policies); |
|
105 | - } |
|
95 | + /** |
|
96 | + * Get the number of policies. |
|
97 | + * |
|
98 | + * @see \Countable::count() |
|
99 | + * |
|
100 | + * @return int |
|
101 | + */ |
|
102 | + public function count(): int |
|
103 | + { |
|
104 | + return count($this->_policies); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Get iterator for policy information terms. |
|
109 | - * |
|
110 | - * @see \IteratorAggregate::getIterator() |
|
111 | - * |
|
112 | - * @return \ArrayIterator |
|
113 | - */ |
|
114 | - public function getIterator(): \ArrayIterator |
|
115 | - { |
|
116 | - return new \ArrayIterator($this->_policies); |
|
117 | - } |
|
107 | + /** |
|
108 | + * Get iterator for policy information terms. |
|
109 | + * |
|
110 | + * @see \IteratorAggregate::getIterator() |
|
111 | + * |
|
112 | + * @return \ArrayIterator |
|
113 | + */ |
|
114 | + public function getIterator(): \ArrayIterator |
|
115 | + { |
|
116 | + return new \ArrayIterator($this->_policies); |
|
117 | + } |
|
118 | 118 | |
119 | - /** |
|
120 | - * {@inheritdoc} |
|
121 | - */ |
|
122 | - protected static function _fromDER(string $data, bool $critical): Extension |
|
123 | - { |
|
124 | - $policies = array_map( |
|
125 | - function (UnspecifiedType $el) { |
|
126 | - return PolicyInformation::fromASN1($el->asSequence()); |
|
127 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
128 | - if (!count($policies)) { |
|
129 | - throw new \UnexpectedValueException( |
|
130 | - 'certificatePolicies must contain at least one PolicyInformation.'); |
|
131 | - } |
|
132 | - return new self($critical, ...$policies); |
|
133 | - } |
|
119 | + /** |
|
120 | + * {@inheritdoc} |
|
121 | + */ |
|
122 | + protected static function _fromDER(string $data, bool $critical): Extension |
|
123 | + { |
|
124 | + $policies = array_map( |
|
125 | + function (UnspecifiedType $el) { |
|
126 | + return PolicyInformation::fromASN1($el->asSequence()); |
|
127 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
128 | + if (!count($policies)) { |
|
129 | + throw new \UnexpectedValueException( |
|
130 | + 'certificatePolicies must contain at least one PolicyInformation.'); |
|
131 | + } |
|
132 | + return new self($critical, ...$policies); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * {@inheritdoc} |
|
137 | - */ |
|
138 | - protected function _valueASN1(): Element |
|
139 | - { |
|
140 | - if (!count($this->_policies)) { |
|
141 | - throw new \LogicException('No policies.'); |
|
142 | - } |
|
143 | - $elements = array_map( |
|
144 | - function (PolicyInformation $pi) { |
|
145 | - return $pi->toASN1(); |
|
146 | - }, array_values($this->_policies)); |
|
147 | - return new Sequence(...$elements); |
|
148 | - } |
|
135 | + /** |
|
136 | + * {@inheritdoc} |
|
137 | + */ |
|
138 | + protected function _valueASN1(): Element |
|
139 | + { |
|
140 | + if (!count($this->_policies)) { |
|
141 | + throw new \LogicException('No policies.'); |
|
142 | + } |
|
143 | + $elements = array_map( |
|
144 | + function (PolicyInformation $pi) { |
|
145 | + return $pi->toASN1(); |
|
146 | + }, array_values($this->_policies)); |
|
147 | + return new Sequence(...$elements); |
|
148 | + } |
|
149 | 149 | } |
@@ -17,114 +17,114 @@ |
||
17 | 17 | */ |
18 | 18 | class PolicyConstraintsExtension extends Extension |
19 | 19 | { |
20 | - /** |
|
21 | - * @var null|int |
|
22 | - */ |
|
23 | - protected $_requireExplicitPolicy; |
|
20 | + /** |
|
21 | + * @var null|int |
|
22 | + */ |
|
23 | + protected $_requireExplicitPolicy; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var null|int |
|
27 | - */ |
|
28 | - protected $_inhibitPolicyMapping; |
|
25 | + /** |
|
26 | + * @var null|int |
|
27 | + */ |
|
28 | + protected $_inhibitPolicyMapping; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor. |
|
32 | - * |
|
33 | - * @param bool $critical |
|
34 | - * @param null|int $require_explicit_policy |
|
35 | - * @param null|int $inhibit_policy_mapping |
|
36 | - */ |
|
37 | - public function __construct(bool $critical, |
|
38 | - ?int $require_explicit_policy = null, ?int $inhibit_policy_mapping = null) |
|
39 | - { |
|
40 | - parent::__construct(self::OID_POLICY_CONSTRAINTS, $critical); |
|
41 | - $this->_requireExplicitPolicy = $require_explicit_policy; |
|
42 | - $this->_inhibitPolicyMapping = $inhibit_policy_mapping; |
|
43 | - } |
|
30 | + /** |
|
31 | + * Constructor. |
|
32 | + * |
|
33 | + * @param bool $critical |
|
34 | + * @param null|int $require_explicit_policy |
|
35 | + * @param null|int $inhibit_policy_mapping |
|
36 | + */ |
|
37 | + public function __construct(bool $critical, |
|
38 | + ?int $require_explicit_policy = null, ?int $inhibit_policy_mapping = null) |
|
39 | + { |
|
40 | + parent::__construct(self::OID_POLICY_CONSTRAINTS, $critical); |
|
41 | + $this->_requireExplicitPolicy = $require_explicit_policy; |
|
42 | + $this->_inhibitPolicyMapping = $inhibit_policy_mapping; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Whether requireExplicitPolicy is present. |
|
47 | - * |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function hasRequireExplicitPolicy(): bool |
|
51 | - { |
|
52 | - return isset($this->_requireExplicitPolicy); |
|
53 | - } |
|
45 | + /** |
|
46 | + * Whether requireExplicitPolicy is present. |
|
47 | + * |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function hasRequireExplicitPolicy(): bool |
|
51 | + { |
|
52 | + return isset($this->_requireExplicitPolicy); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get requireExplicitPolicy. |
|
57 | - * |
|
58 | - * @throws \LogicException If not set |
|
59 | - * |
|
60 | - * @return int |
|
61 | - */ |
|
62 | - public function requireExplicitPolicy(): int |
|
63 | - { |
|
64 | - if (!$this->hasRequireExplicitPolicy()) { |
|
65 | - throw new \LogicException('requireExplicitPolicy not set.'); |
|
66 | - } |
|
67 | - return $this->_requireExplicitPolicy; |
|
68 | - } |
|
55 | + /** |
|
56 | + * Get requireExplicitPolicy. |
|
57 | + * |
|
58 | + * @throws \LogicException If not set |
|
59 | + * |
|
60 | + * @return int |
|
61 | + */ |
|
62 | + public function requireExplicitPolicy(): int |
|
63 | + { |
|
64 | + if (!$this->hasRequireExplicitPolicy()) { |
|
65 | + throw new \LogicException('requireExplicitPolicy not set.'); |
|
66 | + } |
|
67 | + return $this->_requireExplicitPolicy; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Whether inhibitPolicyMapping is present. |
|
72 | - * |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function hasInhibitPolicyMapping(): bool |
|
76 | - { |
|
77 | - return isset($this->_inhibitPolicyMapping); |
|
78 | - } |
|
70 | + /** |
|
71 | + * Whether inhibitPolicyMapping is present. |
|
72 | + * |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function hasInhibitPolicyMapping(): bool |
|
76 | + { |
|
77 | + return isset($this->_inhibitPolicyMapping); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get inhibitPolicyMapping. |
|
82 | - * |
|
83 | - * @throws \LogicException If not set |
|
84 | - * |
|
85 | - * @return int |
|
86 | - */ |
|
87 | - public function inhibitPolicyMapping(): int |
|
88 | - { |
|
89 | - if (!$this->hasInhibitPolicyMapping()) { |
|
90 | - throw new \LogicException('inhibitPolicyMapping not set.'); |
|
91 | - } |
|
92 | - return $this->_inhibitPolicyMapping; |
|
93 | - } |
|
80 | + /** |
|
81 | + * Get inhibitPolicyMapping. |
|
82 | + * |
|
83 | + * @throws \LogicException If not set |
|
84 | + * |
|
85 | + * @return int |
|
86 | + */ |
|
87 | + public function inhibitPolicyMapping(): int |
|
88 | + { |
|
89 | + if (!$this->hasInhibitPolicyMapping()) { |
|
90 | + throw new \LogicException('inhibitPolicyMapping not set.'); |
|
91 | + } |
|
92 | + return $this->_inhibitPolicyMapping; |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * {@inheritdoc} |
|
97 | - */ |
|
98 | - protected static function _fromDER(string $data, bool $critical): Extension |
|
99 | - { |
|
100 | - $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
101 | - $require_explicit_policy = null; |
|
102 | - $inhibit_policy_mapping = null; |
|
103 | - if ($seq->hasTagged(0)) { |
|
104 | - $require_explicit_policy = $seq->getTagged(0) |
|
105 | - ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
106 | - } |
|
107 | - if ($seq->hasTagged(1)) { |
|
108 | - $inhibit_policy_mapping = $seq->getTagged(1) |
|
109 | - ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
110 | - } |
|
111 | - return new self($critical, $require_explicit_policy, $inhibit_policy_mapping); |
|
112 | - } |
|
95 | + /** |
|
96 | + * {@inheritdoc} |
|
97 | + */ |
|
98 | + protected static function _fromDER(string $data, bool $critical): Extension |
|
99 | + { |
|
100 | + $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
101 | + $require_explicit_policy = null; |
|
102 | + $inhibit_policy_mapping = null; |
|
103 | + if ($seq->hasTagged(0)) { |
|
104 | + $require_explicit_policy = $seq->getTagged(0) |
|
105 | + ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
106 | + } |
|
107 | + if ($seq->hasTagged(1)) { |
|
108 | + $inhibit_policy_mapping = $seq->getTagged(1) |
|
109 | + ->asImplicit(Element::TYPE_INTEGER)->asInteger()->intNumber(); |
|
110 | + } |
|
111 | + return new self($critical, $require_explicit_policy, $inhibit_policy_mapping); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * {@inheritdoc} |
|
116 | - */ |
|
117 | - protected function _valueASN1(): Element |
|
118 | - { |
|
119 | - $elements = []; |
|
120 | - if (isset($this->_requireExplicitPolicy)) { |
|
121 | - $elements[] = new ImplicitlyTaggedType(0, |
|
122 | - new Integer($this->_requireExplicitPolicy)); |
|
123 | - } |
|
124 | - if (isset($this->_inhibitPolicyMapping)) { |
|
125 | - $elements[] = new ImplicitlyTaggedType(1, |
|
126 | - new Integer($this->_inhibitPolicyMapping)); |
|
127 | - } |
|
128 | - return new Sequence(...$elements); |
|
129 | - } |
|
114 | + /** |
|
115 | + * {@inheritdoc} |
|
116 | + */ |
|
117 | + protected function _valueASN1(): Element |
|
118 | + { |
|
119 | + $elements = []; |
|
120 | + if (isset($this->_requireExplicitPolicy)) { |
|
121 | + $elements[] = new ImplicitlyTaggedType(0, |
|
122 | + new Integer($this->_requireExplicitPolicy)); |
|
123 | + } |
|
124 | + if (isset($this->_inhibitPolicyMapping)) { |
|
125 | + $elements[] = new ImplicitlyTaggedType(1, |
|
126 | + new Integer($this->_inhibitPolicyMapping)); |
|
127 | + } |
|
128 | + return new Sequence(...$elements); |
|
129 | + } |
|
130 | 130 | } |
@@ -17,86 +17,86 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class PolicyQualifierInfo |
19 | 19 | { |
20 | - /** |
|
21 | - * OID for the CPS Pointer qualifier. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
25 | - const OID_CPS = '1.3.6.1.5.5.7.2.1'; |
|
20 | + /** |
|
21 | + * OID for the CPS Pointer qualifier. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | + const OID_CPS = '1.3.6.1.5.5.7.2.1'; |
|
26 | 26 | |
27 | - /** |
|
28 | - * OID for the user notice qualifier. |
|
29 | - * |
|
30 | - * @var string |
|
31 | - */ |
|
32 | - const OID_UNOTICE = '1.3.6.1.5.5.7.2.2'; |
|
27 | + /** |
|
28 | + * OID for the user notice qualifier. |
|
29 | + * |
|
30 | + * @var string |
|
31 | + */ |
|
32 | + const OID_UNOTICE = '1.3.6.1.5.5.7.2.2'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Qualifier identifier. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $_oid; |
|
34 | + /** |
|
35 | + * Qualifier identifier. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $_oid; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Initialize from qualifier ASN.1 element. |
|
43 | - * |
|
44 | - * @param UnspecifiedType $el |
|
45 | - * |
|
46 | - * @return self |
|
47 | - */ |
|
48 | - public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
|
49 | - { |
|
50 | - throw new \BadMethodCallException( |
|
51 | - __FUNCTION__ . ' must be implemented in the derived class.'); |
|
52 | - } |
|
41 | + /** |
|
42 | + * Initialize from qualifier ASN.1 element. |
|
43 | + * |
|
44 | + * @param UnspecifiedType $el |
|
45 | + * |
|
46 | + * @return self |
|
47 | + */ |
|
48 | + public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
|
49 | + { |
|
50 | + throw new \BadMethodCallException( |
|
51 | + __FUNCTION__ . ' must be implemented in the derived class.'); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Initialize from ASN.1. |
|
56 | - * |
|
57 | - * @param Sequence $seq |
|
58 | - * |
|
59 | - * @throws \UnexpectedValueException |
|
60 | - * |
|
61 | - * @return self |
|
62 | - */ |
|
63 | - public static function fromASN1(Sequence $seq): self |
|
64 | - { |
|
65 | - $oid = $seq->at(0)->asObjectIdentifier()->oid(); |
|
66 | - switch ($oid) { |
|
67 | - case self::OID_CPS: |
|
68 | - return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
69 | - case self::OID_UNOTICE: |
|
70 | - return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
71 | - } |
|
72 | - throw new \UnexpectedValueException("Qualifier {$oid} not supported."); |
|
73 | - } |
|
54 | + /** |
|
55 | + * Initialize from ASN.1. |
|
56 | + * |
|
57 | + * @param Sequence $seq |
|
58 | + * |
|
59 | + * @throws \UnexpectedValueException |
|
60 | + * |
|
61 | + * @return self |
|
62 | + */ |
|
63 | + public static function fromASN1(Sequence $seq): self |
|
64 | + { |
|
65 | + $oid = $seq->at(0)->asObjectIdentifier()->oid(); |
|
66 | + switch ($oid) { |
|
67 | + case self::OID_CPS: |
|
68 | + return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
69 | + case self::OID_UNOTICE: |
|
70 | + return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
71 | + } |
|
72 | + throw new \UnexpectedValueException("Qualifier {$oid} not supported."); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Get qualifier identifier. |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function oid(): string |
|
81 | - { |
|
82 | - return $this->_oid; |
|
83 | - } |
|
75 | + /** |
|
76 | + * Get qualifier identifier. |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function oid(): string |
|
81 | + { |
|
82 | + return $this->_oid; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Generate ASN.1 structure. |
|
87 | - * |
|
88 | - * @return Sequence |
|
89 | - */ |
|
90 | - public function toASN1(): Sequence |
|
91 | - { |
|
92 | - return new Sequence(new ObjectIdentifier($this->_oid), |
|
93 | - $this->_qualifierASN1()); |
|
94 | - } |
|
85 | + /** |
|
86 | + * Generate ASN.1 structure. |
|
87 | + * |
|
88 | + * @return Sequence |
|
89 | + */ |
|
90 | + public function toASN1(): Sequence |
|
91 | + { |
|
92 | + return new Sequence(new ObjectIdentifier($this->_oid), |
|
93 | + $this->_qualifierASN1()); |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Generate ASN.1 for the 'qualifier' field. |
|
98 | - * |
|
99 | - * @return Element |
|
100 | - */ |
|
101 | - abstract protected function _qualifierASN1(): Element; |
|
96 | + /** |
|
97 | + * Generate ASN.1 for the 'qualifier' field. |
|
98 | + * |
|
99 | + * @return Element |
|
100 | + */ |
|
101 | + abstract protected function _qualifierASN1(): Element; |
|
102 | 102 | } |
@@ -16,81 +16,81 @@ |
||
16 | 16 | */ |
17 | 17 | class NoticeReference |
18 | 18 | { |
19 | - /** |
|
20 | - * Organization. |
|
21 | - * |
|
22 | - * @var DisplayText |
|
23 | - */ |
|
24 | - protected $_organization; |
|
19 | + /** |
|
20 | + * Organization. |
|
21 | + * |
|
22 | + * @var DisplayText |
|
23 | + */ |
|
24 | + protected $_organization; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Notification reference numbers. |
|
28 | - * |
|
29 | - * @var int[] |
|
30 | - */ |
|
31 | - protected $_numbers; |
|
26 | + /** |
|
27 | + * Notification reference numbers. |
|
28 | + * |
|
29 | + * @var int[] |
|
30 | + */ |
|
31 | + protected $_numbers; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor. |
|
35 | - * |
|
36 | - * @param DisplayText $organization |
|
37 | - * @param int ...$numbers |
|
38 | - */ |
|
39 | - public function __construct(DisplayText $organization, int ...$numbers) |
|
40 | - { |
|
41 | - $this->_organization = $organization; |
|
42 | - $this->_numbers = $numbers; |
|
43 | - } |
|
33 | + /** |
|
34 | + * Constructor. |
|
35 | + * |
|
36 | + * @param DisplayText $organization |
|
37 | + * @param int ...$numbers |
|
38 | + */ |
|
39 | + public function __construct(DisplayText $organization, int ...$numbers) |
|
40 | + { |
|
41 | + $this->_organization = $organization; |
|
42 | + $this->_numbers = $numbers; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Initialize from ASN.1. |
|
47 | - * |
|
48 | - * @param Sequence $seq |
|
49 | - * |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public static function fromASN1(Sequence $seq): self |
|
53 | - { |
|
54 | - $org = DisplayText::fromASN1($seq->at(0)->asString()); |
|
55 | - $numbers = array_map( |
|
56 | - function (UnspecifiedType $el) { |
|
57 | - return $el->asInteger()->intNumber(); |
|
58 | - }, $seq->at(1)->asSequence()->elements()); |
|
59 | - return new self($org, ...$numbers); |
|
60 | - } |
|
45 | + /** |
|
46 | + * Initialize from ASN.1. |
|
47 | + * |
|
48 | + * @param Sequence $seq |
|
49 | + * |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public static function fromASN1(Sequence $seq): self |
|
53 | + { |
|
54 | + $org = DisplayText::fromASN1($seq->at(0)->asString()); |
|
55 | + $numbers = array_map( |
|
56 | + function (UnspecifiedType $el) { |
|
57 | + return $el->asInteger()->intNumber(); |
|
58 | + }, $seq->at(1)->asSequence()->elements()); |
|
59 | + return new self($org, ...$numbers); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get reference organization. |
|
64 | - * |
|
65 | - * @return DisplayText |
|
66 | - */ |
|
67 | - public function organization(): DisplayText |
|
68 | - { |
|
69 | - return $this->_organization; |
|
70 | - } |
|
62 | + /** |
|
63 | + * Get reference organization. |
|
64 | + * |
|
65 | + * @return DisplayText |
|
66 | + */ |
|
67 | + public function organization(): DisplayText |
|
68 | + { |
|
69 | + return $this->_organization; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Get reference numbers. |
|
74 | - * |
|
75 | - * @return int[] |
|
76 | - */ |
|
77 | - public function numbers(): array |
|
78 | - { |
|
79 | - return $this->_numbers; |
|
80 | - } |
|
72 | + /** |
|
73 | + * Get reference numbers. |
|
74 | + * |
|
75 | + * @return int[] |
|
76 | + */ |
|
77 | + public function numbers(): array |
|
78 | + { |
|
79 | + return $this->_numbers; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Generate ASN.1 structure. |
|
84 | - * |
|
85 | - * @return Sequence |
|
86 | - */ |
|
87 | - public function toASN1(): Sequence |
|
88 | - { |
|
89 | - $org = $this->_organization->toASN1(); |
|
90 | - $nums = array_map( |
|
91 | - function ($number) { |
|
92 | - return new Integer($number); |
|
93 | - }, $this->_numbers); |
|
94 | - return new Sequence($org, new Sequence(...$nums)); |
|
95 | - } |
|
82 | + /** |
|
83 | + * Generate ASN.1 structure. |
|
84 | + * |
|
85 | + * @return Sequence |
|
86 | + */ |
|
87 | + public function toASN1(): Sequence |
|
88 | + { |
|
89 | + $org = $this->_organization->toASN1(); |
|
90 | + $nums = array_map( |
|
91 | + function ($number) { |
|
92 | + return new Integer($number); |
|
93 | + }, $this->_numbers); |
|
94 | + return new Sequence($org, new Sequence(...$nums)); |
|
95 | + } |
|
96 | 96 | } |
@@ -19,95 +19,95 @@ |
||
19 | 19 | */ |
20 | 20 | class DisplayText |
21 | 21 | { |
22 | - /** |
|
23 | - * Text. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_text; |
|
22 | + /** |
|
23 | + * Text. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_text; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Element tag. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
34 | - protected $_tag; |
|
29 | + /** |
|
30 | + * Element tag. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | + protected $_tag; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor. |
|
38 | - * |
|
39 | - * @param string $text |
|
40 | - * @param int $tag |
|
41 | - */ |
|
42 | - public function __construct(string $text, int $tag) |
|
43 | - { |
|
44 | - $this->_text = $text; |
|
45 | - $this->_tag = $tag; |
|
46 | - } |
|
36 | + /** |
|
37 | + * Constructor. |
|
38 | + * |
|
39 | + * @param string $text |
|
40 | + * @param int $tag |
|
41 | + */ |
|
42 | + public function __construct(string $text, int $tag) |
|
43 | + { |
|
44 | + $this->_text = $text; |
|
45 | + $this->_tag = $tag; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return string |
|
50 | - */ |
|
51 | - public function __toString(): string |
|
52 | - { |
|
53 | - return $this->string(); |
|
54 | - } |
|
48 | + /** |
|
49 | + * @return string |
|
50 | + */ |
|
51 | + public function __toString(): string |
|
52 | + { |
|
53 | + return $this->string(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Initialize from ASN.1. |
|
58 | - * |
|
59 | - * @param StringType $el |
|
60 | - * |
|
61 | - * @return self |
|
62 | - */ |
|
63 | - public static function fromASN1(StringType $el): self |
|
64 | - { |
|
65 | - return new self($el->string(), $el->tag()); |
|
66 | - } |
|
56 | + /** |
|
57 | + * Initialize from ASN.1. |
|
58 | + * |
|
59 | + * @param StringType $el |
|
60 | + * |
|
61 | + * @return self |
|
62 | + */ |
|
63 | + public static function fromASN1(StringType $el): self |
|
64 | + { |
|
65 | + return new self($el->string(), $el->tag()); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Initialize from a UTF-8 string. |
|
70 | - * |
|
71 | - * @param string $str |
|
72 | - * |
|
73 | - * @return self |
|
74 | - */ |
|
75 | - public static function fromString(string $str): self |
|
76 | - { |
|
77 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
78 | - } |
|
68 | + /** |
|
69 | + * Initialize from a UTF-8 string. |
|
70 | + * |
|
71 | + * @param string $str |
|
72 | + * |
|
73 | + * @return self |
|
74 | + */ |
|
75 | + public static function fromString(string $str): self |
|
76 | + { |
|
77 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get the text. |
|
82 | - * |
|
83 | - * @return string |
|
84 | - */ |
|
85 | - public function string(): string |
|
86 | - { |
|
87 | - return $this->_text; |
|
88 | - } |
|
80 | + /** |
|
81 | + * Get the text. |
|
82 | + * |
|
83 | + * @return string |
|
84 | + */ |
|
85 | + public function string(): string |
|
86 | + { |
|
87 | + return $this->_text; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Generate ASN.1 element. |
|
92 | - * |
|
93 | - * @throws \UnexpectedValueException |
|
94 | - * |
|
95 | - * @return StringType |
|
96 | - */ |
|
97 | - public function toASN1(): StringType |
|
98 | - { |
|
99 | - switch ($this->_tag) { |
|
100 | - case Element::TYPE_IA5_STRING: |
|
101 | - return new IA5String($this->_text); |
|
102 | - case Element::TYPE_VISIBLE_STRING: |
|
103 | - return new VisibleString($this->_text); |
|
104 | - case Element::TYPE_BMP_STRING: |
|
105 | - return new BMPString($this->_text); |
|
106 | - case Element::TYPE_UTF8_STRING: |
|
107 | - return new UTF8String($this->_text); |
|
108 | - default: |
|
109 | - throw new \UnexpectedValueException( |
|
110 | - 'Type ' . Element::tagToName($this->_tag) . ' not supported.'); |
|
111 | - } |
|
112 | - } |
|
90 | + /** |
|
91 | + * Generate ASN.1 element. |
|
92 | + * |
|
93 | + * @throws \UnexpectedValueException |
|
94 | + * |
|
95 | + * @return StringType |
|
96 | + */ |
|
97 | + public function toASN1(): StringType |
|
98 | + { |
|
99 | + switch ($this->_tag) { |
|
100 | + case Element::TYPE_IA5_STRING: |
|
101 | + return new IA5String($this->_text); |
|
102 | + case Element::TYPE_VISIBLE_STRING: |
|
103 | + return new VisibleString($this->_text); |
|
104 | + case Element::TYPE_BMP_STRING: |
|
105 | + return new BMPString($this->_text); |
|
106 | + case Element::TYPE_UTF8_STRING: |
|
107 | + return new UTF8String($this->_text); |
|
108 | + default: |
|
109 | + throw new \UnexpectedValueException( |
|
110 | + 'Type ' . Element::tagToName($this->_tag) . ' not supported.'); |
|
111 | + } |
|
112 | + } |
|
113 | 113 | } |
@@ -16,210 +16,210 @@ |
||
16 | 16 | */ |
17 | 17 | class PolicyInformation implements \Countable, \IteratorAggregate |
18 | 18 | { |
19 | - /** |
|
20 | - * Wildcard policy. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - const OID_ANY_POLICY = '2.5.29.32.0'; |
|
25 | - |
|
26 | - /** |
|
27 | - * Policy identifier. |
|
28 | - * |
|
29 | - * @var string |
|
30 | - */ |
|
31 | - protected $_oid; |
|
32 | - |
|
33 | - /** |
|
34 | - * Policy qualifiers. |
|
35 | - * |
|
36 | - * @var PolicyQualifierInfo[] |
|
37 | - */ |
|
38 | - protected $_qualifiers; |
|
39 | - |
|
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param string $oid |
|
44 | - * @param PolicyQualifierInfo ...$qualifiers |
|
45 | - */ |
|
46 | - public function __construct(string $oid, PolicyQualifierInfo ...$qualifiers) |
|
47 | - { |
|
48 | - $this->_oid = $oid; |
|
49 | - $this->_qualifiers = []; |
|
50 | - foreach ($qualifiers as $qual) { |
|
51 | - $this->_qualifiers[$qual->oid()] = $qual; |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Initialize from ASN.1. |
|
57 | - * |
|
58 | - * @param Sequence $seq |
|
59 | - * |
|
60 | - * @return self |
|
61 | - */ |
|
62 | - public static function fromASN1(Sequence $seq): self |
|
63 | - { |
|
64 | - $oid = $seq->at(0)->asObjectIdentifier()->oid(); |
|
65 | - $qualifiers = []; |
|
66 | - if (count($seq) > 1) { |
|
67 | - $qualifiers = array_map( |
|
68 | - function (UnspecifiedType $el) { |
|
69 | - return PolicyQualifierInfo::fromASN1($el->asSequence()); |
|
70 | - }, $seq->at(1)->asSequence()->elements()); |
|
71 | - } |
|
72 | - return new self($oid, ...$qualifiers); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Get policy identifier. |
|
77 | - * |
|
78 | - * @return string |
|
79 | - */ |
|
80 | - public function oid(): string |
|
81 | - { |
|
82 | - return $this->_oid; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Check whether this policy is anyPolicy. |
|
87 | - * |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function isAnyPolicy(): bool |
|
91 | - { |
|
92 | - return self::OID_ANY_POLICY === $this->_oid; |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get policy qualifiers. |
|
97 | - * |
|
98 | - * @return PolicyQualifierInfo[] |
|
99 | - */ |
|
100 | - public function qualifiers(): array |
|
101 | - { |
|
102 | - return array_values($this->_qualifiers); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Check whether qualifier is present. |
|
107 | - * |
|
108 | - * @param string $oid |
|
109 | - * |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function has(string $oid): bool |
|
113 | - { |
|
114 | - return isset($this->_qualifiers[$oid]); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get qualifier by OID. |
|
119 | - * |
|
120 | - * @param string $oid |
|
121 | - * |
|
122 | - * @throws \LogicException IF not set |
|
123 | - * |
|
124 | - * @return PolicyQualifierInfo |
|
125 | - */ |
|
126 | - public function get(string $oid): PolicyQualifierInfo |
|
127 | - { |
|
128 | - if (!$this->has($oid)) { |
|
129 | - throw new \LogicException("No {$oid} qualifier."); |
|
130 | - } |
|
131 | - return $this->_qualifiers[$oid]; |
|
132 | - } |
|
133 | - |
|
134 | - /** |
|
135 | - * Check whether CPS qualifier is present. |
|
136 | - * |
|
137 | - * @return bool |
|
138 | - */ |
|
139 | - public function hasCPSQualifier(): bool |
|
140 | - { |
|
141 | - return $this->has(PolicyQualifierInfo::OID_CPS); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Get CPS qualifier. |
|
146 | - * |
|
147 | - * @throws \LogicException If not set |
|
148 | - * |
|
149 | - * @return CPSQualifier |
|
150 | - */ |
|
151 | - public function CPSQualifier(): CPSQualifier |
|
152 | - { |
|
153 | - if (!$this->hasCPSQualifier()) { |
|
154 | - throw new \LogicException('CPS qualifier not set.'); |
|
155 | - } |
|
156 | - return $this->get(PolicyQualifierInfo::OID_CPS); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Check whether user notice qualifier is present. |
|
161 | - * |
|
162 | - * @return bool |
|
163 | - */ |
|
164 | - public function hasUserNoticeQualifier(): bool |
|
165 | - { |
|
166 | - return $this->has(PolicyQualifierInfo::OID_UNOTICE); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Get user notice qualifier. |
|
171 | - * |
|
172 | - * @throws \LogicException If not set |
|
173 | - * |
|
174 | - * @return UserNoticeQualifier |
|
175 | - */ |
|
176 | - public function userNoticeQualifier(): UserNoticeQualifier |
|
177 | - { |
|
178 | - if (!$this->hasUserNoticeQualifier()) { |
|
179 | - throw new \LogicException('User notice qualifier not set.'); |
|
180 | - } |
|
181 | - return $this->get(PolicyQualifierInfo::OID_UNOTICE); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Get ASN.1 structure. |
|
186 | - * |
|
187 | - * @return Sequence |
|
188 | - */ |
|
189 | - public function toASN1(): Sequence |
|
190 | - { |
|
191 | - $elements = [new ObjectIdentifier($this->_oid)]; |
|
192 | - if (count($this->_qualifiers)) { |
|
193 | - $qualifiers = array_map( |
|
194 | - function (PolicyQualifierInfo $pqi) { |
|
195 | - return $pqi->toASN1(); |
|
196 | - }, array_values($this->_qualifiers)); |
|
197 | - $elements[] = new Sequence(...$qualifiers); |
|
198 | - } |
|
199 | - return new Sequence(...$elements); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Get number of qualifiers. |
|
204 | - * |
|
205 | - * @see \Countable::count() |
|
206 | - * |
|
207 | - * @return int |
|
208 | - */ |
|
209 | - public function count(): int |
|
210 | - { |
|
211 | - return count($this->_qualifiers); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Get iterator for qualifiers. |
|
216 | - * |
|
217 | - * @see \IteratorAggregate::getIterator() |
|
218 | - * |
|
219 | - * @return \ArrayIterator |
|
220 | - */ |
|
221 | - public function getIterator(): \ArrayIterator |
|
222 | - { |
|
223 | - return new \ArrayIterator($this->_qualifiers); |
|
224 | - } |
|
19 | + /** |
|
20 | + * Wildcard policy. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + const OID_ANY_POLICY = '2.5.29.32.0'; |
|
25 | + |
|
26 | + /** |
|
27 | + * Policy identifier. |
|
28 | + * |
|
29 | + * @var string |
|
30 | + */ |
|
31 | + protected $_oid; |
|
32 | + |
|
33 | + /** |
|
34 | + * Policy qualifiers. |
|
35 | + * |
|
36 | + * @var PolicyQualifierInfo[] |
|
37 | + */ |
|
38 | + protected $_qualifiers; |
|
39 | + |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param string $oid |
|
44 | + * @param PolicyQualifierInfo ...$qualifiers |
|
45 | + */ |
|
46 | + public function __construct(string $oid, PolicyQualifierInfo ...$qualifiers) |
|
47 | + { |
|
48 | + $this->_oid = $oid; |
|
49 | + $this->_qualifiers = []; |
|
50 | + foreach ($qualifiers as $qual) { |
|
51 | + $this->_qualifiers[$qual->oid()] = $qual; |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Initialize from ASN.1. |
|
57 | + * |
|
58 | + * @param Sequence $seq |
|
59 | + * |
|
60 | + * @return self |
|
61 | + */ |
|
62 | + public static function fromASN1(Sequence $seq): self |
|
63 | + { |
|
64 | + $oid = $seq->at(0)->asObjectIdentifier()->oid(); |
|
65 | + $qualifiers = []; |
|
66 | + if (count($seq) > 1) { |
|
67 | + $qualifiers = array_map( |
|
68 | + function (UnspecifiedType $el) { |
|
69 | + return PolicyQualifierInfo::fromASN1($el->asSequence()); |
|
70 | + }, $seq->at(1)->asSequence()->elements()); |
|
71 | + } |
|
72 | + return new self($oid, ...$qualifiers); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Get policy identifier. |
|
77 | + * |
|
78 | + * @return string |
|
79 | + */ |
|
80 | + public function oid(): string |
|
81 | + { |
|
82 | + return $this->_oid; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Check whether this policy is anyPolicy. |
|
87 | + * |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function isAnyPolicy(): bool |
|
91 | + { |
|
92 | + return self::OID_ANY_POLICY === $this->_oid; |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get policy qualifiers. |
|
97 | + * |
|
98 | + * @return PolicyQualifierInfo[] |
|
99 | + */ |
|
100 | + public function qualifiers(): array |
|
101 | + { |
|
102 | + return array_values($this->_qualifiers); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Check whether qualifier is present. |
|
107 | + * |
|
108 | + * @param string $oid |
|
109 | + * |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function has(string $oid): bool |
|
113 | + { |
|
114 | + return isset($this->_qualifiers[$oid]); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get qualifier by OID. |
|
119 | + * |
|
120 | + * @param string $oid |
|
121 | + * |
|
122 | + * @throws \LogicException IF not set |
|
123 | + * |
|
124 | + * @return PolicyQualifierInfo |
|
125 | + */ |
|
126 | + public function get(string $oid): PolicyQualifierInfo |
|
127 | + { |
|
128 | + if (!$this->has($oid)) { |
|
129 | + throw new \LogicException("No {$oid} qualifier."); |
|
130 | + } |
|
131 | + return $this->_qualifiers[$oid]; |
|
132 | + } |
|
133 | + |
|
134 | + /** |
|
135 | + * Check whether CPS qualifier is present. |
|
136 | + * |
|
137 | + * @return bool |
|
138 | + */ |
|
139 | + public function hasCPSQualifier(): bool |
|
140 | + { |
|
141 | + return $this->has(PolicyQualifierInfo::OID_CPS); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Get CPS qualifier. |
|
146 | + * |
|
147 | + * @throws \LogicException If not set |
|
148 | + * |
|
149 | + * @return CPSQualifier |
|
150 | + */ |
|
151 | + public function CPSQualifier(): CPSQualifier |
|
152 | + { |
|
153 | + if (!$this->hasCPSQualifier()) { |
|
154 | + throw new \LogicException('CPS qualifier not set.'); |
|
155 | + } |
|
156 | + return $this->get(PolicyQualifierInfo::OID_CPS); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Check whether user notice qualifier is present. |
|
161 | + * |
|
162 | + * @return bool |
|
163 | + */ |
|
164 | + public function hasUserNoticeQualifier(): bool |
|
165 | + { |
|
166 | + return $this->has(PolicyQualifierInfo::OID_UNOTICE); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Get user notice qualifier. |
|
171 | + * |
|
172 | + * @throws \LogicException If not set |
|
173 | + * |
|
174 | + * @return UserNoticeQualifier |
|
175 | + */ |
|
176 | + public function userNoticeQualifier(): UserNoticeQualifier |
|
177 | + { |
|
178 | + if (!$this->hasUserNoticeQualifier()) { |
|
179 | + throw new \LogicException('User notice qualifier not set.'); |
|
180 | + } |
|
181 | + return $this->get(PolicyQualifierInfo::OID_UNOTICE); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Get ASN.1 structure. |
|
186 | + * |
|
187 | + * @return Sequence |
|
188 | + */ |
|
189 | + public function toASN1(): Sequence |
|
190 | + { |
|
191 | + $elements = [new ObjectIdentifier($this->_oid)]; |
|
192 | + if (count($this->_qualifiers)) { |
|
193 | + $qualifiers = array_map( |
|
194 | + function (PolicyQualifierInfo $pqi) { |
|
195 | + return $pqi->toASN1(); |
|
196 | + }, array_values($this->_qualifiers)); |
|
197 | + $elements[] = new Sequence(...$qualifiers); |
|
198 | + } |
|
199 | + return new Sequence(...$elements); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Get number of qualifiers. |
|
204 | + * |
|
205 | + * @see \Countable::count() |
|
206 | + * |
|
207 | + * @return int |
|
208 | + */ |
|
209 | + public function count(): int |
|
210 | + { |
|
211 | + return count($this->_qualifiers); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Get iterator for qualifiers. |
|
216 | + * |
|
217 | + * @see \IteratorAggregate::getIterator() |
|
218 | + * |
|
219 | + * @return \ArrayIterator |
|
220 | + */ |
|
221 | + public function getIterator(): \ArrayIterator |
|
222 | + { |
|
223 | + return new \ArrayIterator($this->_qualifiers); |
|
224 | + } |
|
225 | 225 | } |
@@ -16,49 +16,49 @@ |
||
16 | 16 | */ |
17 | 17 | class CPSQualifier extends PolicyQualifierInfo |
18 | 18 | { |
19 | - /** |
|
20 | - * URI. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_uri; |
|
19 | + /** |
|
20 | + * URI. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_uri; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Constructor. |
|
28 | - * |
|
29 | - * @param string $uri |
|
30 | - */ |
|
31 | - public function __construct(string $uri) |
|
32 | - { |
|
33 | - $this->_oid = self::OID_CPS; |
|
34 | - $this->_uri = $uri; |
|
35 | - } |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + * |
|
29 | + * @param string $uri |
|
30 | + */ |
|
31 | + public function __construct(string $uri) |
|
32 | + { |
|
33 | + $this->_oid = self::OID_CPS; |
|
34 | + $this->_uri = $uri; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * {@inheritdoc} |
|
39 | - * |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
|
43 | - { |
|
44 | - return new self($el->asString()->string()); |
|
45 | - } |
|
37 | + /** |
|
38 | + * {@inheritdoc} |
|
39 | + * |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
|
43 | + { |
|
44 | + return new self($el->asString()->string()); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get URI. |
|
49 | - * |
|
50 | - * @return string |
|
51 | - */ |
|
52 | - public function uri(): string |
|
53 | - { |
|
54 | - return $this->_uri; |
|
55 | - } |
|
47 | + /** |
|
48 | + * Get URI. |
|
49 | + * |
|
50 | + * @return string |
|
51 | + */ |
|
52 | + public function uri(): string |
|
53 | + { |
|
54 | + return $this->_uri; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritdoc} |
|
59 | - */ |
|
60 | - protected function _qualifierASN1(): Element |
|
61 | - { |
|
62 | - return new IA5String($this->_uri); |
|
63 | - } |
|
57 | + /** |
|
58 | + * {@inheritdoc} |
|
59 | + */ |
|
60 | + protected function _qualifierASN1(): Element |
|
61 | + { |
|
62 | + return new IA5String($this->_uri); |
|
63 | + } |
|
64 | 64 | } |
@@ -16,116 +16,116 @@ |
||
16 | 16 | */ |
17 | 17 | class UserNoticeQualifier extends PolicyQualifierInfo |
18 | 18 | { |
19 | - /** |
|
20 | - * Explicit notice text. |
|
21 | - * |
|
22 | - * @var null|DisplayText |
|
23 | - */ |
|
24 | - protected $_text; |
|
19 | + /** |
|
20 | + * Explicit notice text. |
|
21 | + * |
|
22 | + * @var null|DisplayText |
|
23 | + */ |
|
24 | + protected $_text; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Notice reference. |
|
28 | - * |
|
29 | - * @var null|NoticeReference |
|
30 | - */ |
|
31 | - protected $_ref; |
|
26 | + /** |
|
27 | + * Notice reference. |
|
28 | + * |
|
29 | + * @var null|NoticeReference |
|
30 | + */ |
|
31 | + protected $_ref; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor. |
|
35 | - * |
|
36 | - * @param null|DisplayText $text |
|
37 | - * @param null|NoticeReference $ref |
|
38 | - */ |
|
39 | - public function __construct(?DisplayText $text = null, |
|
40 | - ?NoticeReference $ref = null) |
|
41 | - { |
|
42 | - $this->_oid = self::OID_UNOTICE; |
|
43 | - $this->_text = $text; |
|
44 | - $this->_ref = $ref; |
|
45 | - } |
|
33 | + /** |
|
34 | + * Constructor. |
|
35 | + * |
|
36 | + * @param null|DisplayText $text |
|
37 | + * @param null|NoticeReference $ref |
|
38 | + */ |
|
39 | + public function __construct(?DisplayText $text = null, |
|
40 | + ?NoticeReference $ref = null) |
|
41 | + { |
|
42 | + $this->_oid = self::OID_UNOTICE; |
|
43 | + $this->_text = $text; |
|
44 | + $this->_ref = $ref; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * {@inheritdoc} |
|
49 | - * |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
|
53 | - { |
|
54 | - $seq = $el->asSequence(); |
|
55 | - $ref = null; |
|
56 | - $text = null; |
|
57 | - $idx = 0; |
|
58 | - if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
59 | - $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
60 | - } |
|
61 | - if ($seq->has($idx, Element::TYPE_STRING)) { |
|
62 | - $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
63 | - } |
|
64 | - return new self($text, $ref); |
|
65 | - } |
|
47 | + /** |
|
48 | + * {@inheritdoc} |
|
49 | + * |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public static function fromQualifierASN1(UnspecifiedType $el): PolicyQualifierInfo |
|
53 | + { |
|
54 | + $seq = $el->asSequence(); |
|
55 | + $ref = null; |
|
56 | + $text = null; |
|
57 | + $idx = 0; |
|
58 | + if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
59 | + $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
60 | + } |
|
61 | + if ($seq->has($idx, Element::TYPE_STRING)) { |
|
62 | + $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
63 | + } |
|
64 | + return new self($text, $ref); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Whether explicit text is present. |
|
69 | - * |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function hasExplicitText(): bool |
|
73 | - { |
|
74 | - return isset($this->_text); |
|
75 | - } |
|
67 | + /** |
|
68 | + * Whether explicit text is present. |
|
69 | + * |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function hasExplicitText(): bool |
|
73 | + { |
|
74 | + return isset($this->_text); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Get explicit text. |
|
79 | - * |
|
80 | - * @throws \LogicException If not set |
|
81 | - * |
|
82 | - * @return DisplayText |
|
83 | - */ |
|
84 | - public function explicitText(): DisplayText |
|
85 | - { |
|
86 | - if (!$this->hasExplicitText()) { |
|
87 | - throw new \LogicException('explicitText not set.'); |
|
88 | - } |
|
89 | - return $this->_text; |
|
90 | - } |
|
77 | + /** |
|
78 | + * Get explicit text. |
|
79 | + * |
|
80 | + * @throws \LogicException If not set |
|
81 | + * |
|
82 | + * @return DisplayText |
|
83 | + */ |
|
84 | + public function explicitText(): DisplayText |
|
85 | + { |
|
86 | + if (!$this->hasExplicitText()) { |
|
87 | + throw new \LogicException('explicitText not set.'); |
|
88 | + } |
|
89 | + return $this->_text; |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Whether notice reference is present. |
|
94 | - * |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function hasNoticeRef(): bool |
|
98 | - { |
|
99 | - return isset($this->_ref); |
|
100 | - } |
|
92 | + /** |
|
93 | + * Whether notice reference is present. |
|
94 | + * |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function hasNoticeRef(): bool |
|
98 | + { |
|
99 | + return isset($this->_ref); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Get notice reference. |
|
104 | - * |
|
105 | - * @throws \LogicException If not set |
|
106 | - * |
|
107 | - * @return NoticeReference |
|
108 | - */ |
|
109 | - public function noticeRef(): NoticeReference |
|
110 | - { |
|
111 | - if (!$this->hasNoticeRef()) { |
|
112 | - throw new \LogicException('noticeRef not set.'); |
|
113 | - } |
|
114 | - return $this->_ref; |
|
115 | - } |
|
102 | + /** |
|
103 | + * Get notice reference. |
|
104 | + * |
|
105 | + * @throws \LogicException If not set |
|
106 | + * |
|
107 | + * @return NoticeReference |
|
108 | + */ |
|
109 | + public function noticeRef(): NoticeReference |
|
110 | + { |
|
111 | + if (!$this->hasNoticeRef()) { |
|
112 | + throw new \LogicException('noticeRef not set.'); |
|
113 | + } |
|
114 | + return $this->_ref; |
|
115 | + } |
|
116 | 116 | |
117 | - /** |
|
118 | - * {@inheritdoc} |
|
119 | - */ |
|
120 | - protected function _qualifierASN1(): Element |
|
121 | - { |
|
122 | - $elements = []; |
|
123 | - if (isset($this->_ref)) { |
|
124 | - $elements[] = $this->_ref->toASN1(); |
|
125 | - } |
|
126 | - if (isset($this->_text)) { |
|
127 | - $elements[] = $this->_text->toASN1(); |
|
128 | - } |
|
129 | - return new Sequence(...$elements); |
|
130 | - } |
|
117 | + /** |
|
118 | + * {@inheritdoc} |
|
119 | + */ |
|
120 | + protected function _qualifierASN1(): Element |
|
121 | + { |
|
122 | + $elements = []; |
|
123 | + if (isset($this->_ref)) { |
|
124 | + $elements[] = $this->_ref->toASN1(); |
|
125 | + } |
|
126 | + if (isset($this->_text)) { |
|
127 | + $elements[] = $this->_text->toASN1(); |
|
128 | + } |
|
129 | + return new Sequence(...$elements); |
|
130 | + } |
|
131 | 131 | } |