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 ( ff3a63...584877 )
by Joni
04:52
created
lib/X509/Certificate/Extension/CertificatePolicy/PolicyInformation.php 2 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -14,207 +14,207 @@
 block discarded – undo
14 14
  */
15 15
 class PolicyInformation implements \Countable, \IteratorAggregate
16 16
 {
17
-    /**
18
-     * Wildcard policy.
19
-     *
20
-     * @var string
21
-     */
22
-    const OID_ANY_POLICY = "2.5.29.32.0";
23
-    
24
-    /**
25
-     * Policy identifier.
26
-     *
27
-     * @var string $_oid
28
-     */
29
-    protected $_oid;
30
-    
31
-    /**
32
-     * Policy qualifiers.
33
-     *
34
-     * @var PolicyQualifierInfo[] $_qualifiers
35
-     */
36
-    protected $_qualifiers;
37
-    
38
-    /**
39
-     * Constructor.
40
-     *
41
-     * @param string $oid
42
-     * @param PolicyQualifierInfo ...$qualifiers
43
-     */
44
-    public function __construct($oid, PolicyQualifierInfo ...$qualifiers)
45
-    {
46
-        $this->_oid = $oid;
47
-        $this->_qualifiers = array();
48
-        foreach ($qualifiers as $qual) {
49
-            $this->_qualifiers[$qual->oid()] = $qual;
50
-        }
51
-    }
52
-    
53
-    /**
54
-     * Initialize from ASN.1.
55
-     *
56
-     * @param Sequence $seq
57
-     * @return self
58
-     */
59
-    public static function fromASN1(Sequence $seq)
60
-    {
61
-        $oid = $seq->at(0)
62
-            ->asObjectIdentifier()
63
-            ->oid();
64
-        $qualifiers = array();
65
-        if (count($seq) > 1) {
66
-            $qualifiers = array_map(
67
-                function (UnspecifiedType $el) {
68
-                    return PolicyQualifierInfo::fromASN1($el->asSequence());
69
-                },
70
-                $seq->at(1)
71
-                    ->asSequence()
72
-                    ->elements());
73
-        }
74
-        return new self($oid, ...$qualifiers);
75
-    }
76
-    
77
-    /**
78
-     * Get policy identifier.
79
-     *
80
-     * @return string
81
-     */
82
-    public function oid()
83
-    {
84
-        return $this->_oid;
85
-    }
86
-    
87
-    /**
88
-     * Check whether this policy is anyPolicy.
89
-     *
90
-     * @return bool
91
-     */
92
-    public function isAnyPolicy()
93
-    {
94
-        return self::OID_ANY_POLICY == $this->_oid;
95
-    }
96
-    
97
-    /**
98
-     * Get policy qualifiers.
99
-     *
100
-     * @return PolicyQualifierInfo[]
101
-     */
102
-    public function qualifiers()
103
-    {
104
-        return array_values($this->_qualifiers);
105
-    }
106
-    
107
-    /**
108
-     * Check whether qualifier is present.
109
-     *
110
-     * @param string $oid
111
-     * @return boolean
112
-     */
113
-    public function has($oid)
114
-    {
115
-        return isset($this->_qualifiers[$oid]);
116
-    }
117
-    
118
-    /**
119
-     * Get qualifier by OID.
120
-     *
121
-     * @param string $oid
122
-     * @throws \OutOfBoundsException
123
-     * @return PolicyQualifierInfo
124
-     */
125
-    public function get($oid)
126
-    {
127
-        if (!$this->has($oid)) {
128
-            throw new \LogicException("No $oid qualifier.");
129
-        }
130
-        return $this->_qualifiers[$oid];
131
-    }
132
-    
133
-    /**
134
-     * Check whether CPS qualifier is present.
135
-     *
136
-     * @return bool
137
-     */
138
-    public function hasCPSQualifier()
139
-    {
140
-        return $this->has(PolicyQualifierInfo::OID_CPS);
141
-    }
142
-    
143
-    /**
144
-     * Get CPS qualifier.
145
-     *
146
-     * @throws \LogicException
147
-     * @return CPSQualifier
148
-     */
149
-    public function CPSQualifier()
150
-    {
151
-        if (!$this->hasCPSQualifier()) {
152
-            throw new \LogicException("CPS qualifier not set.");
153
-        }
154
-        return $this->get(PolicyQualifierInfo::OID_CPS);
155
-    }
156
-    
157
-    /**
158
-     * Check whether user notice qualifier is present.
159
-     *
160
-     * @return bool
161
-     */
162
-    public function hasUserNoticeQualifier()
163
-    {
164
-        return $this->has(PolicyQualifierInfo::OID_UNOTICE);
165
-    }
166
-    
167
-    /**
168
-     * Get user notice qualifier.
169
-     *
170
-     * @throws \LogicException
171
-     * @return UserNoticeQualifier
172
-     */
173
-    public function userNoticeQualifier()
174
-    {
175
-        if (!$this->hasUserNoticeQualifier()) {
176
-            throw new \LogicException("User notice qualifier not set.");
177
-        }
178
-        return $this->get(PolicyQualifierInfo::OID_UNOTICE);
179
-    }
180
-    
181
-    /**
182
-     * Get ASN.1 structure.
183
-     *
184
-     * @return Sequence
185
-     */
186
-    public function toASN1()
187
-    {
188
-        $elements = array(new ObjectIdentifier($this->_oid));
189
-        if (count($this->_qualifiers)) {
190
-            $qualifiers = array_map(
191
-                function (PolicyQualifierInfo $pqi) {
192
-                    return $pqi->toASN1();
193
-                }, array_values($this->_qualifiers));
194
-            $elements[] = new Sequence(...$qualifiers);
195
-        }
196
-        return new Sequence(...$elements);
197
-    }
198
-    
199
-    /**
200
-     * Get number of qualifiers.
201
-     *
202
-     * @see \Countable::count()
203
-     * @return int
204
-     */
205
-    public function count()
206
-    {
207
-        return count($this->_qualifiers);
208
-    }
209
-    
210
-    /**
211
-     * Get iterator for qualifiers.
212
-     *
213
-     * @see \IteratorAggregate::getIterator()
214
-     * @return \ArrayIterator
215
-     */
216
-    public function getIterator()
217
-    {
218
-        return new \ArrayIterator($this->_qualifiers);
219
-    }
17
+	/**
18
+	 * Wildcard policy.
19
+	 *
20
+	 * @var string
21
+	 */
22
+	const OID_ANY_POLICY = "2.5.29.32.0";
23
+    
24
+	/**
25
+	 * Policy identifier.
26
+	 *
27
+	 * @var string $_oid
28
+	 */
29
+	protected $_oid;
30
+    
31
+	/**
32
+	 * Policy qualifiers.
33
+	 *
34
+	 * @var PolicyQualifierInfo[] $_qualifiers
35
+	 */
36
+	protected $_qualifiers;
37
+    
38
+	/**
39
+	 * Constructor.
40
+	 *
41
+	 * @param string $oid
42
+	 * @param PolicyQualifierInfo ...$qualifiers
43
+	 */
44
+	public function __construct($oid, PolicyQualifierInfo ...$qualifiers)
45
+	{
46
+		$this->_oid = $oid;
47
+		$this->_qualifiers = array();
48
+		foreach ($qualifiers as $qual) {
49
+			$this->_qualifiers[$qual->oid()] = $qual;
50
+		}
51
+	}
52
+    
53
+	/**
54
+	 * Initialize from ASN.1.
55
+	 *
56
+	 * @param Sequence $seq
57
+	 * @return self
58
+	 */
59
+	public static function fromASN1(Sequence $seq)
60
+	{
61
+		$oid = $seq->at(0)
62
+			->asObjectIdentifier()
63
+			->oid();
64
+		$qualifiers = array();
65
+		if (count($seq) > 1) {
66
+			$qualifiers = array_map(
67
+				function (UnspecifiedType $el) {
68
+					return PolicyQualifierInfo::fromASN1($el->asSequence());
69
+				},
70
+				$seq->at(1)
71
+					->asSequence()
72
+					->elements());
73
+		}
74
+		return new self($oid, ...$qualifiers);
75
+	}
76
+    
77
+	/**
78
+	 * Get policy identifier.
79
+	 *
80
+	 * @return string
81
+	 */
82
+	public function oid()
83
+	{
84
+		return $this->_oid;
85
+	}
86
+    
87
+	/**
88
+	 * Check whether this policy is anyPolicy.
89
+	 *
90
+	 * @return bool
91
+	 */
92
+	public function isAnyPolicy()
93
+	{
94
+		return self::OID_ANY_POLICY == $this->_oid;
95
+	}
96
+    
97
+	/**
98
+	 * Get policy qualifiers.
99
+	 *
100
+	 * @return PolicyQualifierInfo[]
101
+	 */
102
+	public function qualifiers()
103
+	{
104
+		return array_values($this->_qualifiers);
105
+	}
106
+    
107
+	/**
108
+	 * Check whether qualifier is present.
109
+	 *
110
+	 * @param string $oid
111
+	 * @return boolean
112
+	 */
113
+	public function has($oid)
114
+	{
115
+		return isset($this->_qualifiers[$oid]);
116
+	}
117
+    
118
+	/**
119
+	 * Get qualifier by OID.
120
+	 *
121
+	 * @param string $oid
122
+	 * @throws \OutOfBoundsException
123
+	 * @return PolicyQualifierInfo
124
+	 */
125
+	public function get($oid)
126
+	{
127
+		if (!$this->has($oid)) {
128
+			throw new \LogicException("No $oid qualifier.");
129
+		}
130
+		return $this->_qualifiers[$oid];
131
+	}
132
+    
133
+	/**
134
+	 * Check whether CPS qualifier is present.
135
+	 *
136
+	 * @return bool
137
+	 */
138
+	public function hasCPSQualifier()
139
+	{
140
+		return $this->has(PolicyQualifierInfo::OID_CPS);
141
+	}
142
+    
143
+	/**
144
+	 * Get CPS qualifier.
145
+	 *
146
+	 * @throws \LogicException
147
+	 * @return CPSQualifier
148
+	 */
149
+	public function CPSQualifier()
150
+	{
151
+		if (!$this->hasCPSQualifier()) {
152
+			throw new \LogicException("CPS qualifier not set.");
153
+		}
154
+		return $this->get(PolicyQualifierInfo::OID_CPS);
155
+	}
156
+    
157
+	/**
158
+	 * Check whether user notice qualifier is present.
159
+	 *
160
+	 * @return bool
161
+	 */
162
+	public function hasUserNoticeQualifier()
163
+	{
164
+		return $this->has(PolicyQualifierInfo::OID_UNOTICE);
165
+	}
166
+    
167
+	/**
168
+	 * Get user notice qualifier.
169
+	 *
170
+	 * @throws \LogicException
171
+	 * @return UserNoticeQualifier
172
+	 */
173
+	public function userNoticeQualifier()
174
+	{
175
+		if (!$this->hasUserNoticeQualifier()) {
176
+			throw new \LogicException("User notice qualifier not set.");
177
+		}
178
+		return $this->get(PolicyQualifierInfo::OID_UNOTICE);
179
+	}
180
+    
181
+	/**
182
+	 * Get ASN.1 structure.
183
+	 *
184
+	 * @return Sequence
185
+	 */
186
+	public function toASN1()
187
+	{
188
+		$elements = array(new ObjectIdentifier($this->_oid));
189
+		if (count($this->_qualifiers)) {
190
+			$qualifiers = array_map(
191
+				function (PolicyQualifierInfo $pqi) {
192
+					return $pqi->toASN1();
193
+				}, array_values($this->_qualifiers));
194
+			$elements[] = new Sequence(...$qualifiers);
195
+		}
196
+		return new Sequence(...$elements);
197
+	}
198
+    
199
+	/**
200
+	 * Get number of qualifiers.
201
+	 *
202
+	 * @see \Countable::count()
203
+	 * @return int
204
+	 */
205
+	public function count()
206
+	{
207
+		return count($this->_qualifiers);
208
+	}
209
+    
210
+	/**
211
+	 * Get iterator for qualifiers.
212
+	 *
213
+	 * @see \IteratorAggregate::getIterator()
214
+	 * @return \ArrayIterator
215
+	 */
216
+	public function getIterator()
217
+	{
218
+		return new \ArrayIterator($this->_qualifiers);
219
+	}
220 220
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
         $qualifiers = array();
65 65
         if (count($seq) > 1) {
66 66
             $qualifiers = array_map(
67
-                function (UnspecifiedType $el) {
67
+                function(UnspecifiedType $el) {
68 68
                     return PolicyQualifierInfo::fromASN1($el->asSequence());
69 69
                 },
70 70
                 $seq->at(1)
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
         $elements = array(new ObjectIdentifier($this->_oid));
189 189
         if (count($this->_qualifiers)) {
190 190
             $qualifiers = array_map(
191
-                function (PolicyQualifierInfo $pqi) {
191
+                function(PolicyQualifierInfo $pqi) {
192 192
                     return $pqi->toASN1();
193 193
                 }, array_values($this->_qualifiers));
194 194
             $elements[] = new Sequence(...$qualifiers);
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/SubjectKeyIdentifierExtension.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -11,52 +11,52 @@
 block discarded – undo
11 11
  */
12 12
 class SubjectKeyIdentifierExtension extends Extension
13 13
 {
14
-    /**
15
-     * Key identifier.
16
-     *
17
-     * @var string $_keyIdentifier
18
-     */
19
-    protected $_keyIdentifier;
14
+	/**
15
+	 * Key identifier.
16
+	 *
17
+	 * @var string $_keyIdentifier
18
+	 */
19
+	protected $_keyIdentifier;
20 20
     
21
-    /**
22
-     * Constructor.
23
-     *
24
-     * @param bool $critical
25
-     * @param string $keyIdentifier
26
-     */
27
-    public function __construct($critical, $keyIdentifier)
28
-    {
29
-        parent::__construct(self::OID_SUBJECT_KEY_IDENTIFIER, $critical);
30
-        $this->_keyIdentifier = $keyIdentifier;
31
-    }
21
+	/**
22
+	 * Constructor.
23
+	 *
24
+	 * @param bool $critical
25
+	 * @param string $keyIdentifier
26
+	 */
27
+	public function __construct($critical, $keyIdentifier)
28
+	{
29
+		parent::__construct(self::OID_SUBJECT_KEY_IDENTIFIER, $critical);
30
+		$this->_keyIdentifier = $keyIdentifier;
31
+	}
32 32
     
33
-    /**
34
-     *
35
-     * {@inheritdoc}
36
-     * @return self
37
-     */
38
-    protected static function _fromDER($data, $critical)
39
-    {
40
-        return new self($critical, OctetString::fromDER($data)->string());
41
-    }
33
+	/**
34
+	 *
35
+	 * {@inheritdoc}
36
+	 * @return self
37
+	 */
38
+	protected static function _fromDER($data, $critical)
39
+	{
40
+		return new self($critical, OctetString::fromDER($data)->string());
41
+	}
42 42
     
43
-    /**
44
-     * Get key identifier.
45
-     *
46
-     * @return string
47
-     */
48
-    public function keyIdentifier()
49
-    {
50
-        return $this->_keyIdentifier;
51
-    }
43
+	/**
44
+	 * Get key identifier.
45
+	 *
46
+	 * @return string
47
+	 */
48
+	public function keyIdentifier()
49
+	{
50
+		return $this->_keyIdentifier;
51
+	}
52 52
     
53
-    /**
54
-     *
55
-     * {@inheritdoc}
56
-     * @return OctetString
57
-     */
58
-    protected function _valueASN1()
59
-    {
60
-        return new OctetString($this->_keyIdentifier);
61
-    }
53
+	/**
54
+	 *
55
+	 * {@inheritdoc}
56
+	 * @return OctetString
57
+	 */
58
+	protected function _valueASN1()
59
+	{
60
+		return new OctetString($this->_keyIdentifier);
61
+	}
62 62
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/TargetGroup.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,60 +13,60 @@
 block discarded – undo
13 13
  */
14 14
 class TargetGroup extends Target
15 15
 {
16
-    /**
17
-     * Group name.
18
-     *
19
-     * @var GeneralName $_name
20
-     */
21
-    protected $_name;
16
+	/**
17
+	 * Group name.
18
+	 *
19
+	 * @var GeneralName $_name
20
+	 */
21
+	protected $_name;
22 22
     
23
-    /**
24
-     * Constructor.
25
-     *
26
-     * @param GeneralName $name
27
-     */
28
-    public function __construct(GeneralName $name)
29
-    {
30
-        $this->_name = $name;
31
-        $this->_type = self::TYPE_GROUP;
32
-    }
23
+	/**
24
+	 * Constructor.
25
+	 *
26
+	 * @param GeneralName $name
27
+	 */
28
+	public function __construct(GeneralName $name)
29
+	{
30
+		$this->_name = $name;
31
+		$this->_type = self::TYPE_GROUP;
32
+	}
33 33
     
34
-    /**
35
-     *
36
-     * @param TaggedType $el
37
-     * @return self
38
-     */
39
-    public static function fromChosenASN1(TaggedType $el)
40
-    {
41
-        return new self(GeneralName::fromASN1($el));
42
-    }
34
+	/**
35
+	 *
36
+	 * @param TaggedType $el
37
+	 * @return self
38
+	 */
39
+	public static function fromChosenASN1(TaggedType $el)
40
+	{
41
+		return new self(GeneralName::fromASN1($el));
42
+	}
43 43
     
44
-    /**
45
-     *
46
-     * {@inheritdoc}
47
-     */
48
-    public function string()
49
-    {
50
-        return $this->_name->string();
51
-    }
44
+	/**
45
+	 *
46
+	 * {@inheritdoc}
47
+	 */
48
+	public function string()
49
+	{
50
+		return $this->_name->string();
51
+	}
52 52
     
53
-    /**
54
-     * Get group name.
55
-     *
56
-     * @return GeneralName
57
-     */
58
-    public function name()
59
-    {
60
-        return $this->_name;
61
-    }
53
+	/**
54
+	 * Get group name.
55
+	 *
56
+	 * @return GeneralName
57
+	 */
58
+	public function name()
59
+	{
60
+		return $this->_name;
61
+	}
62 62
     
63
-    /**
64
-     *
65
-     * {@inheritdoc}
66
-     * @return ExplicitlyTaggedType
67
-     */
68
-    public function toASN1()
69
-    {
70
-        return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
-    }
63
+	/**
64
+	 *
65
+	 * {@inheritdoc}
66
+	 * @return ExplicitlyTaggedType
67
+	 */
68
+	public function toASN1()
69
+	{
70
+		return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
+	}
72 72
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/TargetName.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -13,60 +13,60 @@
 block discarded – undo
13 13
  */
14 14
 class TargetName extends Target
15 15
 {
16
-    /**
17
-     * Name.
18
-     *
19
-     * @var GeneralName $_name
20
-     */
21
-    protected $_name;
16
+	/**
17
+	 * Name.
18
+	 *
19
+	 * @var GeneralName $_name
20
+	 */
21
+	protected $_name;
22 22
     
23
-    /**
24
-     * Constructor.
25
-     *
26
-     * @param GeneralName $name
27
-     */
28
-    public function __construct(GeneralName $name)
29
-    {
30
-        $this->_name = $name;
31
-        $this->_type = self::TYPE_NAME;
32
-    }
23
+	/**
24
+	 * Constructor.
25
+	 *
26
+	 * @param GeneralName $name
27
+	 */
28
+	public function __construct(GeneralName $name)
29
+	{
30
+		$this->_name = $name;
31
+		$this->_type = self::TYPE_NAME;
32
+	}
33 33
     
34
-    /**
35
-     *
36
-     * @param TaggedType $el
37
-     * @return self
38
-     */
39
-    public static function fromChosenASN1(TaggedType $el)
40
-    {
41
-        return new self(GeneralName::fromASN1($el));
42
-    }
34
+	/**
35
+	 *
36
+	 * @param TaggedType $el
37
+	 * @return self
38
+	 */
39
+	public static function fromChosenASN1(TaggedType $el)
40
+	{
41
+		return new self(GeneralName::fromASN1($el));
42
+	}
43 43
     
44
-    /**
45
-     *
46
-     * {@inheritdoc}
47
-     */
48
-    public function string()
49
-    {
50
-        return $this->_name->string();
51
-    }
44
+	/**
45
+	 *
46
+	 * {@inheritdoc}
47
+	 */
48
+	public function string()
49
+	{
50
+		return $this->_name->string();
51
+	}
52 52
     
53
-    /**
54
-     * Get name.
55
-     *
56
-     * @return GeneralName
57
-     */
58
-    public function name()
59
-    {
60
-        return $this->_name;
61
-    }
53
+	/**
54
+	 * Get name.
55
+	 *
56
+	 * @return GeneralName
57
+	 */
58
+	public function name()
59
+	{
60
+		return $this->_name;
61
+	}
62 62
     
63
-    /**
64
-     *
65
-     * {@inheritdoc}
66
-     * @return ExplicitlyTaggedType
67
-     */
68
-    public function toASN1()
69
-    {
70
-        return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
-    }
63
+	/**
64
+	 *
65
+	 * {@inheritdoc}
66
+	 * @return ExplicitlyTaggedType
67
+	 */
68
+	public function toASN1()
69
+	{
70
+		return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1());
71
+	}
72 72
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/Target.php 2 patches
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -11,89 +11,89 @@
 block discarded – undo
11 11
  */
12 12
 abstract class Target
13 13
 {
14
-    const TYPE_NAME = 0;
15
-    const TYPE_GROUP = 1;
16
-    const TYPE_CERT = 2;
14
+	const TYPE_NAME = 0;
15
+	const TYPE_GROUP = 1;
16
+	const TYPE_CERT = 2;
17 17
     
18
-    /**
19
-     * Type tag.
20
-     *
21
-     * @var int $_type
22
-     */
23
-    protected $_type;
18
+	/**
19
+	 * Type tag.
20
+	 *
21
+	 * @var int $_type
22
+	 */
23
+	protected $_type;
24 24
     
25
-    /**
26
-     * Generate ASN.1 element.
27
-     *
28
-     * @return \ASN1\Element
29
-     */
30
-    abstract public function toASN1();
25
+	/**
26
+	 * Generate ASN.1 element.
27
+	 *
28
+	 * @return \ASN1\Element
29
+	 */
30
+	abstract public function toASN1();
31 31
     
32
-    /**
33
-     * Get string value of the target.
34
-     *
35
-     * @return string
36
-     */
37
-    abstract public function string();
32
+	/**
33
+	 * Get string value of the target.
34
+	 *
35
+	 * @return string
36
+	 */
37
+	abstract public function string();
38 38
     
39
-    /**
40
-     * Initialize concrete object from the chosen ASN.1 element.
41
-     *
42
-     * @param TaggedType $el
43
-     * @return self
44
-     */
45
-    public static function fromChosenASN1(TaggedType $el)
46
-    {
47
-        throw new \BadMethodCallException(
48
-            __FUNCTION__ . " must be implemented in the derived class.");
49
-    }
39
+	/**
40
+	 * Initialize concrete object from the chosen ASN.1 element.
41
+	 *
42
+	 * @param TaggedType $el
43
+	 * @return self
44
+	 */
45
+	public static function fromChosenASN1(TaggedType $el)
46
+	{
47
+		throw new \BadMethodCallException(
48
+			__FUNCTION__ . " must be implemented in the derived class.");
49
+	}
50 50
     
51
-    /**
52
-     * Parse from ASN.1.
53
-     *
54
-     * @param TaggedType $el
55
-     * @throws \UnexpectedValueException
56
-     * @return self
57
-     */
58
-    public static function fromASN1(TaggedType $el)
59
-    {
60
-        switch ($el->tag()) {
61
-            case self::TYPE_NAME:
62
-                return TargetName::fromChosenASN1($el->asExplicit()->asTagged());
63
-            case self::TYPE_GROUP:
64
-                return TargetGroup::fromChosenASN1(
65
-                    $el->asExplicit()->asTagged());
66
-            case self::TYPE_CERT:
67
-                throw new \RuntimeException("targetCert not supported.");
68
-        }
69
-        throw new \UnexpectedValueException(
70
-            "Target type " . $el->tag() . " not supported.");
71
-    }
51
+	/**
52
+	 * Parse from ASN.1.
53
+	 *
54
+	 * @param TaggedType $el
55
+	 * @throws \UnexpectedValueException
56
+	 * @return self
57
+	 */
58
+	public static function fromASN1(TaggedType $el)
59
+	{
60
+		switch ($el->tag()) {
61
+			case self::TYPE_NAME:
62
+				return TargetName::fromChosenASN1($el->asExplicit()->asTagged());
63
+			case self::TYPE_GROUP:
64
+				return TargetGroup::fromChosenASN1(
65
+					$el->asExplicit()->asTagged());
66
+			case self::TYPE_CERT:
67
+				throw new \RuntimeException("targetCert not supported.");
68
+		}
69
+		throw new \UnexpectedValueException(
70
+			"Target type " . $el->tag() . " not supported.");
71
+	}
72 72
     
73
-    /**
74
-     * Get type tag.
75
-     *
76
-     * @return int
77
-     */
78
-    public function type()
79
-    {
80
-        return $this->_type;
81
-    }
73
+	/**
74
+	 * Get type tag.
75
+	 *
76
+	 * @return int
77
+	 */
78
+	public function type()
79
+	{
80
+		return $this->_type;
81
+	}
82 82
     
83
-    /**
84
-     * Check whether target is equal to another.
85
-     *
86
-     * @param Target $other
87
-     * @return bool
88
-     */
89
-    public function equals(Target $other)
90
-    {
91
-        if ($this->_type != $other->_type) {
92
-            return false;
93
-        }
94
-        if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) {
95
-            return false;
96
-        }
97
-        return true;
98
-    }
83
+	/**
84
+	 * Check whether target is equal to another.
85
+	 *
86
+	 * @param Target $other
87
+	 * @return bool
88
+	 */
89
+	public function equals(Target $other)
90
+	{
91
+		if ($this->_type != $other->_type) {
92
+			return false;
93
+		}
94
+		if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) {
95
+			return false;
96
+		}
97
+		return true;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
Switch Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -58,13 +58,13 @@
 block discarded – undo
58 58
     public static function fromASN1(TaggedType $el)
59 59
     {
60 60
         switch ($el->tag()) {
61
-            case self::TYPE_NAME:
62
-                return TargetName::fromChosenASN1($el->asExplicit()->asTagged());
63
-            case self::TYPE_GROUP:
64
-                return TargetGroup::fromChosenASN1(
65
-                    $el->asExplicit()->asTagged());
66
-            case self::TYPE_CERT:
67
-                throw new \RuntimeException("targetCert not supported.");
61
+        case self::TYPE_NAME:
62
+            return TargetName::fromChosenASN1($el->asExplicit()->asTagged());
63
+        case self::TYPE_GROUP:
64
+            return TargetGroup::fromChosenASN1(
65
+                $el->asExplicit()->asTagged());
66
+        case self::TYPE_CERT:
67
+            throw new \RuntimeException("targetCert not supported.");
68 68
         }
69 69
         throw new \UnexpectedValueException(
70 70
             "Target type " . $el->tag() . " not supported.");
Please login to merge, or discard this patch.
lib/X509/Certificate/Extension/Target/Targets.php 2 patches
Indentation   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -12,131 +12,131 @@
 block discarded – undo
12 12
  */
13 13
 class Targets implements \Countable, \IteratorAggregate
14 14
 {
15
-    /**
16
-     * Target elements.
17
-     *
18
-     * @var Target[] $_targets
19
-     */
20
-    protected $_targets;
15
+	/**
16
+	 * Target elements.
17
+	 *
18
+	 * @var Target[] $_targets
19
+	 */
20
+	protected $_targets;
21 21
     
22
-    /**
23
-     * Constructor.
24
-     *
25
-     * @param Target ...$targets
26
-     */
27
-    public function __construct(Target ...$targets)
28
-    {
29
-        $this->_targets = $targets;
30
-    }
22
+	/**
23
+	 * Constructor.
24
+	 *
25
+	 * @param Target ...$targets
26
+	 */
27
+	public function __construct(Target ...$targets)
28
+	{
29
+		$this->_targets = $targets;
30
+	}
31 31
     
32
-    /**
33
-     * Initialize from ASN.1.
34
-     *
35
-     * @param Sequence $seq
36
-     * @return self
37
-     */
38
-    public static function fromASN1(Sequence $seq)
39
-    {
40
-        $targets = array_map(
41
-            function (UnspecifiedType $el) {
42
-                return Target::fromASN1($el->asTagged());
43
-            }, $seq->elements());
44
-        return new self(...$targets);
45
-    }
32
+	/**
33
+	 * Initialize from ASN.1.
34
+	 *
35
+	 * @param Sequence $seq
36
+	 * @return self
37
+	 */
38
+	public static function fromASN1(Sequence $seq)
39
+	{
40
+		$targets = array_map(
41
+			function (UnspecifiedType $el) {
42
+				return Target::fromASN1($el->asTagged());
43
+			}, $seq->elements());
44
+		return new self(...$targets);
45
+	}
46 46
     
47
-    /**
48
-     * Get all targets.
49
-     *
50
-     * @return Target[]
51
-     */
52
-    public function all()
53
-    {
54
-        return $this->_targets;
55
-    }
47
+	/**
48
+	 * Get all targets.
49
+	 *
50
+	 * @return Target[]
51
+	 */
52
+	public function all()
53
+	{
54
+		return $this->_targets;
55
+	}
56 56
     
57
-    /**
58
-     * Get all targets of given type.
59
-     *
60
-     * @param int $type
61
-     * @return Target[]
62
-     */
63
-    protected function _allOfType($type)
64
-    {
65
-        return array_values(
66
-            array_filter($this->_targets,
67
-                function (Target $target) use ($type) {
68
-                    return $target->type() == $type;
69
-                }));
70
-    }
57
+	/**
58
+	 * Get all targets of given type.
59
+	 *
60
+	 * @param int $type
61
+	 * @return Target[]
62
+	 */
63
+	protected function _allOfType($type)
64
+	{
65
+		return array_values(
66
+			array_filter($this->_targets,
67
+				function (Target $target) use ($type) {
68
+					return $target->type() == $type;
69
+				}));
70
+	}
71 71
     
72
-    /**
73
-     * Get all name targets.
74
-     *
75
-     * @return Target[]
76
-     */
77
-    public function nameTargets()
78
-    {
79
-        return $this->_allOfType(Target::TYPE_NAME);
80
-    }
72
+	/**
73
+	 * Get all name targets.
74
+	 *
75
+	 * @return Target[]
76
+	 */
77
+	public function nameTargets()
78
+	{
79
+		return $this->_allOfType(Target::TYPE_NAME);
80
+	}
81 81
     
82
-    /**
83
-     * Get all group targets.
84
-     *
85
-     * @return Target[]
86
-     */
87
-    public function groupTargets()
88
-    {
89
-        return $this->_allOfType(Target::TYPE_GROUP);
90
-    }
82
+	/**
83
+	 * Get all group targets.
84
+	 *
85
+	 * @return Target[]
86
+	 */
87
+	public function groupTargets()
88
+	{
89
+		return $this->_allOfType(Target::TYPE_GROUP);
90
+	}
91 91
     
92
-    /**
93
-     * Check whether given target is present.
94
-     *
95
-     * @param Target $target
96
-     * @return boolean
97
-     */
98
-    public function hasTarget(Target $target)
99
-    {
100
-        foreach ($this->_allOfType($target->type()) as $t) {
101
-            if ($target->equals($t)) {
102
-                return true;
103
-            }
104
-        }
105
-        return false;
106
-    }
92
+	/**
93
+	 * Check whether given target is present.
94
+	 *
95
+	 * @param Target $target
96
+	 * @return boolean
97
+	 */
98
+	public function hasTarget(Target $target)
99
+	{
100
+		foreach ($this->_allOfType($target->type()) as $t) {
101
+			if ($target->equals($t)) {
102
+				return true;
103
+			}
104
+		}
105
+		return false;
106
+	}
107 107
     
108
-    /**
109
-     * Generate ASN.1 structure.
110
-     *
111
-     * @return Sequence
112
-     */
113
-    public function toASN1()
114
-    {
115
-        $elements = array_map(
116
-            function (Target $target) {
117
-                return $target->toASN1();
118
-            }, $this->_targets);
119
-        return new Sequence(...$elements);
120
-    }
108
+	/**
109
+	 * Generate ASN.1 structure.
110
+	 *
111
+	 * @return Sequence
112
+	 */
113
+	public function toASN1()
114
+	{
115
+		$elements = array_map(
116
+			function (Target $target) {
117
+				return $target->toASN1();
118
+			}, $this->_targets);
119
+		return new Sequence(...$elements);
120
+	}
121 121
     
122
-    /**
123
-     *
124
-     * @see \Countable::count()
125
-     * @return int
126
-     */
127
-    public function count()
128
-    {
129
-        return count($this->_targets);
130
-    }
122
+	/**
123
+	 *
124
+	 * @see \Countable::count()
125
+	 * @return int
126
+	 */
127
+	public function count()
128
+	{
129
+		return count($this->_targets);
130
+	}
131 131
     
132
-    /**
133
-     * Get iterator for targets.
134
-     *
135
-     * @see \IteratorAggregate::getIterator()
136
-     * @return \ArrayIterator
137
-     */
138
-    public function getIterator()
139
-    {
140
-        return new \ArrayIterator($this->_targets);
141
-    }
132
+	/**
133
+	 * Get iterator for targets.
134
+	 *
135
+	 * @see \IteratorAggregate::getIterator()
136
+	 * @return \ArrayIterator
137
+	 */
138
+	public function getIterator()
139
+	{
140
+		return new \ArrayIterator($this->_targets);
141
+	}
142 142
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public static function fromASN1(Sequence $seq)
39 39
     {
40 40
         $targets = array_map(
41
-            function (UnspecifiedType $el) {
41
+            function(UnspecifiedType $el) {
42 42
                 return Target::fromASN1($el->asTagged());
43 43
             }, $seq->elements());
44 44
         return new self(...$targets);
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     {
65 65
         return array_values(
66 66
             array_filter($this->_targets,
67
-                function (Target $target) use ($type) {
67
+                function(Target $target) use ($type) {
68 68
                     return $target->type() == $type;
69 69
                 }));
70 70
     }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     public function toASN1()
114 114
     {
115 115
         $elements = array_map(
116
-            function (Target $target) {
116
+            function(Target $target) {
117 117
                 return $target->toASN1();
118 118
             }, $this->_targets);
119 119
         return new Sequence(...$elements);
Please login to merge, or discard this patch.
lib/X509/Certificate/TBSCertificate.php 1 patch
Indentation   +607 added lines, -607 removed lines patch added patch discarded remove patch
@@ -25,611 +25,611 @@
 block discarded – undo
25 25
  */
26 26
 class TBSCertificate
27 27
 {
28
-    // Certificate version enumerations
29
-    const VERSION_1 = 0;
30
-    const VERSION_2 = 1;
31
-    const VERSION_3 = 2;
32
-    
33
-    /**
34
-     * Certificate version.
35
-     *
36
-     * @var int
37
-     */
38
-    protected $_version;
39
-    
40
-    /**
41
-     * Serial number.
42
-     *
43
-     * @var int|string
44
-     */
45
-    protected $_serialNumber;
46
-    
47
-    /**
48
-     * Signature algorithm.
49
-     *
50
-     * @var SignatureAlgorithmIdentifier
51
-     */
52
-    protected $_signature;
53
-    
54
-    /**
55
-     * Certificate issuer.
56
-     *
57
-     * @var Name $_issuer
58
-     */
59
-    protected $_issuer;
60
-    
61
-    /**
62
-     * Certificate validity period.
63
-     *
64
-     * @var Validity $_validity
65
-     */
66
-    protected $_validity;
67
-    
68
-    /**
69
-     * Certificate subject.
70
-     *
71
-     * @var Name $_subject
72
-     */
73
-    protected $_subject;
74
-    
75
-    /**
76
-     * Subject public key.
77
-     *
78
-     * @var PublicKeyInfo $_subjectPublicKeyInfo
79
-     */
80
-    protected $_subjectPublicKeyInfo;
81
-    
82
-    /**
83
-     * Issuer unique identifier.
84
-     *
85
-     * @var UniqueIdentifier|null $_issuerUniqueID
86
-     */
87
-    protected $_issuerUniqueID;
88
-    
89
-    /**
90
-     * Subject unique identifier.
91
-     *
92
-     * @var UniqueIdentifier|null $_subjectUniqueID
93
-     */
94
-    protected $_subjectUniqueID;
95
-    
96
-    /**
97
-     * Extensions.
98
-     *
99
-     * @var Extensions $_extensions
100
-     */
101
-    protected $_extensions;
102
-    
103
-    /**
104
-     * Constructor.
105
-     *
106
-     * @param Name $subject Certificate subject
107
-     * @param PublicKeyInfo $pki Subject public key
108
-     * @param Name $issuer Certificate issuer
109
-     * @param Validity $validity Validity period
110
-     */
111
-    public function __construct(Name $subject, PublicKeyInfo $pki, Name $issuer,
112
-        Validity $validity)
113
-    {
114
-        $this->_subject = $subject;
115
-        $this->_subjectPublicKeyInfo = $pki;
116
-        $this->_issuer = $issuer;
117
-        $this->_validity = $validity;
118
-        $this->_extensions = new Extensions();
119
-    }
120
-    
121
-    /**
122
-     * Initialize from ASN.1.
123
-     *
124
-     * @param Sequence $seq
125
-     * @return self
126
-     */
127
-    public static function fromASN1(Sequence $seq)
128
-    {
129
-        $idx = 0;
130
-        if ($seq->hasTagged(0)) {
131
-            $idx++;
132
-            $version = intval(
133
-                $seq->getTagged(0)
134
-                    ->asExplicit()
135
-                    ->asInteger()
136
-                    ->number());
137
-        } else {
138
-            $version = self::VERSION_1;
139
-        }
140
-        $serial = $seq->at($idx++)
141
-            ->asInteger()
142
-            ->number();
143
-        $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
144
-        if (!$algo instanceof SignatureAlgorithmIdentifier) {
145
-            throw new \UnexpectedValueException(
146
-                "Unsupported signature algorithm " . $algo->name() . ".");
147
-        }
148
-        $issuer = Name::fromASN1($seq->at($idx++)->asSequence());
149
-        $validity = Validity::fromASN1($seq->at($idx++)->asSequence());
150
-        $subject = Name::fromASN1($seq->at($idx++)->asSequence());
151
-        $pki = PublicKeyInfo::fromASN1($seq->at($idx++)->asSequence());
152
-        $tbs_cert = new self($subject, $pki, $issuer, $validity);
153
-        $tbs_cert->_version = $version;
154
-        $tbs_cert->_serialNumber = $serial;
155
-        $tbs_cert->_signature = $algo;
156
-        if ($seq->hasTagged(1)) {
157
-            $tbs_cert->_issuerUniqueID = UniqueIdentifier::fromASN1(
158
-                $seq->getTagged(1)
159
-                    ->asImplicit(Element::TYPE_BIT_STRING)
160
-                    ->asBitString());
161
-        }
162
-        if ($seq->hasTagged(2)) {
163
-            $tbs_cert->_subjectUniqueID = UniqueIdentifier::fromASN1(
164
-                $seq->getTagged(2)
165
-                    ->asImplicit(Element::TYPE_BIT_STRING)
166
-                    ->asBitString());
167
-        }
168
-        if ($seq->hasTagged(3)) {
169
-            $tbs_cert->_extensions = Extensions::fromASN1(
170
-                $seq->getTagged(3)
171
-                    ->asExplicit()
172
-                    ->asSequence());
173
-        }
174
-        return $tbs_cert;
175
-    }
176
-    
177
-    /**
178
-     * Initialize from certification request.
179
-     *
180
-     * Note that signature is not verified and must be done by the caller.
181
-     *
182
-     * @param CertificationRequest $cr
183
-     * @return self
184
-     */
185
-    public static function fromCSR(CertificationRequest $cr)
186
-    {
187
-        $cri = $cr->certificationRequestInfo();
188
-        $tbs_cert = new self($cri->subject(), $cri->subjectPKInfo(), new Name(),
189
-            Validity::fromStrings(null, null));
190
-        // if CSR has Extension Request attribute
191
-        if ($cri->hasAttributes()) {
192
-            $attribs = $cri->attributes();
193
-            if ($attribs->hasExtensionRequest()) {
194
-                $tbs_cert = $tbs_cert->withExtensions(
195
-                    $attribs->extensionRequest()
196
-                        ->extensions());
197
-            }
198
-        }
199
-        // add Subject Key Identifier extension
200
-        $tbs_cert = $tbs_cert->withAdditionalExtensions(
201
-            new SubjectKeyIdentifierExtension(false,
202
-                $cri->subjectPKInfo()
203
-                    ->keyIdentifier()));
204
-        return $tbs_cert;
205
-    }
206
-    
207
-    /**
208
-     * Get self with fields set from the issuer's certificate.
209
-     *
210
-     * Issuer shall be set to issuing certificate's subject.
211
-     * Authority key identifier extensions shall be added with a key identifier
212
-     * set to issuing certificate's public key identifier.
213
-     *
214
-     * @param Certificate $cert Issuing party's certificate
215
-     * @return self
216
-     */
217
-    public function withIssuerCertificate(Certificate $cert)
218
-    {
219
-        $obj = clone $this;
220
-        // set issuer DN from cert's subject
221
-        $obj->_issuer = $cert->tbsCertificate()->subject();
222
-        // add authority key identifier extension
223
-        $key_id = $cert->tbsCertificate()
224
-            ->subjectPublicKeyInfo()
225
-            ->keyIdentifier();
226
-        $obj->_extensions = $obj->_extensions->withExtensions(
227
-            new AuthorityKeyIdentifierExtension(false, $key_id));
228
-        return $obj;
229
-    }
230
-    
231
-    /**
232
-     * Get self with given version.
233
-     *
234
-     * If version is not set, appropriate version is automatically
235
-     * determined during signing.
236
-     *
237
-     * @param int $version
238
-     * @return self
239
-     */
240
-    public function withVersion($version)
241
-    {
242
-        $obj = clone $this;
243
-        $obj->_version = $version;
244
-        return $obj;
245
-    }
246
-    
247
-    /**
248
-     * Get self with given serial number.
249
-     *
250
-     * @param int|string $serial Base 10 number
251
-     * @return self
252
-     */
253
-    public function withSerialNumber($serial)
254
-    {
255
-        $obj = clone $this;
256
-        $obj->_serialNumber = $serial;
257
-        return $obj;
258
-    }
259
-    
260
-    /**
261
-     * Get self with random positive serial number.
262
-     *
263
-     * @param int $size Number of random bytes
264
-     * @return self
265
-     */
266
-    public function withRandomSerialNumber($size = 16)
267
-    {
268
-        // ensure that first byte is always non-zero and having first bit unset
269
-        $num = gmp_init(mt_rand(1, 0x7f), 10);
270
-        for ($i = 1; $i < $size; ++$i) {
271
-            $num <<= 8;
272
-            $num += mt_rand(0, 0xff);
273
-        }
274
-        return $this->withSerialNumber(gmp_strval($num, 10));
275
-    }
276
-    
277
-    /**
278
-     * Get self with given signature algorithm.
279
-     *
280
-     * @param SignatureAlgorithmIdentifier $algo
281
-     * @return self
282
-     */
283
-    public function withSignature(SignatureAlgorithmIdentifier $algo)
284
-    {
285
-        $obj = clone $this;
286
-        $obj->_signature = $algo;
287
-        return $obj;
288
-    }
289
-    
290
-    /**
291
-     * Get self with given issuer.
292
-     *
293
-     * @param Name $issuer
294
-     * @return self
295
-     */
296
-    public function withIssuer(Name $issuer)
297
-    {
298
-        $obj = clone $this;
299
-        $obj->_issuer = $issuer;
300
-        return $obj;
301
-    }
302
-    
303
-    /**
304
-     * Get self with given validity.
305
-     *
306
-     * @param Validity $validity
307
-     * @return self
308
-     */
309
-    public function withValidity(Validity $validity)
310
-    {
311
-        $obj = clone $this;
312
-        $obj->_validity = $validity;
313
-        return $obj;
314
-    }
315
-    
316
-    /**
317
-     * Get self with given subject.
318
-     *
319
-     * @param Name $subject
320
-     * @return self
321
-     */
322
-    public function withSubject(Name $subject)
323
-    {
324
-        $obj = clone $this;
325
-        $obj->_subject = $subject;
326
-        return $obj;
327
-    }
328
-    
329
-    /**
330
-     * Get self with given subject public key info.
331
-     *
332
-     * @param PublicKeyInfo $pub_key_info
333
-     * @return self
334
-     */
335
-    public function withSubjectPublicKeyInfo(PublicKeyInfo $pub_key_info)
336
-    {
337
-        $obj = clone $this;
338
-        $obj->_subjectPublicKeyInfo = $pub_key_info;
339
-        return $obj;
340
-    }
341
-    
342
-    /**
343
-     * Get self with issuer unique ID.
344
-     *
345
-     * @param UniqueIdentifier $id
346
-     * @return self
347
-     */
348
-    public function withIssuerUniqueID(UniqueIdentifier $id)
349
-    {
350
-        $obj = clone $this;
351
-        $obj->_issuerUniqueID = $id;
352
-        return $obj;
353
-    }
354
-    
355
-    /**
356
-     * Get self with subject unique ID.
357
-     *
358
-     * @param UniqueIdentifier $id
359
-     * @return self
360
-     */
361
-    public function withSubjectUniqueID(UniqueIdentifier $id)
362
-    {
363
-        $obj = clone $this;
364
-        $obj->_subjectUniqueID = $id;
365
-        return $obj;
366
-    }
367
-    
368
-    /**
369
-     * Get self with given extensions.
370
-     *
371
-     * @param Extensions $extensions
372
-     * @return self
373
-     */
374
-    public function withExtensions(Extensions $extensions)
375
-    {
376
-        $obj = clone $this;
377
-        $obj->_extensions = $extensions;
378
-        return $obj;
379
-    }
380
-    
381
-    /**
382
-     * Get self with extensions added.
383
-     *
384
-     * @param Extension ...$exts One or more Extension objects
385
-     * @return self
386
-     */
387
-    public function withAdditionalExtensions(Extension ...$exts)
388
-    {
389
-        $obj = clone $this;
390
-        $obj->_extensions = $obj->_extensions->withExtensions(...$exts);
391
-        return $obj;
392
-    }
393
-    
394
-    /**
395
-     * Check whether version is set.
396
-     *
397
-     * @return bool
398
-     */
399
-    public function hasVersion()
400
-    {
401
-        return isset($this->_version);
402
-    }
403
-    
404
-    /**
405
-     * Get certificate version.
406
-     *
407
-     * @return int
408
-     */
409
-    public function version()
410
-    {
411
-        if (!$this->hasVersion()) {
412
-            throw new \LogicException("version not set.");
413
-        }
414
-        return $this->_version;
415
-    }
416
-    
417
-    /**
418
-     * Check whether serial number is set.
419
-     *
420
-     * @return bool
421
-     */
422
-    public function hasSerialNumber()
423
-    {
424
-        return isset($this->_serialNumber);
425
-    }
426
-    
427
-    /**
428
-     * Get serial number.
429
-     *
430
-     * @return int|string Base 10 integer
431
-     */
432
-    public function serialNumber()
433
-    {
434
-        if (!$this->hasSerialNumber()) {
435
-            throw new \LogicException("serialNumber not set.");
436
-        }
437
-        return $this->_serialNumber;
438
-    }
439
-    
440
-    /**
441
-     * Check whether signature algorithm is set.
442
-     *
443
-     * @return bool
444
-     */
445
-    public function hasSignature()
446
-    {
447
-        return isset($this->_signature);
448
-    }
449
-    
450
-    /**
451
-     * Get signature algorithm.
452
-     *
453
-     * @return SignatureAlgorithmIdentifier
454
-     */
455
-    public function signature()
456
-    {
457
-        if (!$this->hasSignature()) {
458
-            throw new \LogicException("signature not set.");
459
-        }
460
-        return $this->_signature;
461
-    }
462
-    
463
-    /**
464
-     * Get issuer.
465
-     *
466
-     * @return Name
467
-     */
468
-    public function issuer()
469
-    {
470
-        return $this->_issuer;
471
-    }
472
-    
473
-    /**
474
-     * Get validity period.
475
-     *
476
-     * @return Validity
477
-     */
478
-    public function validity()
479
-    {
480
-        return $this->_validity;
481
-    }
482
-    
483
-    /**
484
-     * Get subject.
485
-     *
486
-     * @return Name
487
-     */
488
-    public function subject()
489
-    {
490
-        return $this->_subject;
491
-    }
492
-    
493
-    /**
494
-     * Get subject public key.
495
-     *
496
-     * @return PublicKeyInfo
497
-     */
498
-    public function subjectPublicKeyInfo()
499
-    {
500
-        return $this->_subjectPublicKeyInfo;
501
-    }
502
-    
503
-    /**
504
-     * Whether issuer unique identifier is present.
505
-     *
506
-     * @return bool
507
-     */
508
-    public function hasIssuerUniqueID()
509
-    {
510
-        return isset($this->_issuerUniqueID);
511
-    }
512
-    
513
-    /**
514
-     * Get issuerUniqueID.
515
-     *
516
-     * @return UniqueIdentifier
517
-     */
518
-    public function issuerUniqueID()
519
-    {
520
-        if (!$this->hasIssuerUniqueID()) {
521
-            throw new \LogicException("issuerUniqueID not set.");
522
-        }
523
-        return $this->_issuerUniqueID;
524
-    }
525
-    
526
-    /**
527
-     * Whether subject unique identifier is present.
528
-     *
529
-     * @return bool
530
-     */
531
-    public function hasSubjectUniqueID()
532
-    {
533
-        return isset($this->_subjectUniqueID);
534
-    }
535
-    
536
-    /**
537
-     * Get subjectUniqueID.
538
-     *
539
-     * @return UniqueIdentifier
540
-     */
541
-    public function subjectUniqueID()
542
-    {
543
-        if (!$this->hasSubjectUniqueID()) {
544
-            throw new \LogicException("subjectUniqueID not set.");
545
-        }
546
-        return $this->_subjectUniqueID;
547
-    }
548
-    
549
-    /**
550
-     * Get extensions.
551
-     *
552
-     * @return Extensions
553
-     */
554
-    public function extensions()
555
-    {
556
-        return $this->_extensions;
557
-    }
558
-    
559
-    /**
560
-     * Generate ASN.1 structure.
561
-     *
562
-     * @return Sequence
563
-     */
564
-    public function toASN1()
565
-    {
566
-        $elements = array();
567
-        $version = $this->version();
568
-        // if version is not default
569
-        if ($version != self::VERSION_1) {
570
-            $elements[] = new ExplicitlyTaggedType(0, new Integer($version));
571
-        }
572
-        $serial = $this->serialNumber();
573
-        $signature = $this->signature();
574
-        // add required elements
575
-        array_push($elements, new Integer($serial), $signature->toASN1(),
576
-            $this->_issuer->toASN1(), $this->_validity->toASN1(),
577
-            $this->_subject->toASN1(), $this->_subjectPublicKeyInfo->toASN1());
578
-        if (isset($this->_issuerUniqueID)) {
579
-            $elements[] = new ImplicitlyTaggedType(1,
580
-                $this->_issuerUniqueID->toASN1());
581
-        }
582
-        if (isset($this->_subjectUniqueID)) {
583
-            $elements[] = new ImplicitlyTaggedType(2,
584
-                $this->_subjectUniqueID->toASN1());
585
-        }
586
-        if (count($this->_extensions)) {
587
-            $elements[] = new ExplicitlyTaggedType(3,
588
-                $this->_extensions->toASN1());
589
-        }
590
-        return new Sequence(...$elements);
591
-    }
592
-    
593
-    /**
594
-     * Create signed certificate.
595
-     *
596
-     * @param SignatureAlgorithmIdentifier $algo Algorithm used for signing
597
-     * @param PrivateKeyInfo $privkey_info Private key used for signing
598
-     * @param Crypto|null $crypto Crypto engine, use default if not set
599
-     * @return Certificate
600
-     */
601
-    public function sign(SignatureAlgorithmIdentifier $algo,
602
-        PrivateKeyInfo $privkey_info, Crypto $crypto = null)
603
-    {
604
-        $crypto = $crypto ?: Crypto::getDefault();
605
-        $tbs_cert = clone $this;
606
-        if (!isset($tbs_cert->_version)) {
607
-            $tbs_cert->_version = $tbs_cert->_determineVersion();
608
-        }
609
-        if (!isset($tbs_cert->_serialNumber)) {
610
-            $tbs_cert->_serialNumber = 0;
611
-        }
612
-        $tbs_cert->_signature = $algo;
613
-        $data = $tbs_cert->toASN1()->toDER();
614
-        $signature = $crypto->sign($data, $privkey_info, $algo);
615
-        return new Certificate($tbs_cert, $algo, $signature);
616
-    }
617
-    
618
-    /**
619
-     * Determine minimum version for the certificate.
620
-     *
621
-     * @return int
622
-     */
623
-    protected function _determineVersion()
624
-    {
625
-        // if extensions are present
626
-        if (count($this->_extensions)) {
627
-            return self::VERSION_3;
628
-        }
629
-        // if UniqueIdentifier is present
630
-        if (isset($this->_issuerUniqueID) || isset($this->_subjectUniqueID)) {
631
-            return self::VERSION_2;
632
-        }
633
-        return self::VERSION_1;
634
-    }
28
+	// Certificate version enumerations
29
+	const VERSION_1 = 0;
30
+	const VERSION_2 = 1;
31
+	const VERSION_3 = 2;
32
+    
33
+	/**
34
+	 * Certificate version.
35
+	 *
36
+	 * @var int
37
+	 */
38
+	protected $_version;
39
+    
40
+	/**
41
+	 * Serial number.
42
+	 *
43
+	 * @var int|string
44
+	 */
45
+	protected $_serialNumber;
46
+    
47
+	/**
48
+	 * Signature algorithm.
49
+	 *
50
+	 * @var SignatureAlgorithmIdentifier
51
+	 */
52
+	protected $_signature;
53
+    
54
+	/**
55
+	 * Certificate issuer.
56
+	 *
57
+	 * @var Name $_issuer
58
+	 */
59
+	protected $_issuer;
60
+    
61
+	/**
62
+	 * Certificate validity period.
63
+	 *
64
+	 * @var Validity $_validity
65
+	 */
66
+	protected $_validity;
67
+    
68
+	/**
69
+	 * Certificate subject.
70
+	 *
71
+	 * @var Name $_subject
72
+	 */
73
+	protected $_subject;
74
+    
75
+	/**
76
+	 * Subject public key.
77
+	 *
78
+	 * @var PublicKeyInfo $_subjectPublicKeyInfo
79
+	 */
80
+	protected $_subjectPublicKeyInfo;
81
+    
82
+	/**
83
+	 * Issuer unique identifier.
84
+	 *
85
+	 * @var UniqueIdentifier|null $_issuerUniqueID
86
+	 */
87
+	protected $_issuerUniqueID;
88
+    
89
+	/**
90
+	 * Subject unique identifier.
91
+	 *
92
+	 * @var UniqueIdentifier|null $_subjectUniqueID
93
+	 */
94
+	protected $_subjectUniqueID;
95
+    
96
+	/**
97
+	 * Extensions.
98
+	 *
99
+	 * @var Extensions $_extensions
100
+	 */
101
+	protected $_extensions;
102
+    
103
+	/**
104
+	 * Constructor.
105
+	 *
106
+	 * @param Name $subject Certificate subject
107
+	 * @param PublicKeyInfo $pki Subject public key
108
+	 * @param Name $issuer Certificate issuer
109
+	 * @param Validity $validity Validity period
110
+	 */
111
+	public function __construct(Name $subject, PublicKeyInfo $pki, Name $issuer,
112
+		Validity $validity)
113
+	{
114
+		$this->_subject = $subject;
115
+		$this->_subjectPublicKeyInfo = $pki;
116
+		$this->_issuer = $issuer;
117
+		$this->_validity = $validity;
118
+		$this->_extensions = new Extensions();
119
+	}
120
+    
121
+	/**
122
+	 * Initialize from ASN.1.
123
+	 *
124
+	 * @param Sequence $seq
125
+	 * @return self
126
+	 */
127
+	public static function fromASN1(Sequence $seq)
128
+	{
129
+		$idx = 0;
130
+		if ($seq->hasTagged(0)) {
131
+			$idx++;
132
+			$version = intval(
133
+				$seq->getTagged(0)
134
+					->asExplicit()
135
+					->asInteger()
136
+					->number());
137
+		} else {
138
+			$version = self::VERSION_1;
139
+		}
140
+		$serial = $seq->at($idx++)
141
+			->asInteger()
142
+			->number();
143
+		$algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
144
+		if (!$algo instanceof SignatureAlgorithmIdentifier) {
145
+			throw new \UnexpectedValueException(
146
+				"Unsupported signature algorithm " . $algo->name() . ".");
147
+		}
148
+		$issuer = Name::fromASN1($seq->at($idx++)->asSequence());
149
+		$validity = Validity::fromASN1($seq->at($idx++)->asSequence());
150
+		$subject = Name::fromASN1($seq->at($idx++)->asSequence());
151
+		$pki = PublicKeyInfo::fromASN1($seq->at($idx++)->asSequence());
152
+		$tbs_cert = new self($subject, $pki, $issuer, $validity);
153
+		$tbs_cert->_version = $version;
154
+		$tbs_cert->_serialNumber = $serial;
155
+		$tbs_cert->_signature = $algo;
156
+		if ($seq->hasTagged(1)) {
157
+			$tbs_cert->_issuerUniqueID = UniqueIdentifier::fromASN1(
158
+				$seq->getTagged(1)
159
+					->asImplicit(Element::TYPE_BIT_STRING)
160
+					->asBitString());
161
+		}
162
+		if ($seq->hasTagged(2)) {
163
+			$tbs_cert->_subjectUniqueID = UniqueIdentifier::fromASN1(
164
+				$seq->getTagged(2)
165
+					->asImplicit(Element::TYPE_BIT_STRING)
166
+					->asBitString());
167
+		}
168
+		if ($seq->hasTagged(3)) {
169
+			$tbs_cert->_extensions = Extensions::fromASN1(
170
+				$seq->getTagged(3)
171
+					->asExplicit()
172
+					->asSequence());
173
+		}
174
+		return $tbs_cert;
175
+	}
176
+    
177
+	/**
178
+	 * Initialize from certification request.
179
+	 *
180
+	 * Note that signature is not verified and must be done by the caller.
181
+	 *
182
+	 * @param CertificationRequest $cr
183
+	 * @return self
184
+	 */
185
+	public static function fromCSR(CertificationRequest $cr)
186
+	{
187
+		$cri = $cr->certificationRequestInfo();
188
+		$tbs_cert = new self($cri->subject(), $cri->subjectPKInfo(), new Name(),
189
+			Validity::fromStrings(null, null));
190
+		// if CSR has Extension Request attribute
191
+		if ($cri->hasAttributes()) {
192
+			$attribs = $cri->attributes();
193
+			if ($attribs->hasExtensionRequest()) {
194
+				$tbs_cert = $tbs_cert->withExtensions(
195
+					$attribs->extensionRequest()
196
+						->extensions());
197
+			}
198
+		}
199
+		// add Subject Key Identifier extension
200
+		$tbs_cert = $tbs_cert->withAdditionalExtensions(
201
+			new SubjectKeyIdentifierExtension(false,
202
+				$cri->subjectPKInfo()
203
+					->keyIdentifier()));
204
+		return $tbs_cert;
205
+	}
206
+    
207
+	/**
208
+	 * Get self with fields set from the issuer's certificate.
209
+	 *
210
+	 * Issuer shall be set to issuing certificate's subject.
211
+	 * Authority key identifier extensions shall be added with a key identifier
212
+	 * set to issuing certificate's public key identifier.
213
+	 *
214
+	 * @param Certificate $cert Issuing party's certificate
215
+	 * @return self
216
+	 */
217
+	public function withIssuerCertificate(Certificate $cert)
218
+	{
219
+		$obj = clone $this;
220
+		// set issuer DN from cert's subject
221
+		$obj->_issuer = $cert->tbsCertificate()->subject();
222
+		// add authority key identifier extension
223
+		$key_id = $cert->tbsCertificate()
224
+			->subjectPublicKeyInfo()
225
+			->keyIdentifier();
226
+		$obj->_extensions = $obj->_extensions->withExtensions(
227
+			new AuthorityKeyIdentifierExtension(false, $key_id));
228
+		return $obj;
229
+	}
230
+    
231
+	/**
232
+	 * Get self with given version.
233
+	 *
234
+	 * If version is not set, appropriate version is automatically
235
+	 * determined during signing.
236
+	 *
237
+	 * @param int $version
238
+	 * @return self
239
+	 */
240
+	public function withVersion($version)
241
+	{
242
+		$obj = clone $this;
243
+		$obj->_version = $version;
244
+		return $obj;
245
+	}
246
+    
247
+	/**
248
+	 * Get self with given serial number.
249
+	 *
250
+	 * @param int|string $serial Base 10 number
251
+	 * @return self
252
+	 */
253
+	public function withSerialNumber($serial)
254
+	{
255
+		$obj = clone $this;
256
+		$obj->_serialNumber = $serial;
257
+		return $obj;
258
+	}
259
+    
260
+	/**
261
+	 * Get self with random positive serial number.
262
+	 *
263
+	 * @param int $size Number of random bytes
264
+	 * @return self
265
+	 */
266
+	public function withRandomSerialNumber($size = 16)
267
+	{
268
+		// ensure that first byte is always non-zero and having first bit unset
269
+		$num = gmp_init(mt_rand(1, 0x7f), 10);
270
+		for ($i = 1; $i < $size; ++$i) {
271
+			$num <<= 8;
272
+			$num += mt_rand(0, 0xff);
273
+		}
274
+		return $this->withSerialNumber(gmp_strval($num, 10));
275
+	}
276
+    
277
+	/**
278
+	 * Get self with given signature algorithm.
279
+	 *
280
+	 * @param SignatureAlgorithmIdentifier $algo
281
+	 * @return self
282
+	 */
283
+	public function withSignature(SignatureAlgorithmIdentifier $algo)
284
+	{
285
+		$obj = clone $this;
286
+		$obj->_signature = $algo;
287
+		return $obj;
288
+	}
289
+    
290
+	/**
291
+	 * Get self with given issuer.
292
+	 *
293
+	 * @param Name $issuer
294
+	 * @return self
295
+	 */
296
+	public function withIssuer(Name $issuer)
297
+	{
298
+		$obj = clone $this;
299
+		$obj->_issuer = $issuer;
300
+		return $obj;
301
+	}
302
+    
303
+	/**
304
+	 * Get self with given validity.
305
+	 *
306
+	 * @param Validity $validity
307
+	 * @return self
308
+	 */
309
+	public function withValidity(Validity $validity)
310
+	{
311
+		$obj = clone $this;
312
+		$obj->_validity = $validity;
313
+		return $obj;
314
+	}
315
+    
316
+	/**
317
+	 * Get self with given subject.
318
+	 *
319
+	 * @param Name $subject
320
+	 * @return self
321
+	 */
322
+	public function withSubject(Name $subject)
323
+	{
324
+		$obj = clone $this;
325
+		$obj->_subject = $subject;
326
+		return $obj;
327
+	}
328
+    
329
+	/**
330
+	 * Get self with given subject public key info.
331
+	 *
332
+	 * @param PublicKeyInfo $pub_key_info
333
+	 * @return self
334
+	 */
335
+	public function withSubjectPublicKeyInfo(PublicKeyInfo $pub_key_info)
336
+	{
337
+		$obj = clone $this;
338
+		$obj->_subjectPublicKeyInfo = $pub_key_info;
339
+		return $obj;
340
+	}
341
+    
342
+	/**
343
+	 * Get self with issuer unique ID.
344
+	 *
345
+	 * @param UniqueIdentifier $id
346
+	 * @return self
347
+	 */
348
+	public function withIssuerUniqueID(UniqueIdentifier $id)
349
+	{
350
+		$obj = clone $this;
351
+		$obj->_issuerUniqueID = $id;
352
+		return $obj;
353
+	}
354
+    
355
+	/**
356
+	 * Get self with subject unique ID.
357
+	 *
358
+	 * @param UniqueIdentifier $id
359
+	 * @return self
360
+	 */
361
+	public function withSubjectUniqueID(UniqueIdentifier $id)
362
+	{
363
+		$obj = clone $this;
364
+		$obj->_subjectUniqueID = $id;
365
+		return $obj;
366
+	}
367
+    
368
+	/**
369
+	 * Get self with given extensions.
370
+	 *
371
+	 * @param Extensions $extensions
372
+	 * @return self
373
+	 */
374
+	public function withExtensions(Extensions $extensions)
375
+	{
376
+		$obj = clone $this;
377
+		$obj->_extensions = $extensions;
378
+		return $obj;
379
+	}
380
+    
381
+	/**
382
+	 * Get self with extensions added.
383
+	 *
384
+	 * @param Extension ...$exts One or more Extension objects
385
+	 * @return self
386
+	 */
387
+	public function withAdditionalExtensions(Extension ...$exts)
388
+	{
389
+		$obj = clone $this;
390
+		$obj->_extensions = $obj->_extensions->withExtensions(...$exts);
391
+		return $obj;
392
+	}
393
+    
394
+	/**
395
+	 * Check whether version is set.
396
+	 *
397
+	 * @return bool
398
+	 */
399
+	public function hasVersion()
400
+	{
401
+		return isset($this->_version);
402
+	}
403
+    
404
+	/**
405
+	 * Get certificate version.
406
+	 *
407
+	 * @return int
408
+	 */
409
+	public function version()
410
+	{
411
+		if (!$this->hasVersion()) {
412
+			throw new \LogicException("version not set.");
413
+		}
414
+		return $this->_version;
415
+	}
416
+    
417
+	/**
418
+	 * Check whether serial number is set.
419
+	 *
420
+	 * @return bool
421
+	 */
422
+	public function hasSerialNumber()
423
+	{
424
+		return isset($this->_serialNumber);
425
+	}
426
+    
427
+	/**
428
+	 * Get serial number.
429
+	 *
430
+	 * @return int|string Base 10 integer
431
+	 */
432
+	public function serialNumber()
433
+	{
434
+		if (!$this->hasSerialNumber()) {
435
+			throw new \LogicException("serialNumber not set.");
436
+		}
437
+		return $this->_serialNumber;
438
+	}
439
+    
440
+	/**
441
+	 * Check whether signature algorithm is set.
442
+	 *
443
+	 * @return bool
444
+	 */
445
+	public function hasSignature()
446
+	{
447
+		return isset($this->_signature);
448
+	}
449
+    
450
+	/**
451
+	 * Get signature algorithm.
452
+	 *
453
+	 * @return SignatureAlgorithmIdentifier
454
+	 */
455
+	public function signature()
456
+	{
457
+		if (!$this->hasSignature()) {
458
+			throw new \LogicException("signature not set.");
459
+		}
460
+		return $this->_signature;
461
+	}
462
+    
463
+	/**
464
+	 * Get issuer.
465
+	 *
466
+	 * @return Name
467
+	 */
468
+	public function issuer()
469
+	{
470
+		return $this->_issuer;
471
+	}
472
+    
473
+	/**
474
+	 * Get validity period.
475
+	 *
476
+	 * @return Validity
477
+	 */
478
+	public function validity()
479
+	{
480
+		return $this->_validity;
481
+	}
482
+    
483
+	/**
484
+	 * Get subject.
485
+	 *
486
+	 * @return Name
487
+	 */
488
+	public function subject()
489
+	{
490
+		return $this->_subject;
491
+	}
492
+    
493
+	/**
494
+	 * Get subject public key.
495
+	 *
496
+	 * @return PublicKeyInfo
497
+	 */
498
+	public function subjectPublicKeyInfo()
499
+	{
500
+		return $this->_subjectPublicKeyInfo;
501
+	}
502
+    
503
+	/**
504
+	 * Whether issuer unique identifier is present.
505
+	 *
506
+	 * @return bool
507
+	 */
508
+	public function hasIssuerUniqueID()
509
+	{
510
+		return isset($this->_issuerUniqueID);
511
+	}
512
+    
513
+	/**
514
+	 * Get issuerUniqueID.
515
+	 *
516
+	 * @return UniqueIdentifier
517
+	 */
518
+	public function issuerUniqueID()
519
+	{
520
+		if (!$this->hasIssuerUniqueID()) {
521
+			throw new \LogicException("issuerUniqueID not set.");
522
+		}
523
+		return $this->_issuerUniqueID;
524
+	}
525
+    
526
+	/**
527
+	 * Whether subject unique identifier is present.
528
+	 *
529
+	 * @return bool
530
+	 */
531
+	public function hasSubjectUniqueID()
532
+	{
533
+		return isset($this->_subjectUniqueID);
534
+	}
535
+    
536
+	/**
537
+	 * Get subjectUniqueID.
538
+	 *
539
+	 * @return UniqueIdentifier
540
+	 */
541
+	public function subjectUniqueID()
542
+	{
543
+		if (!$this->hasSubjectUniqueID()) {
544
+			throw new \LogicException("subjectUniqueID not set.");
545
+		}
546
+		return $this->_subjectUniqueID;
547
+	}
548
+    
549
+	/**
550
+	 * Get extensions.
551
+	 *
552
+	 * @return Extensions
553
+	 */
554
+	public function extensions()
555
+	{
556
+		return $this->_extensions;
557
+	}
558
+    
559
+	/**
560
+	 * Generate ASN.1 structure.
561
+	 *
562
+	 * @return Sequence
563
+	 */
564
+	public function toASN1()
565
+	{
566
+		$elements = array();
567
+		$version = $this->version();
568
+		// if version is not default
569
+		if ($version != self::VERSION_1) {
570
+			$elements[] = new ExplicitlyTaggedType(0, new Integer($version));
571
+		}
572
+		$serial = $this->serialNumber();
573
+		$signature = $this->signature();
574
+		// add required elements
575
+		array_push($elements, new Integer($serial), $signature->toASN1(),
576
+			$this->_issuer->toASN1(), $this->_validity->toASN1(),
577
+			$this->_subject->toASN1(), $this->_subjectPublicKeyInfo->toASN1());
578
+		if (isset($this->_issuerUniqueID)) {
579
+			$elements[] = new ImplicitlyTaggedType(1,
580
+				$this->_issuerUniqueID->toASN1());
581
+		}
582
+		if (isset($this->_subjectUniqueID)) {
583
+			$elements[] = new ImplicitlyTaggedType(2,
584
+				$this->_subjectUniqueID->toASN1());
585
+		}
586
+		if (count($this->_extensions)) {
587
+			$elements[] = new ExplicitlyTaggedType(3,
588
+				$this->_extensions->toASN1());
589
+		}
590
+		return new Sequence(...$elements);
591
+	}
592
+    
593
+	/**
594
+	 * Create signed certificate.
595
+	 *
596
+	 * @param SignatureAlgorithmIdentifier $algo Algorithm used for signing
597
+	 * @param PrivateKeyInfo $privkey_info Private key used for signing
598
+	 * @param Crypto|null $crypto Crypto engine, use default if not set
599
+	 * @return Certificate
600
+	 */
601
+	public function sign(SignatureAlgorithmIdentifier $algo,
602
+		PrivateKeyInfo $privkey_info, Crypto $crypto = null)
603
+	{
604
+		$crypto = $crypto ?: Crypto::getDefault();
605
+		$tbs_cert = clone $this;
606
+		if (!isset($tbs_cert->_version)) {
607
+			$tbs_cert->_version = $tbs_cert->_determineVersion();
608
+		}
609
+		if (!isset($tbs_cert->_serialNumber)) {
610
+			$tbs_cert->_serialNumber = 0;
611
+		}
612
+		$tbs_cert->_signature = $algo;
613
+		$data = $tbs_cert->toASN1()->toDER();
614
+		$signature = $crypto->sign($data, $privkey_info, $algo);
615
+		return new Certificate($tbs_cert, $algo, $signature);
616
+	}
617
+    
618
+	/**
619
+	 * Determine minimum version for the certificate.
620
+	 *
621
+	 * @return int
622
+	 */
623
+	protected function _determineVersion()
624
+	{
625
+		// if extensions are present
626
+		if (count($this->_extensions)) {
627
+			return self::VERSION_3;
628
+		}
629
+		// if UniqueIdentifier is present
630
+		if (isset($this->_issuerUniqueID) || isset($this->_subjectUniqueID)) {
631
+			return self::VERSION_2;
632
+		}
633
+		return self::VERSION_1;
634
+	}
635 635
 }
Please login to merge, or discard this patch.
lib/X509/Certificate/Time.php 2 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -15,105 +15,105 @@
 block discarded – undo
15 15
  */
16 16
 class Time
17 17
 {
18
-    use DateTimeHelper;
18
+	use DateTimeHelper;
19 19
     
20
-    /**
21
-     * Datetime.
22
-     *
23
-     * @var \DateTimeImmutable $_dt
24
-     */
25
-    protected $_dt;
20
+	/**
21
+	 * Datetime.
22
+	 *
23
+	 * @var \DateTimeImmutable $_dt
24
+	 */
25
+	protected $_dt;
26 26
     
27
-    /**
28
-     * Time ASN.1 type tag.
29
-     *
30
-     * @var int $_type
31
-     */
32
-    protected $_type;
27
+	/**
28
+	 * Time ASN.1 type tag.
29
+	 *
30
+	 * @var int $_type
31
+	 */
32
+	protected $_type;
33 33
     
34
-    /**
35
-     * Constructor.
36
-     *
37
-     * @param \DateTimeImmutable $dt
38
-     */
39
-    public function __construct(\DateTimeImmutable $dt)
40
-    {
41
-        $this->_dt = $dt;
42
-        $this->_type = self::_determineType($dt);
43
-    }
34
+	/**
35
+	 * Constructor.
36
+	 *
37
+	 * @param \DateTimeImmutable $dt
38
+	 */
39
+	public function __construct(\DateTimeImmutable $dt)
40
+	{
41
+		$this->_dt = $dt;
42
+		$this->_type = self::_determineType($dt);
43
+	}
44 44
     
45
-    /**
46
-     * Initialize from ASN.1.
47
-     *
48
-     * @param TimeType $el
49
-     * @return self
50
-     */
51
-    public static function fromASN1(TimeType $el)
52
-    {
53
-        $obj = new self($el->dateTime());
54
-        $obj->_type = $el->tag();
55
-        return $obj;
56
-    }
45
+	/**
46
+	 * Initialize from ASN.1.
47
+	 *
48
+	 * @param TimeType $el
49
+	 * @return self
50
+	 */
51
+	public static function fromASN1(TimeType $el)
52
+	{
53
+		$obj = new self($el->dateTime());
54
+		$obj->_type = $el->tag();
55
+		return $obj;
56
+	}
57 57
     
58
-    /**
59
-     * Initialize from date string.
60
-     *
61
-     * @param string|null $time
62
-     * @param string|null $tz
63
-     * @return self
64
-     */
65
-    public static function fromString($time, $tz = null)
66
-    {
67
-        return new self(self::_createDateTime($time, $tz));
68
-    }
58
+	/**
59
+	 * Initialize from date string.
60
+	 *
61
+	 * @param string|null $time
62
+	 * @param string|null $tz
63
+	 * @return self
64
+	 */
65
+	public static function fromString($time, $tz = null)
66
+	{
67
+		return new self(self::_createDateTime($time, $tz));
68
+	}
69 69
     
70
-    /**
71
-     * Get datetime.
72
-     *
73
-     * @return \DateTimeImmutable
74
-     */
75
-    public function dateTime()
76
-    {
77
-        return $this->_dt;
78
-    }
70
+	/**
71
+	 * Get datetime.
72
+	 *
73
+	 * @return \DateTimeImmutable
74
+	 */
75
+	public function dateTime()
76
+	{
77
+		return $this->_dt;
78
+	}
79 79
     
80
-    /**
81
-     * Generate ASN.1.
82
-     *
83
-     * @throws \UnexpectedValueException
84
-     * @return TimeType
85
-     */
86
-    public function toASN1()
87
-    {
88
-        $dt = $this->_dt;
89
-        switch ($this->_type) {
90
-            case Element::TYPE_UTC_TIME:
91
-                return new UTCTime($dt);
92
-            case Element::TYPE_GENERALIZED_TIME:
93
-                // GeneralizedTime must not contain fractional seconds
94
-                // (rfc5280 4.1.2.5.2)
95
-                if ($dt->format("u") != 0) {
96
-                    // remove fractional seconds (round down)
97
-                    $dt = \DateTimeImmutable::createFromFormat("Y-m-d H:i:s",
98
-                        $dt->format("Y-m-d H:i:s"), $dt->getTimezone());
99
-                }
100
-                return new GeneralizedTime($dt);
101
-        }
102
-        throw new \UnexpectedValueException(
103
-            "Time type " . Element::tagToName($this->_type) . " not supported.");
104
-    }
80
+	/**
81
+	 * Generate ASN.1.
82
+	 *
83
+	 * @throws \UnexpectedValueException
84
+	 * @return TimeType
85
+	 */
86
+	public function toASN1()
87
+	{
88
+		$dt = $this->_dt;
89
+		switch ($this->_type) {
90
+			case Element::TYPE_UTC_TIME:
91
+				return new UTCTime($dt);
92
+			case Element::TYPE_GENERALIZED_TIME:
93
+				// GeneralizedTime must not contain fractional seconds
94
+				// (rfc5280 4.1.2.5.2)
95
+				if ($dt->format("u") != 0) {
96
+					// remove fractional seconds (round down)
97
+					$dt = \DateTimeImmutable::createFromFormat("Y-m-d H:i:s",
98
+						$dt->format("Y-m-d H:i:s"), $dt->getTimezone());
99
+				}
100
+				return new GeneralizedTime($dt);
101
+		}
102
+		throw new \UnexpectedValueException(
103
+			"Time type " . Element::tagToName($this->_type) . " not supported.");
104
+	}
105 105
     
106
-    /**
107
-     * Determine whether to use UTCTime or GeneralizedTime ASN.1 type.
108
-     *
109
-     * @param \DateTimeImmutable $dt
110
-     * @return int Type tag
111
-     */
112
-    protected static function _determineType(\DateTimeImmutable $dt)
113
-    {
114
-        if ($dt->format("Y") >= 2050) {
115
-            return Element::TYPE_GENERALIZED_TIME;
116
-        }
117
-        return Element::TYPE_UTC_TIME;
118
-    }
106
+	/**
107
+	 * Determine whether to use UTCTime or GeneralizedTime ASN.1 type.
108
+	 *
109
+	 * @param \DateTimeImmutable $dt
110
+	 * @return int Type tag
111
+	 */
112
+	protected static function _determineType(\DateTimeImmutable $dt)
113
+	{
114
+		if ($dt->format("Y") >= 2050) {
115
+			return Element::TYPE_GENERALIZED_TIME;
116
+		}
117
+		return Element::TYPE_UTC_TIME;
118
+	}
119 119
 }
Please login to merge, or discard this patch.
Switch Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -87,17 +87,17 @@
 block discarded – undo
87 87
     {
88 88
         $dt = $this->_dt;
89 89
         switch ($this->_type) {
90
-            case Element::TYPE_UTC_TIME:
91
-                return new UTCTime($dt);
92
-            case Element::TYPE_GENERALIZED_TIME:
93
-                // GeneralizedTime must not contain fractional seconds
94
-                // (rfc5280 4.1.2.5.2)
95
-                if ($dt->format("u") != 0) {
96
-                    // remove fractional seconds (round down)
97
-                    $dt = \DateTimeImmutable::createFromFormat("Y-m-d H:i:s",
98
-                        $dt->format("Y-m-d H:i:s"), $dt->getTimezone());
99
-                }
100
-                return new GeneralizedTime($dt);
90
+        case Element::TYPE_UTC_TIME:
91
+            return new UTCTime($dt);
92
+        case Element::TYPE_GENERALIZED_TIME:
93
+            // GeneralizedTime must not contain fractional seconds
94
+            // (rfc5280 4.1.2.5.2)
95
+            if ($dt->format("u") != 0) {
96
+                // remove fractional seconds (round down)
97
+                $dt = \DateTimeImmutable::createFromFormat("Y-m-d H:i:s",
98
+                    $dt->format("Y-m-d H:i:s"), $dt->getTimezone());
99
+            }
100
+            return new GeneralizedTime($dt);
101 101
         }
102 102
         throw new \UnexpectedValueException(
103 103
             "Time type " . Element::tagToName($this->_type) . " not supported.");
Please login to merge, or discard this patch.
lib/X509/Certificate/UniqueIdentifier.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -11,71 +11,71 @@
 block discarded – undo
11 11
  */
12 12
 class UniqueIdentifier
13 13
 {
14
-    /**
15
-     * Identifier.
16
-     *
17
-     * @var BitString $_uid
18
-     */
19
-    protected $_uid;
14
+	/**
15
+	 * Identifier.
16
+	 *
17
+	 * @var BitString $_uid
18
+	 */
19
+	protected $_uid;
20 20
     
21
-    /**
22
-     * Constructor.
23
-     *
24
-     * @param BitString $bs
25
-     */
26
-    public function __construct(BitString $bs)
27
-    {
28
-        $this->_uid = $bs;
29
-    }
21
+	/**
22
+	 * Constructor.
23
+	 *
24
+	 * @param BitString $bs
25
+	 */
26
+	public function __construct(BitString $bs)
27
+	{
28
+		$this->_uid = $bs;
29
+	}
30 30
     
31
-    /**
32
-     * Initialize from ASN.1.
33
-     *
34
-     * @param BitString $bs
35
-     */
36
-    public static function fromASN1(BitString $bs)
37
-    {
38
-        return new self($bs);
39
-    }
31
+	/**
32
+	 * Initialize from ASN.1.
33
+	 *
34
+	 * @param BitString $bs
35
+	 */
36
+	public static function fromASN1(BitString $bs)
37
+	{
38
+		return new self($bs);
39
+	}
40 40
     
41
-    /**
42
-     * Initialize from string.
43
-     *
44
-     * @param string $str
45
-     * @return self
46
-     */
47
-    public static function fromString($str)
48
-    {
49
-        return new self(new BitString($str));
50
-    }
41
+	/**
42
+	 * Initialize from string.
43
+	 *
44
+	 * @param string $str
45
+	 * @return self
46
+	 */
47
+	public static function fromString($str)
48
+	{
49
+		return new self(new BitString($str));
50
+	}
51 51
     
52
-    /**
53
-     * Get unique identifier as a string.
54
-     *
55
-     * @return string
56
-     */
57
-    public function string()
58
-    {
59
-        return $this->_uid->string();
60
-    }
52
+	/**
53
+	 * Get unique identifier as a string.
54
+	 *
55
+	 * @return string
56
+	 */
57
+	public function string()
58
+	{
59
+		return $this->_uid->string();
60
+	}
61 61
     
62
-    /**
63
-     * Get unique identifier as a bit string.
64
-     *
65
-     * @return BitString
66
-     */
67
-    public function bitString()
68
-    {
69
-        return $this->_uid;
70
-    }
62
+	/**
63
+	 * Get unique identifier as a bit string.
64
+	 *
65
+	 * @return BitString
66
+	 */
67
+	public function bitString()
68
+	{
69
+		return $this->_uid;
70
+	}
71 71
     
72
-    /**
73
-     * Get ASN.1 element.
74
-     *
75
-     * @return BitString
76
-     */
77
-    public function toASN1()
78
-    {
79
-        return $this->_uid;
80
-    }
72
+	/**
73
+	 * Get ASN.1 element.
74
+	 *
75
+	 * @return BitString
76
+	 */
77
+	public function toASN1()
78
+	{
79
+		return $this->_uid;
80
+	}
81 81
 }
Please login to merge, or discard this patch.