GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 91afec...2569ae )
by Joni
05:59
created
lib/X509/AttributeCertificate/Attribute/IetfAttrSyntax.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -19,203 +19,203 @@
 block discarded – undo
19 19
  * @link https://tools.ietf.org/html/rfc5755#section-4.4
20 20
  */
21 21
 abstract class IetfAttrSyntax extends AttributeValue implements 
22
-    \Countable,
23
-    \IteratorAggregate
22
+	\Countable,
23
+	\IteratorAggregate
24 24
 {
25
-    /**
26
-     * Policy authority.
27
-     *
28
-     * @var GeneralNames|null $_policyAuthority
29
-     */
30
-    protected $_policyAuthority;
25
+	/**
26
+	 * Policy authority.
27
+	 *
28
+	 * @var GeneralNames|null $_policyAuthority
29
+	 */
30
+	protected $_policyAuthority;
31 31
     
32
-    /**
33
-     * Values.
34
-     *
35
-     * @var IetfAttrValue[] $_values
36
-     */
37
-    protected $_values;
32
+	/**
33
+	 * Values.
34
+	 *
35
+	 * @var IetfAttrValue[] $_values
36
+	 */
37
+	protected $_values;
38 38
     
39
-    /**
40
-     * Constructor.
41
-     * 
42
-     * @param IetfAttrValue ...$values
43
-     */
44
-    public function __construct(IetfAttrValue ...$values)
45
-    {
46
-        $this->_policyAuthority = null;
47
-        $this->_values = $values;
48
-    }
39
+	/**
40
+	 * Constructor.
41
+	 * 
42
+	 * @param IetfAttrValue ...$values
43
+	 */
44
+	public function __construct(IetfAttrValue ...$values)
45
+	{
46
+		$this->_policyAuthority = null;
47
+		$this->_values = $values;
48
+	}
49 49
     
50
-    /**
51
-     *
52
-     * @param UnspecifiedType $el
53
-     * @return self
54
-     */
55
-    public static function fromASN1(UnspecifiedType $el): self
56
-    {
57
-        $seq = $el->asSequence();
58
-        $authority = null;
59
-        $idx = 0;
60
-        if ($seq->hasTagged(0)) {
61
-            $authority = GeneralNames::fromASN1(
62
-                $seq->getTagged(0)
63
-                    ->asImplicit(Element::TYPE_SEQUENCE)
64
-                    ->asSequence());
65
-            ++$idx;
66
-        }
67
-        $values = array_map(
68
-            function (UnspecifiedType $el) {
69
-                return IetfAttrValue::fromASN1($el);
70
-            },
71
-            $seq->at($idx)
72
-                ->asSequence()
73
-                ->elements());
74
-        $obj = new static(...$values);
75
-        $obj->_policyAuthority = $authority;
76
-        return $obj;
77
-    }
50
+	/**
51
+	 *
52
+	 * @param UnspecifiedType $el
53
+	 * @return self
54
+	 */
55
+	public static function fromASN1(UnspecifiedType $el): self
56
+	{
57
+		$seq = $el->asSequence();
58
+		$authority = null;
59
+		$idx = 0;
60
+		if ($seq->hasTagged(0)) {
61
+			$authority = GeneralNames::fromASN1(
62
+				$seq->getTagged(0)
63
+					->asImplicit(Element::TYPE_SEQUENCE)
64
+					->asSequence());
65
+			++$idx;
66
+		}
67
+		$values = array_map(
68
+			function (UnspecifiedType $el) {
69
+				return IetfAttrValue::fromASN1($el);
70
+			},
71
+			$seq->at($idx)
72
+				->asSequence()
73
+				->elements());
74
+		$obj = new static(...$values);
75
+		$obj->_policyAuthority = $authority;
76
+		return $obj;
77
+	}
78 78
     
79
-    /**
80
-     * Get self with policy authority.
81
-     *
82
-     * @param GeneralNames $names
83
-     * @return self
84
-     */
85
-    public function withPolicyAuthority(GeneralNames $names): self
86
-    {
87
-        $obj = clone $this;
88
-        $obj->_policyAuthority = $names;
89
-        return $obj;
90
-    }
79
+	/**
80
+	 * Get self with policy authority.
81
+	 *
82
+	 * @param GeneralNames $names
83
+	 * @return self
84
+	 */
85
+	public function withPolicyAuthority(GeneralNames $names): self
86
+	{
87
+		$obj = clone $this;
88
+		$obj->_policyAuthority = $names;
89
+		return $obj;
90
+	}
91 91
     
92
-    /**
93
-     * Check whether policy authority is present.
94
-     *
95
-     * @return bool
96
-     */
97
-    public function hasPolicyAuthority(): bool
98
-    {
99
-        return isset($this->_policyAuthority);
100
-    }
92
+	/**
93
+	 * Check whether policy authority is present.
94
+	 *
95
+	 * @return bool
96
+	 */
97
+	public function hasPolicyAuthority(): bool
98
+	{
99
+		return isset($this->_policyAuthority);
100
+	}
101 101
     
102
-    /**
103
-     * Get policy authority.
104
-     *
105
-     * @throws \LogicException
106
-     * @return GeneralNames
107
-     */
108
-    public function policyAuthority(): GeneralNames
109
-    {
110
-        if (!$this->hasPolicyAuthority()) {
111
-            throw new \LogicException("policyAuthority not set.");
112
-        }
113
-        return $this->_policyAuthority;
114
-    }
102
+	/**
103
+	 * Get policy authority.
104
+	 *
105
+	 * @throws \LogicException
106
+	 * @return GeneralNames
107
+	 */
108
+	public function policyAuthority(): GeneralNames
109
+	{
110
+		if (!$this->hasPolicyAuthority()) {
111
+			throw new \LogicException("policyAuthority not set.");
112
+		}
113
+		return $this->_policyAuthority;
114
+	}
115 115
     
116
-    /**
117
-     * Get values.
118
-     *
119
-     * @return IetfAttrValue[]
120
-     */
121
-    public function values(): array
122
-    {
123
-        return $this->_values;
124
-    }
116
+	/**
117
+	 * Get values.
118
+	 *
119
+	 * @return IetfAttrValue[]
120
+	 */
121
+	public function values(): array
122
+	{
123
+		return $this->_values;
124
+	}
125 125
     
126
-    /**
127
-     * Get first value.
128
-     *
129
-     * @throws \LogicException
130
-     * @return IetfAttrValue
131
-     */
132
-    public function first(): IetfAttrValue
133
-    {
134
-        if (!count($this->_values)) {
135
-            throw new \LogicException("No values.");
136
-        }
137
-        return $this->_values[0];
138
-    }
126
+	/**
127
+	 * Get first value.
128
+	 *
129
+	 * @throws \LogicException
130
+	 * @return IetfAttrValue
131
+	 */
132
+	public function first(): IetfAttrValue
133
+	{
134
+		if (!count($this->_values)) {
135
+			throw new \LogicException("No values.");
136
+		}
137
+		return $this->_values[0];
138
+	}
139 139
     
140
-    /**
141
-     *
142
-     * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1()
143
-     * @return Sequence
144
-     */
145
-    public function toASN1(): Sequence
146
-    {
147
-        $elements = array();
148
-        if (isset($this->_policyAuthority)) {
149
-            $elements[] = new ImplicitlyTaggedType(0,
150
-                $this->_policyAuthority->toASN1());
151
-        }
152
-        $values = array_map(
153
-            function (IetfAttrValue $val) {
154
-                return $val->toASN1();
155
-            }, $this->_values);
156
-        $elements[] = new Sequence(...$values);
157
-        return new Sequence(...$elements);
158
-    }
140
+	/**
141
+	 *
142
+	 * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1()
143
+	 * @return Sequence
144
+	 */
145
+	public function toASN1(): Sequence
146
+	{
147
+		$elements = array();
148
+		if (isset($this->_policyAuthority)) {
149
+			$elements[] = new ImplicitlyTaggedType(0,
150
+				$this->_policyAuthority->toASN1());
151
+		}
152
+		$values = array_map(
153
+			function (IetfAttrValue $val) {
154
+				return $val->toASN1();
155
+			}, $this->_values);
156
+		$elements[] = new Sequence(...$values);
157
+		return new Sequence(...$elements);
158
+	}
159 159
     
160
-    /**
161
-     *
162
-     * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue()
163
-     * @return string
164
-     */
165
-    public function stringValue(): string
166
-    {
167
-        return "#" . bin2hex($this->toASN1()->toDER());
168
-    }
160
+	/**
161
+	 *
162
+	 * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue()
163
+	 * @return string
164
+	 */
165
+	public function stringValue(): string
166
+	{
167
+		return "#" . bin2hex($this->toASN1()->toDER());
168
+	}
169 169
     
170
-    /**
171
-     *
172
-     * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule()
173
-     * @return BinaryMatch
174
-     */
175
-    public function equalityMatchingRule(): BinaryMatch
176
-    {
177
-        return new BinaryMatch();
178
-    }
170
+	/**
171
+	 *
172
+	 * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule()
173
+	 * @return BinaryMatch
174
+	 */
175
+	public function equalityMatchingRule(): BinaryMatch
176
+	{
177
+		return new BinaryMatch();
178
+	}
179 179
     
180
-    /**
181
-     *
182
-     * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String()
183
-     * @return string
184
-     */
185
-    public function rfc2253String(): string
186
-    {
187
-        return $this->stringValue();
188
-    }
180
+	/**
181
+	 *
182
+	 * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String()
183
+	 * @return string
184
+	 */
185
+	public function rfc2253String(): string
186
+	{
187
+		return $this->stringValue();
188
+	}
189 189
     
190
-    /**
191
-     *
192
-     * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString()
193
-     * @return string
194
-     */
195
-    protected function _transcodedString(): string
196
-    {
197
-        return $this->stringValue();
198
-    }
190
+	/**
191
+	 *
192
+	 * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString()
193
+	 * @return string
194
+	 */
195
+	protected function _transcodedString(): string
196
+	{
197
+		return $this->stringValue();
198
+	}
199 199
     
200
-    /**
201
-     * Get number of values.
202
-     *
203
-     * @see \Countable::count()
204
-     * @return int
205
-     */
206
-    public function count(): int
207
-    {
208
-        return count($this->_values);
209
-    }
200
+	/**
201
+	 * Get number of values.
202
+	 *
203
+	 * @see \Countable::count()
204
+	 * @return int
205
+	 */
206
+	public function count(): int
207
+	{
208
+		return count($this->_values);
209
+	}
210 210
     
211
-    /**
212
-     * Get iterator for values.
213
-     *
214
-     * @see \IteratorAggregate::getIterator()
215
-     * @return \ArrayIterator
216
-     */
217
-    public function getIterator(): \ArrayIterator
218
-    {
219
-        return new \ArrayIterator($this->_values);
220
-    }
211
+	/**
212
+	 * Get iterator for values.
213
+	 *
214
+	 * @see \IteratorAggregate::getIterator()
215
+	 * @return \ArrayIterator
216
+	 */
217
+	public function getIterator(): \ArrayIterator
218
+	{
219
+		return new \ArrayIterator($this->_values);
220
+	}
221 221
 }
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/Attributes.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -26,200 +26,200 @@
 block discarded – undo
26 26
  */
27 27
 class Attributes implements \Countable, \IteratorAggregate
28 28
 {
29
-    use AttributeContainer;
30
-    
31
-    /**
32
-     * Mapping from OID to attribute value class name.
33
-     *
34
-     * @internal
35
-     *
36
-     * @var array
37
-     */
38
-    const MAP_OID_TO_CLASS = array(
39
-        /* @formatter:off */
40
-        AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class,
41
-        AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class,
42
-        ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class,
43
-        GroupAttributeValue::OID => GroupAttributeValue::class,
44
-        AttributeType::OID_ROLE => RoleAttributeValue::class
45
-        /* @formatter:on */
46
-    );
47
-    
48
-    /**
49
-     * Constructor.
50
-     *
51
-     * @param Attribute ...$attribs
52
-     */
53
-    public function __construct(Attribute ...$attribs)
54
-    {
55
-        $this->_attributes = $attribs;
56
-    }
57
-    
58
-    /**
59
-     * Initialize from attribute values.
60
-     *
61
-     * @param AttributeValue ...$values
62
-     * @return self
63
-     */
64
-    public static function fromAttributeValues(AttributeValue ...$values): self
65
-    {
66
-        $attribs = array_map(
67
-            function (AttributeValue $value) {
68
-                return $value->toAttribute();
69
-            }, $values);
70
-        return new self(...$attribs);
71
-    }
72
-    
73
-    /**
74
-     * Initialize from ASN.1.
75
-     *
76
-     * @param Sequence $seq
77
-     * @return self
78
-     */
79
-    public static function fromASN1(Sequence $seq): self
80
-    {
81
-        $attribs = array_map(
82
-            function (UnspecifiedType $el) {
83
-                return Attribute::fromASN1($el->asSequence());
84
-            }, $seq->elements());
85
-        // cast attributes
86
-        $attribs = array_map(
87
-            function (Attribute $attr) {
88
-                $oid = $attr->oid();
89
-                if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
90
-                    $cls = self::MAP_OID_TO_CLASS[$oid];
91
-                    $attr = $attr->castValues($cls);
92
-                }
93
-                return $attr;
94
-            }, $attribs);
95
-        return new self(...$attribs);
96
-    }
97
-    
98
-    /**
99
-     * Check whether 'Access Identity' attribute is present.
100
-     *
101
-     * @return bool
102
-     */
103
-    public function hasAccessIdentity(): bool
104
-    {
105
-        return $this->has(AccessIdentityAttributeValue::OID);
106
-    }
107
-    
108
-    /**
109
-     * Get the first 'Access Identity' attribute value.
110
-     *
111
-     * @return AccessIdentityAttributeValue
112
-     */
113
-    public function accessIdentity(): AccessIdentityAttributeValue
114
-    {
115
-        return $this->firstOf(AccessIdentityAttributeValue::OID)->first();
116
-    }
117
-    
118
-    /**
119
-     * Check whether 'Service Authentication Information' attribute is present.
120
-     *
121
-     * @return bool
122
-     */
123
-    public function hasAuthenticationInformation(): bool
124
-    {
125
-        return $this->has(AuthenticationInfoAttributeValue::OID);
126
-    }
127
-    
128
-    /**
129
-     * Get the first 'Service Authentication Information' attribute value.
130
-     *
131
-     * @return AuthenticationInfoAttributeValue
132
-     */
133
-    public function authenticationInformation(): AuthenticationInfoAttributeValue
134
-    {
135
-        return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first();
136
-    }
137
-    
138
-    /**
139
-     * Check whether 'Charging Identity' attribute is present.
140
-     *
141
-     * @return bool
142
-     */
143
-    public function hasChargingIdentity(): bool
144
-    {
145
-        return $this->has(ChargingIdentityAttributeValue::OID);
146
-    }
147
-    
148
-    /**
149
-     * Get the first 'Charging Identity' attribute value.
150
-     *
151
-     * @return ChargingIdentityAttributeValue
152
-     */
153
-    public function chargingIdentity(): ChargingIdentityAttributeValue
154
-    {
155
-        return $this->firstOf(ChargingIdentityAttributeValue::OID)->first();
156
-    }
157
-    
158
-    /**
159
-     * Check whether 'Group' attribute is present.
160
-     *
161
-     * @return bool
162
-     */
163
-    public function hasGroup(): bool
164
-    {
165
-        return $this->has(GroupAttributeValue::OID);
166
-    }
167
-    
168
-    /**
169
-     * Get the first 'Group' attribute value.
170
-     *
171
-     * @return GroupAttributeValue
172
-     */
173
-    public function group(): GroupAttributeValue
174
-    {
175
-        return $this->firstOf(GroupAttributeValue::OID)->first();
176
-    }
177
-    
178
-    /**
179
-     * Check whether 'Role' attribute is present.
180
-     *
181
-     * @return bool
182
-     */
183
-    public function hasRole(): bool
184
-    {
185
-        return $this->has(AttributeType::OID_ROLE);
186
-    }
187
-    
188
-    /**
189
-     * Get the first 'Role' attribute value.
190
-     *
191
-     * @return RoleAttributeValue
192
-     */
193
-    public function role(): RoleAttributeValue
194
-    {
195
-        return $this->firstOf(AttributeType::OID_ROLE)->first();
196
-    }
197
-    
198
-    /**
199
-     * Get all 'Role' attribute values.
200
-     *
201
-     * @return RoleAttributeValue[]
202
-     */
203
-    public function roles(): array
204
-    {
205
-        return array_merge(array(),
206
-            ...array_map(
207
-                function (Attribute $attr) {
208
-                    return $attr->values();
209
-                }, $this->allOf(AttributeType::OID_ROLE)));
210
-    }
211
-    
212
-    /**
213
-     * Generate ASN.1 structure.
214
-     *
215
-     * @return Sequence
216
-     */
217
-    public function toASN1(): Sequence
218
-    {
219
-        $elements = array_map(
220
-            function (Attribute $attr) {
221
-                return $attr->toASN1();
222
-            }, array_values($this->_attributes));
223
-        return new Sequence(...$elements);
224
-    }
29
+	use AttributeContainer;
30
+    
31
+	/**
32
+	 * Mapping from OID to attribute value class name.
33
+	 *
34
+	 * @internal
35
+	 *
36
+	 * @var array
37
+	 */
38
+	const MAP_OID_TO_CLASS = array(
39
+		/* @formatter:off */
40
+		AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class,
41
+		AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class,
42
+		ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class,
43
+		GroupAttributeValue::OID => GroupAttributeValue::class,
44
+		AttributeType::OID_ROLE => RoleAttributeValue::class
45
+		/* @formatter:on */
46
+	);
47
+    
48
+	/**
49
+	 * Constructor.
50
+	 *
51
+	 * @param Attribute ...$attribs
52
+	 */
53
+	public function __construct(Attribute ...$attribs)
54
+	{
55
+		$this->_attributes = $attribs;
56
+	}
57
+    
58
+	/**
59
+	 * Initialize from attribute values.
60
+	 *
61
+	 * @param AttributeValue ...$values
62
+	 * @return self
63
+	 */
64
+	public static function fromAttributeValues(AttributeValue ...$values): self
65
+	{
66
+		$attribs = array_map(
67
+			function (AttributeValue $value) {
68
+				return $value->toAttribute();
69
+			}, $values);
70
+		return new self(...$attribs);
71
+	}
72
+    
73
+	/**
74
+	 * Initialize from ASN.1.
75
+	 *
76
+	 * @param Sequence $seq
77
+	 * @return self
78
+	 */
79
+	public static function fromASN1(Sequence $seq): self
80
+	{
81
+		$attribs = array_map(
82
+			function (UnspecifiedType $el) {
83
+				return Attribute::fromASN1($el->asSequence());
84
+			}, $seq->elements());
85
+		// cast attributes
86
+		$attribs = array_map(
87
+			function (Attribute $attr) {
88
+				$oid = $attr->oid();
89
+				if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
90
+					$cls = self::MAP_OID_TO_CLASS[$oid];
91
+					$attr = $attr->castValues($cls);
92
+				}
93
+				return $attr;
94
+			}, $attribs);
95
+		return new self(...$attribs);
96
+	}
97
+    
98
+	/**
99
+	 * Check whether 'Access Identity' attribute is present.
100
+	 *
101
+	 * @return bool
102
+	 */
103
+	public function hasAccessIdentity(): bool
104
+	{
105
+		return $this->has(AccessIdentityAttributeValue::OID);
106
+	}
107
+    
108
+	/**
109
+	 * Get the first 'Access Identity' attribute value.
110
+	 *
111
+	 * @return AccessIdentityAttributeValue
112
+	 */
113
+	public function accessIdentity(): AccessIdentityAttributeValue
114
+	{
115
+		return $this->firstOf(AccessIdentityAttributeValue::OID)->first();
116
+	}
117
+    
118
+	/**
119
+	 * Check whether 'Service Authentication Information' attribute is present.
120
+	 *
121
+	 * @return bool
122
+	 */
123
+	public function hasAuthenticationInformation(): bool
124
+	{
125
+		return $this->has(AuthenticationInfoAttributeValue::OID);
126
+	}
127
+    
128
+	/**
129
+	 * Get the first 'Service Authentication Information' attribute value.
130
+	 *
131
+	 * @return AuthenticationInfoAttributeValue
132
+	 */
133
+	public function authenticationInformation(): AuthenticationInfoAttributeValue
134
+	{
135
+		return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first();
136
+	}
137
+    
138
+	/**
139
+	 * Check whether 'Charging Identity' attribute is present.
140
+	 *
141
+	 * @return bool
142
+	 */
143
+	public function hasChargingIdentity(): bool
144
+	{
145
+		return $this->has(ChargingIdentityAttributeValue::OID);
146
+	}
147
+    
148
+	/**
149
+	 * Get the first 'Charging Identity' attribute value.
150
+	 *
151
+	 * @return ChargingIdentityAttributeValue
152
+	 */
153
+	public function chargingIdentity(): ChargingIdentityAttributeValue
154
+	{
155
+		return $this->firstOf(ChargingIdentityAttributeValue::OID)->first();
156
+	}
157
+    
158
+	/**
159
+	 * Check whether 'Group' attribute is present.
160
+	 *
161
+	 * @return bool
162
+	 */
163
+	public function hasGroup(): bool
164
+	{
165
+		return $this->has(GroupAttributeValue::OID);
166
+	}
167
+    
168
+	/**
169
+	 * Get the first 'Group' attribute value.
170
+	 *
171
+	 * @return GroupAttributeValue
172
+	 */
173
+	public function group(): GroupAttributeValue
174
+	{
175
+		return $this->firstOf(GroupAttributeValue::OID)->first();
176
+	}
177
+    
178
+	/**
179
+	 * Check whether 'Role' attribute is present.
180
+	 *
181
+	 * @return bool
182
+	 */
183
+	public function hasRole(): bool
184
+	{
185
+		return $this->has(AttributeType::OID_ROLE);
186
+	}
187
+    
188
+	/**
189
+	 * Get the first 'Role' attribute value.
190
+	 *
191
+	 * @return RoleAttributeValue
192
+	 */
193
+	public function role(): RoleAttributeValue
194
+	{
195
+		return $this->firstOf(AttributeType::OID_ROLE)->first();
196
+	}
197
+    
198
+	/**
199
+	 * Get all 'Role' attribute values.
200
+	 *
201
+	 * @return RoleAttributeValue[]
202
+	 */
203
+	public function roles(): array
204
+	{
205
+		return array_merge(array(),
206
+			...array_map(
207
+				function (Attribute $attr) {
208
+					return $attr->values();
209
+				}, $this->allOf(AttributeType::OID_ROLE)));
210
+	}
211
+    
212
+	/**
213
+	 * Generate ASN.1 structure.
214
+	 *
215
+	 * @return Sequence
216
+	 */
217
+	public function toASN1(): Sequence
218
+	{
219
+		$elements = array_map(
220
+			function (Attribute $attr) {
221
+				return $attr->toASN1();
222
+			}, array_values($this->_attributes));
223
+		return new Sequence(...$elements);
224
+	}
225 225
 }
Please login to merge, or discard this patch.
lib/X509/CertificationRequest/Attributes.php 1 patch
Indentation   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -20,107 +20,107 @@
 block discarded – undo
20 20
  */
21 21
 class Attributes implements \Countable, \IteratorAggregate
22 22
 {
23
-    use AttributeContainer;
23
+	use AttributeContainer;
24 24
     
25
-    /**
26
-     * Mapping from OID to attribute value class name.
27
-     *
28
-     * @internal
29
-     *
30
-     * @var array
31
-     */
32
-    const MAP_OID_TO_CLASS = array(
33
-        /* @formatter:off */
34
-        ExtensionRequestValue::OID => ExtensionRequestValue::class
35
-        /* @formatter:on */
36
-    );
25
+	/**
26
+	 * Mapping from OID to attribute value class name.
27
+	 *
28
+	 * @internal
29
+	 *
30
+	 * @var array
31
+	 */
32
+	const MAP_OID_TO_CLASS = array(
33
+		/* @formatter:off */
34
+		ExtensionRequestValue::OID => ExtensionRequestValue::class
35
+		/* @formatter:on */
36
+	);
37 37
     
38
-    /**
39
-     * Constructor.
40
-     *
41
-     * @param Attribute ...$attribs Attribute objects
42
-     */
43
-    public function __construct(Attribute ...$attribs)
44
-    {
45
-        $this->_attributes = $attribs;
46
-    }
38
+	/**
39
+	 * Constructor.
40
+	 *
41
+	 * @param Attribute ...$attribs Attribute objects
42
+	 */
43
+	public function __construct(Attribute ...$attribs)
44
+	{
45
+		$this->_attributes = $attribs;
46
+	}
47 47
     
48
-    /**
49
-     * Initialize from attribute values.
50
-     *
51
-     * @param AttributeValue ...$values
52
-     * @return self
53
-     */
54
-    public static function fromAttributeValues(AttributeValue ...$values): Attributes
55
-    {
56
-        $attribs = array_map(
57
-            function (AttributeValue $value) {
58
-                return $value->toAttribute();
59
-            }, $values);
60
-        return new self(...$attribs);
61
-    }
48
+	/**
49
+	 * Initialize from attribute values.
50
+	 *
51
+	 * @param AttributeValue ...$values
52
+	 * @return self
53
+	 */
54
+	public static function fromAttributeValues(AttributeValue ...$values): Attributes
55
+	{
56
+		$attribs = array_map(
57
+			function (AttributeValue $value) {
58
+				return $value->toAttribute();
59
+			}, $values);
60
+		return new self(...$attribs);
61
+	}
62 62
     
63
-    /**
64
-     * Initialize from ASN.1.
65
-     *
66
-     * @param Set $set
67
-     * @return self
68
-     */
69
-    public static function fromASN1(Set $set): Attributes
70
-    {
71
-        $attribs = array_map(
72
-            function (UnspecifiedType $el) {
73
-                return Attribute::fromASN1($el->asSequence());
74
-            }, $set->elements());
75
-        // cast attributes
76
-        $attribs = array_map(
77
-            function (Attribute $attr) {
78
-                $oid = $attr->oid();
79
-                if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
80
-                    $cls = self::MAP_OID_TO_CLASS[$oid];
81
-                    return $attr->castValues($cls);
82
-                }
83
-                return $attr;
84
-            }, $attribs);
85
-        return new self(...$attribs);
86
-    }
63
+	/**
64
+	 * Initialize from ASN.1.
65
+	 *
66
+	 * @param Set $set
67
+	 * @return self
68
+	 */
69
+	public static function fromASN1(Set $set): Attributes
70
+	{
71
+		$attribs = array_map(
72
+			function (UnspecifiedType $el) {
73
+				return Attribute::fromASN1($el->asSequence());
74
+			}, $set->elements());
75
+		// cast attributes
76
+		$attribs = array_map(
77
+			function (Attribute $attr) {
78
+				$oid = $attr->oid();
79
+				if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) {
80
+					$cls = self::MAP_OID_TO_CLASS[$oid];
81
+					return $attr->castValues($cls);
82
+				}
83
+				return $attr;
84
+			}, $attribs);
85
+		return new self(...$attribs);
86
+	}
87 87
     
88
-    /**
89
-     * Check whether extension request attribute is present.
90
-     *
91
-     * @return bool
92
-     */
93
-    public function hasExtensionRequest(): bool
94
-    {
95
-        return $this->has(ExtensionRequestValue::OID);
96
-    }
88
+	/**
89
+	 * Check whether extension request attribute is present.
90
+	 *
91
+	 * @return bool
92
+	 */
93
+	public function hasExtensionRequest(): bool
94
+	{
95
+		return $this->has(ExtensionRequestValue::OID);
96
+	}
97 97
     
98
-    /**
99
-     * Get extension request attribute value.
100
-     *
101
-     * @throws \LogicException
102
-     * @return ExtensionRequestValue
103
-     */
104
-    public function extensionRequest(): ExtensionRequestValue
105
-    {
106
-        if (!$this->hasExtensionRequest()) {
107
-            throw new \LogicException("No extension request attribute.");
108
-        }
109
-        return $this->firstOf(ExtensionRequestValue::OID)->first();
110
-    }
98
+	/**
99
+	 * Get extension request attribute value.
100
+	 *
101
+	 * @throws \LogicException
102
+	 * @return ExtensionRequestValue
103
+	 */
104
+	public function extensionRequest(): ExtensionRequestValue
105
+	{
106
+		if (!$this->hasExtensionRequest()) {
107
+			throw new \LogicException("No extension request attribute.");
108
+		}
109
+		return $this->firstOf(ExtensionRequestValue::OID)->first();
110
+	}
111 111
     
112
-    /**
113
-     * Generate ASN.1 structure.
114
-     *
115
-     * @return Set
116
-     */
117
-    public function toASN1(): Set
118
-    {
119
-        $elements = array_map(
120
-            function (Attribute $attr) {
121
-                return $attr->toASN1();
122
-            }, array_values($this->_attributes));
123
-        $set = new Set(...$elements);
124
-        return $set->sortedSetOf();
125
-    }
112
+	/**
113
+	 * Generate ASN.1 structure.
114
+	 *
115
+	 * @return Set
116
+	 */
117
+	public function toASN1(): Set
118
+	{
119
+		$elements = array_map(
120
+			function (Attribute $attr) {
121
+				return $attr->toASN1();
122
+			}, array_values($this->_attributes));
123
+		$set = new Set(...$elements);
124
+		return $set->sortedSetOf();
125
+	}
126 126
 }
Please login to merge, or discard this patch.
lib/X509/GeneralName/GeneralNames.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -18,183 +18,183 @@
 block discarded – undo
18 18
  */
19 19
 class GeneralNames implements \Countable, \IteratorAggregate
20 20
 {
21
-    /**
22
-     * GeneralName objects.
23
-     *
24
-     * @var GeneralName[] $_names
25
-     */
26
-    protected $_names;
21
+	/**
22
+	 * GeneralName objects.
23
+	 *
24
+	 * @var GeneralName[] $_names
25
+	 */
26
+	protected $_names;
27 27
     
28
-    /**
29
-     * Constructor.
30
-     *
31
-     * @param GeneralName ...$names One or more GeneralName objects
32
-     */
33
-    public function __construct(GeneralName ...$names)
34
-    {
35
-        $this->_names = $names;
36
-    }
28
+	/**
29
+	 * Constructor.
30
+	 *
31
+	 * @param GeneralName ...$names One or more GeneralName objects
32
+	 */
33
+	public function __construct(GeneralName ...$names)
34
+	{
35
+		$this->_names = $names;
36
+	}
37 37
     
38
-    /**
39
-     * Initialize from ASN.1.
40
-     *
41
-     * @param Sequence $seq
42
-     * @throws \UnexpectedValueException
43
-     * @return self
44
-     */
45
-    public static function fromASN1(Sequence $seq): GeneralNames
46
-    {
47
-        if (!count($seq)) {
48
-            throw new \UnexpectedValueException(
49
-                "GeneralNames must have at least one GeneralName.");
50
-        }
51
-        $names = array_map(
52
-            function (UnspecifiedType $el) {
53
-                return GeneralName::fromASN1($el->asTagged());
54
-            }, $seq->elements());
55
-        return new self(...$names);
56
-    }
38
+	/**
39
+	 * Initialize from ASN.1.
40
+	 *
41
+	 * @param Sequence $seq
42
+	 * @throws \UnexpectedValueException
43
+	 * @return self
44
+	 */
45
+	public static function fromASN1(Sequence $seq): GeneralNames
46
+	{
47
+		if (!count($seq)) {
48
+			throw new \UnexpectedValueException(
49
+				"GeneralNames must have at least one GeneralName.");
50
+		}
51
+		$names = array_map(
52
+			function (UnspecifiedType $el) {
53
+				return GeneralName::fromASN1($el->asTagged());
54
+			}, $seq->elements());
55
+		return new self(...$names);
56
+	}
57 57
     
58
-    /**
59
-     * Find first GeneralName by given tag.
60
-     *
61
-     * @param int $tag
62
-     * @return GeneralName|null
63
-     */
64
-    protected function _findFirst(int $tag)
65
-    {
66
-        foreach ($this->_names as $name) {
67
-            if ($name->tag() == $tag) {
68
-                return $name;
69
-            }
70
-        }
71
-        return null;
72
-    }
58
+	/**
59
+	 * Find first GeneralName by given tag.
60
+	 *
61
+	 * @param int $tag
62
+	 * @return GeneralName|null
63
+	 */
64
+	protected function _findFirst(int $tag)
65
+	{
66
+		foreach ($this->_names as $name) {
67
+			if ($name->tag() == $tag) {
68
+				return $name;
69
+			}
70
+		}
71
+		return null;
72
+	}
73 73
     
74
-    /**
75
-     * Check whether GeneralNames contains a GeneralName of given type.
76
-     *
77
-     * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations
78
-     * @return bool
79
-     */
80
-    public function has(int $tag): bool
81
-    {
82
-        return null !== $this->_findFirst($tag);
83
-    }
74
+	/**
75
+	 * Check whether GeneralNames contains a GeneralName of given type.
76
+	 *
77
+	 * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations
78
+	 * @return bool
79
+	 */
80
+	public function has(int $tag): bool
81
+	{
82
+		return null !== $this->_findFirst($tag);
83
+	}
84 84
     
85
-    /**
86
-     * Get first GeneralName of given type.
87
-     *
88
-     * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations
89
-     * @throws \OutOfBoundsException
90
-     * @return GeneralName
91
-     */
92
-    public function firstOf(int $tag): GeneralName
93
-    {
94
-        $name = $this->_findFirst($tag);
95
-        if (!$name) {
96
-            throw new \UnexpectedValueException("No GeneralName by tag $tag.");
97
-        }
98
-        return $name;
99
-    }
85
+	/**
86
+	 * Get first GeneralName of given type.
87
+	 *
88
+	 * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations
89
+	 * @throws \OutOfBoundsException
90
+	 * @return GeneralName
91
+	 */
92
+	public function firstOf(int $tag): GeneralName
93
+	{
94
+		$name = $this->_findFirst($tag);
95
+		if (!$name) {
96
+			throw new \UnexpectedValueException("No GeneralName by tag $tag.");
97
+		}
98
+		return $name;
99
+	}
100 100
     
101
-    /**
102
-     * Get all GeneralName objects of given type.
103
-     *
104
-     * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations
105
-     * @return GeneralName[]
106
-     */
107
-    public function allOf(int $tag): array
108
-    {
109
-        $names = array_filter($this->_names,
110
-            function (GeneralName $name) use ($tag) {
111
-                return $name->tag() == $tag;
112
-            });
113
-        return array_values($names);
114
-    }
101
+	/**
102
+	 * Get all GeneralName objects of given type.
103
+	 *
104
+	 * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations
105
+	 * @return GeneralName[]
106
+	 */
107
+	public function allOf(int $tag): array
108
+	{
109
+		$names = array_filter($this->_names,
110
+			function (GeneralName $name) use ($tag) {
111
+				return $name->tag() == $tag;
112
+			});
113
+		return array_values($names);
114
+	}
115 115
     
116
-    /**
117
-     * Get value of the first 'dNSName' type.
118
-     *
119
-     * @return string
120
-     */
121
-    public function firstDNS(): string
122
-    {
123
-        $gn = $this->firstOf(GeneralName::TAG_DNS_NAME);
124
-        if (!$gn instanceof DNSName) {
125
-            throw new \RuntimeException(
126
-                DNSName::class . " expected, got " . get_class($gn));
127
-        }
128
-        return $gn->name();
129
-    }
116
+	/**
117
+	 * Get value of the first 'dNSName' type.
118
+	 *
119
+	 * @return string
120
+	 */
121
+	public function firstDNS(): string
122
+	{
123
+		$gn = $this->firstOf(GeneralName::TAG_DNS_NAME);
124
+		if (!$gn instanceof DNSName) {
125
+			throw new \RuntimeException(
126
+				DNSName::class . " expected, got " . get_class($gn));
127
+		}
128
+		return $gn->name();
129
+	}
130 130
     
131
-    /**
132
-     * Get value of the first 'directoryName' type.
133
-     *
134
-     * @return Name
135
-     */
136
-    public function firstDN(): Name
137
-    {
138
-        $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME);
139
-        if (!$gn instanceof DirectoryName) {
140
-            throw new \RuntimeException(
141
-                DirectoryName::class . " expected, got " . get_class($gn));
142
-        }
143
-        return $gn->dn();
144
-    }
131
+	/**
132
+	 * Get value of the first 'directoryName' type.
133
+	 *
134
+	 * @return Name
135
+	 */
136
+	public function firstDN(): Name
137
+	{
138
+		$gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME);
139
+		if (!$gn instanceof DirectoryName) {
140
+			throw new \RuntimeException(
141
+				DirectoryName::class . " expected, got " . get_class($gn));
142
+		}
143
+		return $gn->dn();
144
+	}
145 145
     
146
-    /**
147
-     * Get value of the first 'uniformResourceIdentifier' type.
148
-     *
149
-     * @return string
150
-     */
151
-    public function firstURI(): string
152
-    {
153
-        $gn = $this->firstOf(GeneralName::TAG_URI);
154
-        if (!$gn instanceof UniformResourceIdentifier) {
155
-            throw new \RuntimeException(
156
-                UniformResourceIdentifier::class . " expected, got " .
157
-                     get_class($gn));
158
-        }
159
-        return $gn->uri();
160
-    }
146
+	/**
147
+	 * Get value of the first 'uniformResourceIdentifier' type.
148
+	 *
149
+	 * @return string
150
+	 */
151
+	public function firstURI(): string
152
+	{
153
+		$gn = $this->firstOf(GeneralName::TAG_URI);
154
+		if (!$gn instanceof UniformResourceIdentifier) {
155
+			throw new \RuntimeException(
156
+				UniformResourceIdentifier::class . " expected, got " .
157
+					 get_class($gn));
158
+		}
159
+		return $gn->uri();
160
+	}
161 161
     
162
-    /**
163
-     * Generate ASN.1 structure.
164
-     *
165
-     * @return Sequence
166
-     */
167
-    public function toASN1(): Sequence
168
-    {
169
-        if (!count($this->_names)) {
170
-            throw new \LogicException(
171
-                "GeneralNames must have at least one GeneralName.");
172
-        }
173
-        $elements = array_map(
174
-            function (GeneralName $name) {
175
-                return $name->toASN1();
176
-            }, $this->_names);
177
-        return new Sequence(...$elements);
178
-    }
162
+	/**
163
+	 * Generate ASN.1 structure.
164
+	 *
165
+	 * @return Sequence
166
+	 */
167
+	public function toASN1(): Sequence
168
+	{
169
+		if (!count($this->_names)) {
170
+			throw new \LogicException(
171
+				"GeneralNames must have at least one GeneralName.");
172
+		}
173
+		$elements = array_map(
174
+			function (GeneralName $name) {
175
+				return $name->toASN1();
176
+			}, $this->_names);
177
+		return new Sequence(...$elements);
178
+	}
179 179
     
180
-    /**
181
-     *
182
-     * @see \Countable::count()
183
-     * @return int
184
-     */
185
-    public function count(): int
186
-    {
187
-        return count($this->_names);
188
-    }
180
+	/**
181
+	 *
182
+	 * @see \Countable::count()
183
+	 * @return int
184
+	 */
185
+	public function count(): int
186
+	{
187
+		return count($this->_names);
188
+	}
189 189
     
190
-    /**
191
-     * Get iterator for GeneralName objects.
192
-     *
193
-     * @see \IteratorAggregate::getIterator()
194
-     * @return \ArrayIterator
195
-     */
196
-    public function getIterator(): \ArrayIterator
197
-    {
198
-        return new \ArrayIterator($this->_names);
199
-    }
190
+	/**
191
+	 * Get iterator for GeneralName objects.
192
+	 *
193
+	 * @see \IteratorAggregate::getIterator()
194
+	 * @return \ArrayIterator
195
+	 */
196
+	public function getIterator(): \ArrayIterator
197
+	{
198
+		return new \ArrayIterator($this->_names);
199
+	}
200 200
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extensions.php 1 patch
Indentation   +410 added lines, -410 removed lines patch added patch discarded remove patch
@@ -18,414 +18,414 @@
 block discarded – undo
18 18
  */
19 19
 class Extensions implements \Countable, \IteratorAggregate
20 20
 {
21
-    /**
22
-     * Extensions.
23
-     *
24
-     * @var Extension\Extension[] $_extensions
25
-     */
26
-    protected $_extensions;
27
-    
28
-    /**
29
-     * Constructor.
30
-     *
31
-     * @param Ext\Extension ...$extensions Extension objects
32
-     */
33
-    public function __construct(Ext\Extension ...$extensions)
34
-    {
35
-        $this->_extensions = array();
36
-        foreach ($extensions as $ext) {
37
-            $this->_extensions[$ext->oid()] = $ext;
38
-        }
39
-    }
40
-    
41
-    /**
42
-     * Initialize from ASN.1.
43
-     *
44
-     * @param Sequence $seq
45
-     * @return self
46
-     */
47
-    public static function fromASN1(Sequence $seq): Extensions
48
-    {
49
-        $extensions = array_map(
50
-            function (UnspecifiedType $el) {
51
-                return Ext\Extension::fromASN1($el->asSequence());
52
-            }, $seq->elements());
53
-        return new self(...$extensions);
54
-    }
55
-    
56
-    /**
57
-     * Generate ASN.1 structure.
58
-     *
59
-     * @return Sequence
60
-     */
61
-    public function toASN1(): Sequence
62
-    {
63
-        $elements = array_values(
64
-            array_map(
65
-                function ($ext) {
66
-                    return $ext->toASN1();
67
-                }, $this->_extensions));
68
-        return new Sequence(...$elements);
69
-    }
70
-    
71
-    /**
72
-     * Get self with extensions added.
73
-     *
74
-     * @param Ext\Extension ...$exts One or more extensions to add
75
-     * @return self
76
-     */
77
-    public function withExtensions(Ext\Extension ...$exts): Extensions
78
-    {
79
-        $obj = clone $this;
80
-        foreach ($exts as $ext) {
81
-            $obj->_extensions[$ext->oid()] = $ext;
82
-        }
83
-        return $obj;
84
-    }
85
-    
86
-    /**
87
-     * Check whether extension is present.
88
-     *
89
-     * @param string $oid Extensions OID
90
-     * @return bool
91
-     */
92
-    public function has(string $oid): bool
93
-    {
94
-        return isset($this->_extensions[$oid]);
95
-    }
96
-    
97
-    /**
98
-     * Get extension by OID.
99
-     *
100
-     * @param string $oid
101
-     * @throws \LogicException If extension is not present
102
-     * @return Extension\Extension
103
-     */
104
-    public function get(string $oid): Ext\Extension
105
-    {
106
-        if (!$this->has($oid)) {
107
-            throw new \LogicException("No extension by OID $oid.");
108
-        }
109
-        return $this->_extensions[$oid];
110
-    }
111
-    
112
-    /**
113
-     * Check whether 'Authority Key Identifier' extension is present.
114
-     *
115
-     * @return bool
116
-     */
117
-    public function hasAuthorityKeyIdentifier(): bool
118
-    {
119
-        return $this->has(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER);
120
-    }
121
-    
122
-    /**
123
-     * Get 'Authority Key Identifier' extension.
124
-     *
125
-     * @throws \LogicException If extension is not present
126
-     * @return \X509\Certificate\Extension\AuthorityKeyIdentifierExtension
127
-     */
128
-    public function authorityKeyIdentifier(): Ext\AuthorityKeyIdentifierExtension
129
-    {
130
-        /** @var Extension\AuthorityKeyIdentifierExtension $keyIdentifier */
131
-        $keyIdentifier = $this->get(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER);
132
-        return $keyIdentifier;
133
-    }
134
-    
135
-    /**
136
-     * Check whether 'Subject Key Identifier' extension is present.
137
-     *
138
-     * @return bool
139
-     */
140
-    public function hasSubjectKeyIdentifier(): bool
141
-    {
142
-        return $this->has(Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER);
143
-    }
144
-    
145
-    /**
146
-     * Get 'Subject Key Identifier' extension.
147
-     *
148
-     * @throws \LogicException If extension is not present
149
-     * @return \X509\Certificate\Extension\SubjectKeyIdentifierExtension
150
-     */
151
-    public function subjectKeyIdentifier(): Ext\SubjectKeyIdentifierExtension
152
-    {
153
-        /** @var Extension\SubjectKeyIdentifierExtension $subjectKeyIdentifier */
154
-        $subjectKeyIdentifier = $this->get(
155
-            Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER);
156
-        return $subjectKeyIdentifier;
157
-    }
158
-    
159
-    /**
160
-     * Check whether 'Key Usage' extension is present.
161
-     *
162
-     * @return bool
163
-     */
164
-    public function hasKeyUsage(): bool
165
-    {
166
-        return $this->has(Ext\Extension::OID_KEY_USAGE);
167
-    }
168
-    
169
-    /**
170
-     * Get 'Key Usage' extension.
171
-     *
172
-     * @throws \LogicException If extension is not present
173
-     * @return \X509\Certificate\Extension\KeyUsageExtension
174
-     */
175
-    public function keyUsage(): Ext\KeyUsageExtension
176
-    {
177
-        /** @var Extension\KeyUsageExtension $keyUsage */
178
-        $keyUsage = $this->get(Ext\Extension::OID_KEY_USAGE);
179
-        return $keyUsage;
180
-    }
181
-    
182
-    /**
183
-     * Check whether 'Certificate Policies' extension is present.
184
-     *
185
-     * @return bool
186
-     */
187
-    public function hasCertificatePolicies(): bool
188
-    {
189
-        return $this->has(Ext\Extension::OID_CERTIFICATE_POLICIES);
190
-    }
191
-    
192
-    /**
193
-     * Get 'Certificate Policies' extension.
194
-     *
195
-     * @throws \LogicException If extension is not present
196
-     * @return \X509\Certificate\Extension\CertificatePoliciesExtension
197
-     */
198
-    public function certificatePolicies(): Ext\CertificatePoliciesExtension
199
-    {
200
-        /** @var Extension\CertificatePoliciesExtension $certPolicies */
201
-        $certPolicies = $this->get(Ext\Extension::OID_CERTIFICATE_POLICIES);
202
-        return $certPolicies;
203
-    }
204
-    
205
-    /**
206
-     * Check whether 'Policy Mappings' extension is present.
207
-     *
208
-     * @return bool
209
-     */
210
-    public function hasPolicyMappings(): bool
211
-    {
212
-        return $this->has(Ext\Extension::OID_POLICY_MAPPINGS);
213
-    }
214
-    
215
-    /**
216
-     * Get 'Policy Mappings' extension.
217
-     *
218
-     * @throws \LogicException If extension is not present
219
-     * @return \X509\Certificate\Extension\PolicyMappingsExtension
220
-     */
221
-    public function policyMappings(): Ext\PolicyMappingsExtension
222
-    {
223
-        /** @var Extension\PolicyMappingsExtension $policyMappings */
224
-        $policyMappings = $this->get(Ext\Extension::OID_POLICY_MAPPINGS);
225
-        return $policyMappings;
226
-    }
227
-    
228
-    /**
229
-     * Check whether 'Subject Alternative Name' extension is present.
230
-     *
231
-     * @return bool
232
-     */
233
-    public function hasSubjectAlternativeName(): bool
234
-    {
235
-        return $this->has(Ext\Extension::OID_SUBJECT_ALT_NAME);
236
-    }
237
-    
238
-    /**
239
-     * Get 'Subject Alternative Name' extension.
240
-     *
241
-     * @throws \LogicException If extension is not present
242
-     * @return \X509\Certificate\Extension\SubjectAlternativeNameExtension
243
-     */
244
-    public function subjectAlternativeName(): Ext\SubjectAlternativeNameExtension
245
-    {
246
-        /** @var Extension\SubjectAlternativeNameExtension $subjectAltName */
247
-        $subjectAltName = $this->get(Ext\Extension::OID_SUBJECT_ALT_NAME);
248
-        return $subjectAltName;
249
-    }
250
-    
251
-    /**
252
-     * Check whether 'Issuer Alternative Name' extension is present.
253
-     *
254
-     * @return bool
255
-     */
256
-    public function hasIssuerAlternativeName(): bool
257
-    {
258
-        return $this->has(Ext\Extension::OID_ISSUER_ALT_NAME);
259
-    }
260
-    
261
-    /**
262
-     * Get 'Issuer Alternative Name' extension.
263
-     *
264
-     * @return \X509\Certificate\Extension\IssuerAlternativeNameExtension
265
-     */
266
-    public function issuerAlternativeName(): Ext\IssuerAlternativeNameExtension
267
-    {
268
-        /** @var Extension\IssuerAlternativeNameExtension $issuerAltName */
269
-        $issuerAltName = $this->get(Ext\Extension::OID_ISSUER_ALT_NAME);
270
-        return $issuerAltName;
271
-    }
272
-    
273
-    /**
274
-     * Check whether 'Basic Constraints' extension is present.
275
-     *
276
-     * @return bool
277
-     */
278
-    public function hasBasicConstraints(): bool
279
-    {
280
-        return $this->has(Ext\Extension::OID_BASIC_CONSTRAINTS);
281
-    }
282
-    
283
-    /**
284
-     * Get 'Basic Constraints' extension.
285
-     *
286
-     * @throws \LogicException If extension is not present
287
-     * @return \X509\Certificate\Extension\BasicConstraintsExtension
288
-     */
289
-    public function basicConstraints(): Ext\BasicConstraintsExtension
290
-    {
291
-        /** @var Extension\BasicConstraintsExtension $basicConstraints */
292
-        $basicConstraints = $this->get(Ext\Extension::OID_BASIC_CONSTRAINTS);
293
-        return $basicConstraints;
294
-    }
295
-    
296
-    /**
297
-     * Check whether 'Name Constraints' extension is present.
298
-     *
299
-     * @return bool
300
-     */
301
-    public function hasNameConstraints(): bool
302
-    {
303
-        return $this->has(Ext\Extension::OID_NAME_CONSTRAINTS);
304
-    }
305
-    
306
-    /**
307
-     * Get 'Name Constraints' extension.
308
-     *
309
-     * @throws \LogicException If extension is not present
310
-     * @return \X509\Certificate\Extension\NameConstraintsExtension
311
-     */
312
-    public function nameConstraints(): Ext\NameConstraintsExtension
313
-    {
314
-        /** @var Extension\NameConstraintsExtension $nameConstraints */
315
-        $nameConstraints = $this->get(Ext\Extension::OID_NAME_CONSTRAINTS);
316
-        return $nameConstraints;
317
-    }
318
-    
319
-    /**
320
-     * Check whether 'Policy Constraints' extension is present.
321
-     *
322
-     * @return bool
323
-     */
324
-    public function hasPolicyConstraints(): bool
325
-    {
326
-        return $this->has(Ext\Extension::OID_POLICY_CONSTRAINTS);
327
-    }
328
-    
329
-    /**
330
-     * Get 'Policy Constraints' extension.
331
-     *
332
-     * @throws \LogicException If extension is not present
333
-     * @return \X509\Certificate\Extension\PolicyConstraintsExtension
334
-     */
335
-    public function policyConstraints(): Ext\PolicyConstraintsExtension
336
-    {
337
-        /** @var Extension\PolicyConstraintsExtension $policyConstraints */
338
-        $policyConstraints = $this->get(Ext\Extension::OID_POLICY_CONSTRAINTS);
339
-        return $policyConstraints;
340
-    }
341
-    
342
-    /**
343
-     * Check whether 'Extended Key Usage' extension is present.
344
-     *
345
-     * @return bool
346
-     */
347
-    public function hasExtendedKeyUsage(): bool
348
-    {
349
-        return $this->has(Ext\Extension::OID_EXT_KEY_USAGE);
350
-    }
351
-    
352
-    /**
353
-     * Get 'Extended Key Usage' extension.
354
-     *
355
-     * @throws \LogicException If extension is not present
356
-     * @return \X509\Certificate\Extension\ExtendedKeyUsageExtension
357
-     */
358
-    public function extendedKeyUsage(): Ext\ExtendedKeyUsageExtension
359
-    {
360
-        /** @var Extension\ExtendedKeyUsageExtension $keyUsage */
361
-        $keyUsage = $this->get(Ext\Extension::OID_EXT_KEY_USAGE);
362
-        return $keyUsage;
363
-    }
364
-    
365
-    /**
366
-     * Check whether 'CRL Distribution Points' extension is present.
367
-     *
368
-     * @return bool
369
-     */
370
-    public function hasCRLDistributionPoints(): bool
371
-    {
372
-        return $this->has(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS);
373
-    }
374
-    
375
-    /**
376
-     * Get 'CRL Distribution Points' extension.
377
-     *
378
-     * @throws \LogicException If extension is not present
379
-     * @return \X509\Certificate\Extension\CRLDistributionPointsExtension
380
-     */
381
-    public function crlDistributionPoints(): Ext\CRLDistributionPointsExtension
382
-    {
383
-        /** @var Extension\CRLDistributionPointsExtension $crlDist */
384
-        $crlDist = $this->get(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS);
385
-        return $crlDist;
386
-    }
387
-    
388
-    /**
389
-     * Check whether 'Inhibit anyPolicy' extension is present.
390
-     *
391
-     * @return bool
392
-     */
393
-    public function hasInhibitAnyPolicy(): bool
394
-    {
395
-        return $this->has(Ext\Extension::OID_INHIBIT_ANY_POLICY);
396
-    }
397
-    
398
-    /**
399
-     * Get 'Inhibit anyPolicy' extension.
400
-     *
401
-     * @throws \LogicException If extension is not present
402
-     * @return \X509\Certificate\Extension\InhibitAnyPolicyExtension
403
-     */
404
-    public function inhibitAnyPolicy(): Ext\InhibitAnyPolicyExtension
405
-    {
406
-        /** @var Extension\InhibitAnyPolicyExtension $inhibitAny */
407
-        $inhibitAny = $this->get(Ext\Extension::OID_INHIBIT_ANY_POLICY);
408
-        return $inhibitAny;
409
-    }
410
-    
411
-    /**
412
-     *
413
-     * @see \Countable::count()
414
-     * @return int
415
-     */
416
-    public function count(): int
417
-    {
418
-        return count($this->_extensions);
419
-    }
420
-    
421
-    /**
422
-     * Get iterator for extensions.
423
-     *
424
-     * @see \IteratorAggregate::getIterator()
425
-     * @return \Traversable
426
-     */
427
-    public function getIterator(): \Traversable
428
-    {
429
-        return new \ArrayIterator($this->_extensions);
430
-    }
21
+	/**
22
+	 * Extensions.
23
+	 *
24
+	 * @var Extension\Extension[] $_extensions
25
+	 */
26
+	protected $_extensions;
27
+    
28
+	/**
29
+	 * Constructor.
30
+	 *
31
+	 * @param Ext\Extension ...$extensions Extension objects
32
+	 */
33
+	public function __construct(Ext\Extension ...$extensions)
34
+	{
35
+		$this->_extensions = array();
36
+		foreach ($extensions as $ext) {
37
+			$this->_extensions[$ext->oid()] = $ext;
38
+		}
39
+	}
40
+    
41
+	/**
42
+	 * Initialize from ASN.1.
43
+	 *
44
+	 * @param Sequence $seq
45
+	 * @return self
46
+	 */
47
+	public static function fromASN1(Sequence $seq): Extensions
48
+	{
49
+		$extensions = array_map(
50
+			function (UnspecifiedType $el) {
51
+				return Ext\Extension::fromASN1($el->asSequence());
52
+			}, $seq->elements());
53
+		return new self(...$extensions);
54
+	}
55
+    
56
+	/**
57
+	 * Generate ASN.1 structure.
58
+	 *
59
+	 * @return Sequence
60
+	 */
61
+	public function toASN1(): Sequence
62
+	{
63
+		$elements = array_values(
64
+			array_map(
65
+				function ($ext) {
66
+					return $ext->toASN1();
67
+				}, $this->_extensions));
68
+		return new Sequence(...$elements);
69
+	}
70
+    
71
+	/**
72
+	 * Get self with extensions added.
73
+	 *
74
+	 * @param Ext\Extension ...$exts One or more extensions to add
75
+	 * @return self
76
+	 */
77
+	public function withExtensions(Ext\Extension ...$exts): Extensions
78
+	{
79
+		$obj = clone $this;
80
+		foreach ($exts as $ext) {
81
+			$obj->_extensions[$ext->oid()] = $ext;
82
+		}
83
+		return $obj;
84
+	}
85
+    
86
+	/**
87
+	 * Check whether extension is present.
88
+	 *
89
+	 * @param string $oid Extensions OID
90
+	 * @return bool
91
+	 */
92
+	public function has(string $oid): bool
93
+	{
94
+		return isset($this->_extensions[$oid]);
95
+	}
96
+    
97
+	/**
98
+	 * Get extension by OID.
99
+	 *
100
+	 * @param string $oid
101
+	 * @throws \LogicException If extension is not present
102
+	 * @return Extension\Extension
103
+	 */
104
+	public function get(string $oid): Ext\Extension
105
+	{
106
+		if (!$this->has($oid)) {
107
+			throw new \LogicException("No extension by OID $oid.");
108
+		}
109
+		return $this->_extensions[$oid];
110
+	}
111
+    
112
+	/**
113
+	 * Check whether 'Authority Key Identifier' extension is present.
114
+	 *
115
+	 * @return bool
116
+	 */
117
+	public function hasAuthorityKeyIdentifier(): bool
118
+	{
119
+		return $this->has(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER);
120
+	}
121
+    
122
+	/**
123
+	 * Get 'Authority Key Identifier' extension.
124
+	 *
125
+	 * @throws \LogicException If extension is not present
126
+	 * @return \X509\Certificate\Extension\AuthorityKeyIdentifierExtension
127
+	 */
128
+	public function authorityKeyIdentifier(): Ext\AuthorityKeyIdentifierExtension
129
+	{
130
+		/** @var Extension\AuthorityKeyIdentifierExtension $keyIdentifier */
131
+		$keyIdentifier = $this->get(Ext\Extension::OID_AUTHORITY_KEY_IDENTIFIER);
132
+		return $keyIdentifier;
133
+	}
134
+    
135
+	/**
136
+	 * Check whether 'Subject Key Identifier' extension is present.
137
+	 *
138
+	 * @return bool
139
+	 */
140
+	public function hasSubjectKeyIdentifier(): bool
141
+	{
142
+		return $this->has(Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER);
143
+	}
144
+    
145
+	/**
146
+	 * Get 'Subject Key Identifier' extension.
147
+	 *
148
+	 * @throws \LogicException If extension is not present
149
+	 * @return \X509\Certificate\Extension\SubjectKeyIdentifierExtension
150
+	 */
151
+	public function subjectKeyIdentifier(): Ext\SubjectKeyIdentifierExtension
152
+	{
153
+		/** @var Extension\SubjectKeyIdentifierExtension $subjectKeyIdentifier */
154
+		$subjectKeyIdentifier = $this->get(
155
+			Ext\Extension::OID_SUBJECT_KEY_IDENTIFIER);
156
+		return $subjectKeyIdentifier;
157
+	}
158
+    
159
+	/**
160
+	 * Check whether 'Key Usage' extension is present.
161
+	 *
162
+	 * @return bool
163
+	 */
164
+	public function hasKeyUsage(): bool
165
+	{
166
+		return $this->has(Ext\Extension::OID_KEY_USAGE);
167
+	}
168
+    
169
+	/**
170
+	 * Get 'Key Usage' extension.
171
+	 *
172
+	 * @throws \LogicException If extension is not present
173
+	 * @return \X509\Certificate\Extension\KeyUsageExtension
174
+	 */
175
+	public function keyUsage(): Ext\KeyUsageExtension
176
+	{
177
+		/** @var Extension\KeyUsageExtension $keyUsage */
178
+		$keyUsage = $this->get(Ext\Extension::OID_KEY_USAGE);
179
+		return $keyUsage;
180
+	}
181
+    
182
+	/**
183
+	 * Check whether 'Certificate Policies' extension is present.
184
+	 *
185
+	 * @return bool
186
+	 */
187
+	public function hasCertificatePolicies(): bool
188
+	{
189
+		return $this->has(Ext\Extension::OID_CERTIFICATE_POLICIES);
190
+	}
191
+    
192
+	/**
193
+	 * Get 'Certificate Policies' extension.
194
+	 *
195
+	 * @throws \LogicException If extension is not present
196
+	 * @return \X509\Certificate\Extension\CertificatePoliciesExtension
197
+	 */
198
+	public function certificatePolicies(): Ext\CertificatePoliciesExtension
199
+	{
200
+		/** @var Extension\CertificatePoliciesExtension $certPolicies */
201
+		$certPolicies = $this->get(Ext\Extension::OID_CERTIFICATE_POLICIES);
202
+		return $certPolicies;
203
+	}
204
+    
205
+	/**
206
+	 * Check whether 'Policy Mappings' extension is present.
207
+	 *
208
+	 * @return bool
209
+	 */
210
+	public function hasPolicyMappings(): bool
211
+	{
212
+		return $this->has(Ext\Extension::OID_POLICY_MAPPINGS);
213
+	}
214
+    
215
+	/**
216
+	 * Get 'Policy Mappings' extension.
217
+	 *
218
+	 * @throws \LogicException If extension is not present
219
+	 * @return \X509\Certificate\Extension\PolicyMappingsExtension
220
+	 */
221
+	public function policyMappings(): Ext\PolicyMappingsExtension
222
+	{
223
+		/** @var Extension\PolicyMappingsExtension $policyMappings */
224
+		$policyMappings = $this->get(Ext\Extension::OID_POLICY_MAPPINGS);
225
+		return $policyMappings;
226
+	}
227
+    
228
+	/**
229
+	 * Check whether 'Subject Alternative Name' extension is present.
230
+	 *
231
+	 * @return bool
232
+	 */
233
+	public function hasSubjectAlternativeName(): bool
234
+	{
235
+		return $this->has(Ext\Extension::OID_SUBJECT_ALT_NAME);
236
+	}
237
+    
238
+	/**
239
+	 * Get 'Subject Alternative Name' extension.
240
+	 *
241
+	 * @throws \LogicException If extension is not present
242
+	 * @return \X509\Certificate\Extension\SubjectAlternativeNameExtension
243
+	 */
244
+	public function subjectAlternativeName(): Ext\SubjectAlternativeNameExtension
245
+	{
246
+		/** @var Extension\SubjectAlternativeNameExtension $subjectAltName */
247
+		$subjectAltName = $this->get(Ext\Extension::OID_SUBJECT_ALT_NAME);
248
+		return $subjectAltName;
249
+	}
250
+    
251
+	/**
252
+	 * Check whether 'Issuer Alternative Name' extension is present.
253
+	 *
254
+	 * @return bool
255
+	 */
256
+	public function hasIssuerAlternativeName(): bool
257
+	{
258
+		return $this->has(Ext\Extension::OID_ISSUER_ALT_NAME);
259
+	}
260
+    
261
+	/**
262
+	 * Get 'Issuer Alternative Name' extension.
263
+	 *
264
+	 * @return \X509\Certificate\Extension\IssuerAlternativeNameExtension
265
+	 */
266
+	public function issuerAlternativeName(): Ext\IssuerAlternativeNameExtension
267
+	{
268
+		/** @var Extension\IssuerAlternativeNameExtension $issuerAltName */
269
+		$issuerAltName = $this->get(Ext\Extension::OID_ISSUER_ALT_NAME);
270
+		return $issuerAltName;
271
+	}
272
+    
273
+	/**
274
+	 * Check whether 'Basic Constraints' extension is present.
275
+	 *
276
+	 * @return bool
277
+	 */
278
+	public function hasBasicConstraints(): bool
279
+	{
280
+		return $this->has(Ext\Extension::OID_BASIC_CONSTRAINTS);
281
+	}
282
+    
283
+	/**
284
+	 * Get 'Basic Constraints' extension.
285
+	 *
286
+	 * @throws \LogicException If extension is not present
287
+	 * @return \X509\Certificate\Extension\BasicConstraintsExtension
288
+	 */
289
+	public function basicConstraints(): Ext\BasicConstraintsExtension
290
+	{
291
+		/** @var Extension\BasicConstraintsExtension $basicConstraints */
292
+		$basicConstraints = $this->get(Ext\Extension::OID_BASIC_CONSTRAINTS);
293
+		return $basicConstraints;
294
+	}
295
+    
296
+	/**
297
+	 * Check whether 'Name Constraints' extension is present.
298
+	 *
299
+	 * @return bool
300
+	 */
301
+	public function hasNameConstraints(): bool
302
+	{
303
+		return $this->has(Ext\Extension::OID_NAME_CONSTRAINTS);
304
+	}
305
+    
306
+	/**
307
+	 * Get 'Name Constraints' extension.
308
+	 *
309
+	 * @throws \LogicException If extension is not present
310
+	 * @return \X509\Certificate\Extension\NameConstraintsExtension
311
+	 */
312
+	public function nameConstraints(): Ext\NameConstraintsExtension
313
+	{
314
+		/** @var Extension\NameConstraintsExtension $nameConstraints */
315
+		$nameConstraints = $this->get(Ext\Extension::OID_NAME_CONSTRAINTS);
316
+		return $nameConstraints;
317
+	}
318
+    
319
+	/**
320
+	 * Check whether 'Policy Constraints' extension is present.
321
+	 *
322
+	 * @return bool
323
+	 */
324
+	public function hasPolicyConstraints(): bool
325
+	{
326
+		return $this->has(Ext\Extension::OID_POLICY_CONSTRAINTS);
327
+	}
328
+    
329
+	/**
330
+	 * Get 'Policy Constraints' extension.
331
+	 *
332
+	 * @throws \LogicException If extension is not present
333
+	 * @return \X509\Certificate\Extension\PolicyConstraintsExtension
334
+	 */
335
+	public function policyConstraints(): Ext\PolicyConstraintsExtension
336
+	{
337
+		/** @var Extension\PolicyConstraintsExtension $policyConstraints */
338
+		$policyConstraints = $this->get(Ext\Extension::OID_POLICY_CONSTRAINTS);
339
+		return $policyConstraints;
340
+	}
341
+    
342
+	/**
343
+	 * Check whether 'Extended Key Usage' extension is present.
344
+	 *
345
+	 * @return bool
346
+	 */
347
+	public function hasExtendedKeyUsage(): bool
348
+	{
349
+		return $this->has(Ext\Extension::OID_EXT_KEY_USAGE);
350
+	}
351
+    
352
+	/**
353
+	 * Get 'Extended Key Usage' extension.
354
+	 *
355
+	 * @throws \LogicException If extension is not present
356
+	 * @return \X509\Certificate\Extension\ExtendedKeyUsageExtension
357
+	 */
358
+	public function extendedKeyUsage(): Ext\ExtendedKeyUsageExtension
359
+	{
360
+		/** @var Extension\ExtendedKeyUsageExtension $keyUsage */
361
+		$keyUsage = $this->get(Ext\Extension::OID_EXT_KEY_USAGE);
362
+		return $keyUsage;
363
+	}
364
+    
365
+	/**
366
+	 * Check whether 'CRL Distribution Points' extension is present.
367
+	 *
368
+	 * @return bool
369
+	 */
370
+	public function hasCRLDistributionPoints(): bool
371
+	{
372
+		return $this->has(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS);
373
+	}
374
+    
375
+	/**
376
+	 * Get 'CRL Distribution Points' extension.
377
+	 *
378
+	 * @throws \LogicException If extension is not present
379
+	 * @return \X509\Certificate\Extension\CRLDistributionPointsExtension
380
+	 */
381
+	public function crlDistributionPoints(): Ext\CRLDistributionPointsExtension
382
+	{
383
+		/** @var Extension\CRLDistributionPointsExtension $crlDist */
384
+		$crlDist = $this->get(Ext\Extension::OID_CRL_DISTRIBUTION_POINTS);
385
+		return $crlDist;
386
+	}
387
+    
388
+	/**
389
+	 * Check whether 'Inhibit anyPolicy' extension is present.
390
+	 *
391
+	 * @return bool
392
+	 */
393
+	public function hasInhibitAnyPolicy(): bool
394
+	{
395
+		return $this->has(Ext\Extension::OID_INHIBIT_ANY_POLICY);
396
+	}
397
+    
398
+	/**
399
+	 * Get 'Inhibit anyPolicy' extension.
400
+	 *
401
+	 * @throws \LogicException If extension is not present
402
+	 * @return \X509\Certificate\Extension\InhibitAnyPolicyExtension
403
+	 */
404
+	public function inhibitAnyPolicy(): Ext\InhibitAnyPolicyExtension
405
+	{
406
+		/** @var Extension\InhibitAnyPolicyExtension $inhibitAny */
407
+		$inhibitAny = $this->get(Ext\Extension::OID_INHIBIT_ANY_POLICY);
408
+		return $inhibitAny;
409
+	}
410
+    
411
+	/**
412
+	 *
413
+	 * @see \Countable::count()
414
+	 * @return int
415
+	 */
416
+	public function count(): int
417
+	{
418
+		return count($this->_extensions);
419
+	}
420
+    
421
+	/**
422
+	 * Get iterator for extensions.
423
+	 *
424
+	 * @see \IteratorAggregate::getIterator()
425
+	 * @return \Traversable
426
+	 */
427
+	public function getIterator(): \Traversable
428
+	{
429
+		return new \ArrayIterator($this->_extensions);
430
+	}
431 431
 }
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/ObjectDigestInfo.php 1 patch
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -20,92 +20,92 @@
 block discarded – undo
20 20
  */
21 21
 class ObjectDigestInfo
22 22
 {
23
-    const TYPE_PUBLIC_KEY = 0;
24
-    const TYPE_PUBLIC_KEY_CERT = 1;
25
-    const TYPE_OTHER_OBJECT_TYPES = 2;
23
+	const TYPE_PUBLIC_KEY = 0;
24
+	const TYPE_PUBLIC_KEY_CERT = 1;
25
+	const TYPE_OTHER_OBJECT_TYPES = 2;
26 26
     
27
-    /**
28
-     * Object type.
29
-     *
30
-     * @var int $_digestedObjectType
31
-     */
32
-    protected $_digestedObjectType;
27
+	/**
28
+	 * Object type.
29
+	 *
30
+	 * @var int $_digestedObjectType
31
+	 */
32
+	protected $_digestedObjectType;
33 33
     
34
-    /**
35
-     * OID of other object type.
36
-     *
37
-     * @var string|null $_otherObjectTypeID
38
-     */
39
-    protected $_otherObjectTypeID;
34
+	/**
35
+	 * OID of other object type.
36
+	 *
37
+	 * @var string|null $_otherObjectTypeID
38
+	 */
39
+	protected $_otherObjectTypeID;
40 40
     
41
-    /**
42
-     * Digest algorithm.
43
-     *
44
-     * @var AlgorithmIdentifierType $_digestAlgorithm
45
-     */
46
-    protected $_digestAlgorithm;
41
+	/**
42
+	 * Digest algorithm.
43
+	 *
44
+	 * @var AlgorithmIdentifierType $_digestAlgorithm
45
+	 */
46
+	protected $_digestAlgorithm;
47 47
     
48
-    /**
49
-     * Object digest.
50
-     *
51
-     * @var BitString $_objectDigest
52
-     */
53
-    protected $_objectDigest;
48
+	/**
49
+	 * Object digest.
50
+	 *
51
+	 * @var BitString $_objectDigest
52
+	 */
53
+	protected $_objectDigest;
54 54
     
55
-    /**
56
-     * Constructor.
57
-     *
58
-     * @param int $type
59
-     * @param AlgorithmIdentifierType $algo
60
-     * @param BitString $digest
61
-     */
62
-    public function __construct(int $type, AlgorithmIdentifierType $algo,
63
-        BitString $digest)
64
-    {
65
-        $this->_digestedObjectType = $type;
66
-        $this->_otherObjectTypeID = null;
67
-        $this->_digestAlgorithm = $algo;
68
-        $this->_objectDigest = $digest;
69
-    }
55
+	/**
56
+	 * Constructor.
57
+	 *
58
+	 * @param int $type
59
+	 * @param AlgorithmIdentifierType $algo
60
+	 * @param BitString $digest
61
+	 */
62
+	public function __construct(int $type, AlgorithmIdentifierType $algo,
63
+		BitString $digest)
64
+	{
65
+		$this->_digestedObjectType = $type;
66
+		$this->_otherObjectTypeID = null;
67
+		$this->_digestAlgorithm = $algo;
68
+		$this->_objectDigest = $digest;
69
+	}
70 70
     
71
-    /**
72
-     * Initialize from ASN.1.
73
-     *
74
-     * @param Sequence $seq
75
-     * @return self
76
-     */
77
-    public static function fromASN1(Sequence $seq): ObjectDigestInfo
78
-    {
79
-        $type = $seq->at(0)
80
-            ->asEnumerated()
81
-            ->intNumber();
82
-        $oid = null;
83
-        $idx = 1;
84
-        if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) {
85
-            $oid = $seq->at($idx++)
86
-                ->asObjectIdentifier()
87
-                ->oid();
88
-        }
89
-        $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
90
-        $digest = $seq->at($idx)->asBitString();
91
-        $obj = new self($type, $algo, $digest);
92
-        $obj->_otherObjectTypeID = $oid;
93
-        return $obj;
94
-    }
71
+	/**
72
+	 * Initialize from ASN.1.
73
+	 *
74
+	 * @param Sequence $seq
75
+	 * @return self
76
+	 */
77
+	public static function fromASN1(Sequence $seq): ObjectDigestInfo
78
+	{
79
+		$type = $seq->at(0)
80
+			->asEnumerated()
81
+			->intNumber();
82
+		$oid = null;
83
+		$idx = 1;
84
+		if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) {
85
+			$oid = $seq->at($idx++)
86
+				->asObjectIdentifier()
87
+				->oid();
88
+		}
89
+		$algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
90
+		$digest = $seq->at($idx)->asBitString();
91
+		$obj = new self($type, $algo, $digest);
92
+		$obj->_otherObjectTypeID = $oid;
93
+		return $obj;
94
+	}
95 95
     
96
-    /**
97
-     * Generate ASN.1 structure.
98
-     *
99
-     * @return Sequence
100
-     */
101
-    public function toASN1(): Sequence
102
-    {
103
-        $elements = array(new Enumerated($this->_digestedObjectType));
104
-        if (isset($this->_otherObjectTypeID)) {
105
-            $elements[] = new ObjectIdentifier($this->_otherObjectTypeID);
106
-        }
107
-        $elements[] = $this->_digestAlgorithm->toASN1();
108
-        $elements[] = $this->_objectDigest;
109
-        return new Sequence(...$elements);
110
-    }
96
+	/**
97
+	 * Generate ASN.1 structure.
98
+	 *
99
+	 * @return Sequence
100
+	 */
101
+	public function toASN1(): Sequence
102
+	{
103
+		$elements = array(new Enumerated($this->_digestedObjectType));
104
+		if (isset($this->_otherObjectTypeID)) {
105
+			$elements[] = new ObjectIdentifier($this->_otherObjectTypeID);
106
+		}
107
+		$elements[] = $this->_digestAlgorithm->toASN1();
108
+		$elements[] = $this->_objectDigest;
109
+		return new Sequence(...$elements);
110
+	}
111 111
 }
Please login to merge, or discard this patch.
lib/X509/AttributeCertificate/IssuerSerial.php 1 patch
Indentation   +156 added lines, -156 removed lines patch added patch discarded remove patch
@@ -19,172 +19,172 @@
 block discarded – undo
19 19
  */
20 20
 class IssuerSerial
21 21
 {
22
-    /**
23
-     * Issuer name.
24
-     *
25
-     * @var GeneralNames $_issuer
26
-     */
27
-    protected $_issuer;
22
+	/**
23
+	 * Issuer name.
24
+	 *
25
+	 * @var GeneralNames $_issuer
26
+	 */
27
+	protected $_issuer;
28 28
     
29
-    /**
30
-     * Serial number.
31
-     *
32
-     * @var string $_serial
33
-     */
34
-    protected $_serial;
29
+	/**
30
+	 * Serial number.
31
+	 *
32
+	 * @var string $_serial
33
+	 */
34
+	protected $_serial;
35 35
     
36
-    /**
37
-     * Issuer unique ID.
38
-     *
39
-     * @var UniqueIdentifier|null $_issuerUID
40
-     */
41
-    protected $_issuerUID;
36
+	/**
37
+	 * Issuer unique ID.
38
+	 *
39
+	 * @var UniqueIdentifier|null $_issuerUID
40
+	 */
41
+	protected $_issuerUID;
42 42
     
43
-    /**
44
-     * Constructor.
45
-     *
46
-     * @param GeneralNames $issuer
47
-     * @param string|int $serial
48
-     * @param UniqueIdentifier|null $uid
49
-     */
50
-    public function __construct(GeneralNames $issuer, $serial,
51
-        UniqueIdentifier $uid = null)
52
-    {
53
-        $this->_issuer = $issuer;
54
-        $this->_serial = strval($serial);
55
-        $this->_issuerUID = $uid;
56
-    }
43
+	/**
44
+	 * Constructor.
45
+	 *
46
+	 * @param GeneralNames $issuer
47
+	 * @param string|int $serial
48
+	 * @param UniqueIdentifier|null $uid
49
+	 */
50
+	public function __construct(GeneralNames $issuer, $serial,
51
+		UniqueIdentifier $uid = null)
52
+	{
53
+		$this->_issuer = $issuer;
54
+		$this->_serial = strval($serial);
55
+		$this->_issuerUID = $uid;
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): IssuerSerial
65
-    {
66
-        $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence());
67
-        $serial = $seq->at(1)
68
-            ->asInteger()
69
-            ->number();
70
-        $uid = null;
71
-        if ($seq->has(2, Element::TYPE_BIT_STRING)) {
72
-            $uid = UniqueIdentifier::fromASN1($seq->at(2)->asBitString());
73
-        }
74
-        return new self($issuer, $serial, $uid);
75
-    }
58
+	/**
59
+	 * Initialize from ASN.1.
60
+	 *
61
+	 * @param Sequence $seq
62
+	 * @return self
63
+	 */
64
+	public static function fromASN1(Sequence $seq): IssuerSerial
65
+	{
66
+		$issuer = GeneralNames::fromASN1($seq->at(0)->asSequence());
67
+		$serial = $seq->at(1)
68
+			->asInteger()
69
+			->number();
70
+		$uid = null;
71
+		if ($seq->has(2, Element::TYPE_BIT_STRING)) {
72
+			$uid = UniqueIdentifier::fromASN1($seq->at(2)->asBitString());
73
+		}
74
+		return new self($issuer, $serial, $uid);
75
+	}
76 76
     
77
-    /**
78
-     * Initialize from a public key certificate.
79
-     *
80
-     * @param Certificate $cert
81
-     * @return self
82
-     */
83
-    public static function fromPKC(Certificate $cert): IssuerSerial
84
-    {
85
-        $tbsCert = $cert->tbsCertificate();
86
-        $issuer = new GeneralNames(new DirectoryName($tbsCert->issuer()));
87
-        $serial = $tbsCert->serialNumber();
88
-        $uid = $tbsCert->hasIssuerUniqueID() ? $tbsCert->issuerUniqueID() : null;
89
-        return new self($issuer, $serial, $uid);
90
-    }
77
+	/**
78
+	 * Initialize from a public key certificate.
79
+	 *
80
+	 * @param Certificate $cert
81
+	 * @return self
82
+	 */
83
+	public static function fromPKC(Certificate $cert): IssuerSerial
84
+	{
85
+		$tbsCert = $cert->tbsCertificate();
86
+		$issuer = new GeneralNames(new DirectoryName($tbsCert->issuer()));
87
+		$serial = $tbsCert->serialNumber();
88
+		$uid = $tbsCert->hasIssuerUniqueID() ? $tbsCert->issuerUniqueID() : null;
89
+		return new self($issuer, $serial, $uid);
90
+	}
91 91
     
92
-    /**
93
-     * Get issuer name.
94
-     *
95
-     * @return GeneralNames
96
-     */
97
-    public function issuer(): GeneralNames
98
-    {
99
-        return $this->_issuer;
100
-    }
92
+	/**
93
+	 * Get issuer name.
94
+	 *
95
+	 * @return GeneralNames
96
+	 */
97
+	public function issuer(): GeneralNames
98
+	{
99
+		return $this->_issuer;
100
+	}
101 101
     
102
-    /**
103
-     * Get serial number.
104
-     *
105
-     * @return string
106
-     */
107
-    public function serial(): string
108
-    {
109
-        return $this->_serial;
110
-    }
102
+	/**
103
+	 * Get serial number.
104
+	 *
105
+	 * @return string
106
+	 */
107
+	public function serial(): string
108
+	{
109
+		return $this->_serial;
110
+	}
111 111
     
112
-    /**
113
-     * Check whether issuer unique identifier is present.
114
-     *
115
-     * @return bool
116
-     */
117
-    public function hasIssuerUID(): bool
118
-    {
119
-        return isset($this->_issuerUID);
120
-    }
112
+	/**
113
+	 * Check whether issuer unique identifier is present.
114
+	 *
115
+	 * @return bool
116
+	 */
117
+	public function hasIssuerUID(): bool
118
+	{
119
+		return isset($this->_issuerUID);
120
+	}
121 121
     
122
-    /**
123
-     * Get issuer unique identifier.
124
-     *
125
-     * @throws \LogicException
126
-     * @return UniqueIdentifier
127
-     */
128
-    public function issuerUID(): UniqueIdentifier
129
-    {
130
-        if (!$this->hasIssuerUID()) {
131
-            throw new \LogicException("issuerUID not set.");
132
-        }
133
-        return $this->_issuerUID;
134
-    }
122
+	/**
123
+	 * Get issuer unique identifier.
124
+	 *
125
+	 * @throws \LogicException
126
+	 * @return UniqueIdentifier
127
+	 */
128
+	public function issuerUID(): UniqueIdentifier
129
+	{
130
+		if (!$this->hasIssuerUID()) {
131
+			throw new \LogicException("issuerUID not set.");
132
+		}
133
+		return $this->_issuerUID;
134
+	}
135 135
     
136
-    /**
137
-     * Generate ASN.1 structure.
138
-     *
139
-     * @return Sequence
140
-     */
141
-    public function toASN1(): Sequence
142
-    {
143
-        $elements = array($this->_issuer->toASN1(), new Integer($this->_serial));
144
-        if (isset($this->_issuerUID)) {
145
-            $elements[] = $this->_issuerUID->toASN1();
146
-        }
147
-        return new Sequence(...$elements);
148
-    }
136
+	/**
137
+	 * Generate ASN.1 structure.
138
+	 *
139
+	 * @return Sequence
140
+	 */
141
+	public function toASN1(): Sequence
142
+	{
143
+		$elements = array($this->_issuer->toASN1(), new Integer($this->_serial));
144
+		if (isset($this->_issuerUID)) {
145
+			$elements[] = $this->_issuerUID->toASN1();
146
+		}
147
+		return new Sequence(...$elements);
148
+	}
149 149
     
150
-    /**
151
-     * Check whether this IssuerSerial identifies given certificate.
152
-     *
153
-     * @param Certificate $cert
154
-     * @return boolean
155
-     */
156
-    public function identifiesPKC(Certificate $cert): bool
157
-    {
158
-        $tbs = $cert->tbsCertificate();
159
-        if (!$tbs->issuer()->equals($this->_issuer->firstDN())) {
160
-            return false;
161
-        }
162
-        if (strval($tbs->serialNumber()) != strval($this->_serial)) {
163
-            return false;
164
-        }
165
-        if ($this->_issuerUID && !$this->_checkUniqueID($cert)) {
166
-            return false;
167
-        }
168
-        return true;
169
-    }
150
+	/**
151
+	 * Check whether this IssuerSerial identifies given certificate.
152
+	 *
153
+	 * @param Certificate $cert
154
+	 * @return boolean
155
+	 */
156
+	public function identifiesPKC(Certificate $cert): bool
157
+	{
158
+		$tbs = $cert->tbsCertificate();
159
+		if (!$tbs->issuer()->equals($this->_issuer->firstDN())) {
160
+			return false;
161
+		}
162
+		if (strval($tbs->serialNumber()) != strval($this->_serial)) {
163
+			return false;
164
+		}
165
+		if ($this->_issuerUID && !$this->_checkUniqueID($cert)) {
166
+			return false;
167
+		}
168
+		return true;
169
+	}
170 170
     
171
-    /**
172
-     * Check whether issuerUID matches given certificate.
173
-     *
174
-     * @param Certificate $cert
175
-     * @return boolean
176
-     */
177
-    private function _checkUniqueID(Certificate $cert): bool
178
-    {
179
-        if (!$cert->tbsCertificate()->hasIssuerUniqueID()) {
180
-            return false;
181
-        }
182
-        $uid = $cert->tbsCertificate()
183
-            ->issuerUniqueID()
184
-            ->string();
185
-        if ($this->_issuerUID->string() != $uid) {
186
-            return false;
187
-        }
188
-        return true;
189
-    }
171
+	/**
172
+	 * Check whether issuerUID matches given certificate.
173
+	 *
174
+	 * @param Certificate $cert
175
+	 * @return boolean
176
+	 */
177
+	private function _checkUniqueID(Certificate $cert): bool
178
+	{
179
+		if (!$cert->tbsCertificate()->hasIssuerUniqueID()) {
180
+			return false;
181
+		}
182
+		$uid = $cert->tbsCertificate()
183
+			->issuerUniqueID()
184
+			->string();
185
+		if ($this->_issuerUID->string() != $uid) {
186
+			return false;
187
+		}
188
+		return true;
189
+	}
190 190
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Certificate.php 1 patch
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -20,235 +20,235 @@
 block discarded – undo
20 20
  */
21 21
 class Certificate
22 22
 {
23
-    /**
24
-     * "To be signed" certificate information.
25
-     *
26
-     * @var TBSCertificate $_tbsCertificate
27
-     */
28
-    protected $_tbsCertificate;
29
-    
30
-    /**
31
-     * Signature algorithm.
32
-     *
33
-     * @var SignatureAlgorithmIdentifier $_signatureAlgorithm
34
-     */
35
-    protected $_signatureAlgorithm;
36
-    
37
-    /**
38
-     * Signature value.
39
-     *
40
-     * @var Signature $_signatureValue
41
-     */
42
-    protected $_signatureValue;
43
-    
44
-    /**
45
-     * Constructor.
46
-     *
47
-     * @param TBSCertificate $tbsCert
48
-     * @param SignatureAlgorithmIdentifier $algo
49
-     * @param Signature $signature
50
-     */
51
-    public function __construct(TBSCertificate $tbsCert,
52
-        SignatureAlgorithmIdentifier $algo, Signature $signature)
53
-    {
54
-        $this->_tbsCertificate = $tbsCert;
55
-        $this->_signatureAlgorithm = $algo;
56
-        $this->_signatureValue = $signature;
57
-    }
58
-    
59
-    /**
60
-     * Initialize from ASN.1.
61
-     *
62
-     * @param Sequence $seq
63
-     * @return self
64
-     */
65
-    public static function fromASN1(Sequence $seq): self
66
-    {
67
-        $tbsCert = TBSCertificate::fromASN1($seq->at(0)->asSequence());
68
-        $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence());
69
-        if (!$algo instanceof SignatureAlgorithmIdentifier) {
70
-            throw new \UnexpectedValueException(
71
-                "Unsupported signature algorithm " . $algo->oid() . ".");
72
-        }
73
-        $signature = Signature::fromSignatureData(
74
-            $seq->at(2)
75
-                ->asBitString()
76
-                ->string(), $algo);
77
-        return new self($tbsCert, $algo, $signature);
78
-    }
79
-    
80
-    /**
81
-     * Initialize from DER.
82
-     *
83
-     * @param string $data
84
-     * @return self
85
-     */
86
-    public static function fromDER(string $data): self
87
-    {
88
-        return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence());
89
-    }
90
-    
91
-    /**
92
-     * Initialize from PEM.
93
-     *
94
-     * @param PEM $pem
95
-     * @throws \UnexpectedValueException
96
-     * @return self
97
-     */
98
-    public static function fromPEM(PEM $pem): self
99
-    {
100
-        if ($pem->type() != PEM::TYPE_CERTIFICATE) {
101
-            throw new \UnexpectedValueException("Invalid PEM type.");
102
-        }
103
-        return self::fromDER($pem->data());
104
-    }
105
-    
106
-    /**
107
-     * Get certificate information.
108
-     *
109
-     * @return TBSCertificate
110
-     */
111
-    public function tbsCertificate(): TBSCertificate
112
-    {
113
-        return $this->_tbsCertificate;
114
-    }
115
-    
116
-    /**
117
-     * Get signature algorithm.
118
-     *
119
-     * @return SignatureAlgorithmIdentifier
120
-     */
121
-    public function signatureAlgorithm(): SignatureAlgorithmIdentifier
122
-    {
123
-        return $this->_signatureAlgorithm;
124
-    }
125
-    
126
-    /**
127
-     * Get signature value.
128
-     *
129
-     * @return Signature
130
-     */
131
-    public function signatureValue(): Signature
132
-    {
133
-        return $this->_signatureValue;
134
-    }
135
-    
136
-    /**
137
-     * Check whether certificate is self-issued.
138
-     *
139
-     * @return bool
140
-     */
141
-    public function isSelfIssued(): bool
142
-    {
143
-        return $this->_tbsCertificate->subject()->equals(
144
-            $this->_tbsCertificate->issuer());
145
-    }
146
-    
147
-    /**
148
-     * Check whether certificate is semantically equal to another.
149
-     *
150
-     * @param Certificate $cert Certificate to compare to
151
-     * @return bool
152
-     */
153
-    public function equals(Certificate $cert): bool
154
-    {
155
-        return $this->_hasEqualSerialNumber($cert) &&
156
-             $this->_hasEqualPublicKey($cert) && $this->_hasEqualSubject($cert);
157
-    }
158
-    
159
-    /**
160
-     * Check whether certificate has serial number equal to another.
161
-     *
162
-     * @param Certificate $cert
163
-     * @return bool
164
-     */
165
-    private function _hasEqualSerialNumber(Certificate $cert): bool
166
-    {
167
-        $sn1 = $this->_tbsCertificate->serialNumber();
168
-        $sn2 = $cert->_tbsCertificate->serialNumber();
169
-        return $sn1 == $sn2;
170
-    }
171
-    
172
-    /**
173
-     * Check whether certificate has public key equal to another.
174
-     *
175
-     * @param Certificate $cert
176
-     * @return bool
177
-     */
178
-    private function _hasEqualPublicKey(Certificate $cert): bool
179
-    {
180
-        $kid1 = $this->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier();
181
-        $kid2 = $cert->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier();
182
-        return $kid1 == $kid2;
183
-    }
184
-    
185
-    /**
186
-     * Check whether certificate has subject equal to another.
187
-     *
188
-     * @param Certificate $cert
189
-     * @return bool
190
-     */
191
-    private function _hasEqualSubject(Certificate $cert): bool
192
-    {
193
-        $dn1 = $this->_tbsCertificate->subject();
194
-        $dn2 = $cert->_tbsCertificate->subject();
195
-        return $dn1->equals($dn2);
196
-    }
197
-    
198
-    /**
199
-     * Generate ASN.1 structure.
200
-     *
201
-     * @return Sequence
202
-     */
203
-    public function toASN1(): Sequence
204
-    {
205
-        return new Sequence($this->_tbsCertificate->toASN1(),
206
-            $this->_signatureAlgorithm->toASN1(),
207
-            $this->_signatureValue->bitString());
208
-    }
209
-    
210
-    /**
211
-     * Get certificate as a DER.
212
-     *
213
-     * @return string
214
-     */
215
-    public function toDER(): string
216
-    {
217
-        return $this->toASN1()->toDER();
218
-    }
219
-    
220
-    /**
221
-     * Get certificate as a PEM.
222
-     *
223
-     * @return PEM
224
-     */
225
-    public function toPEM(): PEM
226
-    {
227
-        return new PEM(PEM::TYPE_CERTIFICATE, $this->toDER());
228
-    }
229
-    
230
-    /**
231
-     * Verify certificate signature.
232
-     *
233
-     * @param PublicKeyInfo $pubkey_info Issuer's public key
234
-     * @param Crypto|null $crypto Crypto engine, use default if not set
235
-     * @return bool True if certificate signature is valid
236
-     */
237
-    public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool
238
-    {
239
-        $crypto = $crypto ?: Crypto::getDefault();
240
-        $data = $this->_tbsCertificate->toASN1()->toDER();
241
-        return $crypto->verify($data, $this->_signatureValue, $pubkey_info,
242
-            $this->_signatureAlgorithm);
243
-    }
244
-    
245
-    /**
246
-     * Get certificate as a PEM formatted string.
247
-     *
248
-     * @return string
249
-     */
250
-    public function __toString()
251
-    {
252
-        return $this->toPEM()->string();
253
-    }
23
+	/**
24
+	 * "To be signed" certificate information.
25
+	 *
26
+	 * @var TBSCertificate $_tbsCertificate
27
+	 */
28
+	protected $_tbsCertificate;
29
+    
30
+	/**
31
+	 * Signature algorithm.
32
+	 *
33
+	 * @var SignatureAlgorithmIdentifier $_signatureAlgorithm
34
+	 */
35
+	protected $_signatureAlgorithm;
36
+    
37
+	/**
38
+	 * Signature value.
39
+	 *
40
+	 * @var Signature $_signatureValue
41
+	 */
42
+	protected $_signatureValue;
43
+    
44
+	/**
45
+	 * Constructor.
46
+	 *
47
+	 * @param TBSCertificate $tbsCert
48
+	 * @param SignatureAlgorithmIdentifier $algo
49
+	 * @param Signature $signature
50
+	 */
51
+	public function __construct(TBSCertificate $tbsCert,
52
+		SignatureAlgorithmIdentifier $algo, Signature $signature)
53
+	{
54
+		$this->_tbsCertificate = $tbsCert;
55
+		$this->_signatureAlgorithm = $algo;
56
+		$this->_signatureValue = $signature;
57
+	}
58
+    
59
+	/**
60
+	 * Initialize from ASN.1.
61
+	 *
62
+	 * @param Sequence $seq
63
+	 * @return self
64
+	 */
65
+	public static function fromASN1(Sequence $seq): self
66
+	{
67
+		$tbsCert = TBSCertificate::fromASN1($seq->at(0)->asSequence());
68
+		$algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence());
69
+		if (!$algo instanceof SignatureAlgorithmIdentifier) {
70
+			throw new \UnexpectedValueException(
71
+				"Unsupported signature algorithm " . $algo->oid() . ".");
72
+		}
73
+		$signature = Signature::fromSignatureData(
74
+			$seq->at(2)
75
+				->asBitString()
76
+				->string(), $algo);
77
+		return new self($tbsCert, $algo, $signature);
78
+	}
79
+    
80
+	/**
81
+	 * Initialize from DER.
82
+	 *
83
+	 * @param string $data
84
+	 * @return self
85
+	 */
86
+	public static function fromDER(string $data): self
87
+	{
88
+		return self::fromASN1(UnspecifiedType::fromDER($data)->asSequence());
89
+	}
90
+    
91
+	/**
92
+	 * Initialize from PEM.
93
+	 *
94
+	 * @param PEM $pem
95
+	 * @throws \UnexpectedValueException
96
+	 * @return self
97
+	 */
98
+	public static function fromPEM(PEM $pem): self
99
+	{
100
+		if ($pem->type() != PEM::TYPE_CERTIFICATE) {
101
+			throw new \UnexpectedValueException("Invalid PEM type.");
102
+		}
103
+		return self::fromDER($pem->data());
104
+	}
105
+    
106
+	/**
107
+	 * Get certificate information.
108
+	 *
109
+	 * @return TBSCertificate
110
+	 */
111
+	public function tbsCertificate(): TBSCertificate
112
+	{
113
+		return $this->_tbsCertificate;
114
+	}
115
+    
116
+	/**
117
+	 * Get signature algorithm.
118
+	 *
119
+	 * @return SignatureAlgorithmIdentifier
120
+	 */
121
+	public function signatureAlgorithm(): SignatureAlgorithmIdentifier
122
+	{
123
+		return $this->_signatureAlgorithm;
124
+	}
125
+    
126
+	/**
127
+	 * Get signature value.
128
+	 *
129
+	 * @return Signature
130
+	 */
131
+	public function signatureValue(): Signature
132
+	{
133
+		return $this->_signatureValue;
134
+	}
135
+    
136
+	/**
137
+	 * Check whether certificate is self-issued.
138
+	 *
139
+	 * @return bool
140
+	 */
141
+	public function isSelfIssued(): bool
142
+	{
143
+		return $this->_tbsCertificate->subject()->equals(
144
+			$this->_tbsCertificate->issuer());
145
+	}
146
+    
147
+	/**
148
+	 * Check whether certificate is semantically equal to another.
149
+	 *
150
+	 * @param Certificate $cert Certificate to compare to
151
+	 * @return bool
152
+	 */
153
+	public function equals(Certificate $cert): bool
154
+	{
155
+		return $this->_hasEqualSerialNumber($cert) &&
156
+			 $this->_hasEqualPublicKey($cert) && $this->_hasEqualSubject($cert);
157
+	}
158
+    
159
+	/**
160
+	 * Check whether certificate has serial number equal to another.
161
+	 *
162
+	 * @param Certificate $cert
163
+	 * @return bool
164
+	 */
165
+	private function _hasEqualSerialNumber(Certificate $cert): bool
166
+	{
167
+		$sn1 = $this->_tbsCertificate->serialNumber();
168
+		$sn2 = $cert->_tbsCertificate->serialNumber();
169
+		return $sn1 == $sn2;
170
+	}
171
+    
172
+	/**
173
+	 * Check whether certificate has public key equal to another.
174
+	 *
175
+	 * @param Certificate $cert
176
+	 * @return bool
177
+	 */
178
+	private function _hasEqualPublicKey(Certificate $cert): bool
179
+	{
180
+		$kid1 = $this->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier();
181
+		$kid2 = $cert->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier();
182
+		return $kid1 == $kid2;
183
+	}
184
+    
185
+	/**
186
+	 * Check whether certificate has subject equal to another.
187
+	 *
188
+	 * @param Certificate $cert
189
+	 * @return bool
190
+	 */
191
+	private function _hasEqualSubject(Certificate $cert): bool
192
+	{
193
+		$dn1 = $this->_tbsCertificate->subject();
194
+		$dn2 = $cert->_tbsCertificate->subject();
195
+		return $dn1->equals($dn2);
196
+	}
197
+    
198
+	/**
199
+	 * Generate ASN.1 structure.
200
+	 *
201
+	 * @return Sequence
202
+	 */
203
+	public function toASN1(): Sequence
204
+	{
205
+		return new Sequence($this->_tbsCertificate->toASN1(),
206
+			$this->_signatureAlgorithm->toASN1(),
207
+			$this->_signatureValue->bitString());
208
+	}
209
+    
210
+	/**
211
+	 * Get certificate as a DER.
212
+	 *
213
+	 * @return string
214
+	 */
215
+	public function toDER(): string
216
+	{
217
+		return $this->toASN1()->toDER();
218
+	}
219
+    
220
+	/**
221
+	 * Get certificate as a PEM.
222
+	 *
223
+	 * @return PEM
224
+	 */
225
+	public function toPEM(): PEM
226
+	{
227
+		return new PEM(PEM::TYPE_CERTIFICATE, $this->toDER());
228
+	}
229
+    
230
+	/**
231
+	 * Verify certificate signature.
232
+	 *
233
+	 * @param PublicKeyInfo $pubkey_info Issuer's public key
234
+	 * @param Crypto|null $crypto Crypto engine, use default if not set
235
+	 * @return bool True if certificate signature is valid
236
+	 */
237
+	public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null): bool
238
+	{
239
+		$crypto = $crypto ?: Crypto::getDefault();
240
+		$data = $this->_tbsCertificate->toASN1()->toDER();
241
+		return $crypto->verify($data, $this->_signatureValue, $pubkey_info,
242
+			$this->_signatureAlgorithm);
243
+	}
244
+    
245
+	/**
246
+	 * Get certificate as a PEM formatted string.
247
+	 *
248
+	 * @return string
249
+	 */
250
+	public function __toString()
251
+	{
252
+		return $this->toPEM()->string();
253
+	}
254 254
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/PolicyMappingsExtension.php 1 patch
Indentation   +155 added lines, -155 removed lines patch added patch discarded remove patch
@@ -15,170 +15,170 @@
 block discarded – undo
15 15
  * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.5
16 16
  */
17 17
 class PolicyMappingsExtension extends Extension implements 
18
-    \Countable,
19
-    \IteratorAggregate
18
+	\Countable,
19
+	\IteratorAggregate
20 20
 {
21
-    /**
22
-     * Policy mappings.
23
-     *
24
-     * @var PolicyMapping[] $_mappings
25
-     */
26
-    protected $_mappings;
21
+	/**
22
+	 * Policy mappings.
23
+	 *
24
+	 * @var PolicyMapping[] $_mappings
25
+	 */
26
+	protected $_mappings;
27 27
     
28
-    /**
29
-     * Constructor.
30
-     *
31
-     * @param bool $critical
32
-     * @param PolicyMapping ...$mappings One or more PolicyMapping objects
33
-     */
34
-    public function __construct(bool $critical, PolicyMapping ...$mappings)
35
-    {
36
-        parent::__construct(self::OID_POLICY_MAPPINGS, $critical);
37
-        $this->_mappings = $mappings;
38
-    }
28
+	/**
29
+	 * Constructor.
30
+	 *
31
+	 * @param bool $critical
32
+	 * @param PolicyMapping ...$mappings One or more PolicyMapping objects
33
+	 */
34
+	public function __construct(bool $critical, PolicyMapping ...$mappings)
35
+	{
36
+		parent::__construct(self::OID_POLICY_MAPPINGS, $critical);
37
+		$this->_mappings = $mappings;
38
+	}
39 39
     
40
-    /**
41
-     *
42
-     * {@inheritdoc}
43
-     * @return self
44
-     */
45
-    protected static function _fromDER(string $data, bool $critical): self
46
-    {
47
-        $mappings = array_map(
48
-            function (UnspecifiedType $el) {
49
-                return PolicyMapping::fromASN1($el->asSequence());
50
-            }, UnspecifiedType::fromDER($data)->asSequence()->elements());
51
-        if (!count($mappings)) {
52
-            throw new \UnexpectedValueException(
53
-                "PolicyMappings must have at least one mapping.");
54
-        }
55
-        return new self($critical, ...$mappings);
56
-    }
40
+	/**
41
+	 *
42
+	 * {@inheritdoc}
43
+	 * @return self
44
+	 */
45
+	protected static function _fromDER(string $data, bool $critical): self
46
+	{
47
+		$mappings = array_map(
48
+			function (UnspecifiedType $el) {
49
+				return PolicyMapping::fromASN1($el->asSequence());
50
+			}, UnspecifiedType::fromDER($data)->asSequence()->elements());
51
+		if (!count($mappings)) {
52
+			throw new \UnexpectedValueException(
53
+				"PolicyMappings must have at least one mapping.");
54
+		}
55
+		return new self($critical, ...$mappings);
56
+	}
57 57
     
58
-    /**
59
-     *
60
-     * {@inheritdoc}
61
-     * @return Sequence
62
-     */
63
-    protected function _valueASN1(): Sequence
64
-    {
65
-        if (!count($this->_mappings)) {
66
-            throw new \LogicException("No mappings.");
67
-        }
68
-        $elements = array_map(
69
-            function (PolicyMapping $mapping) {
70
-                return $mapping->toASN1();
71
-            }, $this->_mappings);
72
-        return new Sequence(...$elements);
73
-    }
58
+	/**
59
+	 *
60
+	 * {@inheritdoc}
61
+	 * @return Sequence
62
+	 */
63
+	protected function _valueASN1(): Sequence
64
+	{
65
+		if (!count($this->_mappings)) {
66
+			throw new \LogicException("No mappings.");
67
+		}
68
+		$elements = array_map(
69
+			function (PolicyMapping $mapping) {
70
+				return $mapping->toASN1();
71
+			}, $this->_mappings);
72
+		return new Sequence(...$elements);
73
+	}
74 74
     
75
-    /**
76
-     * Get all mappings.
77
-     *
78
-     * @return PolicyMapping[]
79
-     */
80
-    public function mappings(): array
81
-    {
82
-        return $this->_mappings;
83
-    }
75
+	/**
76
+	 * Get all mappings.
77
+	 *
78
+	 * @return PolicyMapping[]
79
+	 */
80
+	public function mappings(): array
81
+	{
82
+		return $this->_mappings;
83
+	}
84 84
     
85
-    /**
86
-     * Get mappings flattened into a single array of arrays of subject domains
87
-     * keyed by issuer domain.
88
-     *
89
-     * Eg. if policy mappings contains multiple mappings with the same issuer
90
-     * domain policy, their corresponding subject domain policies are placed
91
-     * under the same key.
92
-     *
93
-     * @return (string[])[]
94
-     */
95
-    public function flattenedMappings(): array
96
-    {
97
-        $mappings = array();
98
-        foreach ($this->_mappings as $mapping) {
99
-            $idp = $mapping->issuerDomainPolicy();
100
-            if (!isset($mappings[$idp])) {
101
-                $mappings[$idp] = array();
102
-            }
103
-            array_push($mappings[$idp], $mapping->subjectDomainPolicy());
104
-        }
105
-        return $mappings;
106
-    }
85
+	/**
86
+	 * Get mappings flattened into a single array of arrays of subject domains
87
+	 * keyed by issuer domain.
88
+	 *
89
+	 * Eg. if policy mappings contains multiple mappings with the same issuer
90
+	 * domain policy, their corresponding subject domain policies are placed
91
+	 * under the same key.
92
+	 *
93
+	 * @return (string[])[]
94
+	 */
95
+	public function flattenedMappings(): array
96
+	{
97
+		$mappings = array();
98
+		foreach ($this->_mappings as $mapping) {
99
+			$idp = $mapping->issuerDomainPolicy();
100
+			if (!isset($mappings[$idp])) {
101
+				$mappings[$idp] = array();
102
+			}
103
+			array_push($mappings[$idp], $mapping->subjectDomainPolicy());
104
+		}
105
+		return $mappings;
106
+	}
107 107
     
108
-    /**
109
-     * Get all subject domain policy OIDs that are mapped to given issuer
110
-     * domain policy OID.
111
-     *
112
-     * @param string $oid Issuer domain policy
113
-     * @return string[] List of OIDs in dotted format
114
-     */
115
-    public function issuerMappings(string $oid): array
116
-    {
117
-        $oids = array();
118
-        foreach ($this->_mappings as $mapping) {
119
-            if ($mapping->issuerDomainPolicy() == $oid) {
120
-                $oids[] = $mapping->subjectDomainPolicy();
121
-            }
122
-        }
123
-        return $oids;
124
-    }
108
+	/**
109
+	 * Get all subject domain policy OIDs that are mapped to given issuer
110
+	 * domain policy OID.
111
+	 *
112
+	 * @param string $oid Issuer domain policy
113
+	 * @return string[] List of OIDs in dotted format
114
+	 */
115
+	public function issuerMappings(string $oid): array
116
+	{
117
+		$oids = array();
118
+		foreach ($this->_mappings as $mapping) {
119
+			if ($mapping->issuerDomainPolicy() == $oid) {
120
+				$oids[] = $mapping->subjectDomainPolicy();
121
+			}
122
+		}
123
+		return $oids;
124
+	}
125 125
     
126
-    /**
127
-     * Get all mapped issuer domain policy OIDs.
128
-     *
129
-     * @return string[]
130
-     */
131
-    public function issuerDomainPolicies(): array
132
-    {
133
-        $idps = array_map(
134
-            function (PolicyMapping $mapping) {
135
-                return $mapping->issuerDomainPolicy();
136
-            }, $this->_mappings);
137
-        return array_values(array_unique($idps));
138
-    }
126
+	/**
127
+	 * Get all mapped issuer domain policy OIDs.
128
+	 *
129
+	 * @return string[]
130
+	 */
131
+	public function issuerDomainPolicies(): array
132
+	{
133
+		$idps = array_map(
134
+			function (PolicyMapping $mapping) {
135
+				return $mapping->issuerDomainPolicy();
136
+			}, $this->_mappings);
137
+		return array_values(array_unique($idps));
138
+	}
139 139
     
140
-    /**
141
-     * Check whether policy mappings have anyPolicy mapped.
142
-     *
143
-     * RFC 5280 section 4.2.1.5 states that "Policies MUST NOT be mapped either
144
-     * to or from the special value anyPolicy".
145
-     *
146
-     * @return bool
147
-     */
148
-    public function hasAnyPolicyMapping(): bool
149
-    {
150
-        foreach ($this->_mappings as $mapping) {
151
-            if ($mapping->issuerDomainPolicy() ==
152
-                 PolicyInformation::OID_ANY_POLICY) {
153
-                return true;
154
-            }
155
-            if ($mapping->subjectDomainPolicy() ==
156
-                 PolicyInformation::OID_ANY_POLICY) {
157
-                return true;
158
-            }
159
-        }
160
-        return false;
161
-    }
140
+	/**
141
+	 * Check whether policy mappings have anyPolicy mapped.
142
+	 *
143
+	 * RFC 5280 section 4.2.1.5 states that "Policies MUST NOT be mapped either
144
+	 * to or from the special value anyPolicy".
145
+	 *
146
+	 * @return bool
147
+	 */
148
+	public function hasAnyPolicyMapping(): bool
149
+	{
150
+		foreach ($this->_mappings as $mapping) {
151
+			if ($mapping->issuerDomainPolicy() ==
152
+				 PolicyInformation::OID_ANY_POLICY) {
153
+				return true;
154
+			}
155
+			if ($mapping->subjectDomainPolicy() ==
156
+				 PolicyInformation::OID_ANY_POLICY) {
157
+				return true;
158
+			}
159
+		}
160
+		return false;
161
+	}
162 162
     
163
-    /**
164
-     * Get the number of mappings.
165
-     *
166
-     * @see \Countable::count()
167
-     * @return int
168
-     */
169
-    public function count(): int
170
-    {
171
-        return count($this->_mappings);
172
-    }
163
+	/**
164
+	 * Get the number of mappings.
165
+	 *
166
+	 * @see \Countable::count()
167
+	 * @return int
168
+	 */
169
+	public function count(): int
170
+	{
171
+		return count($this->_mappings);
172
+	}
173 173
     
174
-    /**
175
-     * Get iterator for policy mappings.
176
-     *
177
-     * @see \IteratorAggregate::getIterator()
178
-     * @return \ArrayIterator
179
-     */
180
-    public function getIterator(): \ArrayIterator
181
-    {
182
-        return new \ArrayIterator($this->_mappings);
183
-    }
174
+	/**
175
+	 * Get iterator for policy mappings.
176
+	 *
177
+	 * @see \IteratorAggregate::getIterator()
178
+	 * @return \ArrayIterator
179
+	 */
180
+	public function getIterator(): \ArrayIterator
181
+	{
182
+		return new \ArrayIterator($this->_mappings);
183
+	}
184 184
 }
Please login to merge, or discard this patch.