1- <?php
1+ <?php declare (strict_types= 1 );
22
33namespace KDuma \CertificateChainOfTrust ;
44
5+ use KDuma \BinaryTools \BinaryReader ;
6+ use KDuma \BinaryTools \BinaryString ;
7+ use KDuma \BinaryTools \BinaryWriter ;
58use KDuma \CertificateChainOfTrust \Crypto \KeyId ;
69use KDuma \CertificateChainOfTrust \Crypto \PublicKey ;
710use KDuma \CertificateChainOfTrust \DTO \CertificateFlagsCollection ;
811use KDuma \CertificateChainOfTrust \DTO \Signature ;
912use KDuma \CertificateChainOfTrust \DTO \UserDescriptor ;
10- use KDuma \BinaryTools \BinaryReader ;
11- use KDuma \BinaryTools \BinaryString ;
12- use KDuma \BinaryTools \BinaryWriter ;
1313
1414readonly class Certificate
1515{
16- const string MAGIC = "\x08\x44\x53" ;
16+ public const string MAGIC = "\x08\x44\x53" ;
1717
1818 public function __construct (
1919 public PublicKey $ key ,
@@ -23,8 +23,7 @@ public function __construct(
2323 public CertificateFlagsCollection $ flags ,
2424 /** @var Signature[] */
2525 public array $ signatures
26- )
27- {
26+ ) {
2827 if (empty ($ this ->key ->id ->value )) {
2928 throw new \InvalidArgumentException ('KeyId cannot be empty ' );
3029 }
@@ -49,11 +48,11 @@ public function __construct(
4948 throw new \InvalidArgumentException ('Description must be valid UTF-8 ' );
5049 }
5150
52- if (array_any ($ this ->userDescriptors , fn ($ element ) => !$ element instanceof UserDescriptor)) {
51+ if (array_any ($ this ->userDescriptors , fn ($ element ) => !$ element instanceof UserDescriptor)) {
5352 throw new \InvalidArgumentException ('All elements of $userDescriptors must be instances of UserDescriptor ' );
5453 }
5554
56- if (array_any ($ this ->signatures , fn ($ element ) => !$ element instanceof Signature)) {
55+ if (array_any ($ this ->signatures , fn ($ element ) => !$ element instanceof Signature)) {
5756 throw new \InvalidArgumentException ('All elements of $signatures must be instances of Signature ' );
5857 }
5958 }
@@ -65,7 +64,7 @@ public function isSelfSigned(): bool
6564
6665 public function getSignatureByKeyId (KeyId $ keyId ): ?Signature
6766 {
68- return array_find ($ this ->signatures , fn (Signature $ signature ) => $ signature ->keyId ->equals ($ keyId ));
67+ return array_find ($ this ->signatures , fn (Signature $ signature ) => $ signature ->keyId ->equals ($ keyId ));
6968 }
7069
7170 public function getSelfSignature (): ?Signature
@@ -146,7 +145,7 @@ public static function fromBinaryReader(BinaryReader $reader): self
146145 throw new \InvalidArgumentException ('Failed to parse Certificate: ' . $ e ->getMessage ());
147146 }
148147
149- if ($ reader ->has_more_data && !$ reader ->peekBytes (3 )->equals (BinaryString::fromString (self ::MAGIC ))) {
148+ if ($ reader ->has_more_data && !$ reader ->peekBytes (3 )->equals (BinaryString::fromString (self ::MAGIC ))) {
150149 throw new \InvalidArgumentException ('Extra data found after parsing Certificate ' );
151150 }
152151
@@ -166,8 +165,7 @@ public function with(
166165 ?array $ userDescriptors = null ,
167166 ?CertificateFlagsCollection $ flags = null ,
168167 ?array $ signatures = null
169- ): Certificate
170- {
168+ ): Certificate {
171169 return new self (
172170 $ key ?? $ this ->key ,
173171 $ description ?? $ this ->description ,
@@ -177,4 +175,4 @@ public function with(
177175 );
178176 }
179177 // @codeCoverageIgnoreEnd
180- }
178+ }
0 commit comments