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 — php72 ( 84962a...e2a8e9 )
by Joni
02:36
created
lib/X509/CertificationRequest/Attribute/ExtensionRequestValue.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -18,83 +18,83 @@
 block discarded – undo
18 18
  */
19 19
 class ExtensionRequestValue extends AttributeValue
20 20
 {
21
-    const OID = '1.2.840.113549.1.9.14';
21
+	const OID = '1.2.840.113549.1.9.14';
22 22
 
23
-    /**
24
-     * Extensions.
25
-     *
26
-     * @var Extensions
27
-     */
28
-    protected $_extensions;
23
+	/**
24
+	 * Extensions.
25
+	 *
26
+	 * @var Extensions
27
+	 */
28
+	protected $_extensions;
29 29
 
30
-    /**
31
-     * Constructor.
32
-     *
33
-     * @param Extensions $extensions
34
-     */
35
-    public function __construct(Extensions $extensions)
36
-    {
37
-        $this->_extensions = $extensions;
38
-        $this->_oid = self::OID;
39
-    }
30
+	/**
31
+	 * Constructor.
32
+	 *
33
+	 * @param Extensions $extensions
34
+	 */
35
+	public function __construct(Extensions $extensions)
36
+	{
37
+		$this->_extensions = $extensions;
38
+		$this->_oid = self::OID;
39
+	}
40 40
 
41
-    /**
42
-     * {@inheritdoc}
43
-     *
44
-     * @return self
45
-     */
46
-    public static function fromASN1(UnspecifiedType $el): AttributeValue
47
-    {
48
-        return new self(Extensions::fromASN1($el->asSequence()));
49
-    }
41
+	/**
42
+	 * {@inheritdoc}
43
+	 *
44
+	 * @return self
45
+	 */
46
+	public static function fromASN1(UnspecifiedType $el): AttributeValue
47
+	{
48
+		return new self(Extensions::fromASN1($el->asSequence()));
49
+	}
50 50
 
51
-    /**
52
-     * Get requested extensions.
53
-     *
54
-     * @return Extensions
55
-     */
56
-    public function extensions(): Extensions
57
-    {
58
-        return $this->_extensions;
59
-    }
51
+	/**
52
+	 * Get requested extensions.
53
+	 *
54
+	 * @return Extensions
55
+	 */
56
+	public function extensions(): Extensions
57
+	{
58
+		return $this->_extensions;
59
+	}
60 60
 
61
-    /**
62
-     * {@inheritdoc}
63
-     */
64
-    public function toASN1(): Element
65
-    {
66
-        return $this->_extensions->toASN1();
67
-    }
61
+	/**
62
+	 * {@inheritdoc}
63
+	 */
64
+	public function toASN1(): Element
65
+	{
66
+		return $this->_extensions->toASN1();
67
+	}
68 68
 
69
-    /**
70
-     * {@inheritdoc}
71
-     */
72
-    public function stringValue(): string
73
-    {
74
-        return '#' . bin2hex($this->toASN1()->toDER());
75
-    }
69
+	/**
70
+	 * {@inheritdoc}
71
+	 */
72
+	public function stringValue(): string
73
+	{
74
+		return '#' . bin2hex($this->toASN1()->toDER());
75
+	}
76 76
 
77
-    /**
78
-     * {@inheritdoc}
79
-     */
80
-    public function equalityMatchingRule(): MatchingRule
81
-    {
82
-        return new BinaryMatch();
83
-    }
77
+	/**
78
+	 * {@inheritdoc}
79
+	 */
80
+	public function equalityMatchingRule(): MatchingRule
81
+	{
82
+		return new BinaryMatch();
83
+	}
84 84
 
85
-    /**
86
-     * {@inheritdoc}
87
-     */
88
-    public function rfc2253String(): string
89
-    {
90
-        return $this->stringValue();
91
-    }
85
+	/**
86
+	 * {@inheritdoc}
87
+	 */
88
+	public function rfc2253String(): string
89
+	{
90
+		return $this->stringValue();
91
+	}
92 92
 
93
-    /**
94
-     * {@inheritdoc}
95
-     */
96
-    protected function _transcodedString(): string
97
-    {
98
-        return $this->stringValue();
99
-    }
93
+	/**
94
+	 * {@inheritdoc}
95
+	 */
96
+	protected function _transcodedString(): string
97
+	{
98
+		return $this->stringValue();
99
+	}
100 100
 }
Please login to merge, or discard this patch.
lib/X509/CertificationRequest/Attributes.php 1 patch
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -20,108 +20,108 @@
 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 = [
33
-        ExtensionRequestValue::OID => ExtensionRequestValue::class,
34
-    ];
25
+	/**
26
+	 * Mapping from OID to attribute value class name.
27
+	 *
28
+	 * @internal
29
+	 *
30
+	 * @var array
31
+	 */
32
+	const MAP_OID_TO_CLASS = [
33
+		ExtensionRequestValue::OID => ExtensionRequestValue::class,
34
+	];
35 35
 
36
-    /**
37
-     * Constructor.
38
-     *
39
-     * @param Attribute ...$attribs Attribute objects
40
-     */
41
-    public function __construct(Attribute ...$attribs)
42
-    {
43
-        $this->_attributes = $attribs;
44
-    }
36
+	/**
37
+	 * Constructor.
38
+	 *
39
+	 * @param Attribute ...$attribs Attribute objects
40
+	 */
41
+	public function __construct(Attribute ...$attribs)
42
+	{
43
+		$this->_attributes = $attribs;
44
+	}
45 45
 
46
-    /**
47
-     * Initialize from attribute values.
48
-     *
49
-     * @param AttributeValue ...$values
50
-     *
51
-     * @return self
52
-     */
53
-    public static function fromAttributeValues(AttributeValue ...$values): Attributes
54
-    {
55
-        $attribs = array_map(
56
-            function (AttributeValue $value) {
57
-                return $value->toAttribute();
58
-            }, $values);
59
-        return new self(...$attribs);
60
-    }
46
+	/**
47
+	 * Initialize from attribute values.
48
+	 *
49
+	 * @param AttributeValue ...$values
50
+	 *
51
+	 * @return self
52
+	 */
53
+	public static function fromAttributeValues(AttributeValue ...$values): Attributes
54
+	{
55
+		$attribs = array_map(
56
+			function (AttributeValue $value) {
57
+				return $value->toAttribute();
58
+			}, $values);
59
+		return new self(...$attribs);
60
+	}
61 61
 
62
-    /**
63
-     * Initialize from ASN.1.
64
-     *
65
-     * @param Set $set
66
-     *
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
-    }
62
+	/**
63
+	 * Initialize from ASN.1.
64
+	 *
65
+	 * @param Set $set
66
+	 *
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
-     *
103
-     * @return ExtensionRequestValue
104
-     */
105
-    public function extensionRequest(): ExtensionRequestValue
106
-    {
107
-        if (!$this->hasExtensionRequest()) {
108
-            throw new \LogicException('No extension request attribute.');
109
-        }
110
-        return $this->firstOf(ExtensionRequestValue::OID)->first();
111
-    }
98
+	/**
99
+	 * Get extension request attribute value.
100
+	 *
101
+	 * @throws \LogicException
102
+	 *
103
+	 * @return ExtensionRequestValue
104
+	 */
105
+	public function extensionRequest(): ExtensionRequestValue
106
+	{
107
+		if (!$this->hasExtensionRequest()) {
108
+			throw new \LogicException('No extension request attribute.');
109
+		}
110
+		return $this->firstOf(ExtensionRequestValue::OID)->first();
111
+	}
112 112
 
113
-    /**
114
-     * Generate ASN.1 structure.
115
-     *
116
-     * @return Set
117
-     */
118
-    public function toASN1(): Set
119
-    {
120
-        $elements = array_map(
121
-            function (Attribute $attr) {
122
-                return $attr->toASN1();
123
-            }, array_values($this->_attributes));
124
-        $set = new Set(...$elements);
125
-        return $set->sortedSetOf();
126
-    }
113
+	/**
114
+	 * Generate ASN.1 structure.
115
+	 *
116
+	 * @return Set
117
+	 */
118
+	public function toASN1(): Set
119
+	{
120
+		$elements = array_map(
121
+			function (Attribute $attr) {
122
+				return $attr->toASN1();
123
+			}, array_values($this->_attributes));
124
+		$set = new Set(...$elements);
125
+		return $set->sortedSetOf();
126
+	}
127 127
 }
Please login to merge, or discard this patch.
lib/X509/CertificationRequest/CertificationRequestInfo.php 1 patch
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -24,206 +24,206 @@
 block discarded – undo
24 24
  */
25 25
 class CertificationRequestInfo
26 26
 {
27
-    const VERSION_1 = 0;
28
-
29
-    /**
30
-     * Version.
31
-     *
32
-     * @var int
33
-     */
34
-    protected $_version;
35
-
36
-    /**
37
-     * Subject.
38
-     *
39
-     * @var Name
40
-     */
41
-    protected $_subject;
42
-
43
-    /**
44
-     * Public key info.
45
-     *
46
-     * @var PublicKeyInfo
47
-     */
48
-    protected $_subjectPKInfo;
49
-
50
-    /**
51
-     * Attributes.
52
-     *
53
-     * @var null|Attributes
54
-     */
55
-    protected $_attributes;
56
-
57
-    /**
58
-     * Constructor.
59
-     *
60
-     * @param Name          $subject Subject
61
-     * @param PublicKeyInfo $pkinfo  Public key info
62
-     */
63
-    public function __construct(Name $subject, PublicKeyInfo $pkinfo)
64
-    {
65
-        $this->_version = self::VERSION_1;
66
-        $this->_subject = $subject;
67
-        $this->_subjectPKInfo = $pkinfo;
68
-    }
69
-
70
-    /**
71
-     * Initialize from ASN.1.
72
-     *
73
-     * @param Sequence $seq
74
-     *
75
-     * @throws \UnexpectedValueException
76
-     *
77
-     * @return self
78
-     */
79
-    public static function fromASN1(Sequence $seq): self
80
-    {
81
-        $version = $seq->at(0)->asInteger()->intNumber();
82
-        if (self::VERSION_1 != $version) {
83
-            throw new \UnexpectedValueException(
84
-                "Version {$version} not supported.");
85
-        }
86
-        $subject = Name::fromASN1($seq->at(1)->asSequence());
87
-        $pkinfo = PublicKeyInfo::fromASN1($seq->at(2)->asSequence());
88
-        $obj = new self($subject, $pkinfo);
89
-        if ($seq->hasTagged(0)) {
90
-            $obj->_attributes = Attributes::fromASN1(
91
-                $seq->getTagged(0)->asImplicit(Element::TYPE_SET)->asSet());
92
-        }
93
-        return $obj;
94
-    }
95
-
96
-    /**
97
-     * Get version.
98
-     *
99
-     * @return int
100
-     */
101
-    public function version(): int
102
-    {
103
-        return $this->_version;
104
-    }
105
-
106
-    /**
107
-     * Get self with subject.
108
-     *
109
-     * @param Name $subject
110
-     *
111
-     * @return self
112
-     */
113
-    public function withSubject(Name $subject): self
114
-    {
115
-        $obj = clone $this;
116
-        $obj->_subject = $subject;
117
-        return $obj;
118
-    }
119
-
120
-    /**
121
-     * Get subject.
122
-     *
123
-     * @return Name
124
-     */
125
-    public function subject(): Name
126
-    {
127
-        return $this->_subject;
128
-    }
129
-
130
-    /**
131
-     * Get subject public key info.
132
-     *
133
-     * @return PublicKeyInfo
134
-     */
135
-    public function subjectPKInfo(): PublicKeyInfo
136
-    {
137
-        return $this->_subjectPKInfo;
138
-    }
139
-
140
-    /**
141
-     * Whether certification request info has attributes.
142
-     *
143
-     * @return bool
144
-     */
145
-    public function hasAttributes(): bool
146
-    {
147
-        return isset($this->_attributes);
148
-    }
149
-
150
-    /**
151
-     * Get attributes.
152
-     *
153
-     * @throws \LogicException If not set
154
-     *
155
-     * @return Attributes
156
-     */
157
-    public function attributes(): Attributes
158
-    {
159
-        if (!$this->hasAttributes()) {
160
-            throw new \LogicException('No attributes.');
161
-        }
162
-        return $this->_attributes;
163
-    }
164
-
165
-    /**
166
-     * Get instance of self with attributes.
167
-     *
168
-     * @param Attributes $attribs
169
-     */
170
-    public function withAttributes(Attributes $attribs): self
171
-    {
172
-        $obj = clone $this;
173
-        $obj->_attributes = $attribs;
174
-        return $obj;
175
-    }
176
-
177
-    /**
178
-     * Get self with extension request attribute.
179
-     *
180
-     * @param Extensions $extensions Extensions to request
181
-     *
182
-     * @return self
183
-     */
184
-    public function withExtensionRequest(Extensions $extensions): self
185
-    {
186
-        $obj = clone $this;
187
-        if (!isset($obj->_attributes)) {
188
-            $obj->_attributes = new Attributes();
189
-        }
190
-        $obj->_attributes = $obj->_attributes->withUnique(
191
-            Attribute::fromAttributeValues(
192
-                new ExtensionRequestValue($extensions)));
193
-        return $obj;
194
-    }
195
-
196
-    /**
197
-     * Generate ASN.1 structure.
198
-     *
199
-     * @return Sequence
200
-     */
201
-    public function toASN1(): Sequence
202
-    {
203
-        $elements = [new Integer($this->_version),
204
-            $this->_subject->toASN1(), $this->_subjectPKInfo->toASN1(), ];
205
-        if (isset($this->_attributes)) {
206
-            $elements[] = new ImplicitlyTaggedType(0,
207
-                $this->_attributes->toASN1());
208
-        }
209
-        return new Sequence(...$elements);
210
-    }
211
-
212
-    /**
213
-     * Create signed CertificationRequest.
214
-     *
215
-     * @param SignatureAlgorithmIdentifier $algo         Algorithm used for signing
216
-     * @param PrivateKeyInfo               $privkey_info Private key used for signing
217
-     * @param null|Crypto                  $crypto       Crypto engine, use default if not set
218
-     *
219
-     * @return CertificationRequest
220
-     */
221
-    public function sign(SignatureAlgorithmIdentifier $algo,
222
-        PrivateKeyInfo $privkey_info, ?Crypto $crypto = null): CertificationRequest
223
-    {
224
-        $crypto = $crypto ?? Crypto::getDefault();
225
-        $data = $this->toASN1()->toDER();
226
-        $signature = $crypto->sign($data, $privkey_info, $algo);
227
-        return new CertificationRequest($this, $algo, $signature);
228
-    }
27
+	const VERSION_1 = 0;
28
+
29
+	/**
30
+	 * Version.
31
+	 *
32
+	 * @var int
33
+	 */
34
+	protected $_version;
35
+
36
+	/**
37
+	 * Subject.
38
+	 *
39
+	 * @var Name
40
+	 */
41
+	protected $_subject;
42
+
43
+	/**
44
+	 * Public key info.
45
+	 *
46
+	 * @var PublicKeyInfo
47
+	 */
48
+	protected $_subjectPKInfo;
49
+
50
+	/**
51
+	 * Attributes.
52
+	 *
53
+	 * @var null|Attributes
54
+	 */
55
+	protected $_attributes;
56
+
57
+	/**
58
+	 * Constructor.
59
+	 *
60
+	 * @param Name          $subject Subject
61
+	 * @param PublicKeyInfo $pkinfo  Public key info
62
+	 */
63
+	public function __construct(Name $subject, PublicKeyInfo $pkinfo)
64
+	{
65
+		$this->_version = self::VERSION_1;
66
+		$this->_subject = $subject;
67
+		$this->_subjectPKInfo = $pkinfo;
68
+	}
69
+
70
+	/**
71
+	 * Initialize from ASN.1.
72
+	 *
73
+	 * @param Sequence $seq
74
+	 *
75
+	 * @throws \UnexpectedValueException
76
+	 *
77
+	 * @return self
78
+	 */
79
+	public static function fromASN1(Sequence $seq): self
80
+	{
81
+		$version = $seq->at(0)->asInteger()->intNumber();
82
+		if (self::VERSION_1 != $version) {
83
+			throw new \UnexpectedValueException(
84
+				"Version {$version} not supported.");
85
+		}
86
+		$subject = Name::fromASN1($seq->at(1)->asSequence());
87
+		$pkinfo = PublicKeyInfo::fromASN1($seq->at(2)->asSequence());
88
+		$obj = new self($subject, $pkinfo);
89
+		if ($seq->hasTagged(0)) {
90
+			$obj->_attributes = Attributes::fromASN1(
91
+				$seq->getTagged(0)->asImplicit(Element::TYPE_SET)->asSet());
92
+		}
93
+		return $obj;
94
+	}
95
+
96
+	/**
97
+	 * Get version.
98
+	 *
99
+	 * @return int
100
+	 */
101
+	public function version(): int
102
+	{
103
+		return $this->_version;
104
+	}
105
+
106
+	/**
107
+	 * Get self with subject.
108
+	 *
109
+	 * @param Name $subject
110
+	 *
111
+	 * @return self
112
+	 */
113
+	public function withSubject(Name $subject): self
114
+	{
115
+		$obj = clone $this;
116
+		$obj->_subject = $subject;
117
+		return $obj;
118
+	}
119
+
120
+	/**
121
+	 * Get subject.
122
+	 *
123
+	 * @return Name
124
+	 */
125
+	public function subject(): Name
126
+	{
127
+		return $this->_subject;
128
+	}
129
+
130
+	/**
131
+	 * Get subject public key info.
132
+	 *
133
+	 * @return PublicKeyInfo
134
+	 */
135
+	public function subjectPKInfo(): PublicKeyInfo
136
+	{
137
+		return $this->_subjectPKInfo;
138
+	}
139
+
140
+	/**
141
+	 * Whether certification request info has attributes.
142
+	 *
143
+	 * @return bool
144
+	 */
145
+	public function hasAttributes(): bool
146
+	{
147
+		return isset($this->_attributes);
148
+	}
149
+
150
+	/**
151
+	 * Get attributes.
152
+	 *
153
+	 * @throws \LogicException If not set
154
+	 *
155
+	 * @return Attributes
156
+	 */
157
+	public function attributes(): Attributes
158
+	{
159
+		if (!$this->hasAttributes()) {
160
+			throw new \LogicException('No attributes.');
161
+		}
162
+		return $this->_attributes;
163
+	}
164
+
165
+	/**
166
+	 * Get instance of self with attributes.
167
+	 *
168
+	 * @param Attributes $attribs
169
+	 */
170
+	public function withAttributes(Attributes $attribs): self
171
+	{
172
+		$obj = clone $this;
173
+		$obj->_attributes = $attribs;
174
+		return $obj;
175
+	}
176
+
177
+	/**
178
+	 * Get self with extension request attribute.
179
+	 *
180
+	 * @param Extensions $extensions Extensions to request
181
+	 *
182
+	 * @return self
183
+	 */
184
+	public function withExtensionRequest(Extensions $extensions): self
185
+	{
186
+		$obj = clone $this;
187
+		if (!isset($obj->_attributes)) {
188
+			$obj->_attributes = new Attributes();
189
+		}
190
+		$obj->_attributes = $obj->_attributes->withUnique(
191
+			Attribute::fromAttributeValues(
192
+				new ExtensionRequestValue($extensions)));
193
+		return $obj;
194
+	}
195
+
196
+	/**
197
+	 * Generate ASN.1 structure.
198
+	 *
199
+	 * @return Sequence
200
+	 */
201
+	public function toASN1(): Sequence
202
+	{
203
+		$elements = [new Integer($this->_version),
204
+			$this->_subject->toASN1(), $this->_subjectPKInfo->toASN1(), ];
205
+		if (isset($this->_attributes)) {
206
+			$elements[] = new ImplicitlyTaggedType(0,
207
+				$this->_attributes->toASN1());
208
+		}
209
+		return new Sequence(...$elements);
210
+	}
211
+
212
+	/**
213
+	 * Create signed CertificationRequest.
214
+	 *
215
+	 * @param SignatureAlgorithmIdentifier $algo         Algorithm used for signing
216
+	 * @param PrivateKeyInfo               $privkey_info Private key used for signing
217
+	 * @param null|Crypto                  $crypto       Crypto engine, use default if not set
218
+	 *
219
+	 * @return CertificationRequest
220
+	 */
221
+	public function sign(SignatureAlgorithmIdentifier $algo,
222
+		PrivateKeyInfo $privkey_info, ?Crypto $crypto = null): CertificationRequest
223
+	{
224
+		$crypto = $crypto ?? Crypto::getDefault();
225
+		$data = $this->toASN1()->toDER();
226
+		$signature = $crypto->sign($data, $privkey_info, $algo);
227
+		return new CertificationRequest($this, $algo, $signature);
228
+	}
229 229
 }
Please login to merge, or discard this patch.
lib/X509/Feature/DateTimeHelper.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -9,76 +9,76 @@
 block discarded – undo
9 9
  */
10 10
 trait DateTimeHelper
11 11
 {
12
-    /**
13
-     * Create DateTime object from time string and timezone.
14
-     *
15
-     * @param null|string $time Time string, default to 'now'
16
-     * @param null|string $tz   Timezone, default if omitted
17
-     *
18
-     * @throws \RuntimeException
19
-     *
20
-     * @return \DateTimeImmutable
21
-     */
22
-    private static function _createDateTime(
23
-        ?string $time = null, ?string $tz = null): \DateTimeImmutable
24
-    {
25
-        if (!isset($time)) {
26
-            $time = 'now';
27
-        }
28
-        if (!isset($tz)) {
29
-            $tz = date_default_timezone_get();
30
-        }
31
-        try {
32
-            $dt = new \DateTimeImmutable($time, self::_createTimeZone($tz));
33
-            return self::_roundDownFractionalSeconds($dt);
34
-        } catch (\Exception $e) {
35
-            throw new \RuntimeException(
36
-                'Failed to create DateTime: ' .
37
-                     self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
38
-        }
39
-    }
12
+	/**
13
+	 * Create DateTime object from time string and timezone.
14
+	 *
15
+	 * @param null|string $time Time string, default to 'now'
16
+	 * @param null|string $tz   Timezone, default if omitted
17
+	 *
18
+	 * @throws \RuntimeException
19
+	 *
20
+	 * @return \DateTimeImmutable
21
+	 */
22
+	private static function _createDateTime(
23
+		?string $time = null, ?string $tz = null): \DateTimeImmutable
24
+	{
25
+		if (!isset($time)) {
26
+			$time = 'now';
27
+		}
28
+		if (!isset($tz)) {
29
+			$tz = date_default_timezone_get();
30
+		}
31
+		try {
32
+			$dt = new \DateTimeImmutable($time, self::_createTimeZone($tz));
33
+			return self::_roundDownFractionalSeconds($dt);
34
+		} catch (\Exception $e) {
35
+			throw new \RuntimeException(
36
+				'Failed to create DateTime: ' .
37
+					 self::_getLastDateTimeImmutableErrorsStr(), 0, $e);
38
+		}
39
+	}
40 40
 
41
-    /**
42
-     * Rounds a \DateTimeImmutable value such that fractional
43
-     * seconds are removed.
44
-     *
45
-     * @param \DateTimeImmutable $dt
46
-     *
47
-     * @return \DateTimeImmutable
48
-     */
49
-    private static function _roundDownFractionalSeconds(
50
-        \DateTimeImmutable $dt): \DateTimeImmutable
51
-    {
52
-        return \DateTimeImmutable::createFromFormat('Y-m-d H:i:s',
53
-            $dt->format('Y-m-d H:i:s'), $dt->getTimezone());
54
-    }
41
+	/**
42
+	 * Rounds a \DateTimeImmutable value such that fractional
43
+	 * seconds are removed.
44
+	 *
45
+	 * @param \DateTimeImmutable $dt
46
+	 *
47
+	 * @return \DateTimeImmutable
48
+	 */
49
+	private static function _roundDownFractionalSeconds(
50
+		\DateTimeImmutable $dt): \DateTimeImmutable
51
+	{
52
+		return \DateTimeImmutable::createFromFormat('Y-m-d H:i:s',
53
+			$dt->format('Y-m-d H:i:s'), $dt->getTimezone());
54
+	}
55 55
 
56
-    /**
57
-     * Create DateTimeZone object from string.
58
-     *
59
-     * @param string $tz
60
-     *
61
-     * @throws \UnexpectedValueException
62
-     *
63
-     * @return \DateTimeZone
64
-     */
65
-    private static function _createTimeZone(string $tz): \DateTimeZone
66
-    {
67
-        try {
68
-            return new \DateTimeZone($tz);
69
-        } catch (\Exception $e) {
70
-            throw new \UnexpectedValueException('Invalid timezone.', 0, $e);
71
-        }
72
-    }
56
+	/**
57
+	 * Create DateTimeZone object from string.
58
+	 *
59
+	 * @param string $tz
60
+	 *
61
+	 * @throws \UnexpectedValueException
62
+	 *
63
+	 * @return \DateTimeZone
64
+	 */
65
+	private static function _createTimeZone(string $tz): \DateTimeZone
66
+	{
67
+		try {
68
+			return new \DateTimeZone($tz);
69
+		} catch (\Exception $e) {
70
+			throw new \UnexpectedValueException('Invalid timezone.', 0, $e);
71
+		}
72
+	}
73 73
 
74
-    /**
75
-     * Get last error caused by DateTimeImmutable.
76
-     *
77
-     * @return string
78
-     */
79
-    private static function _getLastDateTimeImmutableErrorsStr(): string
80
-    {
81
-        $errors = \DateTimeImmutable::getLastErrors()['errors'];
82
-        return implode(', ', $errors);
83
-    }
74
+	/**
75
+	 * Get last error caused by DateTimeImmutable.
76
+	 *
77
+	 * @return string
78
+	 */
79
+	private static function _getLastDateTimeImmutableErrorsStr(): string
80
+	{
81
+		$errors = \DateTimeImmutable::getLastErrors()['errors'];
82
+		return implode(', ', $errors);
83
+	}
84 84
 }
Please login to merge, or discard this patch.
lib/X509/Feature/AttributeContainer.php 1 patch
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -14,145 +14,145 @@
 block discarded – undo
14 14
  */
15 15
 trait AttributeContainer
16 16
 {
17
-    /**
18
-     * Array of attributes.
19
-     *
20
-     * @var Attribute[]
21
-     */
22
-    protected $_attributes;
17
+	/**
18
+	 * Array of attributes.
19
+	 *
20
+	 * @var Attribute[]
21
+	 */
22
+	protected $_attributes;
23 23
 
24
-    /**
25
-     * Check whether attribute is present.
26
-     *
27
-     * @param string $name OID or attribute name
28
-     *
29
-     * @return bool
30
-     */
31
-    public function has(string $name): bool
32
-    {
33
-        return null !== $this->_findFirst($name);
34
-    }
24
+	/**
25
+	 * Check whether attribute is present.
26
+	 *
27
+	 * @param string $name OID or attribute name
28
+	 *
29
+	 * @return bool
30
+	 */
31
+	public function has(string $name): bool
32
+	{
33
+		return null !== $this->_findFirst($name);
34
+	}
35 35
 
36
-    /**
37
-     * Get first attribute by OID or attribute name.
38
-     *
39
-     * @param string $name OID or attribute name
40
-     *
41
-     * @throws \OutOfBoundsException
42
-     *
43
-     * @return Attribute
44
-     */
45
-    public function firstOf(string $name): Attribute
46
-    {
47
-        $attr = $this->_findFirst($name);
48
-        if (!$attr) {
49
-            throw new \UnexpectedValueException("No {$name} attribute.");
50
-        }
51
-        return $attr;
52
-    }
36
+	/**
37
+	 * Get first attribute by OID or attribute name.
38
+	 *
39
+	 * @param string $name OID or attribute name
40
+	 *
41
+	 * @throws \OutOfBoundsException
42
+	 *
43
+	 * @return Attribute
44
+	 */
45
+	public function firstOf(string $name): Attribute
46
+	{
47
+		$attr = $this->_findFirst($name);
48
+		if (!$attr) {
49
+			throw new \UnexpectedValueException("No {$name} attribute.");
50
+		}
51
+		return $attr;
52
+	}
53 53
 
54
-    /**
55
-     * Get all attributes of given name.
56
-     *
57
-     * @param string $name OID or attribute name
58
-     *
59
-     * @return Attribute[]
60
-     */
61
-    public function allOf(string $name): array
62
-    {
63
-        $oid = AttributeType::attrNameToOID($name);
64
-        $attrs = array_filter($this->_attributes,
65
-            function (Attribute $attr) use ($oid) {
66
-                return $attr->oid() === $oid;
67
-            });
68
-        return array_values($attrs);
69
-    }
54
+	/**
55
+	 * Get all attributes of given name.
56
+	 *
57
+	 * @param string $name OID or attribute name
58
+	 *
59
+	 * @return Attribute[]
60
+	 */
61
+	public function allOf(string $name): array
62
+	{
63
+		$oid = AttributeType::attrNameToOID($name);
64
+		$attrs = array_filter($this->_attributes,
65
+			function (Attribute $attr) use ($oid) {
66
+				return $attr->oid() === $oid;
67
+			});
68
+		return array_values($attrs);
69
+	}
70 70
 
71
-    /**
72
-     * Get all attributes.
73
-     *
74
-     * @return Attribute[]
75
-     */
76
-    public function all(): array
77
-    {
78
-        return $this->_attributes;
79
-    }
71
+	/**
72
+	 * Get all attributes.
73
+	 *
74
+	 * @return Attribute[]
75
+	 */
76
+	public function all(): array
77
+	{
78
+		return $this->_attributes;
79
+	}
80 80
 
81
-    /**
82
-     * Get self with additional attributes added.
83
-     *
84
-     * @param Attribute ...$attribs
85
-     *
86
-     * @return self
87
-     */
88
-    public function withAdditional(Attribute ...$attribs): self
89
-    {
90
-        $obj = clone $this;
91
-        foreach ($attribs as $attr) {
92
-            $obj->_attributes[] = $attr;
93
-        }
94
-        return $obj;
95
-    }
81
+	/**
82
+	 * Get self with additional attributes added.
83
+	 *
84
+	 * @param Attribute ...$attribs
85
+	 *
86
+	 * @return self
87
+	 */
88
+	public function withAdditional(Attribute ...$attribs): self
89
+	{
90
+		$obj = clone $this;
91
+		foreach ($attribs as $attr) {
92
+			$obj->_attributes[] = $attr;
93
+		}
94
+		return $obj;
95
+	}
96 96
 
97
-    /**
98
-     * Get self with single unique attribute added.
99
-     *
100
-     * All previous attributes of the same type are removed.
101
-     *
102
-     * @param Attribute $attr
103
-     *
104
-     * @return self
105
-     */
106
-    public function withUnique(Attribute $attr): self
107
-    {
108
-        $obj = clone $this;
109
-        $obj->_attributes = array_filter($obj->_attributes,
110
-            function (Attribute $a) use ($attr) {
111
-                return $a->oid() !== $attr->oid();
112
-            });
113
-        $obj->_attributes[] = $attr;
114
-        return $obj;
115
-    }
97
+	/**
98
+	 * Get self with single unique attribute added.
99
+	 *
100
+	 * All previous attributes of the same type are removed.
101
+	 *
102
+	 * @param Attribute $attr
103
+	 *
104
+	 * @return self
105
+	 */
106
+	public function withUnique(Attribute $attr): self
107
+	{
108
+		$obj = clone $this;
109
+		$obj->_attributes = array_filter($obj->_attributes,
110
+			function (Attribute $a) use ($attr) {
111
+				return $a->oid() !== $attr->oid();
112
+			});
113
+		$obj->_attributes[] = $attr;
114
+		return $obj;
115
+	}
116 116
 
117
-    /**
118
-     * Get number of attributes.
119
-     *
120
-     * @see \Countable::count()
121
-     *
122
-     * @return int
123
-     */
124
-    public function count(): int
125
-    {
126
-        return count($this->_attributes);
127
-    }
117
+	/**
118
+	 * Get number of attributes.
119
+	 *
120
+	 * @see \Countable::count()
121
+	 *
122
+	 * @return int
123
+	 */
124
+	public function count(): int
125
+	{
126
+		return count($this->_attributes);
127
+	}
128 128
 
129
-    /**
130
-     * Get iterator for attributes.
131
-     *
132
-     * @see \IteratorAggregate::getIterator()
133
-     *
134
-     * @return \ArrayIterator
135
-     */
136
-    public function getIterator(): \ArrayIterator
137
-    {
138
-        return new \ArrayIterator($this->_attributes);
139
-    }
129
+	/**
130
+	 * Get iterator for attributes.
131
+	 *
132
+	 * @see \IteratorAggregate::getIterator()
133
+	 *
134
+	 * @return \ArrayIterator
135
+	 */
136
+	public function getIterator(): \ArrayIterator
137
+	{
138
+		return new \ArrayIterator($this->_attributes);
139
+	}
140 140
 
141
-    /**
142
-     * Find first attribute of given name or OID.
143
-     *
144
-     * @param string $name
145
-     *
146
-     * @return null|Attribute
147
-     */
148
-    protected function _findFirst(string $name): ?Attribute
149
-    {
150
-        $oid = AttributeType::attrNameToOID($name);
151
-        foreach ($this->_attributes as $attr) {
152
-            if ($attr->oid() === $oid) {
153
-                return $attr;
154
-            }
155
-        }
156
-        return null;
157
-    }
141
+	/**
142
+	 * Find first attribute of given name or OID.
143
+	 *
144
+	 * @param string $name
145
+	 *
146
+	 * @return null|Attribute
147
+	 */
148
+	protected function _findFirst(string $name): ?Attribute
149
+	{
150
+		$oid = AttributeType::attrNameToOID($name);
151
+		foreach ($this->_attributes as $attr) {
152
+			if ($attr->oid() === $oid) {
153
+				return $attr;
154
+			}
155
+		}
156
+		return null;
157
+	}
158 158
 }
Please login to merge, or discard this patch.
examples/create-csr.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 
19 19
 // load EC private key from PEM
20 20
 $private_key_info = PrivateKeyInfo::fromPEM(
21
-    PEM::fromFile(dirname(__DIR__) . '/test/assets/ec/private_key.pem'));
21
+	PEM::fromFile(dirname(__DIR__) . '/test/assets/ec/private_key.pem'));
22 22
 // extract public key from private key
23 23
 $public_key_info = $private_key_info->publicKeyInfo();
24 24
 // DN of the subject
@@ -27,6 +27,6 @@  discard block
 block discarded – undo
27 27
 $cri = new CertificationRequestInfo($subject, $public_key_info);
28 28
 // sign certificate request with private key
29 29
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
30
-    $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier());
30
+	$private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier());
31 31
 $csr = $cri->sign($algo, $private_key_info);
32 32
 echo $csr;
Please login to merge, or discard this patch.
examples/ac-example.php 1 patch
Indentation   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -38,106 +38,106 @@  discard block
 block discarded – undo
38 38
 
39 39
 // CA private key
40 40
 openssl_pkey_export(
41
-    openssl_pkey_new(
42
-        ['private_key_type' => OPENSSL_KEYTYPE_RSA,
43
-            'private_key_bits' => 2048, ]), $pkey);
41
+	openssl_pkey_new(
42
+		['private_key_type' => OPENSSL_KEYTYPE_RSA,
43
+			'private_key_bits' => 2048, ]), $pkey);
44 44
 $ca_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey));
45 45
 // Issuer private key
46 46
 openssl_pkey_export(
47
-    openssl_pkey_new(
48
-        ['private_key_type' => OPENSSL_KEYTYPE_RSA,
49
-            'private_key_bits' => 2048, ]), $pkey);
47
+	openssl_pkey_new(
48
+		['private_key_type' => OPENSSL_KEYTYPE_RSA,
49
+			'private_key_bits' => 2048, ]), $pkey);
50 50
 $issuer_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey));
51 51
 // Holder private key
52 52
 openssl_pkey_export(
53
-    openssl_pkey_new(
54
-        ['private_key_type' => OPENSSL_KEYTYPE_RSA,
55
-            'private_key_bits' => 2048, ]), $pkey);
53
+	openssl_pkey_new(
54
+		['private_key_type' => OPENSSL_KEYTYPE_RSA,
55
+			'private_key_bits' => 2048, ]), $pkey);
56 56
 $holder_private_key = PrivateKeyInfo::fromPEM(PEM::fromString($pkey));
57 57
 
58 58
 // create trust anchor certificate (self signed)
59 59
 $tbs_cert = new TBSCertificate(
60
-    Name::fromString('cn=CA'),
61
-    $ca_private_key->publicKeyInfo(),
62
-    Name::fromString('cn=CA'),
63
-    Validity::fromStrings('now', 'now + 1 year'));
60
+	Name::fromString('cn=CA'),
61
+	$ca_private_key->publicKeyInfo(),
62
+	Name::fromString('cn=CA'),
63
+	Validity::fromStrings('now', 'now + 1 year'));
64 64
 $tbs_cert = $tbs_cert->withRandomSerialNumber()
65
-    ->withAdditionalExtensions(
66
-        new BasicConstraintsExtension(true, true),
67
-        new SubjectKeyIdentifierExtension(false,
68
-            $ca_private_key->publicKeyInfo()->keyIdentifier()),
69
-        new KeyUsageExtension(true,
70
-            KeyUsageExtension::DIGITAL_SIGNATURE |
71
-            KeyUsageExtension::KEY_CERT_SIGN));
65
+	->withAdditionalExtensions(
66
+		new BasicConstraintsExtension(true, true),
67
+		new SubjectKeyIdentifierExtension(false,
68
+			$ca_private_key->publicKeyInfo()->keyIdentifier()),
69
+		new KeyUsageExtension(true,
70
+			KeyUsageExtension::DIGITAL_SIGNATURE |
71
+			KeyUsageExtension::KEY_CERT_SIGN));
72 72
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
73
-    $ca_private_key->algorithmIdentifier(),
74
-    new SHA256AlgorithmIdentifier());
73
+	$ca_private_key->algorithmIdentifier(),
74
+	new SHA256AlgorithmIdentifier());
75 75
 $ca_cert = $tbs_cert->sign($algo, $ca_private_key);
76 76
 
77 77
 // create AC issuer certificate
78 78
 $tbs_cert = new TBSCertificate(
79
-    Name::fromString('cn=Issuer'),
80
-    $issuer_private_key->publicKeyInfo(),
81
-    new Name(),
82
-    Validity::fromStrings('now', 'now + 6 months'));
79
+	Name::fromString('cn=Issuer'),
80
+	$issuer_private_key->publicKeyInfo(),
81
+	new Name(),
82
+	Validity::fromStrings('now', 'now + 6 months'));
83 83
 $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert)
84
-    ->withRandomSerialNumber()
85
-    ->withAdditionalExtensions(
86
-        // issuer must not be a CA
87
-        new BasicConstraintsExtension(true, false),
88
-        new KeyUsageExtension(true,
89
-            KeyUsageExtension::DIGITAL_SIGNATURE |
90
-             KeyUsageExtension::KEY_ENCIPHERMENT));
84
+	->withRandomSerialNumber()
85
+	->withAdditionalExtensions(
86
+		// issuer must not be a CA
87
+		new BasicConstraintsExtension(true, false),
88
+		new KeyUsageExtension(true,
89
+			KeyUsageExtension::DIGITAL_SIGNATURE |
90
+			 KeyUsageExtension::KEY_ENCIPHERMENT));
91 91
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
92
-    $ca_private_key->algorithmIdentifier(),
93
-    new SHA256AlgorithmIdentifier());
92
+	$ca_private_key->algorithmIdentifier(),
93
+	new SHA256AlgorithmIdentifier());
94 94
 $issuer_cert = $tbs_cert->sign($algo, $ca_private_key);
95 95
 
96 96
 // create AC holder certificate
97 97
 $tbs_cert = new TBSCertificate(
98
-    Name::fromString('cn=Holder, gn=John, sn=Doe'),
99
-    $holder_private_key->publicKeyInfo(),
100
-    new Name(),
101
-    Validity::fromStrings('now', 'now + 6 months'));
98
+	Name::fromString('cn=Holder, gn=John, sn=Doe'),
99
+	$holder_private_key->publicKeyInfo(),
100
+	new Name(),
101
+	Validity::fromStrings('now', 'now + 6 months'));
102 102
 $tbs_cert = $tbs_cert->withIssuerCertificate($ca_cert)
103
-    ->withRandomSerialNumber()
104
-    ->withAdditionalExtensions(
105
-        new BasicConstraintsExtension(true, false),
106
-        new KeyUsageExtension(true,
107
-            KeyUsageExtension::DIGITAL_SIGNATURE |
108
-             KeyUsageExtension::KEY_ENCIPHERMENT));
103
+	->withRandomSerialNumber()
104
+	->withAdditionalExtensions(
105
+		new BasicConstraintsExtension(true, false),
106
+		new KeyUsageExtension(true,
107
+			KeyUsageExtension::DIGITAL_SIGNATURE |
108
+			 KeyUsageExtension::KEY_ENCIPHERMENT));
109 109
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
110
-    $ca_private_key->algorithmIdentifier(),
111
-    new SHA256AlgorithmIdentifier());
110
+	$ca_private_key->algorithmIdentifier(),
111
+	new SHA256AlgorithmIdentifier());
112 112
 $holder_cert = $tbs_cert->sign($algo, $ca_private_key);
113 113
 
114 114
 // named authority that grants the attributes
115 115
 $authority = new GeneralNames(
116
-    new UniformResourceIdentifier('uri:trusted_authority'));
116
+	new UniformResourceIdentifier('uri:trusted_authority'));
117 117
 // role attribute
118 118
 $attribs = new Attributes(
119
-    Attribute::fromAttributeValues(
120
-        RoleAttributeValue::fromString('role-name', $authority)));
119
+	Attribute::fromAttributeValues(
120
+		RoleAttributeValue::fromString('role-name', $authority)));
121 121
 $aci = new AttributeCertificateInfo(
122
-    // holder is identified by the holder's public key certificate
123
-    new Holder(IssuerSerial::fromPKC($holder_cert)),
124
-    AttCertIssuer::fromPKC($issuer_cert),
125
-    AttCertValidityPeriod::fromStrings('now - 1 hour', 'now + 3 months'),
126
-    $attribs);
122
+	// holder is identified by the holder's public key certificate
123
+	new Holder(IssuerSerial::fromPKC($holder_cert)),
124
+	AttCertIssuer::fromPKC($issuer_cert),
125
+	AttCertValidityPeriod::fromStrings('now - 1 hour', 'now + 3 months'),
126
+	$attribs);
127 127
 $aci = $aci->withRandomSerialNumber()
128
-    ->withAdditionalExtensions(
129
-        // named target identifier
130
-        TargetInformationExtension::fromTargets(
131
-            new TargetName(
132
-                new UniformResourceIdentifier('uri:target_identifier'))),
133
-        // key identifier of the AC issuer
134
-        new AuthorityKeyIdentifierExtension(false,
135
-            $issuer_cert->tbsCertificate()
136
-                ->subjectPublicKeyInfo()
137
-                ->keyIdentifier()));
128
+	->withAdditionalExtensions(
129
+		// named target identifier
130
+		TargetInformationExtension::fromTargets(
131
+			new TargetName(
132
+				new UniformResourceIdentifier('uri:target_identifier'))),
133
+		// key identifier of the AC issuer
134
+		new AuthorityKeyIdentifierExtension(false,
135
+			$issuer_cert->tbsCertificate()
136
+				->subjectPublicKeyInfo()
137
+				->keyIdentifier()));
138 138
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
139
-    $issuer_private_key->algorithmIdentifier(),
140
-    new SHA256AlgorithmIdentifier());
139
+	$issuer_private_key->algorithmIdentifier(),
140
+	new SHA256AlgorithmIdentifier());
141 141
 $ac = $aci->sign($algo, $issuer_private_key);
142 142
 
143 143
 // validate AC
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 $validator_config = $validator_config->withTargets($target);
150 150
 $validator = new ACValidator($ac, $validator_config);
151 151
 if ($validator->validate()) {
152
-    fprintf(STDERR, "AC validation succeeded.\n");
152
+	fprintf(STDERR, "AC validation succeeded.\n");
153 153
 }
154 154
 
155 155
 fprintf(STDERR, "Root certificate:\n");
Please login to merge, or discard this patch.
examples/issue-cert.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -27,27 +27,27 @@
 block discarded – undo
27 27
 $csr = CertificationRequest::fromPEM(PEM::fromFile($argv[2]));
28 28
 // verify CSR
29 29
 if (!$csr->verify()) {
30
-    echo "Failed to verify certification request signature.\n";
31
-    exit(1);
30
+	echo "Failed to verify certification request signature.\n";
31
+	exit(1);
32 32
 }
33 33
 // load CA's private key from PEM
34 34
 $private_key_info = PrivateKeyInfo::fromPEM(
35
-    PEM::fromFile(dirname(__DIR__) . '/test/assets/rsa/private_key.pem'));
35
+	PEM::fromFile(dirname(__DIR__) . '/test/assets/rsa/private_key.pem'));
36 36
 // initialize certificate from CSR and issuer's certificate
37 37
 $tbs_cert = TBSCertificate::fromCSR($csr)->withIssuerCertificate($issuer_cert);
38 38
 // set random serial number
39 39
 $tbs_cert = $tbs_cert->withRandomSerialNumber();
40 40
 // set validity period
41 41
 $tbs_cert = $tbs_cert->withValidity(
42
-    Validity::fromStrings('now', 'now + 3 months'));
42
+	Validity::fromStrings('now', 'now + 3 months'));
43 43
 // add extensions
44 44
 $tbs_cert = $tbs_cert->withAdditionalExtensions(
45
-    new KeyUsageExtension(true,
46
-        KeyUsageExtension::DIGITAL_SIGNATURE |
47
-             KeyUsageExtension::KEY_ENCIPHERMENT),
48
-    new BasicConstraintsExtension(true, false));
45
+	new KeyUsageExtension(true,
46
+		KeyUsageExtension::DIGITAL_SIGNATURE |
47
+			 KeyUsageExtension::KEY_ENCIPHERMENT),
48
+	new BasicConstraintsExtension(true, false));
49 49
 // sign certificate with issuer's private key
50 50
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
51
-    $private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier());
51
+	$private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier());
52 52
 $cert = $tbs_cert->sign($algo, $private_key_info);
53 53
 echo $cert;
Please login to merge, or discard this patch.
examples/create-ca-cert.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 
23 23
 // load RSA private key from PEM
24 24
 $private_key_info = PrivateKeyInfo::fromPEM(
25
-    PEM::fromFile(dirname(__DIR__) . '/test/assets/rsa/private_key.pem'));
25
+	PEM::fromFile(dirname(__DIR__) . '/test/assets/rsa/private_key.pem'));
26 26
 // extract public key from private key
27 27
 $public_key_info = $private_key_info->publicKeyInfo();
28 28
 // DN of the certification authority
@@ -32,12 +32,12 @@  discard block
 block discarded – undo
32 32
 // create "to be signed" certificate object with extensions
33 33
 $tbs_cert = new TBSCertificate($name, $public_key_info, $name, $validity);
34 34
 $tbs_cert = $tbs_cert->withRandomSerialNumber()->withAdditionalExtensions(
35
-    new BasicConstraintsExtension(true, true),
36
-    new SubjectKeyIdentifierExtension(false, $public_key_info->keyIdentifier()),
37
-    new KeyUsageExtension(true,
38
-        KeyUsageExtension::DIGITAL_SIGNATURE | KeyUsageExtension::KEY_CERT_SIGN));
35
+	new BasicConstraintsExtension(true, true),
36
+	new SubjectKeyIdentifierExtension(false, $public_key_info->keyIdentifier()),
37
+	new KeyUsageExtension(true,
38
+		KeyUsageExtension::DIGITAL_SIGNATURE | KeyUsageExtension::KEY_CERT_SIGN));
39 39
 // sign certificate with private key
40 40
 $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto(
41
-    $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier());
41
+	$private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier());
42 42
 $cert = $tbs_cert->sign($algo, $private_key_info);
43 43
 echo $cert;
Please login to merge, or discard this patch.