@@ -10,112 +10,112 @@ |
||
10 | 10 | */ |
11 | 11 | class ACValidationConfig |
12 | 12 | { |
13 | - /** |
|
14 | - * Certification path of the AC holder. |
|
15 | - * |
|
16 | - * @var CertificationPath |
|
17 | - */ |
|
18 | - protected $_holderPath; |
|
13 | + /** |
|
14 | + * Certification path of the AC holder. |
|
15 | + * |
|
16 | + * @var CertificationPath |
|
17 | + */ |
|
18 | + protected $_holderPath; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Certification path of the AC issuer. |
|
22 | - * |
|
23 | - * @var CertificationPath |
|
24 | - */ |
|
25 | - protected $_issuerPath; |
|
20 | + /** |
|
21 | + * Certification path of the AC issuer. |
|
22 | + * |
|
23 | + * @var CertificationPath |
|
24 | + */ |
|
25 | + protected $_issuerPath; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Evaluation reference time. |
|
29 | - * |
|
30 | - * @var \DateTimeImmutable |
|
31 | - */ |
|
32 | - protected $_evalTime; |
|
27 | + /** |
|
28 | + * Evaluation reference time. |
|
29 | + * |
|
30 | + * @var \DateTimeImmutable |
|
31 | + */ |
|
32 | + protected $_evalTime; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Permitted targets. |
|
36 | - * |
|
37 | - * @var Target[] |
|
38 | - */ |
|
39 | - protected $_targets; |
|
34 | + /** |
|
35 | + * Permitted targets. |
|
36 | + * |
|
37 | + * @var Target[] |
|
38 | + */ |
|
39 | + protected $_targets; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor. |
|
43 | - * |
|
44 | - * @param CertificationPath $holder_path Certification path of the AC holder |
|
45 | - * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
46 | - */ |
|
47 | - public function __construct(CertificationPath $holder_path, |
|
48 | - CertificationPath $issuer_path) |
|
49 | - { |
|
50 | - $this->_holderPath = $holder_path; |
|
51 | - $this->_issuerPath = $issuer_path; |
|
52 | - $this->_evalTime = new \DateTimeImmutable(); |
|
53 | - $this->_targets = array(); |
|
54 | - } |
|
41 | + /** |
|
42 | + * Constructor. |
|
43 | + * |
|
44 | + * @param CertificationPath $holder_path Certification path of the AC holder |
|
45 | + * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
46 | + */ |
|
47 | + public function __construct(CertificationPath $holder_path, |
|
48 | + CertificationPath $issuer_path) |
|
49 | + { |
|
50 | + $this->_holderPath = $holder_path; |
|
51 | + $this->_issuerPath = $issuer_path; |
|
52 | + $this->_evalTime = new \DateTimeImmutable(); |
|
53 | + $this->_targets = array(); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get certification path of the AC's holder. |
|
58 | - * |
|
59 | - * @return CertificationPath |
|
60 | - */ |
|
61 | - public function holderPath() |
|
62 | - { |
|
63 | - return $this->_holderPath; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Get certification path of the AC's holder. |
|
58 | + * |
|
59 | + * @return CertificationPath |
|
60 | + */ |
|
61 | + public function holderPath() |
|
62 | + { |
|
63 | + return $this->_holderPath; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Get certification path of the AC's issuer. |
|
68 | - * |
|
69 | - * @return CertificationPath |
|
70 | - */ |
|
71 | - public function issuerPath() |
|
72 | - { |
|
73 | - return $this->_issuerPath; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Get certification path of the AC's issuer. |
|
68 | + * |
|
69 | + * @return CertificationPath |
|
70 | + */ |
|
71 | + public function issuerPath() |
|
72 | + { |
|
73 | + return $this->_issuerPath; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Get self with given evaluation reference time. |
|
78 | - * |
|
79 | - * @param \DateTimeImmutable $dt |
|
80 | - * @return self |
|
81 | - */ |
|
82 | - public function withEvaluationTime(\DateTimeImmutable $dt) |
|
83 | - { |
|
84 | - $obj = clone $this; |
|
85 | - $obj->_evalTime = $dt; |
|
86 | - return $obj; |
|
87 | - } |
|
76 | + /** |
|
77 | + * Get self with given evaluation reference time. |
|
78 | + * |
|
79 | + * @param \DateTimeImmutable $dt |
|
80 | + * @return self |
|
81 | + */ |
|
82 | + public function withEvaluationTime(\DateTimeImmutable $dt) |
|
83 | + { |
|
84 | + $obj = clone $this; |
|
85 | + $obj->_evalTime = $dt; |
|
86 | + return $obj; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * Get the evaluation reference time. |
|
91 | - * |
|
92 | - * @return \DateTimeImmutable |
|
93 | - */ |
|
94 | - public function evaluationTime() |
|
95 | - { |
|
96 | - return $this->_evalTime; |
|
97 | - } |
|
89 | + /** |
|
90 | + * Get the evaluation reference time. |
|
91 | + * |
|
92 | + * @return \DateTimeImmutable |
|
93 | + */ |
|
94 | + public function evaluationTime() |
|
95 | + { |
|
96 | + return $this->_evalTime; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get self with permitted targets. |
|
101 | - * |
|
102 | - * @param Target ...$targets |
|
103 | - * @return self |
|
104 | - */ |
|
105 | - public function withTargets(Target ...$targets) |
|
106 | - { |
|
107 | - $obj = clone $this; |
|
108 | - $obj->_targets = $targets; |
|
109 | - return $obj; |
|
110 | - } |
|
99 | + /** |
|
100 | + * Get self with permitted targets. |
|
101 | + * |
|
102 | + * @param Target ...$targets |
|
103 | + * @return self |
|
104 | + */ |
|
105 | + public function withTargets(Target ...$targets) |
|
106 | + { |
|
107 | + $obj = clone $this; |
|
108 | + $obj->_targets = $targets; |
|
109 | + return $obj; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Get array of permitted targets |
|
114 | - * |
|
115 | - * @return Target[] |
|
116 | - */ |
|
117 | - public function targets() |
|
118 | - { |
|
119 | - return $this->_targets; |
|
120 | - } |
|
112 | + /** |
|
113 | + * Get array of permitted targets |
|
114 | + * |
|
115 | + * @return Target[] |
|
116 | + */ |
|
117 | + public function targets() |
|
118 | + { |
|
119 | + return $this->_targets; |
|
120 | + } |
|
121 | 121 | } |
@@ -11,17 +11,17 @@ |
||
11 | 11 | */ |
12 | 12 | class AccessIdentityAttributeValue extends SvceAuthInfo |
13 | 13 | { |
14 | - const OID = "1.3.6.1.5.5.7.10.2"; |
|
14 | + const OID = "1.3.6.1.5.5.7.10.2"; |
|
15 | 15 | |
16 | - /** |
|
17 | - * Constructor. |
|
18 | - * |
|
19 | - * @param GeneralName $service |
|
20 | - * @param GeneralName $ident |
|
21 | - */ |
|
22 | - public function __construct(GeneralName $service, GeneralName $ident) |
|
23 | - { |
|
24 | - parent::__construct($service, $ident, null); |
|
25 | - $this->_oid = self::OID; |
|
26 | - } |
|
16 | + /** |
|
17 | + * Constructor. |
|
18 | + * |
|
19 | + * @param GeneralName $service |
|
20 | + * @param GeneralName $ident |
|
21 | + */ |
|
22 | + public function __construct(GeneralName $service, GeneralName $ident) |
|
23 | + { |
|
24 | + parent::__construct($service, $ident, null); |
|
25 | + $this->_oid = self::OID; |
|
26 | + } |
|
27 | 27 | } |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | |
21 | 21 | // load RSA private key from PEM |
22 | 22 | $private_key_info = PrivateKeyInfo::fromPEM( |
23 | - PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
23 | + PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
24 | 24 | // extract public key from private key |
25 | 25 | $public_key_info = $private_key_info->publicKeyInfo(); |
26 | 26 | // DN of the certification authority |
@@ -30,12 +30,12 @@ discard block |
||
30 | 30 | // create "to be signed" certificate object with extensions |
31 | 31 | $tbs_cert = new TBSCertificate($name, $public_key_info, $name, $validity); |
32 | 32 | $tbs_cert = $tbs_cert->withRandomSerialNumber()->withAdditionalExtensions( |
33 | - new BasicConstraintsExtension(true, true), |
|
34 | - new SubjectKeyIdentifierExtension(false, $public_key_info->keyIdentifier()), |
|
35 | - new KeyUsageExtension(true, |
|
36 | - KeyUsageExtension::DIGITAL_SIGNATURE | KeyUsageExtension::KEY_CERT_SIGN)); |
|
33 | + new BasicConstraintsExtension(true, true), |
|
34 | + new SubjectKeyIdentifierExtension(false, $public_key_info->keyIdentifier()), |
|
35 | + new KeyUsageExtension(true, |
|
36 | + KeyUsageExtension::DIGITAL_SIGNATURE | KeyUsageExtension::KEY_CERT_SIGN)); |
|
37 | 37 | // sign certificate with private key |
38 | 38 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
39 | - $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
39 | + $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
40 | 40 | $cert = $tbs_cert->sign($algo, $private_key_info); |
41 | 41 | echo $cert; |
@@ -25,27 +25,27 @@ |
||
25 | 25 | $csr = CertificationRequest::fromPEM(PEM::fromFile($argv[2])); |
26 | 26 | // verify CSR |
27 | 27 | if (!$csr->verify()) { |
28 | - echo "Failed to verify certification request signature.\n"; |
|
29 | - exit(1); |
|
28 | + echo "Failed to verify certification request signature.\n"; |
|
29 | + exit(1); |
|
30 | 30 | } |
31 | 31 | // load CA's private key from PEM |
32 | 32 | $private_key_info = PrivateKeyInfo::fromPEM( |
33 | - PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
33 | + PEM::fromFile(dirname(__DIR__) . "/test/assets/rsa/private_key.pem")); |
|
34 | 34 | // initialize certificate from CSR and issuer's certificate |
35 | 35 | $tbs_cert = TBSCertificate::fromCSR($csr)->withIssuerCertificate($issuer_cert); |
36 | 36 | // set random serial number |
37 | 37 | $tbs_cert = $tbs_cert->withRandomSerialNumber(); |
38 | 38 | // set validity period |
39 | 39 | $tbs_cert = $tbs_cert->withValidity( |
40 | - Validity::fromStrings("now", "now + 3 months")); |
|
40 | + Validity::fromStrings("now", "now + 3 months")); |
|
41 | 41 | // add extensions |
42 | 42 | $tbs_cert = $tbs_cert->withAdditionalExtensions( |
43 | - new KeyUsageExtension(true, |
|
44 | - KeyUsageExtension::DIGITAL_SIGNATURE | |
|
45 | - KeyUsageExtension::KEY_ENCIPHERMENT), |
|
46 | - new BasicConstraintsExtension(true, false)); |
|
43 | + new KeyUsageExtension(true, |
|
44 | + KeyUsageExtension::DIGITAL_SIGNATURE | |
|
45 | + KeyUsageExtension::KEY_ENCIPHERMENT), |
|
46 | + new BasicConstraintsExtension(true, false)); |
|
47 | 47 | // sign certificate with issuer's private key |
48 | 48 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
49 | - $private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier()); |
|
49 | + $private_key_info->algorithmIdentifier(), new SHA512AlgorithmIdentifier()); |
|
50 | 50 | $cert = $tbs_cert->sign($algo, $private_key_info); |
51 | 51 | echo $cert; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | |
17 | 17 | // load EC private key from PEM |
18 | 18 | $private_key_info = PrivateKeyInfo::fromPEM( |
19 | - PEM::fromFile(dirname(__DIR__) . "/test/assets/ec/private_key.pem")); |
|
19 | + PEM::fromFile(dirname(__DIR__) . "/test/assets/ec/private_key.pem")); |
|
20 | 20 | // extract public key from private key |
21 | 21 | $public_key_info = $private_key_info->publicKeyInfo(); |
22 | 22 | // DN of the subject |
@@ -25,6 +25,6 @@ discard block |
||
25 | 25 | $cri = new CertificationRequestInfo($subject, $public_key_info); |
26 | 26 | // sign certificate request with private key |
27 | 27 | $algo = SignatureAlgorithmIdentifierFactory::algoForAsymmetricCrypto( |
28 | - $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
28 | + $private_key_info->algorithmIdentifier(), new SHA256AlgorithmIdentifier()); |
|
29 | 29 | $csr = $cri->sign($algo, $private_key_info); |
30 | 30 | echo $csr; |
@@ -28,19 +28,19 @@ |
||
28 | 28 | // build certification path from CA to end-entity certificate |
29 | 29 | $path = CertificationPath::fromTrustAnchorToTarget($ca, $cert); |
30 | 30 | foreach ($path->certificates() as $idx => $cert) { |
31 | - printf("#%d: %s\n", $idx, |
|
32 | - $cert->tbsCertificate() |
|
33 | - ->subject() |
|
34 | - ->toString()); |
|
31 | + printf("#%d: %s\n", $idx, |
|
32 | + $cert->tbsCertificate() |
|
33 | + ->subject() |
|
34 | + ->toString()); |
|
35 | 35 | } |
36 | 36 | // validate certification path with default configuration |
37 | 37 | $config = PathValidationConfig::defaultConfig(); |
38 | 38 | $result = $path->validate($config); |
39 | 39 | printf("Certificate '%s' is valid.\n", |
40 | - $result->certificate() |
|
41 | - ->tbsCertificate() |
|
42 | - ->subject() |
|
43 | - ->toString()); |
|
40 | + $result->certificate() |
|
41 | + ->tbsCertificate() |
|
42 | + ->subject() |
|
43 | + ->toString()); |
|
44 | 44 | // remove temporary files |
45 | 45 | unlink($ca_file); |
46 | 46 | unlink($csr_file); |
@@ -12,274 +12,274 @@ |
||
12 | 12 | */ |
13 | 13 | class PathValidationConfig |
14 | 14 | { |
15 | - /** |
|
16 | - * Maximum allowed certification path length. |
|
17 | - * |
|
18 | - * @var int $_maxLength |
|
19 | - */ |
|
20 | - protected $_maxLength; |
|
15 | + /** |
|
16 | + * Maximum allowed certification path length. |
|
17 | + * |
|
18 | + * @var int $_maxLength |
|
19 | + */ |
|
20 | + protected $_maxLength; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Reference time. |
|
24 | - * |
|
25 | - * @var \DateTimeImmutable $_dateTime |
|
26 | - */ |
|
27 | - protected $_dateTime; |
|
22 | + /** |
|
23 | + * Reference time. |
|
24 | + * |
|
25 | + * @var \DateTimeImmutable $_dateTime |
|
26 | + */ |
|
27 | + protected $_dateTime; |
|
28 | 28 | |
29 | - /** |
|
30 | - * List of acceptable policy identifiers. |
|
31 | - * |
|
32 | - * @var string[] $_policySet |
|
33 | - */ |
|
34 | - protected $_policySet; |
|
29 | + /** |
|
30 | + * List of acceptable policy identifiers. |
|
31 | + * |
|
32 | + * @var string[] $_policySet |
|
33 | + */ |
|
34 | + protected $_policySet; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Trust anchor certificate. |
|
38 | - * |
|
39 | - * If not set, path validation uses the first certificate of the path. |
|
40 | - * |
|
41 | - * @var Certificate|null $_trustAnchor |
|
42 | - */ |
|
43 | - protected $_trustAnchor; |
|
36 | + /** |
|
37 | + * Trust anchor certificate. |
|
38 | + * |
|
39 | + * If not set, path validation uses the first certificate of the path. |
|
40 | + * |
|
41 | + * @var Certificate|null $_trustAnchor |
|
42 | + */ |
|
43 | + protected $_trustAnchor; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Whether policy mapping in inhibited. |
|
47 | - * |
|
48 | - * Setting this to true disallows policy mapping. |
|
49 | - * |
|
50 | - * @var bool $_policyMappingInhibit |
|
51 | - */ |
|
52 | - protected $_policyMappingInhibit; |
|
45 | + /** |
|
46 | + * Whether policy mapping in inhibited. |
|
47 | + * |
|
48 | + * Setting this to true disallows policy mapping. |
|
49 | + * |
|
50 | + * @var bool $_policyMappingInhibit |
|
51 | + */ |
|
52 | + protected $_policyMappingInhibit; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Whether the path must be valid for at least one policy in the |
|
56 | - * initial policy set. |
|
57 | - * |
|
58 | - * @var bool $_explicitPolicy |
|
59 | - */ |
|
60 | - protected $_explicitPolicy; |
|
54 | + /** |
|
55 | + * Whether the path must be valid for at least one policy in the |
|
56 | + * initial policy set. |
|
57 | + * |
|
58 | + * @var bool $_explicitPolicy |
|
59 | + */ |
|
60 | + protected $_explicitPolicy; |
|
61 | 61 | |
62 | - /** |
|
63 | - * Whether anyPolicy OID processing should be inhibited. |
|
64 | - * |
|
65 | - * Setting this to true disallows the usage of anyPolicy. |
|
66 | - * |
|
67 | - * @var bool $_anyPolicyInhibit |
|
68 | - */ |
|
69 | - protected $_anyPolicyInhibit; |
|
62 | + /** |
|
63 | + * Whether anyPolicy OID processing should be inhibited. |
|
64 | + * |
|
65 | + * Setting this to true disallows the usage of anyPolicy. |
|
66 | + * |
|
67 | + * @var bool $_anyPolicyInhibit |
|
68 | + */ |
|
69 | + protected $_anyPolicyInhibit; |
|
70 | 70 | |
71 | - /** |
|
72 | - * |
|
73 | - * @todo Implement |
|
74 | - * @var mixed $_permittedSubtrees |
|
75 | - */ |
|
76 | - protected $_permittedSubtrees; |
|
71 | + /** |
|
72 | + * |
|
73 | + * @todo Implement |
|
74 | + * @var mixed $_permittedSubtrees |
|
75 | + */ |
|
76 | + protected $_permittedSubtrees; |
|
77 | 77 | |
78 | - /** |
|
79 | - * |
|
80 | - * @todo Implement |
|
81 | - * @var mixed $_excludedSubtrees |
|
82 | - */ |
|
83 | - protected $_excludedSubtrees; |
|
78 | + /** |
|
79 | + * |
|
80 | + * @todo Implement |
|
81 | + * @var mixed $_excludedSubtrees |
|
82 | + */ |
|
83 | + protected $_excludedSubtrees; |
|
84 | 84 | |
85 | - /** |
|
86 | - * Constructor. |
|
87 | - * |
|
88 | - * @param \DateTimeImmutable $dt Reference date and time |
|
89 | - * @param int $max_length Maximum certification path length |
|
90 | - */ |
|
91 | - public function __construct(\DateTimeImmutable $dt, $max_length) |
|
92 | - { |
|
93 | - $this->_dateTime = $dt; |
|
94 | - $this->_maxLength = (int) $max_length; |
|
95 | - $this->_policySet = array((string) PolicyInformation::OID_ANY_POLICY); |
|
96 | - $this->_policyMappingInhibit = false; |
|
97 | - $this->_explicitPolicy = false; |
|
98 | - $this->_anyPolicyInhibit = false; |
|
99 | - } |
|
85 | + /** |
|
86 | + * Constructor. |
|
87 | + * |
|
88 | + * @param \DateTimeImmutable $dt Reference date and time |
|
89 | + * @param int $max_length Maximum certification path length |
|
90 | + */ |
|
91 | + public function __construct(\DateTimeImmutable $dt, $max_length) |
|
92 | + { |
|
93 | + $this->_dateTime = $dt; |
|
94 | + $this->_maxLength = (int) $max_length; |
|
95 | + $this->_policySet = array((string) PolicyInformation::OID_ANY_POLICY); |
|
96 | + $this->_policyMappingInhibit = false; |
|
97 | + $this->_explicitPolicy = false; |
|
98 | + $this->_anyPolicyInhibit = false; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get default configuration. |
|
103 | - * |
|
104 | - * @return self |
|
105 | - */ |
|
106 | - public static function defaultConfig() |
|
107 | - { |
|
108 | - return new self(new \DateTimeImmutable(), 3); |
|
109 | - } |
|
101 | + /** |
|
102 | + * Get default configuration. |
|
103 | + * |
|
104 | + * @return self |
|
105 | + */ |
|
106 | + public static function defaultConfig() |
|
107 | + { |
|
108 | + return new self(new \DateTimeImmutable(), 3); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Get self with maximum path length. |
|
113 | - * |
|
114 | - * @param int $length |
|
115 | - * @return self |
|
116 | - */ |
|
117 | - public function withMaxLength($length) |
|
118 | - { |
|
119 | - $obj = clone $this; |
|
120 | - $obj->_maxLength = $length; |
|
121 | - return $obj; |
|
122 | - } |
|
111 | + /** |
|
112 | + * Get self with maximum path length. |
|
113 | + * |
|
114 | + * @param int $length |
|
115 | + * @return self |
|
116 | + */ |
|
117 | + public function withMaxLength($length) |
|
118 | + { |
|
119 | + $obj = clone $this; |
|
120 | + $obj->_maxLength = $length; |
|
121 | + return $obj; |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Get self with reference date and time. |
|
126 | - * |
|
127 | - * @param \DateTimeImmutable $dt |
|
128 | - * @return self |
|
129 | - */ |
|
130 | - public function withDateTime(\DateTimeImmutable $dt) |
|
131 | - { |
|
132 | - $obj = clone $this; |
|
133 | - $obj->_dateTime = $dt; |
|
134 | - return $obj; |
|
135 | - } |
|
124 | + /** |
|
125 | + * Get self with reference date and time. |
|
126 | + * |
|
127 | + * @param \DateTimeImmutable $dt |
|
128 | + * @return self |
|
129 | + */ |
|
130 | + public function withDateTime(\DateTimeImmutable $dt) |
|
131 | + { |
|
132 | + $obj = clone $this; |
|
133 | + $obj->_dateTime = $dt; |
|
134 | + return $obj; |
|
135 | + } |
|
136 | 136 | |
137 | - /** |
|
138 | - * Get self with trust anchor certificate. |
|
139 | - * |
|
140 | - * @param Certificate $ca |
|
141 | - * @return self |
|
142 | - */ |
|
143 | - public function withTrustAnchor(Certificate $ca) |
|
144 | - { |
|
145 | - $obj = clone $this; |
|
146 | - $obj->_trustAnchor = $ca; |
|
147 | - return $obj; |
|
148 | - } |
|
137 | + /** |
|
138 | + * Get self with trust anchor certificate. |
|
139 | + * |
|
140 | + * @param Certificate $ca |
|
141 | + * @return self |
|
142 | + */ |
|
143 | + public function withTrustAnchor(Certificate $ca) |
|
144 | + { |
|
145 | + $obj = clone $this; |
|
146 | + $obj->_trustAnchor = $ca; |
|
147 | + return $obj; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Get self with initial-policy-mapping-inhibit set. |
|
152 | - * |
|
153 | - * @param bool $flag |
|
154 | - * @return self |
|
155 | - */ |
|
156 | - public function withPolicyMappingInhibit($flag) |
|
157 | - { |
|
158 | - $obj = clone $this; |
|
159 | - $obj->_policyMappingInhibit = (bool) $flag; |
|
160 | - return $obj; |
|
161 | - } |
|
150 | + /** |
|
151 | + * Get self with initial-policy-mapping-inhibit set. |
|
152 | + * |
|
153 | + * @param bool $flag |
|
154 | + * @return self |
|
155 | + */ |
|
156 | + public function withPolicyMappingInhibit($flag) |
|
157 | + { |
|
158 | + $obj = clone $this; |
|
159 | + $obj->_policyMappingInhibit = (bool) $flag; |
|
160 | + return $obj; |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Get self with initial-explicit-policy set. |
|
165 | - * |
|
166 | - * @param bool $flag |
|
167 | - * @return self |
|
168 | - */ |
|
169 | - public function withExplicitPolicy($flag) |
|
170 | - { |
|
171 | - $obj = clone $this; |
|
172 | - $obj->_explicitPolicy = (bool) $flag; |
|
173 | - return $obj; |
|
174 | - } |
|
163 | + /** |
|
164 | + * Get self with initial-explicit-policy set. |
|
165 | + * |
|
166 | + * @param bool $flag |
|
167 | + * @return self |
|
168 | + */ |
|
169 | + public function withExplicitPolicy($flag) |
|
170 | + { |
|
171 | + $obj = clone $this; |
|
172 | + $obj->_explicitPolicy = (bool) $flag; |
|
173 | + return $obj; |
|
174 | + } |
|
175 | 175 | |
176 | - /** |
|
177 | - * Get self with initial-any-policy-inhibit set. |
|
178 | - * |
|
179 | - * @param bool $flag |
|
180 | - * @return self |
|
181 | - */ |
|
182 | - public function withAnyPolicyInhibit($flag) |
|
183 | - { |
|
184 | - $obj = clone $this; |
|
185 | - $obj->_anyPolicyInhibit = (bool) $flag; |
|
186 | - return $obj; |
|
187 | - } |
|
176 | + /** |
|
177 | + * Get self with initial-any-policy-inhibit set. |
|
178 | + * |
|
179 | + * @param bool $flag |
|
180 | + * @return self |
|
181 | + */ |
|
182 | + public function withAnyPolicyInhibit($flag) |
|
183 | + { |
|
184 | + $obj = clone $this; |
|
185 | + $obj->_anyPolicyInhibit = (bool) $flag; |
|
186 | + return $obj; |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Get self with user-initial-policy-set set to policy OIDs. |
|
191 | - * |
|
192 | - * @param string ...$policies List of policy OIDs |
|
193 | - * @return self |
|
194 | - */ |
|
195 | - public function withPolicySet(...$policies) |
|
196 | - { |
|
197 | - $obj = clone $this; |
|
198 | - $obj->_policySet = $policies; |
|
199 | - return $obj; |
|
200 | - } |
|
189 | + /** |
|
190 | + * Get self with user-initial-policy-set set to policy OIDs. |
|
191 | + * |
|
192 | + * @param string ...$policies List of policy OIDs |
|
193 | + * @return self |
|
194 | + */ |
|
195 | + public function withPolicySet(...$policies) |
|
196 | + { |
|
197 | + $obj = clone $this; |
|
198 | + $obj->_policySet = $policies; |
|
199 | + return $obj; |
|
200 | + } |
|
201 | 201 | |
202 | - /** |
|
203 | - * Get maximum certification path length. |
|
204 | - * |
|
205 | - * @return int |
|
206 | - */ |
|
207 | - public function maxLength() |
|
208 | - { |
|
209 | - return $this->_maxLength; |
|
210 | - } |
|
202 | + /** |
|
203 | + * Get maximum certification path length. |
|
204 | + * |
|
205 | + * @return int |
|
206 | + */ |
|
207 | + public function maxLength() |
|
208 | + { |
|
209 | + return $this->_maxLength; |
|
210 | + } |
|
211 | 211 | |
212 | - /** |
|
213 | - * Get reference date and time. |
|
214 | - * |
|
215 | - * @return \DateTimeImmutable |
|
216 | - */ |
|
217 | - public function dateTime() |
|
218 | - { |
|
219 | - return $this->_dateTime; |
|
220 | - } |
|
212 | + /** |
|
213 | + * Get reference date and time. |
|
214 | + * |
|
215 | + * @return \DateTimeImmutable |
|
216 | + */ |
|
217 | + public function dateTime() |
|
218 | + { |
|
219 | + return $this->_dateTime; |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * Get user-initial-policy-set. |
|
224 | - * |
|
225 | - * @return string[] Array of OID's |
|
226 | - */ |
|
227 | - public function policySet() |
|
228 | - { |
|
229 | - return $this->_policySet; |
|
230 | - } |
|
222 | + /** |
|
223 | + * Get user-initial-policy-set. |
|
224 | + * |
|
225 | + * @return string[] Array of OID's |
|
226 | + */ |
|
227 | + public function policySet() |
|
228 | + { |
|
229 | + return $this->_policySet; |
|
230 | + } |
|
231 | 231 | |
232 | - /** |
|
233 | - * Check whether trust anchor certificate is set. |
|
234 | - * |
|
235 | - * @return bool |
|
236 | - */ |
|
237 | - public function hasTrustAnchor() |
|
238 | - { |
|
239 | - return isset($this->_trustAnchor); |
|
240 | - } |
|
232 | + /** |
|
233 | + * Check whether trust anchor certificate is set. |
|
234 | + * |
|
235 | + * @return bool |
|
236 | + */ |
|
237 | + public function hasTrustAnchor() |
|
238 | + { |
|
239 | + return isset($this->_trustAnchor); |
|
240 | + } |
|
241 | 241 | |
242 | - /** |
|
243 | - * Get trust anchor certificate. |
|
244 | - * |
|
245 | - * @throws \LogicException |
|
246 | - * @return Certificate |
|
247 | - */ |
|
248 | - public function trustAnchor() |
|
249 | - { |
|
250 | - if (!$this->hasTrustAnchor()) { |
|
251 | - throw new \LogicException("No trust anchor."); |
|
252 | - } |
|
253 | - return $this->_trustAnchor; |
|
254 | - } |
|
242 | + /** |
|
243 | + * Get trust anchor certificate. |
|
244 | + * |
|
245 | + * @throws \LogicException |
|
246 | + * @return Certificate |
|
247 | + */ |
|
248 | + public function trustAnchor() |
|
249 | + { |
|
250 | + if (!$this->hasTrustAnchor()) { |
|
251 | + throw new \LogicException("No trust anchor."); |
|
252 | + } |
|
253 | + return $this->_trustAnchor; |
|
254 | + } |
|
255 | 255 | |
256 | - /** |
|
257 | - * Get initial-policy-mapping-inhibit. |
|
258 | - * |
|
259 | - * @return bool |
|
260 | - */ |
|
261 | - public function policyMappingInhibit() |
|
262 | - { |
|
263 | - return $this->_policyMappingInhibit; |
|
264 | - } |
|
256 | + /** |
|
257 | + * Get initial-policy-mapping-inhibit. |
|
258 | + * |
|
259 | + * @return bool |
|
260 | + */ |
|
261 | + public function policyMappingInhibit() |
|
262 | + { |
|
263 | + return $this->_policyMappingInhibit; |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * Get initial-explicit-policy. |
|
268 | - * |
|
269 | - * @return bool |
|
270 | - */ |
|
271 | - public function explicitPolicy() |
|
272 | - { |
|
273 | - return $this->_explicitPolicy; |
|
274 | - } |
|
266 | + /** |
|
267 | + * Get initial-explicit-policy. |
|
268 | + * |
|
269 | + * @return bool |
|
270 | + */ |
|
271 | + public function explicitPolicy() |
|
272 | + { |
|
273 | + return $this->_explicitPolicy; |
|
274 | + } |
|
275 | 275 | |
276 | - /** |
|
277 | - * Get initial-any-policy-inhibit. |
|
278 | - * |
|
279 | - * @return bool |
|
280 | - */ |
|
281 | - public function anyPolicyInhibit() |
|
282 | - { |
|
283 | - return $this->_anyPolicyInhibit; |
|
284 | - } |
|
276 | + /** |
|
277 | + * Get initial-any-policy-inhibit. |
|
278 | + * |
|
279 | + * @return bool |
|
280 | + */ |
|
281 | + public function anyPolicyInhibit() |
|
282 | + { |
|
283 | + return $this->_anyPolicyInhibit; |
|
284 | + } |
|
285 | 285 | } |
@@ -26,200 +26,200 @@ |
||
26 | 26 | */ |
27 | 27 | class Attributes implements \Countable, \IteratorAggregate |
28 | 28 | { |
29 | - use AttributeContainer; |
|
30 | - |
|
31 | - /** |
|
32 | - * Mapping from OID to attribute value class name. |
|
33 | - * |
|
34 | - * @internal |
|
35 | - * |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - const MAP_OID_TO_CLASS = array( |
|
39 | - /* @formatter:off */ |
|
40 | - AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
41 | - AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
42 | - ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
43 | - GroupAttributeValue::OID => GroupAttributeValue::class, |
|
44 | - AttributeType::OID_ROLE => RoleAttributeValue::class |
|
45 | - /* @formatter:on */ |
|
46 | - ); |
|
47 | - |
|
48 | - /** |
|
49 | - * Constructor. |
|
50 | - * |
|
51 | - * @param Attribute[] $attribs |
|
52 | - */ |
|
53 | - public function __construct(Attribute ...$attribs) |
|
54 | - { |
|
55 | - $this->_attributes = $attribs; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Initialize from attribute values. |
|
60 | - * |
|
61 | - * @param AttributeValue[] $values |
|
62 | - * @return self |
|
63 | - */ |
|
64 | - public static function fromAttributeValues(AttributeValue ...$values) |
|
65 | - { |
|
66 | - $attribs = array_map( |
|
67 | - function (AttributeValue $value) { |
|
68 | - return $value->toAttribute(); |
|
69 | - }, $values); |
|
70 | - return new self(...$attribs); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Initialize from ASN.1. |
|
75 | - * |
|
76 | - * @param Sequence $seq |
|
77 | - * @return self |
|
78 | - */ |
|
79 | - public static function fromASN1(Sequence $seq) |
|
80 | - { |
|
81 | - $attribs = array_map( |
|
82 | - function (UnspecifiedType $el) { |
|
83 | - return Attribute::fromASN1($el->asSequence()); |
|
84 | - }, $seq->elements()); |
|
85 | - // cast attributes |
|
86 | - $attribs = array_map( |
|
87 | - function (Attribute $attr) { |
|
88 | - $oid = $attr->oid(); |
|
89 | - if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
90 | - $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
91 | - $attr = $attr->castValues($cls); |
|
92 | - } |
|
93 | - return $attr; |
|
94 | - }, $attribs); |
|
95 | - return new self(...$attribs); |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Check whether 'Access Identity' attribute is present. |
|
100 | - * |
|
101 | - * @return bool |
|
102 | - */ |
|
103 | - public function hasAccessIdentity(): bool |
|
104 | - { |
|
105 | - return $this->has(AccessIdentityAttributeValue::OID); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Get the first 'Access Identity' attribute value. |
|
110 | - * |
|
111 | - * @return AccessIdentityAttributeValue |
|
112 | - */ |
|
113 | - public function accessIdentity(): AccessIdentityAttributeValue |
|
114 | - { |
|
115 | - return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Check whether 'Service Authentication Information' attribute is present. |
|
120 | - * |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public function hasAuthenticationInformation(): bool |
|
124 | - { |
|
125 | - return $this->has(AuthenticationInfoAttributeValue::OID); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Get the first 'Service Authentication Information' attribute value. |
|
130 | - * |
|
131 | - * @return AuthenticationInfoAttributeValue |
|
132 | - */ |
|
133 | - public function authenticationInformation(): AuthenticationInfoAttributeValue |
|
134 | - { |
|
135 | - return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Check whether 'Charging Identity' attribute is present. |
|
140 | - * |
|
141 | - * @return bool |
|
142 | - */ |
|
143 | - public function hasChargingIdentity(): bool |
|
144 | - { |
|
145 | - return $this->has(ChargingIdentityAttributeValue::OID); |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Get the first 'Charging Identity' attribute value. |
|
150 | - * |
|
151 | - * @return ChargingIdentityAttributeValue |
|
152 | - */ |
|
153 | - public function chargingIdentity(): ChargingIdentityAttributeValue |
|
154 | - { |
|
155 | - return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Check whether 'Group' attribute is present. |
|
160 | - * |
|
161 | - * @return bool |
|
162 | - */ |
|
163 | - public function hasGroup(): bool |
|
164 | - { |
|
165 | - return $this->has(GroupAttributeValue::OID); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Get the first 'Group' attribute value. |
|
170 | - * |
|
171 | - * @return GroupAttributeValue |
|
172 | - */ |
|
173 | - public function group(): GroupAttributeValue |
|
174 | - { |
|
175 | - return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Check whether 'Role' attribute is present. |
|
180 | - * |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - public function hasRole(): bool |
|
184 | - { |
|
185 | - return $this->has(AttributeType::OID_ROLE); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Get the first 'Role' attribute value. |
|
190 | - * |
|
191 | - * @return RoleAttributeValue |
|
192 | - */ |
|
193 | - public function role(): RoleAttributeValue |
|
194 | - { |
|
195 | - return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Get all 'Role' attribute values. |
|
200 | - * |
|
201 | - * @return RoleAttributeValue[] |
|
202 | - */ |
|
203 | - public function roles(): array |
|
204 | - { |
|
205 | - return array_merge(array(), |
|
206 | - ...array_map( |
|
207 | - function (Attribute $attr) { |
|
208 | - return $attr->values(); |
|
209 | - }, $this->allOf(AttributeType::OID_ROLE))); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Generate ASN.1 structure. |
|
214 | - * |
|
215 | - * @return Sequence |
|
216 | - */ |
|
217 | - public function toASN1(): Sequence |
|
218 | - { |
|
219 | - $elements = array_map( |
|
220 | - function (Attribute $attr) { |
|
221 | - return $attr->toASN1(); |
|
222 | - }, array_values($this->_attributes)); |
|
223 | - return new Sequence(...$elements); |
|
224 | - } |
|
29 | + use AttributeContainer; |
|
30 | + |
|
31 | + /** |
|
32 | + * Mapping from OID to attribute value class name. |
|
33 | + * |
|
34 | + * @internal |
|
35 | + * |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + const MAP_OID_TO_CLASS = array( |
|
39 | + /* @formatter:off */ |
|
40 | + AccessIdentityAttributeValue::OID => AccessIdentityAttributeValue::class, |
|
41 | + AuthenticationInfoAttributeValue::OID => AuthenticationInfoAttributeValue::class, |
|
42 | + ChargingIdentityAttributeValue::OID => ChargingIdentityAttributeValue::class, |
|
43 | + GroupAttributeValue::OID => GroupAttributeValue::class, |
|
44 | + AttributeType::OID_ROLE => RoleAttributeValue::class |
|
45 | + /* @formatter:on */ |
|
46 | + ); |
|
47 | + |
|
48 | + /** |
|
49 | + * Constructor. |
|
50 | + * |
|
51 | + * @param Attribute[] $attribs |
|
52 | + */ |
|
53 | + public function __construct(Attribute ...$attribs) |
|
54 | + { |
|
55 | + $this->_attributes = $attribs; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Initialize from attribute values. |
|
60 | + * |
|
61 | + * @param AttributeValue[] $values |
|
62 | + * @return self |
|
63 | + */ |
|
64 | + public static function fromAttributeValues(AttributeValue ...$values) |
|
65 | + { |
|
66 | + $attribs = array_map( |
|
67 | + function (AttributeValue $value) { |
|
68 | + return $value->toAttribute(); |
|
69 | + }, $values); |
|
70 | + return new self(...$attribs); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Initialize from ASN.1. |
|
75 | + * |
|
76 | + * @param Sequence $seq |
|
77 | + * @return self |
|
78 | + */ |
|
79 | + public static function fromASN1(Sequence $seq) |
|
80 | + { |
|
81 | + $attribs = array_map( |
|
82 | + function (UnspecifiedType $el) { |
|
83 | + return Attribute::fromASN1($el->asSequence()); |
|
84 | + }, $seq->elements()); |
|
85 | + // cast attributes |
|
86 | + $attribs = array_map( |
|
87 | + function (Attribute $attr) { |
|
88 | + $oid = $attr->oid(); |
|
89 | + if (array_key_exists($oid, self::MAP_OID_TO_CLASS)) { |
|
90 | + $cls = self::MAP_OID_TO_CLASS[$oid]; |
|
91 | + $attr = $attr->castValues($cls); |
|
92 | + } |
|
93 | + return $attr; |
|
94 | + }, $attribs); |
|
95 | + return new self(...$attribs); |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Check whether 'Access Identity' attribute is present. |
|
100 | + * |
|
101 | + * @return bool |
|
102 | + */ |
|
103 | + public function hasAccessIdentity(): bool |
|
104 | + { |
|
105 | + return $this->has(AccessIdentityAttributeValue::OID); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Get the first 'Access Identity' attribute value. |
|
110 | + * |
|
111 | + * @return AccessIdentityAttributeValue |
|
112 | + */ |
|
113 | + public function accessIdentity(): AccessIdentityAttributeValue |
|
114 | + { |
|
115 | + return $this->firstOf(AccessIdentityAttributeValue::OID)->first(); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Check whether 'Service Authentication Information' attribute is present. |
|
120 | + * |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public function hasAuthenticationInformation(): bool |
|
124 | + { |
|
125 | + return $this->has(AuthenticationInfoAttributeValue::OID); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Get the first 'Service Authentication Information' attribute value. |
|
130 | + * |
|
131 | + * @return AuthenticationInfoAttributeValue |
|
132 | + */ |
|
133 | + public function authenticationInformation(): AuthenticationInfoAttributeValue |
|
134 | + { |
|
135 | + return $this->firstOf(AuthenticationInfoAttributeValue::OID)->first(); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Check whether 'Charging Identity' attribute is present. |
|
140 | + * |
|
141 | + * @return bool |
|
142 | + */ |
|
143 | + public function hasChargingIdentity(): bool |
|
144 | + { |
|
145 | + return $this->has(ChargingIdentityAttributeValue::OID); |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Get the first 'Charging Identity' attribute value. |
|
150 | + * |
|
151 | + * @return ChargingIdentityAttributeValue |
|
152 | + */ |
|
153 | + public function chargingIdentity(): ChargingIdentityAttributeValue |
|
154 | + { |
|
155 | + return $this->firstOf(ChargingIdentityAttributeValue::OID)->first(); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Check whether 'Group' attribute is present. |
|
160 | + * |
|
161 | + * @return bool |
|
162 | + */ |
|
163 | + public function hasGroup(): bool |
|
164 | + { |
|
165 | + return $this->has(GroupAttributeValue::OID); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Get the first 'Group' attribute value. |
|
170 | + * |
|
171 | + * @return GroupAttributeValue |
|
172 | + */ |
|
173 | + public function group(): GroupAttributeValue |
|
174 | + { |
|
175 | + return $this->firstOf(GroupAttributeValue::OID)->first(); |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Check whether 'Role' attribute is present. |
|
180 | + * |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + public function hasRole(): bool |
|
184 | + { |
|
185 | + return $this->has(AttributeType::OID_ROLE); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Get the first 'Role' attribute value. |
|
190 | + * |
|
191 | + * @return RoleAttributeValue |
|
192 | + */ |
|
193 | + public function role(): RoleAttributeValue |
|
194 | + { |
|
195 | + return $this->firstOf(AttributeType::OID_ROLE)->first(); |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Get all 'Role' attribute values. |
|
200 | + * |
|
201 | + * @return RoleAttributeValue[] |
|
202 | + */ |
|
203 | + public function roles(): array |
|
204 | + { |
|
205 | + return array_merge(array(), |
|
206 | + ...array_map( |
|
207 | + function (Attribute $attr) { |
|
208 | + return $attr->values(); |
|
209 | + }, $this->allOf(AttributeType::OID_ROLE))); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Generate ASN.1 structure. |
|
214 | + * |
|
215 | + * @return Sequence |
|
216 | + */ |
|
217 | + public function toASN1(): Sequence |
|
218 | + { |
|
219 | + $elements = array_map( |
|
220 | + function (Attribute $attr) { |
|
221 | + return $attr->toASN1(); |
|
222 | + }, array_values($this->_attributes)); |
|
223 | + return new Sequence(...$elements); |
|
224 | + } |
|
225 | 225 | } |
@@ -20,92 +20,92 @@ |
||
20 | 20 | */ |
21 | 21 | class ObjectDigestInfo |
22 | 22 | { |
23 | - const TYPE_PUBLIC_KEY = 0; |
|
24 | - const TYPE_PUBLIC_KEY_CERT = 1; |
|
25 | - const TYPE_OTHER_OBJECT_TYPES = 2; |
|
23 | + const TYPE_PUBLIC_KEY = 0; |
|
24 | + const TYPE_PUBLIC_KEY_CERT = 1; |
|
25 | + const TYPE_OTHER_OBJECT_TYPES = 2; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Object type. |
|
29 | - * |
|
30 | - * @var int $_digestedObjectType |
|
31 | - */ |
|
32 | - protected $_digestedObjectType; |
|
27 | + /** |
|
28 | + * Object type. |
|
29 | + * |
|
30 | + * @var int $_digestedObjectType |
|
31 | + */ |
|
32 | + protected $_digestedObjectType; |
|
33 | 33 | |
34 | - /** |
|
35 | - * OID of other object type. |
|
36 | - * |
|
37 | - * @var string|null $_otherObjectTypeID |
|
38 | - */ |
|
39 | - protected $_otherObjectTypeID; |
|
34 | + /** |
|
35 | + * OID of other object type. |
|
36 | + * |
|
37 | + * @var string|null $_otherObjectTypeID |
|
38 | + */ |
|
39 | + protected $_otherObjectTypeID; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Digest algorithm. |
|
43 | - * |
|
44 | - * @var AlgorithmIdentifierType $_digestAlgorithm |
|
45 | - */ |
|
46 | - protected $_digestAlgorithm; |
|
41 | + /** |
|
42 | + * Digest algorithm. |
|
43 | + * |
|
44 | + * @var AlgorithmIdentifierType $_digestAlgorithm |
|
45 | + */ |
|
46 | + protected $_digestAlgorithm; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Object digest. |
|
50 | - * |
|
51 | - * @var BitString $_objectDigest |
|
52 | - */ |
|
53 | - protected $_objectDigest; |
|
48 | + /** |
|
49 | + * Object digest. |
|
50 | + * |
|
51 | + * @var BitString $_objectDigest |
|
52 | + */ |
|
53 | + protected $_objectDigest; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Constructor. |
|
57 | - * |
|
58 | - * @param int $type |
|
59 | - * @param AlgorithmIdentifierType $algo |
|
60 | - * @param BitString $digest |
|
61 | - */ |
|
62 | - public function __construct($type, AlgorithmIdentifierType $algo, |
|
63 | - BitString $digest) |
|
64 | - { |
|
65 | - $this->_digestedObjectType = $type; |
|
66 | - $this->_otherObjectTypeID = null; |
|
67 | - $this->_digestAlgorithm = $algo; |
|
68 | - $this->_objectDigest = $digest; |
|
69 | - } |
|
55 | + /** |
|
56 | + * Constructor. |
|
57 | + * |
|
58 | + * @param int $type |
|
59 | + * @param AlgorithmIdentifierType $algo |
|
60 | + * @param BitString $digest |
|
61 | + */ |
|
62 | + public function __construct($type, AlgorithmIdentifierType $algo, |
|
63 | + BitString $digest) |
|
64 | + { |
|
65 | + $this->_digestedObjectType = $type; |
|
66 | + $this->_otherObjectTypeID = null; |
|
67 | + $this->_digestAlgorithm = $algo; |
|
68 | + $this->_objectDigest = $digest; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Initialize from ASN.1. |
|
73 | - * |
|
74 | - * @param Sequence $seq |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - public static function fromASN1(Sequence $seq) |
|
78 | - { |
|
79 | - $type = $seq->at(0) |
|
80 | - ->asEnumerated() |
|
81 | - ->number(); |
|
82 | - $oid = null; |
|
83 | - $idx = 1; |
|
84 | - if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) { |
|
85 | - $oid = $seq->at($idx++) |
|
86 | - ->asObjectIdentifier() |
|
87 | - ->oid(); |
|
88 | - } |
|
89 | - $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); |
|
90 | - $digest = $seq->at($idx)->asBitString(); |
|
91 | - $obj = new self($type, $algo, $digest); |
|
92 | - $obj->_otherObjectTypeID = $oid; |
|
93 | - return $obj; |
|
94 | - } |
|
71 | + /** |
|
72 | + * Initialize from ASN.1. |
|
73 | + * |
|
74 | + * @param Sequence $seq |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + public static function fromASN1(Sequence $seq) |
|
78 | + { |
|
79 | + $type = $seq->at(0) |
|
80 | + ->asEnumerated() |
|
81 | + ->number(); |
|
82 | + $oid = null; |
|
83 | + $idx = 1; |
|
84 | + if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) { |
|
85 | + $oid = $seq->at($idx++) |
|
86 | + ->asObjectIdentifier() |
|
87 | + ->oid(); |
|
88 | + } |
|
89 | + $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence()); |
|
90 | + $digest = $seq->at($idx)->asBitString(); |
|
91 | + $obj = new self($type, $algo, $digest); |
|
92 | + $obj->_otherObjectTypeID = $oid; |
|
93 | + return $obj; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Generate ASN.1 structure. |
|
98 | - * |
|
99 | - * @return Sequence |
|
100 | - */ |
|
101 | - public function toASN1(): Sequence |
|
102 | - { |
|
103 | - $elements = array(new Enumerated($this->_digestedObjectType)); |
|
104 | - if (isset($this->_otherObjectTypeID)) { |
|
105 | - $elements[] = new ObjectIdentifier($this->_otherObjectTypeID); |
|
106 | - } |
|
107 | - $elements[] = $this->_digestAlgorithm->toASN1(); |
|
108 | - $elements[] = $this->_objectDigest; |
|
109 | - return new Sequence(...$elements); |
|
110 | - } |
|
96 | + /** |
|
97 | + * Generate ASN.1 structure. |
|
98 | + * |
|
99 | + * @return Sequence |
|
100 | + */ |
|
101 | + public function toASN1(): Sequence |
|
102 | + { |
|
103 | + $elements = array(new Enumerated($this->_digestedObjectType)); |
|
104 | + if (isset($this->_otherObjectTypeID)) { |
|
105 | + $elements[] = new ObjectIdentifier($this->_otherObjectTypeID); |
|
106 | + } |
|
107 | + $elements[] = $this->_digestAlgorithm->toASN1(); |
|
108 | + $elements[] = $this->_objectDigest; |
|
109 | + return new Sequence(...$elements); |
|
110 | + } |
|
111 | 111 | } |