@@ -15,55 +15,55 @@ |
||
15 | 15 | * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.8 |
16 | 16 | */ |
17 | 17 | class SubjectDirectoryAttributesExtension extends Extension implements |
18 | - \Countable, |
|
19 | - \IteratorAggregate |
|
18 | + \Countable, |
|
19 | + \IteratorAggregate |
|
20 | 20 | { |
21 | - use AttributeContainer; |
|
21 | + use AttributeContainer; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param bool $critical |
|
27 | - * @param Attribute ...$attribs One or more Attribute objects |
|
28 | - */ |
|
29 | - public function __construct(bool $critical, Attribute ...$attribs) |
|
30 | - { |
|
31 | - parent::__construct(self::OID_SUBJECT_DIRECTORY_ATTRIBUTES, $critical); |
|
32 | - $this->_attributes = $attribs; |
|
33 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param bool $critical |
|
27 | + * @param Attribute ...$attribs One or more Attribute objects |
|
28 | + */ |
|
29 | + public function __construct(bool $critical, Attribute ...$attribs) |
|
30 | + { |
|
31 | + parent::__construct(self::OID_SUBJECT_DIRECTORY_ATTRIBUTES, $critical); |
|
32 | + $this->_attributes = $attribs; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * |
|
37 | - * {@inheritdoc} |
|
38 | - * @return self |
|
39 | - */ |
|
40 | - protected static function _fromDER(string $data, bool $critical): self |
|
41 | - { |
|
42 | - $attribs = array_map( |
|
43 | - function (UnspecifiedType $el) { |
|
44 | - return Attribute::fromASN1($el->asSequence()); |
|
45 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
46 | - if (!count($attribs)) { |
|
47 | - throw new \UnexpectedValueException( |
|
48 | - "SubjectDirectoryAttributes must have at least one Attribute."); |
|
49 | - } |
|
50 | - return new self($critical, ...$attribs); |
|
51 | - } |
|
35 | + /** |
|
36 | + * |
|
37 | + * {@inheritdoc} |
|
38 | + * @return self |
|
39 | + */ |
|
40 | + protected static function _fromDER(string $data, bool $critical): self |
|
41 | + { |
|
42 | + $attribs = array_map( |
|
43 | + function (UnspecifiedType $el) { |
|
44 | + return Attribute::fromASN1($el->asSequence()); |
|
45 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
46 | + if (!count($attribs)) { |
|
47 | + throw new \UnexpectedValueException( |
|
48 | + "SubjectDirectoryAttributes must have at least one Attribute."); |
|
49 | + } |
|
50 | + return new self($critical, ...$attribs); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * {@inheritdoc} |
|
56 | - * @return Sequence |
|
57 | - */ |
|
58 | - protected function _valueASN1(): Sequence |
|
59 | - { |
|
60 | - if (!count($this->_attributes)) { |
|
61 | - throw new \LogicException("No attributes"); |
|
62 | - } |
|
63 | - $elements = array_map( |
|
64 | - function (Attribute $attr) { |
|
65 | - return $attr->toASN1(); |
|
66 | - }, array_values($this->_attributes)); |
|
67 | - return new Sequence(...$elements); |
|
68 | - } |
|
53 | + /** |
|
54 | + * |
|
55 | + * {@inheritdoc} |
|
56 | + * @return Sequence |
|
57 | + */ |
|
58 | + protected function _valueASN1(): Sequence |
|
59 | + { |
|
60 | + if (!count($this->_attributes)) { |
|
61 | + throw new \LogicException("No attributes"); |
|
62 | + } |
|
63 | + $elements = array_map( |
|
64 | + function (Attribute $attr) { |
|
65 | + return $attr->toASN1(); |
|
66 | + }, array_values($this->_attributes)); |
|
67 | + return new Sequence(...$elements); |
|
68 | + } |
|
69 | 69 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | protected static function _fromDER(string $data, bool $critical): self |
41 | 41 | { |
42 | 42 | $attribs = array_map( |
43 | - function (UnspecifiedType $el) { |
|
43 | + function(UnspecifiedType $el) { |
|
44 | 44 | return Attribute::fromASN1($el->asSequence()); |
45 | 45 | }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
46 | 46 | if (!count($attribs)) { |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | throw new \LogicException("No attributes"); |
62 | 62 | } |
63 | 63 | $elements = array_map( |
64 | - function (Attribute $attr) { |
|
64 | + function(Attribute $attr) { |
|
65 | 65 | return $attr->toASN1(); |
66 | 66 | }, array_values($this->_attributes)); |
67 | 67 | return new Sequence(...$elements); |
@@ -17,122 +17,122 @@ |
||
17 | 17 | */ |
18 | 18 | class NameConstraintsExtension extends Extension |
19 | 19 | { |
20 | - /** |
|
21 | - * Permitted subtrees. |
|
22 | - * |
|
23 | - * @var GeneralSubtrees|null $_permitted |
|
24 | - */ |
|
25 | - protected $_permitted; |
|
20 | + /** |
|
21 | + * Permitted subtrees. |
|
22 | + * |
|
23 | + * @var GeneralSubtrees|null $_permitted |
|
24 | + */ |
|
25 | + protected $_permitted; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Excluded subtrees. |
|
29 | - * |
|
30 | - * @var GeneralSubtrees|null $_excluded |
|
31 | - */ |
|
32 | - protected $_excluded; |
|
27 | + /** |
|
28 | + * Excluded subtrees. |
|
29 | + * |
|
30 | + * @var GeneralSubtrees|null $_excluded |
|
31 | + */ |
|
32 | + protected $_excluded; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor. |
|
36 | - * |
|
37 | - * @param bool $critical |
|
38 | - * @param GeneralSubtrees $permitted |
|
39 | - * @param GeneralSubtrees $excluded |
|
40 | - */ |
|
41 | - public function __construct(bool $critical, GeneralSubtrees $permitted = null, |
|
42 | - GeneralSubtrees $excluded = null) |
|
43 | - { |
|
44 | - parent::__construct(self::OID_NAME_CONSTRAINTS, $critical); |
|
45 | - $this->_permitted = $permitted; |
|
46 | - $this->_excluded = $excluded; |
|
47 | - } |
|
34 | + /** |
|
35 | + * Constructor. |
|
36 | + * |
|
37 | + * @param bool $critical |
|
38 | + * @param GeneralSubtrees $permitted |
|
39 | + * @param GeneralSubtrees $excluded |
|
40 | + */ |
|
41 | + public function __construct(bool $critical, GeneralSubtrees $permitted = null, |
|
42 | + GeneralSubtrees $excluded = null) |
|
43 | + { |
|
44 | + parent::__construct(self::OID_NAME_CONSTRAINTS, $critical); |
|
45 | + $this->_permitted = $permitted; |
|
46 | + $this->_excluded = $excluded; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * |
|
51 | - * {@inheritdoc} |
|
52 | - * @return self |
|
53 | - */ |
|
54 | - protected static function _fromDER(string $data, bool $critical): self |
|
55 | - { |
|
56 | - $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
57 | - $permitted = null; |
|
58 | - $excluded = null; |
|
59 | - if ($seq->hasTagged(0)) { |
|
60 | - $permitted = GeneralSubtrees::fromASN1( |
|
61 | - $seq->getTagged(0) |
|
62 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
63 | - ->asSequence()); |
|
64 | - } |
|
65 | - if ($seq->hasTagged(1)) { |
|
66 | - $excluded = GeneralSubtrees::fromASN1( |
|
67 | - $seq->getTagged(1) |
|
68 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
69 | - ->asSequence()); |
|
70 | - } |
|
71 | - return new self($critical, $permitted, $excluded); |
|
72 | - } |
|
49 | + /** |
|
50 | + * |
|
51 | + * {@inheritdoc} |
|
52 | + * @return self |
|
53 | + */ |
|
54 | + protected static function _fromDER(string $data, bool $critical): self |
|
55 | + { |
|
56 | + $seq = UnspecifiedType::fromDER($data)->asSequence(); |
|
57 | + $permitted = null; |
|
58 | + $excluded = null; |
|
59 | + if ($seq->hasTagged(0)) { |
|
60 | + $permitted = GeneralSubtrees::fromASN1( |
|
61 | + $seq->getTagged(0) |
|
62 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
63 | + ->asSequence()); |
|
64 | + } |
|
65 | + if ($seq->hasTagged(1)) { |
|
66 | + $excluded = GeneralSubtrees::fromASN1( |
|
67 | + $seq->getTagged(1) |
|
68 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
69 | + ->asSequence()); |
|
70 | + } |
|
71 | + return new self($critical, $permitted, $excluded); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Whether permitted subtrees are present. |
|
76 | - * |
|
77 | - * @return bool |
|
78 | - */ |
|
79 | - public function hasPermittedSubtrees(): bool |
|
80 | - { |
|
81 | - return isset($this->_permitted); |
|
82 | - } |
|
74 | + /** |
|
75 | + * Whether permitted subtrees are present. |
|
76 | + * |
|
77 | + * @return bool |
|
78 | + */ |
|
79 | + public function hasPermittedSubtrees(): bool |
|
80 | + { |
|
81 | + return isset($this->_permitted); |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get permitted subtrees. |
|
86 | - * |
|
87 | - * @throws \LogicException |
|
88 | - * @return GeneralSubtrees |
|
89 | - */ |
|
90 | - public function permittedSubtrees(): GeneralSubtrees |
|
91 | - { |
|
92 | - if (!$this->hasPermittedSubtrees()) { |
|
93 | - throw new \LogicException("No permitted subtrees."); |
|
94 | - } |
|
95 | - return $this->_permitted; |
|
96 | - } |
|
84 | + /** |
|
85 | + * Get permitted subtrees. |
|
86 | + * |
|
87 | + * @throws \LogicException |
|
88 | + * @return GeneralSubtrees |
|
89 | + */ |
|
90 | + public function permittedSubtrees(): GeneralSubtrees |
|
91 | + { |
|
92 | + if (!$this->hasPermittedSubtrees()) { |
|
93 | + throw new \LogicException("No permitted subtrees."); |
|
94 | + } |
|
95 | + return $this->_permitted; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Whether excluded subtrees are present. |
|
100 | - * |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function hasExcludedSubtrees(): bool |
|
104 | - { |
|
105 | - return isset($this->_excluded); |
|
106 | - } |
|
98 | + /** |
|
99 | + * Whether excluded subtrees are present. |
|
100 | + * |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function hasExcludedSubtrees(): bool |
|
104 | + { |
|
105 | + return isset($this->_excluded); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Get excluded subtrees. |
|
110 | - * |
|
111 | - * @throws \LogicException |
|
112 | - * @return GeneralSubtrees |
|
113 | - */ |
|
114 | - public function excludedSubtrees(): GeneralSubtrees |
|
115 | - { |
|
116 | - if (!$this->hasExcludedSubtrees()) { |
|
117 | - throw new \LogicException("No excluded subtrees."); |
|
118 | - } |
|
119 | - return $this->_excluded; |
|
120 | - } |
|
108 | + /** |
|
109 | + * Get excluded subtrees. |
|
110 | + * |
|
111 | + * @throws \LogicException |
|
112 | + * @return GeneralSubtrees |
|
113 | + */ |
|
114 | + public function excludedSubtrees(): GeneralSubtrees |
|
115 | + { |
|
116 | + if (!$this->hasExcludedSubtrees()) { |
|
117 | + throw new \LogicException("No excluded subtrees."); |
|
118 | + } |
|
119 | + return $this->_excluded; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * |
|
124 | - * {@inheritdoc} |
|
125 | - * @return Sequence |
|
126 | - */ |
|
127 | - protected function _valueASN1(): Sequence |
|
128 | - { |
|
129 | - $elements = array(); |
|
130 | - if (isset($this->_permitted)) { |
|
131 | - $elements[] = new ImplicitlyTaggedType(0, $this->_permitted->toASN1()); |
|
132 | - } |
|
133 | - if (isset($this->_excluded)) { |
|
134 | - $elements[] = new ImplicitlyTaggedType(1, $this->_excluded->toASN1()); |
|
135 | - } |
|
136 | - return new Sequence(...$elements); |
|
137 | - } |
|
122 | + /** |
|
123 | + * |
|
124 | + * {@inheritdoc} |
|
125 | + * @return Sequence |
|
126 | + */ |
|
127 | + protected function _valueASN1(): Sequence |
|
128 | + { |
|
129 | + $elements = array(); |
|
130 | + if (isset($this->_permitted)) { |
|
131 | + $elements[] = new ImplicitlyTaggedType(0, $this->_permitted->toASN1()); |
|
132 | + } |
|
133 | + if (isset($this->_excluded)) { |
|
134 | + $elements[] = new ImplicitlyTaggedType(1, $this->_excluded->toASN1()); |
|
135 | + } |
|
136 | + return new Sequence(...$elements); |
|
137 | + } |
|
138 | 138 | } |
@@ -19,139 +19,139 @@ |
||
19 | 19 | * @link https://tools.ietf.org/html/rfc5755#section-4.3.2 |
20 | 20 | */ |
21 | 21 | class TargetInformationExtension extends Extension implements |
22 | - \Countable, |
|
23 | - \IteratorAggregate |
|
22 | + \Countable, |
|
23 | + \IteratorAggregate |
|
24 | 24 | { |
25 | - /** |
|
26 | - * Targets elements. |
|
27 | - * |
|
28 | - * @var Targets[] $_targets |
|
29 | - */ |
|
30 | - protected $_targets; |
|
25 | + /** |
|
26 | + * Targets elements. |
|
27 | + * |
|
28 | + * @var Targets[] $_targets |
|
29 | + */ |
|
30 | + protected $_targets; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Targets[] merged to single Targets. |
|
34 | - * |
|
35 | - * @var Targets|null |
|
36 | - */ |
|
37 | - private $_merged; |
|
32 | + /** |
|
33 | + * Targets[] merged to single Targets. |
|
34 | + * |
|
35 | + * @var Targets|null |
|
36 | + */ |
|
37 | + private $_merged; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor. |
|
41 | - * |
|
42 | - * @param bool $critical |
|
43 | - * @param Targets ...$targets |
|
44 | - */ |
|
45 | - public function __construct(bool $critical, Targets ...$targets) |
|
46 | - { |
|
47 | - parent::__construct(self::OID_TARGET_INFORMATION, $critical); |
|
48 | - $this->_targets = $targets; |
|
49 | - } |
|
39 | + /** |
|
40 | + * Constructor. |
|
41 | + * |
|
42 | + * @param bool $critical |
|
43 | + * @param Targets ...$targets |
|
44 | + */ |
|
45 | + public function __construct(bool $critical, Targets ...$targets) |
|
46 | + { |
|
47 | + parent::__construct(self::OID_TARGET_INFORMATION, $critical); |
|
48 | + $this->_targets = $targets; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Initialize from one or more Target objects. |
|
53 | - * |
|
54 | - * Extension criticality shall be set to true as specified by RFC 5755. |
|
55 | - * |
|
56 | - * @param Target ...$target |
|
57 | - * @return TargetInformationExtension |
|
58 | - */ |
|
59 | - public static function fromTargets(Target ...$target): self |
|
60 | - { |
|
61 | - return new self(true, new Targets(...$target)); |
|
62 | - } |
|
51 | + /** |
|
52 | + * Initialize from one or more Target objects. |
|
53 | + * |
|
54 | + * Extension criticality shall be set to true as specified by RFC 5755. |
|
55 | + * |
|
56 | + * @param Target ...$target |
|
57 | + * @return TargetInformationExtension |
|
58 | + */ |
|
59 | + public static function fromTargets(Target ...$target): self |
|
60 | + { |
|
61 | + return new self(true, new Targets(...$target)); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Reset internal state on clone. |
|
66 | - */ |
|
67 | - public function __clone() |
|
68 | - { |
|
69 | - $this->_merged = null; |
|
70 | - } |
|
64 | + /** |
|
65 | + * Reset internal state on clone. |
|
66 | + */ |
|
67 | + public function __clone() |
|
68 | + { |
|
69 | + $this->_merged = null; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * |
|
74 | - * {@inheritdoc} |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - protected static function _fromDER(string $data, bool $critical): self |
|
78 | - { |
|
79 | - $targets = array_map( |
|
80 | - function (UnspecifiedType $el) { |
|
81 | - return Targets::fromASN1($el->asSequence()); |
|
82 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
83 | - return new self($critical, ...$targets); |
|
84 | - } |
|
72 | + /** |
|
73 | + * |
|
74 | + * {@inheritdoc} |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + protected static function _fromDER(string $data, bool $critical): self |
|
78 | + { |
|
79 | + $targets = array_map( |
|
80 | + function (UnspecifiedType $el) { |
|
81 | + return Targets::fromASN1($el->asSequence()); |
|
82 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
83 | + return new self($critical, ...$targets); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Get all targets. |
|
88 | - * |
|
89 | - * @return Targets |
|
90 | - */ |
|
91 | - public function targets(): Targets |
|
92 | - { |
|
93 | - if (!isset($this->_merged)) { |
|
94 | - $a = array(); |
|
95 | - foreach ($this->_targets as $targets) { |
|
96 | - $a = array_merge($a, $targets->all()); |
|
97 | - } |
|
98 | - $this->_merged = new Targets(...$a); |
|
99 | - } |
|
100 | - return $this->_merged; |
|
101 | - } |
|
86 | + /** |
|
87 | + * Get all targets. |
|
88 | + * |
|
89 | + * @return Targets |
|
90 | + */ |
|
91 | + public function targets(): Targets |
|
92 | + { |
|
93 | + if (!isset($this->_merged)) { |
|
94 | + $a = array(); |
|
95 | + foreach ($this->_targets as $targets) { |
|
96 | + $a = array_merge($a, $targets->all()); |
|
97 | + } |
|
98 | + $this->_merged = new Targets(...$a); |
|
99 | + } |
|
100 | + return $this->_merged; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Get all name targets. |
|
105 | - * |
|
106 | - * @return Target[] |
|
107 | - */ |
|
108 | - public function names(): array |
|
109 | - { |
|
110 | - return $this->targets()->nameTargets(); |
|
111 | - } |
|
103 | + /** |
|
104 | + * Get all name targets. |
|
105 | + * |
|
106 | + * @return Target[] |
|
107 | + */ |
|
108 | + public function names(): array |
|
109 | + { |
|
110 | + return $this->targets()->nameTargets(); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get all group targets. |
|
115 | - * |
|
116 | - * @return Target[] |
|
117 | - */ |
|
118 | - public function groups(): array |
|
119 | - { |
|
120 | - return $this->targets()->groupTargets(); |
|
121 | - } |
|
113 | + /** |
|
114 | + * Get all group targets. |
|
115 | + * |
|
116 | + * @return Target[] |
|
117 | + */ |
|
118 | + public function groups(): array |
|
119 | + { |
|
120 | + return $this->targets()->groupTargets(); |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * |
|
125 | - * @see \X509\Certificate\Extension\Extension::_valueASN1() |
|
126 | - * @return Sequence |
|
127 | - */ |
|
128 | - protected function _valueASN1(): Sequence |
|
129 | - { |
|
130 | - $elements = array_map( |
|
131 | - function (Targets $targets) { |
|
132 | - return $targets->toASN1(); |
|
133 | - }, $this->_targets); |
|
134 | - return new Sequence(...$elements); |
|
135 | - } |
|
123 | + /** |
|
124 | + * |
|
125 | + * @see \X509\Certificate\Extension\Extension::_valueASN1() |
|
126 | + * @return Sequence |
|
127 | + */ |
|
128 | + protected function _valueASN1(): Sequence |
|
129 | + { |
|
130 | + $elements = array_map( |
|
131 | + function (Targets $targets) { |
|
132 | + return $targets->toASN1(); |
|
133 | + }, $this->_targets); |
|
134 | + return new Sequence(...$elements); |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * |
|
139 | - * @see \Countable::count() |
|
140 | - * @return int |
|
141 | - */ |
|
142 | - public function count(): int |
|
143 | - { |
|
144 | - return count($this->targets()); |
|
145 | - } |
|
137 | + /** |
|
138 | + * |
|
139 | + * @see \Countable::count() |
|
140 | + * @return int |
|
141 | + */ |
|
142 | + public function count(): int |
|
143 | + { |
|
144 | + return count($this->targets()); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Get iterator for targets. |
|
149 | - * |
|
150 | - * @see \IteratorAggregate::getIterator() |
|
151 | - * @return \ArrayIterator |
|
152 | - */ |
|
153 | - public function getIterator(): \ArrayIterator |
|
154 | - { |
|
155 | - return new \ArrayIterator($this->targets()->all()); |
|
156 | - } |
|
147 | + /** |
|
148 | + * Get iterator for targets. |
|
149 | + * |
|
150 | + * @see \IteratorAggregate::getIterator() |
|
151 | + * @return \ArrayIterator |
|
152 | + */ |
|
153 | + public function getIterator(): \ArrayIterator |
|
154 | + { |
|
155 | + return new \ArrayIterator($this->targets()->all()); |
|
156 | + } |
|
157 | 157 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | protected static function _fromDER(string $data, bool $critical): self |
78 | 78 | { |
79 | 79 | $targets = array_map( |
80 | - function (UnspecifiedType $el) { |
|
80 | + function(UnspecifiedType $el) { |
|
81 | 81 | return Targets::fromASN1($el->asSequence()); |
82 | 82 | }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
83 | 83 | return new self($critical, ...$targets); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | protected function _valueASN1(): Sequence |
129 | 129 | { |
130 | 130 | $elements = array_map( |
131 | - function (Targets $targets) { |
|
131 | + function(Targets $targets) { |
|
132 | 132 | return $targets->toASN1(); |
133 | 133 | }, $this->_targets); |
134 | 134 | return new Sequence(...$elements); |
@@ -15,54 +15,54 @@ |
||
15 | 15 | */ |
16 | 16 | class SubjectAlternativeNameExtension extends Extension |
17 | 17 | { |
18 | - /** |
|
19 | - * Names. |
|
20 | - * |
|
21 | - * @var GeneralNames $_names |
|
22 | - */ |
|
23 | - protected $_names; |
|
18 | + /** |
|
19 | + * Names. |
|
20 | + * |
|
21 | + * @var GeneralNames $_names |
|
22 | + */ |
|
23 | + protected $_names; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param bool $critical |
|
29 | - * @param GeneralNames $names |
|
30 | - */ |
|
31 | - public function __construct(bool $critical, GeneralNames $names) |
|
32 | - { |
|
33 | - parent::__construct(self::OID_SUBJECT_ALT_NAME, $critical); |
|
34 | - $this->_names = $names; |
|
35 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param bool $critical |
|
29 | + * @param GeneralNames $names |
|
30 | + */ |
|
31 | + public function __construct(bool $critical, GeneralNames $names) |
|
32 | + { |
|
33 | + parent::__construct(self::OID_SUBJECT_ALT_NAME, $critical); |
|
34 | + $this->_names = $names; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * |
|
39 | - * {@inheritdoc} |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - protected static function _fromDER(string $data, bool $critical): self |
|
43 | - { |
|
44 | - return new self($critical, |
|
45 | - GeneralNames::fromASN1( |
|
46 | - UnspecifiedType::fromDER($data)->asSequence())); |
|
47 | - } |
|
37 | + /** |
|
38 | + * |
|
39 | + * {@inheritdoc} |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + protected static function _fromDER(string $data, bool $critical): self |
|
43 | + { |
|
44 | + return new self($critical, |
|
45 | + GeneralNames::fromASN1( |
|
46 | + UnspecifiedType::fromDER($data)->asSequence())); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get names. |
|
51 | - * |
|
52 | - * @return GeneralNames |
|
53 | - */ |
|
54 | - public function names(): GeneralNames |
|
55 | - { |
|
56 | - return $this->_names; |
|
57 | - } |
|
49 | + /** |
|
50 | + * Get names. |
|
51 | + * |
|
52 | + * @return GeneralNames |
|
53 | + */ |
|
54 | + public function names(): GeneralNames |
|
55 | + { |
|
56 | + return $this->_names; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * |
|
61 | - * {@inheritdoc} |
|
62 | - * @return Sequence |
|
63 | - */ |
|
64 | - protected function _valueASN1(): Sequence |
|
65 | - { |
|
66 | - return $this->_names->toASN1(); |
|
67 | - } |
|
59 | + /** |
|
60 | + * |
|
61 | + * {@inheritdoc} |
|
62 | + * @return Sequence |
|
63 | + */ |
|
64 | + protected function _valueASN1(): Sequence |
|
65 | + { |
|
66 | + return $this->_names->toASN1(); |
|
67 | + } |
|
68 | 68 | } |
@@ -15,54 +15,54 @@ |
||
15 | 15 | */ |
16 | 16 | class IssuerAlternativeNameExtension extends Extension |
17 | 17 | { |
18 | - /** |
|
19 | - * Names. |
|
20 | - * |
|
21 | - * @var GeneralNames |
|
22 | - */ |
|
23 | - protected $_names; |
|
18 | + /** |
|
19 | + * Names. |
|
20 | + * |
|
21 | + * @var GeneralNames |
|
22 | + */ |
|
23 | + protected $_names; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param bool $critical |
|
29 | - * @param GeneralNames $names |
|
30 | - */ |
|
31 | - public function __construct(bool $critical, GeneralNames $names) |
|
32 | - { |
|
33 | - parent::__construct(self::OID_ISSUER_ALT_NAME, $critical); |
|
34 | - $this->_names = $names; |
|
35 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param bool $critical |
|
29 | + * @param GeneralNames $names |
|
30 | + */ |
|
31 | + public function __construct(bool $critical, GeneralNames $names) |
|
32 | + { |
|
33 | + parent::__construct(self::OID_ISSUER_ALT_NAME, $critical); |
|
34 | + $this->_names = $names; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * |
|
39 | - * {@inheritdoc} |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - protected static function _fromDER(string $data, bool $critical) |
|
43 | - { |
|
44 | - return new self($critical, |
|
45 | - GeneralNames::fromASN1( |
|
46 | - UnspecifiedType::fromDER($data)->asSequence())); |
|
47 | - } |
|
37 | + /** |
|
38 | + * |
|
39 | + * {@inheritdoc} |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + protected static function _fromDER(string $data, bool $critical) |
|
43 | + { |
|
44 | + return new self($critical, |
|
45 | + GeneralNames::fromASN1( |
|
46 | + UnspecifiedType::fromDER($data)->asSequence())); |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Get names. |
|
51 | - * |
|
52 | - * @return GeneralNames |
|
53 | - */ |
|
54 | - public function names(): GeneralNames |
|
55 | - { |
|
56 | - return $this->_names; |
|
57 | - } |
|
49 | + /** |
|
50 | + * Get names. |
|
51 | + * |
|
52 | + * @return GeneralNames |
|
53 | + */ |
|
54 | + public function names(): GeneralNames |
|
55 | + { |
|
56 | + return $this->_names; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * |
|
61 | - * {@inheritdoc} |
|
62 | - * @return Sequence |
|
63 | - */ |
|
64 | - protected function _valueASN1(): Sequence |
|
65 | - { |
|
66 | - return $this->_names->toASN1(); |
|
67 | - } |
|
59 | + /** |
|
60 | + * |
|
61 | + * {@inheritdoc} |
|
62 | + * @return Sequence |
|
63 | + */ |
|
64 | + protected function _valueASN1(): Sequence |
|
65 | + { |
|
66 | + return $this->_names->toASN1(); |
|
67 | + } |
|
68 | 68 | } |
@@ -14,133 +14,133 @@ |
||
14 | 14 | * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.12 |
15 | 15 | */ |
16 | 16 | class ExtendedKeyUsageExtension extends Extension implements |
17 | - \Countable, |
|
18 | - \IteratorAggregate |
|
17 | + \Countable, |
|
18 | + \IteratorAggregate |
|
19 | 19 | { |
20 | - const OID_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"; |
|
21 | - const OID_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2"; |
|
22 | - const OID_CODE_SIGNING = "1.3.6.1.5.5.7.3.3"; |
|
23 | - const OID_EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4"; |
|
24 | - const OID_IPSEC_END_SYSTEM = "1.3.6.1.5.5.7.3.5"; |
|
25 | - const OID_IPSEC_TUNNEL = "1.3.6.1.5.5.7.3.6"; |
|
26 | - const OID_IPSEC_USER = "1.3.6.1.5.5.7.3.7"; |
|
27 | - const OID_TIME_STAMPING = "1.3.6.1.5.5.7.3.8"; |
|
28 | - const OID_OCSP_SIGNING = "1.3.6.1.5.5.7.3.9"; |
|
29 | - const OID_DVCS = "1.3.6.1.5.5.7.3.10"; |
|
30 | - const OID_SBGP_CERT_AA_SERVER_AUTH = "1.3.6.1.5.5.7.3.11"; |
|
31 | - const OID_SCVP_RESPONDER = "1.3.6.1.5.5.7.3.12"; |
|
32 | - const OID_EAP_OVER_PPP = "1.3.6.1.5.5.7.3.13"; |
|
33 | - const OID_EAP_OVER_LAN = "1.3.6.1.5.5.7.3.14"; |
|
34 | - const OID_SCVP_SERVER = "1.3.6.1.5.5.7.3.15"; |
|
35 | - const OID_SCVP_CLIENT = "1.3.6.1.5.5.7.3.16"; |
|
36 | - const OID_IPSEC_IKE = "1.3.6.1.5.5.7.3.17"; |
|
37 | - const OID_CAPWAP_AC = "1.3.6.1.5.5.7.3.18"; |
|
38 | - const OID_CAPWAP_WTP = "1.3.6.1.5.5.7.3.19"; |
|
39 | - const OID_SIP_DOMAIN = "1.3.6.1.5.5.7.3.20"; |
|
40 | - const OID_SECURE_SHELL_CLIENT = "1.3.6.1.5.5.7.3.21"; |
|
41 | - const OID_SECURE_SHELL_SERVER = "1.3.6.1.5.5.7.3.22"; |
|
42 | - const OID_SEND_ROUTER = "1.3.6.1.5.5.7.3.23"; |
|
43 | - const OID_SEND_PROXY = "1.3.6.1.5.5.7.3.24"; |
|
44 | - const OID_SEND_OWNER = "1.3.6.1.5.5.7.3.25"; |
|
45 | - const OID_SEND_PROXIED_OWNER = "1.3.6.1.5.5.7.3.26"; |
|
46 | - const OID_CMC_CA = "1.3.6.1.5.5.7.3.27"; |
|
47 | - const OID_CMC_RA = "1.3.6.1.5.5.7.3.28"; |
|
48 | - const OID_CMC_ARCHIVE = "1.3.6.1.5.5.7.3.29"; |
|
20 | + const OID_SERVER_AUTH = "1.3.6.1.5.5.7.3.1"; |
|
21 | + const OID_CLIENT_AUTH = "1.3.6.1.5.5.7.3.2"; |
|
22 | + const OID_CODE_SIGNING = "1.3.6.1.5.5.7.3.3"; |
|
23 | + const OID_EMAIL_PROTECTION = "1.3.6.1.5.5.7.3.4"; |
|
24 | + const OID_IPSEC_END_SYSTEM = "1.3.6.1.5.5.7.3.5"; |
|
25 | + const OID_IPSEC_TUNNEL = "1.3.6.1.5.5.7.3.6"; |
|
26 | + const OID_IPSEC_USER = "1.3.6.1.5.5.7.3.7"; |
|
27 | + const OID_TIME_STAMPING = "1.3.6.1.5.5.7.3.8"; |
|
28 | + const OID_OCSP_SIGNING = "1.3.6.1.5.5.7.3.9"; |
|
29 | + const OID_DVCS = "1.3.6.1.5.5.7.3.10"; |
|
30 | + const OID_SBGP_CERT_AA_SERVER_AUTH = "1.3.6.1.5.5.7.3.11"; |
|
31 | + const OID_SCVP_RESPONDER = "1.3.6.1.5.5.7.3.12"; |
|
32 | + const OID_EAP_OVER_PPP = "1.3.6.1.5.5.7.3.13"; |
|
33 | + const OID_EAP_OVER_LAN = "1.3.6.1.5.5.7.3.14"; |
|
34 | + const OID_SCVP_SERVER = "1.3.6.1.5.5.7.3.15"; |
|
35 | + const OID_SCVP_CLIENT = "1.3.6.1.5.5.7.3.16"; |
|
36 | + const OID_IPSEC_IKE = "1.3.6.1.5.5.7.3.17"; |
|
37 | + const OID_CAPWAP_AC = "1.3.6.1.5.5.7.3.18"; |
|
38 | + const OID_CAPWAP_WTP = "1.3.6.1.5.5.7.3.19"; |
|
39 | + const OID_SIP_DOMAIN = "1.3.6.1.5.5.7.3.20"; |
|
40 | + const OID_SECURE_SHELL_CLIENT = "1.3.6.1.5.5.7.3.21"; |
|
41 | + const OID_SECURE_SHELL_SERVER = "1.3.6.1.5.5.7.3.22"; |
|
42 | + const OID_SEND_ROUTER = "1.3.6.1.5.5.7.3.23"; |
|
43 | + const OID_SEND_PROXY = "1.3.6.1.5.5.7.3.24"; |
|
44 | + const OID_SEND_OWNER = "1.3.6.1.5.5.7.3.25"; |
|
45 | + const OID_SEND_PROXIED_OWNER = "1.3.6.1.5.5.7.3.26"; |
|
46 | + const OID_CMC_CA = "1.3.6.1.5.5.7.3.27"; |
|
47 | + const OID_CMC_RA = "1.3.6.1.5.5.7.3.28"; |
|
48 | + const OID_CMC_ARCHIVE = "1.3.6.1.5.5.7.3.29"; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Purpose OID's. |
|
52 | - * |
|
53 | - * @var string[] $_purposes |
|
54 | - */ |
|
55 | - protected $_purposes; |
|
50 | + /** |
|
51 | + * Purpose OID's. |
|
52 | + * |
|
53 | + * @var string[] $_purposes |
|
54 | + */ |
|
55 | + protected $_purposes; |
|
56 | 56 | |
57 | - /** |
|
58 | - * Constructor. |
|
59 | - * |
|
60 | - * @param bool $critical |
|
61 | - * @param string ...$purposes |
|
62 | - */ |
|
63 | - public function __construct(bool $critical, string ...$purposes) |
|
64 | - { |
|
65 | - parent::__construct(self::OID_EXT_KEY_USAGE, $critical); |
|
66 | - $this->_purposes = $purposes; |
|
67 | - } |
|
57 | + /** |
|
58 | + * Constructor. |
|
59 | + * |
|
60 | + * @param bool $critical |
|
61 | + * @param string ...$purposes |
|
62 | + */ |
|
63 | + public function __construct(bool $critical, string ...$purposes) |
|
64 | + { |
|
65 | + parent::__construct(self::OID_EXT_KEY_USAGE, $critical); |
|
66 | + $this->_purposes = $purposes; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * |
|
71 | - * {@inheritdoc} |
|
72 | - * @return self |
|
73 | - */ |
|
74 | - protected static function _fromDER(string $data, bool $critical): self |
|
75 | - { |
|
76 | - $purposes = array_map( |
|
77 | - function (UnspecifiedType $el) { |
|
78 | - return $el->asObjectIdentifier()->oid(); |
|
79 | - }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
80 | - return new self($critical, ...$purposes); |
|
81 | - } |
|
69 | + /** |
|
70 | + * |
|
71 | + * {@inheritdoc} |
|
72 | + * @return self |
|
73 | + */ |
|
74 | + protected static function _fromDER(string $data, bool $critical): self |
|
75 | + { |
|
76 | + $purposes = array_map( |
|
77 | + function (UnspecifiedType $el) { |
|
78 | + return $el->asObjectIdentifier()->oid(); |
|
79 | + }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
|
80 | + return new self($critical, ...$purposes); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Whether purposes are present. |
|
85 | - * |
|
86 | - * If multiple purposes are checked, all must be present. |
|
87 | - * |
|
88 | - * @param string ...$oids |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function has(string ...$oids): bool |
|
92 | - { |
|
93 | - foreach ($oids as $oid) { |
|
94 | - if (!in_array($oid, $this->_purposes)) { |
|
95 | - return false; |
|
96 | - } |
|
97 | - } |
|
98 | - return true; |
|
99 | - } |
|
83 | + /** |
|
84 | + * Whether purposes are present. |
|
85 | + * |
|
86 | + * If multiple purposes are checked, all must be present. |
|
87 | + * |
|
88 | + * @param string ...$oids |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function has(string ...$oids): bool |
|
92 | + { |
|
93 | + foreach ($oids as $oid) { |
|
94 | + if (!in_array($oid, $this->_purposes)) { |
|
95 | + return false; |
|
96 | + } |
|
97 | + } |
|
98 | + return true; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get key usage purpose OID's. |
|
103 | - * |
|
104 | - * @return string[] |
|
105 | - */ |
|
106 | - public function purposes(): array |
|
107 | - { |
|
108 | - return $this->_purposes; |
|
109 | - } |
|
101 | + /** |
|
102 | + * Get key usage purpose OID's. |
|
103 | + * |
|
104 | + * @return string[] |
|
105 | + */ |
|
106 | + public function purposes(): array |
|
107 | + { |
|
108 | + return $this->_purposes; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * |
|
113 | - * {@inheritdoc} |
|
114 | - * @return Sequence |
|
115 | - */ |
|
116 | - protected function _valueASN1(): Sequence |
|
117 | - { |
|
118 | - $elements = array_map( |
|
119 | - function ($oid) { |
|
120 | - return new ObjectIdentifier($oid); |
|
121 | - }, $this->_purposes); |
|
122 | - return new Sequence(...$elements); |
|
123 | - } |
|
111 | + /** |
|
112 | + * |
|
113 | + * {@inheritdoc} |
|
114 | + * @return Sequence |
|
115 | + */ |
|
116 | + protected function _valueASN1(): Sequence |
|
117 | + { |
|
118 | + $elements = array_map( |
|
119 | + function ($oid) { |
|
120 | + return new ObjectIdentifier($oid); |
|
121 | + }, $this->_purposes); |
|
122 | + return new Sequence(...$elements); |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Get the number of purposes. |
|
127 | - * |
|
128 | - * @see \Countable::count() |
|
129 | - * @return int |
|
130 | - */ |
|
131 | - public function count(): int |
|
132 | - { |
|
133 | - return count($this->_purposes); |
|
134 | - } |
|
125 | + /** |
|
126 | + * Get the number of purposes. |
|
127 | + * |
|
128 | + * @see \Countable::count() |
|
129 | + * @return int |
|
130 | + */ |
|
131 | + public function count(): int |
|
132 | + { |
|
133 | + return count($this->_purposes); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Get iterator for usage purposes. |
|
138 | - * |
|
139 | - * @see \IteratorAggregate::getIterator() |
|
140 | - * @return \ArrayIterator |
|
141 | - */ |
|
142 | - public function getIterator(): \ArrayIterator |
|
143 | - { |
|
144 | - return new \ArrayIterator($this->_purposes); |
|
145 | - } |
|
136 | + /** |
|
137 | + * Get iterator for usage purposes. |
|
138 | + * |
|
139 | + * @see \IteratorAggregate::getIterator() |
|
140 | + * @return \ArrayIterator |
|
141 | + */ |
|
142 | + public function getIterator(): \ArrayIterator |
|
143 | + { |
|
144 | + return new \ArrayIterator($this->_purposes); |
|
145 | + } |
|
146 | 146 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | protected static function _fromDER(string $data, bool $critical): self |
75 | 75 | { |
76 | 76 | $purposes = array_map( |
77 | - function (UnspecifiedType $el) { |
|
77 | + function(UnspecifiedType $el) { |
|
78 | 78 | return $el->asObjectIdentifier()->oid(); |
79 | 79 | }, UnspecifiedType::fromDER($data)->asSequence()->elements()); |
80 | 80 | return new self($critical, ...$purposes); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | protected function _valueASN1(): Sequence |
117 | 117 | { |
118 | 118 | $elements = array_map( |
119 | - function ($oid) { |
|
119 | + function($oid) { |
|
120 | 120 | return new ObjectIdentifier($oid); |
121 | 121 | }, $this->_purposes); |
122 | 122 | return new Sequence(...$elements); |
@@ -14,52 +14,52 @@ |
||
14 | 14 | */ |
15 | 15 | class InhibitAnyPolicyExtension extends Extension |
16 | 16 | { |
17 | - /** |
|
18 | - * |
|
19 | - * @var int $_skipCerts |
|
20 | - */ |
|
21 | - protected $_skipCerts; |
|
17 | + /** |
|
18 | + * |
|
19 | + * @var int $_skipCerts |
|
20 | + */ |
|
21 | + protected $_skipCerts; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param bool $critical |
|
27 | - * @param int $skip_certs |
|
28 | - */ |
|
29 | - public function __construct(bool $critical, int $skip_certs) |
|
30 | - { |
|
31 | - parent::__construct(self::OID_INHIBIT_ANY_POLICY, $critical); |
|
32 | - $this->_skipCerts = $skip_certs; |
|
33 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param bool $critical |
|
27 | + * @param int $skip_certs |
|
28 | + */ |
|
29 | + public function __construct(bool $critical, int $skip_certs) |
|
30 | + { |
|
31 | + parent::__construct(self::OID_INHIBIT_ANY_POLICY, $critical); |
|
32 | + $this->_skipCerts = $skip_certs; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * |
|
37 | - * {@inheritdoc} |
|
38 | - * @return self |
|
39 | - */ |
|
40 | - protected static function _fromDER(string $data, bool $critical): self |
|
41 | - { |
|
42 | - return new self($critical, |
|
43 | - UnspecifiedType::fromDER($data)->asInteger()->intNumber()); |
|
44 | - } |
|
35 | + /** |
|
36 | + * |
|
37 | + * {@inheritdoc} |
|
38 | + * @return self |
|
39 | + */ |
|
40 | + protected static function _fromDER(string $data, bool $critical): self |
|
41 | + { |
|
42 | + return new self($critical, |
|
43 | + UnspecifiedType::fromDER($data)->asInteger()->intNumber()); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get value. |
|
48 | - * |
|
49 | - * @return int |
|
50 | - */ |
|
51 | - public function skipCerts(): int |
|
52 | - { |
|
53 | - return $this->_skipCerts; |
|
54 | - } |
|
46 | + /** |
|
47 | + * Get value. |
|
48 | + * |
|
49 | + * @return int |
|
50 | + */ |
|
51 | + public function skipCerts(): int |
|
52 | + { |
|
53 | + return $this->_skipCerts; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * |
|
58 | - * {@inheritdoc} |
|
59 | - * @return Integer |
|
60 | - */ |
|
61 | - protected function _valueASN1(): Integer |
|
62 | - { |
|
63 | - return new Integer($this->_skipCerts); |
|
64 | - } |
|
56 | + /** |
|
57 | + * |
|
58 | + * {@inheritdoc} |
|
59 | + * @return Integer |
|
60 | + */ |
|
61 | + protected function _valueASN1(): Integer |
|
62 | + { |
|
63 | + return new Integer($this->_skipCerts); |
|
64 | + } |
|
65 | 65 | } |
@@ -21,203 +21,203 @@ |
||
21 | 21 | */ |
22 | 22 | class AttributeCertificate |
23 | 23 | { |
24 | - /** |
|
25 | - * Attribute certificate info. |
|
26 | - * |
|
27 | - * @var AttributeCertificateInfo $_acinfo |
|
28 | - */ |
|
29 | - protected $_acinfo; |
|
30 | - |
|
31 | - /** |
|
32 | - * Signature algorithm identifier. |
|
33 | - * |
|
34 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
35 | - */ |
|
36 | - protected $_signatureAlgorithm; |
|
37 | - |
|
38 | - /** |
|
39 | - * Signature value. |
|
40 | - * |
|
41 | - * @var Signature $_signatureValue |
|
42 | - */ |
|
43 | - protected $_signatureValue; |
|
44 | - |
|
45 | - /** |
|
46 | - * Constructor. |
|
47 | - * |
|
48 | - * @param AttributeCertificateInfo $acinfo |
|
49 | - * @param SignatureAlgorithmIdentifier $algo |
|
50 | - * @param Signature $signature |
|
51 | - */ |
|
52 | - public function __construct(AttributeCertificateInfo $acinfo, |
|
53 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
54 | - { |
|
55 | - $this->_acinfo = $acinfo; |
|
56 | - $this->_signatureAlgorithm = $algo; |
|
57 | - $this->_signatureValue = $signature; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Initialize from ASN.1. |
|
62 | - * |
|
63 | - * @param Sequence $seq |
|
64 | - * @return self |
|
65 | - */ |
|
66 | - public static function fromASN1(Sequence $seq): self |
|
67 | - { |
|
68 | - $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
69 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
70 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
71 | - throw new \UnexpectedValueException( |
|
72 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
73 | - } |
|
74 | - $signature = Signature::fromSignatureData( |
|
75 | - $seq->at(2) |
|
76 | - ->asBitString() |
|
77 | - ->string(), $algo); |
|
78 | - return new self($acinfo, $algo, $signature); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Initialize from DER data. |
|
83 | - * |
|
84 | - * @param string $data |
|
85 | - * @return self |
|
86 | - */ |
|
87 | - public static function fromDER(string $data): self |
|
88 | - { |
|
89 | - return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Initialize from PEM. |
|
94 | - * |
|
95 | - * @param PEM $pem |
|
96 | - * @throws \UnexpectedValueException |
|
97 | - * @return self |
|
98 | - */ |
|
99 | - public static function fromPEM(PEM $pem): self |
|
100 | - { |
|
101 | - if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
102 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
103 | - } |
|
104 | - return self::fromDER($pem->data()); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Get attribute certificate info. |
|
109 | - * |
|
110 | - * @return AttributeCertificateInfo |
|
111 | - */ |
|
112 | - public function acinfo(): AttributeCertificateInfo |
|
113 | - { |
|
114 | - return $this->_acinfo; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get signature algorithm identifier. |
|
119 | - * |
|
120 | - * @return SignatureAlgorithmIdentifier |
|
121 | - */ |
|
122 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
123 | - { |
|
124 | - return $this->_signatureAlgorithm; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Get signature value. |
|
129 | - * |
|
130 | - * @return Signature |
|
131 | - */ |
|
132 | - public function signatureValue(): Signature |
|
133 | - { |
|
134 | - return $this->_signatureValue; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Get ASN.1 structure. |
|
139 | - * |
|
140 | - * @return Sequence |
|
141 | - */ |
|
142 | - public function toASN1(): Sequence |
|
143 | - { |
|
144 | - return new Sequence($this->_acinfo->toASN1(), |
|
145 | - $this->_signatureAlgorithm->toASN1(), |
|
146 | - $this->_signatureValue->bitString()); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Get attribute certificate as a DER. |
|
151 | - * |
|
152 | - * @return string |
|
153 | - */ |
|
154 | - public function toDER(): string |
|
155 | - { |
|
156 | - return $this->toASN1()->toDER(); |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * Get attribute certificate as a PEM. |
|
161 | - * |
|
162 | - * @return PEM |
|
163 | - */ |
|
164 | - public function toPEM(): PEM |
|
165 | - { |
|
166 | - return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Check whether attribute certificate is issued to the subject identified |
|
171 | - * by given public key certificate. |
|
172 | - * |
|
173 | - * @param Certificate $cert Certificate |
|
174 | - * @return boolean |
|
175 | - */ |
|
176 | - public function isHeldBy(Certificate $cert): bool |
|
177 | - { |
|
178 | - if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
179 | - return false; |
|
180 | - } |
|
181 | - return true; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Check whether attribute certificate is issued by given public key |
|
186 | - * certificate. |
|
187 | - * |
|
188 | - * @param Certificate $cert Certificate |
|
189 | - * @return boolean |
|
190 | - */ |
|
191 | - public function isIssuedBy(Certificate $cert): bool |
|
192 | - { |
|
193 | - if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
194 | - return false; |
|
195 | - } |
|
196 | - return true; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Verify signature. |
|
201 | - * |
|
202 | - * @param PublicKeyInfo $pubkey_info Signer's public key |
|
203 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
207 | - { |
|
208 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
209 | - $data = $this->_acinfo->toASN1()->toDER(); |
|
210 | - return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
211 | - $this->_signatureAlgorithm); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Get attribute certificate as a PEM formatted string. |
|
216 | - * |
|
217 | - * @return string |
|
218 | - */ |
|
219 | - public function __toString() |
|
220 | - { |
|
221 | - return $this->toPEM()->string(); |
|
222 | - } |
|
24 | + /** |
|
25 | + * Attribute certificate info. |
|
26 | + * |
|
27 | + * @var AttributeCertificateInfo $_acinfo |
|
28 | + */ |
|
29 | + protected $_acinfo; |
|
30 | + |
|
31 | + /** |
|
32 | + * Signature algorithm identifier. |
|
33 | + * |
|
34 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
35 | + */ |
|
36 | + protected $_signatureAlgorithm; |
|
37 | + |
|
38 | + /** |
|
39 | + * Signature value. |
|
40 | + * |
|
41 | + * @var Signature $_signatureValue |
|
42 | + */ |
|
43 | + protected $_signatureValue; |
|
44 | + |
|
45 | + /** |
|
46 | + * Constructor. |
|
47 | + * |
|
48 | + * @param AttributeCertificateInfo $acinfo |
|
49 | + * @param SignatureAlgorithmIdentifier $algo |
|
50 | + * @param Signature $signature |
|
51 | + */ |
|
52 | + public function __construct(AttributeCertificateInfo $acinfo, |
|
53 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
54 | + { |
|
55 | + $this->_acinfo = $acinfo; |
|
56 | + $this->_signatureAlgorithm = $algo; |
|
57 | + $this->_signatureValue = $signature; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Initialize from ASN.1. |
|
62 | + * |
|
63 | + * @param Sequence $seq |
|
64 | + * @return self |
|
65 | + */ |
|
66 | + public static function fromASN1(Sequence $seq): self |
|
67 | + { |
|
68 | + $acinfo = AttributeCertificateInfo::fromASN1($seq->at(0)->asSequence()); |
|
69 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
70 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
71 | + throw new \UnexpectedValueException( |
|
72 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
73 | + } |
|
74 | + $signature = Signature::fromSignatureData( |
|
75 | + $seq->at(2) |
|
76 | + ->asBitString() |
|
77 | + ->string(), $algo); |
|
78 | + return new self($acinfo, $algo, $signature); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Initialize from DER data. |
|
83 | + * |
|
84 | + * @param string $data |
|
85 | + * @return self |
|
86 | + */ |
|
87 | + public static function fromDER(string $data): self |
|
88 | + { |
|
89 | + return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Initialize from PEM. |
|
94 | + * |
|
95 | + * @param PEM $pem |
|
96 | + * @throws \UnexpectedValueException |
|
97 | + * @return self |
|
98 | + */ |
|
99 | + public static function fromPEM(PEM $pem): self |
|
100 | + { |
|
101 | + if ($pem->type() !== PEM::TYPE_ATTRIBUTE_CERTIFICATE) { |
|
102 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
103 | + } |
|
104 | + return self::fromDER($pem->data()); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Get attribute certificate info. |
|
109 | + * |
|
110 | + * @return AttributeCertificateInfo |
|
111 | + */ |
|
112 | + public function acinfo(): AttributeCertificateInfo |
|
113 | + { |
|
114 | + return $this->_acinfo; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get signature algorithm identifier. |
|
119 | + * |
|
120 | + * @return SignatureAlgorithmIdentifier |
|
121 | + */ |
|
122 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
123 | + { |
|
124 | + return $this->_signatureAlgorithm; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Get signature value. |
|
129 | + * |
|
130 | + * @return Signature |
|
131 | + */ |
|
132 | + public function signatureValue(): Signature |
|
133 | + { |
|
134 | + return $this->_signatureValue; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Get ASN.1 structure. |
|
139 | + * |
|
140 | + * @return Sequence |
|
141 | + */ |
|
142 | + public function toASN1(): Sequence |
|
143 | + { |
|
144 | + return new Sequence($this->_acinfo->toASN1(), |
|
145 | + $this->_signatureAlgorithm->toASN1(), |
|
146 | + $this->_signatureValue->bitString()); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Get attribute certificate as a DER. |
|
151 | + * |
|
152 | + * @return string |
|
153 | + */ |
|
154 | + public function toDER(): string |
|
155 | + { |
|
156 | + return $this->toASN1()->toDER(); |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * Get attribute certificate as a PEM. |
|
161 | + * |
|
162 | + * @return PEM |
|
163 | + */ |
|
164 | + public function toPEM(): PEM |
|
165 | + { |
|
166 | + return new PEM(PEM::TYPE_ATTRIBUTE_CERTIFICATE, $this->toDER()); |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Check whether attribute certificate is issued to the subject identified |
|
171 | + * by given public key certificate. |
|
172 | + * |
|
173 | + * @param Certificate $cert Certificate |
|
174 | + * @return boolean |
|
175 | + */ |
|
176 | + public function isHeldBy(Certificate $cert): bool |
|
177 | + { |
|
178 | + if (!$this->_acinfo->holder()->identifiesPKC($cert)) { |
|
179 | + return false; |
|
180 | + } |
|
181 | + return true; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Check whether attribute certificate is issued by given public key |
|
186 | + * certificate. |
|
187 | + * |
|
188 | + * @param Certificate $cert Certificate |
|
189 | + * @return boolean |
|
190 | + */ |
|
191 | + public function isIssuedBy(Certificate $cert): bool |
|
192 | + { |
|
193 | + if (!$this->_acinfo->issuer()->identifiesPKC($cert)) { |
|
194 | + return false; |
|
195 | + } |
|
196 | + return true; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Verify signature. |
|
201 | + * |
|
202 | + * @param PublicKeyInfo $pubkey_info Signer's public key |
|
203 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool |
|
207 | + { |
|
208 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
209 | + $data = $this->_acinfo->toASN1()->toDER(); |
|
210 | + return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
211 | + $this->_signatureAlgorithm); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Get attribute certificate as a PEM formatted string. |
|
216 | + * |
|
217 | + * @return string |
|
218 | + */ |
|
219 | + public function __toString() |
|
220 | + { |
|
221 | + return $this->toPEM()->string(); |
|
222 | + } |
|
223 | 223 | } |
@@ -19,172 +19,172 @@ |
||
19 | 19 | */ |
20 | 20 | class CertificationRequest |
21 | 21 | { |
22 | - /** |
|
23 | - * Certification request info. |
|
24 | - * |
|
25 | - * @var CertificationRequestInfo $_certificationRequestInfo |
|
26 | - */ |
|
27 | - protected $_certificationRequestInfo; |
|
22 | + /** |
|
23 | + * Certification request info. |
|
24 | + * |
|
25 | + * @var CertificationRequestInfo $_certificationRequestInfo |
|
26 | + */ |
|
27 | + protected $_certificationRequestInfo; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Signature algorithm. |
|
31 | - * |
|
32 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
33 | - */ |
|
34 | - protected $_signatureAlgorithm; |
|
29 | + /** |
|
30 | + * Signature algorithm. |
|
31 | + * |
|
32 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
33 | + */ |
|
34 | + protected $_signatureAlgorithm; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Signature. |
|
38 | - * |
|
39 | - * @var Signature $_signature |
|
40 | - */ |
|
41 | - protected $_signature; |
|
36 | + /** |
|
37 | + * Signature. |
|
38 | + * |
|
39 | + * @var Signature $_signature |
|
40 | + */ |
|
41 | + protected $_signature; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor. |
|
45 | - * |
|
46 | - * @param CertificationRequestInfo $info |
|
47 | - * @param SignatureAlgorithmIdentifier $algo |
|
48 | - * @param Signature $signature |
|
49 | - */ |
|
50 | - public function __construct(CertificationRequestInfo $info, |
|
51 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
52 | - { |
|
53 | - $this->_certificationRequestInfo = $info; |
|
54 | - $this->_signatureAlgorithm = $algo; |
|
55 | - $this->_signature = $signature; |
|
56 | - } |
|
43 | + /** |
|
44 | + * Constructor. |
|
45 | + * |
|
46 | + * @param CertificationRequestInfo $info |
|
47 | + * @param SignatureAlgorithmIdentifier $algo |
|
48 | + * @param Signature $signature |
|
49 | + */ |
|
50 | + public function __construct(CertificationRequestInfo $info, |
|
51 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
52 | + { |
|
53 | + $this->_certificationRequestInfo = $info; |
|
54 | + $this->_signatureAlgorithm = $algo; |
|
55 | + $this->_signature = $signature; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Initialize from ASN.1. |
|
60 | - * |
|
61 | - * @param Sequence $seq |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - public static function fromASN1(Sequence $seq): self |
|
65 | - { |
|
66 | - $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
67 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
68 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
69 | - throw new \UnexpectedValueException( |
|
70 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
71 | - } |
|
72 | - $signature = Signature::fromSignatureData( |
|
73 | - $seq->at(2) |
|
74 | - ->asBitString() |
|
75 | - ->string(), $algo); |
|
76 | - return new self($info, $algo, $signature); |
|
77 | - } |
|
58 | + /** |
|
59 | + * Initialize from ASN.1. |
|
60 | + * |
|
61 | + * @param Sequence $seq |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + public static function fromASN1(Sequence $seq): self |
|
65 | + { |
|
66 | + $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
67 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
68 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
69 | + throw new \UnexpectedValueException( |
|
70 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
71 | + } |
|
72 | + $signature = Signature::fromSignatureData( |
|
73 | + $seq->at(2) |
|
74 | + ->asBitString() |
|
75 | + ->string(), $algo); |
|
76 | + return new self($info, $algo, $signature); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Initialize from DER. |
|
81 | - * |
|
82 | - * @param string $data |
|
83 | - * @return self |
|
84 | - */ |
|
85 | - public static function fromDER(string $data): self |
|
86 | - { |
|
87 | - return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
88 | - } |
|
79 | + /** |
|
80 | + * Initialize from DER. |
|
81 | + * |
|
82 | + * @param string $data |
|
83 | + * @return self |
|
84 | + */ |
|
85 | + public static function fromDER(string $data): self |
|
86 | + { |
|
87 | + return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence()); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Initialize from PEM. |
|
92 | - * |
|
93 | - * @param PEM $pem |
|
94 | - * @throws \UnexpectedValueException |
|
95 | - * @return self |
|
96 | - */ |
|
97 | - public static function fromPEM(PEM $pem): self |
|
98 | - { |
|
99 | - if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
100 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
101 | - } |
|
102 | - return self::fromDER($pem->data()); |
|
103 | - } |
|
90 | + /** |
|
91 | + * Initialize from PEM. |
|
92 | + * |
|
93 | + * @param PEM $pem |
|
94 | + * @throws \UnexpectedValueException |
|
95 | + * @return self |
|
96 | + */ |
|
97 | + public static function fromPEM(PEM $pem): self |
|
98 | + { |
|
99 | + if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
100 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
101 | + } |
|
102 | + return self::fromDER($pem->data()); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * Get certification request info. |
|
107 | - * |
|
108 | - * @return CertificationRequestInfo |
|
109 | - */ |
|
110 | - public function certificationRequestInfo(): CertificationRequestInfo |
|
111 | - { |
|
112 | - return $this->_certificationRequestInfo; |
|
113 | - } |
|
105 | + /** |
|
106 | + * Get certification request info. |
|
107 | + * |
|
108 | + * @return CertificationRequestInfo |
|
109 | + */ |
|
110 | + public function certificationRequestInfo(): CertificationRequestInfo |
|
111 | + { |
|
112 | + return $this->_certificationRequestInfo; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Get signature algorithm. |
|
117 | - * |
|
118 | - * @return SignatureAlgorithmIdentifier |
|
119 | - */ |
|
120 | - public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
121 | - { |
|
122 | - return $this->_signatureAlgorithm; |
|
123 | - } |
|
115 | + /** |
|
116 | + * Get signature algorithm. |
|
117 | + * |
|
118 | + * @return SignatureAlgorithmIdentifier |
|
119 | + */ |
|
120 | + public function signatureAlgorithm(): SignatureAlgorithmIdentifier |
|
121 | + { |
|
122 | + return $this->_signatureAlgorithm; |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Get signature. |
|
127 | - * |
|
128 | - * @return Signature |
|
129 | - */ |
|
130 | - public function signature(): Signature |
|
131 | - { |
|
132 | - return $this->_signature; |
|
133 | - } |
|
125 | + /** |
|
126 | + * Get signature. |
|
127 | + * |
|
128 | + * @return Signature |
|
129 | + */ |
|
130 | + public function signature(): Signature |
|
131 | + { |
|
132 | + return $this->_signature; |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Generate ASN.1 structure. |
|
137 | - * |
|
138 | - * @return Sequence |
|
139 | - */ |
|
140 | - public function toASN1(): Sequence |
|
141 | - { |
|
142 | - return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
143 | - $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
144 | - } |
|
135 | + /** |
|
136 | + * Generate ASN.1 structure. |
|
137 | + * |
|
138 | + * @return Sequence |
|
139 | + */ |
|
140 | + public function toASN1(): Sequence |
|
141 | + { |
|
142 | + return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
143 | + $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Get certification request as a DER. |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function toDER(): string |
|
152 | - { |
|
153 | - return $this->toASN1()->toDER(); |
|
154 | - } |
|
146 | + /** |
|
147 | + * Get certification request as a DER. |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function toDER(): string |
|
152 | + { |
|
153 | + return $this->toASN1()->toDER(); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * Get certification request as a PEM. |
|
158 | - * |
|
159 | - * @return PEM |
|
160 | - */ |
|
161 | - public function toPEM(): PEM |
|
162 | - { |
|
163 | - return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
164 | - } |
|
156 | + /** |
|
157 | + * Get certification request as a PEM. |
|
158 | + * |
|
159 | + * @return PEM |
|
160 | + */ |
|
161 | + public function toPEM(): PEM |
|
162 | + { |
|
163 | + return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Verify certification request signature. |
|
168 | - * |
|
169 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
170 | - * @return bool True if signature matches |
|
171 | - */ |
|
172 | - public function verify(Crypto $crypto = null): bool |
|
173 | - { |
|
174 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
175 | - $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
176 | - $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
177 | - return $crypto->verify($data, $this->_signature, $pk_info, |
|
178 | - $this->_signatureAlgorithm); |
|
179 | - } |
|
166 | + /** |
|
167 | + * Verify certification request signature. |
|
168 | + * |
|
169 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
170 | + * @return bool True if signature matches |
|
171 | + */ |
|
172 | + public function verify(Crypto $crypto = null): bool |
|
173 | + { |
|
174 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
175 | + $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
176 | + $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
177 | + return $crypto->verify($data, $this->_signature, $pk_info, |
|
178 | + $this->_signatureAlgorithm); |
|
179 | + } |
|
180 | 180 | |
181 | - /** |
|
182 | - * Get certification request as a PEM formatted string. |
|
183 | - * |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - public function __toString() |
|
187 | - { |
|
188 | - return $this->toPEM()->string(); |
|
189 | - } |
|
181 | + /** |
|
182 | + * Get certification request as a PEM formatted string. |
|
183 | + * |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + public function __toString() |
|
187 | + { |
|
188 | + return $this->toPEM()->string(); |
|
189 | + } |
|
190 | 190 | } |