@@ -4,57 +4,57 @@ |
||
4 | 4 | |
5 | 5 | class IPv6Address extends IPAddress |
6 | 6 | { |
7 | - /** |
|
8 | - * Initialize from octets. |
|
9 | - * |
|
10 | - * @param string $octets |
|
11 | - * @throws \InvalidArgumentException |
|
12 | - * @return self |
|
13 | - */ |
|
14 | - public static function fromOctets($octets) |
|
15 | - { |
|
16 | - $mask = null; |
|
17 | - $words = unpack("n*", $octets); |
|
18 | - switch (count($words)) { |
|
19 | - case 8: |
|
20 | - $ip = self::_wordsToIPv6String($words); |
|
21 | - break; |
|
22 | - case 16: |
|
23 | - $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
24 | - $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
25 | - break; |
|
26 | - default: |
|
27 | - throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
28 | - } |
|
29 | - return new self($ip, $mask); |
|
30 | - } |
|
7 | + /** |
|
8 | + * Initialize from octets. |
|
9 | + * |
|
10 | + * @param string $octets |
|
11 | + * @throws \InvalidArgumentException |
|
12 | + * @return self |
|
13 | + */ |
|
14 | + public static function fromOctets($octets) |
|
15 | + { |
|
16 | + $mask = null; |
|
17 | + $words = unpack("n*", $octets); |
|
18 | + switch (count($words)) { |
|
19 | + case 8: |
|
20 | + $ip = self::_wordsToIPv6String($words); |
|
21 | + break; |
|
22 | + case 16: |
|
23 | + $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
24 | + $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
25 | + break; |
|
26 | + default: |
|
27 | + throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
28 | + } |
|
29 | + return new self($ip, $mask); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Convert an array of 16 bit words to an IPv6 string representation. |
|
34 | - * |
|
35 | - * @param int[] $words |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - protected static function _wordsToIPv6String(array $words) |
|
39 | - { |
|
40 | - $groups = array_map( |
|
41 | - function ($word) { |
|
42 | - return sprintf("%04x", $word); |
|
43 | - }, $words); |
|
44 | - return implode(":", $groups); |
|
45 | - } |
|
32 | + /** |
|
33 | + * Convert an array of 16 bit words to an IPv6 string representation. |
|
34 | + * |
|
35 | + * @param int[] $words |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + protected static function _wordsToIPv6String(array $words) |
|
39 | + { |
|
40 | + $groups = array_map( |
|
41 | + function ($word) { |
|
42 | + return sprintf("%04x", $word); |
|
43 | + }, $words); |
|
44 | + return implode(":", $groups); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * |
|
49 | - * {@inheritdoc} |
|
50 | - */ |
|
51 | - protected function _octets() |
|
52 | - { |
|
53 | - $words = array_map("hexdec", explode(":", $this->_ip)); |
|
54 | - if (isset($this->_mask)) { |
|
55 | - $words = array_merge($words, |
|
56 | - array_map("hexdec", explode(":", $this->_mask))); |
|
57 | - } |
|
58 | - return pack("n*", ...$words); |
|
59 | - } |
|
47 | + /** |
|
48 | + * |
|
49 | + * {@inheritdoc} |
|
50 | + */ |
|
51 | + protected function _octets() |
|
52 | + { |
|
53 | + $words = array_map("hexdec", explode(":", $this->_ip)); |
|
54 | + if (isset($this->_mask)) { |
|
55 | + $words = array_merge($words, |
|
56 | + array_map("hexdec", explode(":", $this->_mask))); |
|
57 | + } |
|
58 | + return pack("n*", ...$words); |
|
59 | + } |
|
60 | 60 | } |
@@ -16,15 +16,15 @@ |
||
16 | 16 | $mask = null; |
17 | 17 | $words = unpack("n*", $octets); |
18 | 18 | switch (count($words)) { |
19 | - case 8: |
|
20 | - $ip = self::_wordsToIPv6String($words); |
|
21 | - break; |
|
22 | - case 16: |
|
23 | - $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
24 | - $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
25 | - break; |
|
26 | - default: |
|
27 | - throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
19 | + case 8: |
|
20 | + $ip = self::_wordsToIPv6String($words); |
|
21 | + break; |
|
22 | + case 16: |
|
23 | + $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
24 | + $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
25 | + break; |
|
26 | + default: |
|
27 | + throw new \UnexpectedValueException("Invalid IPv6 octet length."); |
|
28 | 28 | } |
29 | 29 | return new self($ip, $mask); |
30 | 30 | } |
@@ -38,7 +38,7 @@ |
||
38 | 38 | protected static function _wordsToIPv6String(array $words) |
39 | 39 | { |
40 | 40 | $groups = array_map( |
41 | - function ($word) { |
|
41 | + function($word) { |
|
42 | 42 | return sprintf("%04x", $word); |
43 | 43 | }, $words); |
44 | 44 | return implode(":", $groups); |
@@ -13,60 +13,60 @@ |
||
13 | 13 | */ |
14 | 14 | class RegisteredID extends GeneralName |
15 | 15 | { |
16 | - /** |
|
17 | - * Object identifier. |
|
18 | - * |
|
19 | - * @var string $_oid |
|
20 | - */ |
|
21 | - protected $_oid; |
|
16 | + /** |
|
17 | + * Object identifier. |
|
18 | + * |
|
19 | + * @var string $_oid |
|
20 | + */ |
|
21 | + protected $_oid; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param string $oid OID in dotted format |
|
27 | - */ |
|
28 | - public function __construct($oid) |
|
29 | - { |
|
30 | - $this->_tag = self::TAG_REGISTERED_ID; |
|
31 | - $this->_oid = $oid; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param string $oid OID in dotted format |
|
27 | + */ |
|
28 | + public function __construct($oid) |
|
29 | + { |
|
30 | + $this->_tag = self::TAG_REGISTERED_ID; |
|
31 | + $this->_oid = $oid; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @param UnspecifiedType $el |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | - { |
|
41 | - return new self($el->asObjectIdentifier()->oid()); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param UnspecifiedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | + { |
|
41 | + return new self($el->asObjectIdentifier()->oid()); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return $this->_oid; |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return $this->_oid; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get object identifier in dotted format. |
|
55 | - * |
|
56 | - * @return string OID |
|
57 | - */ |
|
58 | - public function oid() |
|
59 | - { |
|
60 | - return $this->_oid; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get object identifier in dotted format. |
|
55 | + * |
|
56 | + * @return string OID |
|
57 | + */ |
|
58 | + public function oid() |
|
59 | + { |
|
60 | + return $this->_oid; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - protected function _choiceASN1() |
|
68 | - { |
|
69 | - return new ImplicitlyTaggedType($this->_tag, |
|
70 | - new ObjectIdentifier($this->_oid)); |
|
71 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + protected function _choiceASN1() |
|
68 | + { |
|
69 | + return new ImplicitlyTaggedType($this->_tag, |
|
70 | + new ObjectIdentifier($this->_oid)); |
|
71 | + } |
|
72 | 72 | } |
@@ -13,147 +13,147 @@ |
||
13 | 13 | */ |
14 | 14 | abstract class GeneralName |
15 | 15 | { |
16 | - // GeneralName CHOICE tags |
|
17 | - const TAG_OTHER_NAME = 0; |
|
18 | - const TAG_RFC822_NAME = 1; |
|
19 | - const TAG_DNS_NAME = 2; |
|
20 | - const TAG_X400_ADDRESS = 3; |
|
21 | - const TAG_DIRECTORY_NAME = 4; |
|
22 | - const TAG_EDI_PARTY_NAME = 5; |
|
23 | - const TAG_URI = 6; |
|
24 | - const TAG_IP_ADDRESS = 7; |
|
25 | - const TAG_REGISTERED_ID = 8; |
|
16 | + // GeneralName CHOICE tags |
|
17 | + const TAG_OTHER_NAME = 0; |
|
18 | + const TAG_RFC822_NAME = 1; |
|
19 | + const TAG_DNS_NAME = 2; |
|
20 | + const TAG_X400_ADDRESS = 3; |
|
21 | + const TAG_DIRECTORY_NAME = 4; |
|
22 | + const TAG_EDI_PARTY_NAME = 5; |
|
23 | + const TAG_URI = 6; |
|
24 | + const TAG_IP_ADDRESS = 7; |
|
25 | + const TAG_REGISTERED_ID = 8; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Chosen tag. |
|
29 | - * |
|
30 | - * @var int $_tag |
|
31 | - */ |
|
32 | - protected $_tag; |
|
27 | + /** |
|
28 | + * Chosen tag. |
|
29 | + * |
|
30 | + * @var int $_tag |
|
31 | + */ |
|
32 | + protected $_tag; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Get string value of the type. |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - abstract public function string(); |
|
34 | + /** |
|
35 | + * Get string value of the type. |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + abstract public function string(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * Get ASN.1 value in GeneralName CHOICE context. |
|
43 | - * |
|
44 | - * @return TaggedType |
|
45 | - */ |
|
46 | - abstract protected function _choiceASN1(); |
|
41 | + /** |
|
42 | + * Get ASN.1 value in GeneralName CHOICE context. |
|
43 | + * |
|
44 | + * @return TaggedType |
|
45 | + */ |
|
46 | + abstract protected function _choiceASN1(); |
|
47 | 47 | |
48 | - /** |
|
49 | - * Initialize concrete object from the chosen ASN.1 element. |
|
50 | - * |
|
51 | - * @param UnspecifiedType $el |
|
52 | - * @return self |
|
53 | - */ |
|
54 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
55 | - { |
|
56 | - throw new \BadMethodCallException( |
|
57 | - __FUNCTION__ . " must be implemented in the derived class."); |
|
58 | - } |
|
48 | + /** |
|
49 | + * Initialize concrete object from the chosen ASN.1 element. |
|
50 | + * |
|
51 | + * @param UnspecifiedType $el |
|
52 | + * @return self |
|
53 | + */ |
|
54 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
55 | + { |
|
56 | + throw new \BadMethodCallException( |
|
57 | + __FUNCTION__ . " must be implemented in the derived class."); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Initialize from ASN.1. |
|
62 | - * |
|
63 | - * @param TaggedType $el |
|
64 | - * @throws \UnexpectedValueException |
|
65 | - * @return self |
|
66 | - */ |
|
67 | - public static function fromASN1(TaggedType $el) |
|
68 | - { |
|
69 | - switch ($el->tag()) { |
|
70 | - // otherName |
|
71 | - case self::TAG_OTHER_NAME: |
|
72 | - return OtherName::fromChosenASN1( |
|
73 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
74 | - // rfc822Name |
|
75 | - case self::TAG_RFC822_NAME: |
|
76 | - return RFC822Name::fromChosenASN1( |
|
77 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
78 | - // dNSName |
|
79 | - case self::TAG_DNS_NAME: |
|
80 | - return DNSName::fromChosenASN1( |
|
81 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
82 | - // x400Address |
|
83 | - case self::TAG_X400_ADDRESS: |
|
84 | - return X400Address::fromChosenASN1( |
|
85 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
86 | - // directoryName |
|
87 | - case self::TAG_DIRECTORY_NAME: |
|
88 | - // because Name is a CHOICE, albeit having only one option, |
|
89 | - // explicit tagging must be used |
|
90 | - // (see X.680 07/2002 30.6.c) |
|
91 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
92 | - // ediPartyName |
|
93 | - case self::TAG_EDI_PARTY_NAME: |
|
94 | - return EDIPartyName::fromChosenASN1( |
|
95 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
96 | - // uniformResourceIdentifier |
|
97 | - case self::TAG_URI: |
|
98 | - return UniformResourceIdentifier::fromChosenASN1( |
|
99 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
100 | - // iPAddress |
|
101 | - case self::TAG_IP_ADDRESS: |
|
102 | - return IPAddress::fromChosenASN1( |
|
103 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
104 | - // registeredID |
|
105 | - case self::TAG_REGISTERED_ID: |
|
106 | - return RegisteredID::fromChosenASN1( |
|
107 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
108 | - } |
|
109 | - throw new \UnexpectedValueException( |
|
110 | - "GeneralName type " . $el->tag() . " not supported."); |
|
111 | - } |
|
60 | + /** |
|
61 | + * Initialize from ASN.1. |
|
62 | + * |
|
63 | + * @param TaggedType $el |
|
64 | + * @throws \UnexpectedValueException |
|
65 | + * @return self |
|
66 | + */ |
|
67 | + public static function fromASN1(TaggedType $el) |
|
68 | + { |
|
69 | + switch ($el->tag()) { |
|
70 | + // otherName |
|
71 | + case self::TAG_OTHER_NAME: |
|
72 | + return OtherName::fromChosenASN1( |
|
73 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
74 | + // rfc822Name |
|
75 | + case self::TAG_RFC822_NAME: |
|
76 | + return RFC822Name::fromChosenASN1( |
|
77 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
78 | + // dNSName |
|
79 | + case self::TAG_DNS_NAME: |
|
80 | + return DNSName::fromChosenASN1( |
|
81 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
82 | + // x400Address |
|
83 | + case self::TAG_X400_ADDRESS: |
|
84 | + return X400Address::fromChosenASN1( |
|
85 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
86 | + // directoryName |
|
87 | + case self::TAG_DIRECTORY_NAME: |
|
88 | + // because Name is a CHOICE, albeit having only one option, |
|
89 | + // explicit tagging must be used |
|
90 | + // (see X.680 07/2002 30.6.c) |
|
91 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
92 | + // ediPartyName |
|
93 | + case self::TAG_EDI_PARTY_NAME: |
|
94 | + return EDIPartyName::fromChosenASN1( |
|
95 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
96 | + // uniformResourceIdentifier |
|
97 | + case self::TAG_URI: |
|
98 | + return UniformResourceIdentifier::fromChosenASN1( |
|
99 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
100 | + // iPAddress |
|
101 | + case self::TAG_IP_ADDRESS: |
|
102 | + return IPAddress::fromChosenASN1( |
|
103 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
104 | + // registeredID |
|
105 | + case self::TAG_REGISTERED_ID: |
|
106 | + return RegisteredID::fromChosenASN1( |
|
107 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
108 | + } |
|
109 | + throw new \UnexpectedValueException( |
|
110 | + "GeneralName type " . $el->tag() . " not supported."); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get type tag. |
|
115 | - * |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function tag() |
|
119 | - { |
|
120 | - return $this->_tag; |
|
121 | - } |
|
113 | + /** |
|
114 | + * Get type tag. |
|
115 | + * |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function tag() |
|
119 | + { |
|
120 | + return $this->_tag; |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
124 | - * Generate ASN.1 element. |
|
125 | - * |
|
126 | - * @return Element |
|
127 | - */ |
|
128 | - public function toASN1() |
|
129 | - { |
|
130 | - return $this->_choiceASN1(); |
|
131 | - } |
|
123 | + /** |
|
124 | + * Generate ASN.1 element. |
|
125 | + * |
|
126 | + * @return Element |
|
127 | + */ |
|
128 | + public function toASN1() |
|
129 | + { |
|
130 | + return $this->_choiceASN1(); |
|
131 | + } |
|
132 | 132 | |
133 | - /** |
|
134 | - * Check whether GeneralName is equal to other. |
|
135 | - * |
|
136 | - * @param GeneralName $other GeneralName to compare to |
|
137 | - * @return boolean True if names are equal |
|
138 | - */ |
|
139 | - public function equals(GeneralName $other) |
|
140 | - { |
|
141 | - if ($this->_tag != $other->_tag) { |
|
142 | - return false; |
|
143 | - } |
|
144 | - if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
145 | - return false; |
|
146 | - } |
|
147 | - return true; |
|
148 | - } |
|
133 | + /** |
|
134 | + * Check whether GeneralName is equal to other. |
|
135 | + * |
|
136 | + * @param GeneralName $other GeneralName to compare to |
|
137 | + * @return boolean True if names are equal |
|
138 | + */ |
|
139 | + public function equals(GeneralName $other) |
|
140 | + { |
|
141 | + if ($this->_tag != $other->_tag) { |
|
142 | + return false; |
|
143 | + } |
|
144 | + if ($this->_choiceASN1()->toDER() != $other->_choiceASN1()->toDER()) { |
|
145 | + return false; |
|
146 | + } |
|
147 | + return true; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Get general name as a string. |
|
152 | - * |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - public function __toString() |
|
156 | - { |
|
157 | - return $this->string(); |
|
158 | - } |
|
150 | + /** |
|
151 | + * Get general name as a string. |
|
152 | + * |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + public function __toString() |
|
156 | + { |
|
157 | + return $this->string(); |
|
158 | + } |
|
159 | 159 | } |
@@ -68,43 +68,43 @@ |
||
68 | 68 | { |
69 | 69 | switch ($el->tag()) { |
70 | 70 | // otherName |
71 | - case self::TAG_OTHER_NAME: |
|
72 | - return OtherName::fromChosenASN1( |
|
73 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
74 | - // rfc822Name |
|
75 | - case self::TAG_RFC822_NAME: |
|
76 | - return RFC822Name::fromChosenASN1( |
|
77 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
78 | - // dNSName |
|
79 | - case self::TAG_DNS_NAME: |
|
80 | - return DNSName::fromChosenASN1( |
|
81 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
82 | - // x400Address |
|
83 | - case self::TAG_X400_ADDRESS: |
|
84 | - return X400Address::fromChosenASN1( |
|
85 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
86 | - // directoryName |
|
87 | - case self::TAG_DIRECTORY_NAME: |
|
88 | - // because Name is a CHOICE, albeit having only one option, |
|
89 | - // explicit tagging must be used |
|
90 | - // (see X.680 07/2002 30.6.c) |
|
91 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
92 | - // ediPartyName |
|
93 | - case self::TAG_EDI_PARTY_NAME: |
|
94 | - return EDIPartyName::fromChosenASN1( |
|
95 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
96 | - // uniformResourceIdentifier |
|
97 | - case self::TAG_URI: |
|
98 | - return UniformResourceIdentifier::fromChosenASN1( |
|
99 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
100 | - // iPAddress |
|
101 | - case self::TAG_IP_ADDRESS: |
|
102 | - return IPAddress::fromChosenASN1( |
|
103 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
104 | - // registeredID |
|
105 | - case self::TAG_REGISTERED_ID: |
|
106 | - return RegisteredID::fromChosenASN1( |
|
107 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
71 | + case self::TAG_OTHER_NAME: |
|
72 | + return OtherName::fromChosenASN1( |
|
73 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
74 | + // rfc822Name |
|
75 | + case self::TAG_RFC822_NAME: |
|
76 | + return RFC822Name::fromChosenASN1( |
|
77 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
78 | + // dNSName |
|
79 | + case self::TAG_DNS_NAME: |
|
80 | + return DNSName::fromChosenASN1( |
|
81 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
82 | + // x400Address |
|
83 | + case self::TAG_X400_ADDRESS: |
|
84 | + return X400Address::fromChosenASN1( |
|
85 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
86 | + // directoryName |
|
87 | + case self::TAG_DIRECTORY_NAME: |
|
88 | + // because Name is a CHOICE, albeit having only one option, |
|
89 | + // explicit tagging must be used |
|
90 | + // (see X.680 07/2002 30.6.c) |
|
91 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
92 | + // ediPartyName |
|
93 | + case self::TAG_EDI_PARTY_NAME: |
|
94 | + return EDIPartyName::fromChosenASN1( |
|
95 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
96 | + // uniformResourceIdentifier |
|
97 | + case self::TAG_URI: |
|
98 | + return UniformResourceIdentifier::fromChosenASN1( |
|
99 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
100 | + // iPAddress |
|
101 | + case self::TAG_IP_ADDRESS: |
|
102 | + return IPAddress::fromChosenASN1( |
|
103 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
104 | + // registeredID |
|
105 | + case self::TAG_REGISTERED_ID: |
|
106 | + return RegisteredID::fromChosenASN1( |
|
107 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
108 | 108 | } |
109 | 109 | throw new \UnexpectedValueException( |
110 | 110 | "GeneralName type " . $el->tag() . " not supported."); |
@@ -13,72 +13,72 @@ |
||
13 | 13 | */ |
14 | 14 | class DirectoryName extends GeneralName |
15 | 15 | { |
16 | - /** |
|
17 | - * Directory name. |
|
18 | - * |
|
19 | - * @var Name $_dn |
|
20 | - */ |
|
21 | - protected $_dn; |
|
16 | + /** |
|
17 | + * Directory name. |
|
18 | + * |
|
19 | + * @var Name $_dn |
|
20 | + */ |
|
21 | + protected $_dn; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param Name $dn |
|
27 | - */ |
|
28 | - public function __construct(Name $dn) |
|
29 | - { |
|
30 | - $this->_tag = self::TAG_DIRECTORY_NAME; |
|
31 | - $this->_dn = $dn; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param Name $dn |
|
27 | + */ |
|
28 | + public function __construct(Name $dn) |
|
29 | + { |
|
30 | + $this->_tag = self::TAG_DIRECTORY_NAME; |
|
31 | + $this->_dn = $dn; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @param UnspecifiedType $el |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | - { |
|
41 | - return new self(Name::fromASN1($el->asSequence())); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param UnspecifiedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | + { |
|
41 | + return new self(Name::fromASN1($el->asSequence())); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Initialize from distinguished name string. |
|
46 | - * |
|
47 | - * @param string $str |
|
48 | - * @return self |
|
49 | - */ |
|
50 | - public static function fromDNString($str) |
|
51 | - { |
|
52 | - return new self(Name::fromString($str)); |
|
53 | - } |
|
44 | + /** |
|
45 | + * Initialize from distinguished name string. |
|
46 | + * |
|
47 | + * @param string $str |
|
48 | + * @return self |
|
49 | + */ |
|
50 | + public static function fromDNString($str) |
|
51 | + { |
|
52 | + return new self(Name::fromString($str)); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * |
|
57 | - * {@inheritdoc} |
|
58 | - */ |
|
59 | - public function string() |
|
60 | - { |
|
61 | - return $this->_dn->toString(); |
|
62 | - } |
|
55 | + /** |
|
56 | + * |
|
57 | + * {@inheritdoc} |
|
58 | + */ |
|
59 | + public function string() |
|
60 | + { |
|
61 | + return $this->_dn->toString(); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Get directory name. |
|
66 | - * |
|
67 | - * @return Name |
|
68 | - */ |
|
69 | - public function dn() |
|
70 | - { |
|
71 | - return $this->_dn; |
|
72 | - } |
|
64 | + /** |
|
65 | + * Get directory name. |
|
66 | + * |
|
67 | + * @return Name |
|
68 | + */ |
|
69 | + public function dn() |
|
70 | + { |
|
71 | + return $this->_dn; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * |
|
76 | - * {@inheritdoc} |
|
77 | - */ |
|
78 | - protected function _choiceASN1() |
|
79 | - { |
|
80 | - // Name type is itself a CHOICE, so explicit tagging must be |
|
81 | - // employed to avoid ambiguities |
|
82 | - return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
83 | - } |
|
74 | + /** |
|
75 | + * |
|
76 | + * {@inheritdoc} |
|
77 | + */ |
|
78 | + protected function _choiceASN1() |
|
79 | + { |
|
80 | + // Name type is itself a CHOICE, so explicit tagging must be |
|
81 | + // employed to avoid ambiguities |
|
82 | + return new ExplicitlyTaggedType($this->_tag, $this->_dn->toASN1()); |
|
83 | + } |
|
84 | 84 | } |
@@ -17,235 +17,235 @@ |
||
17 | 17 | */ |
18 | 18 | class Certificate |
19 | 19 | { |
20 | - /** |
|
21 | - * "To be signed" certificate information. |
|
22 | - * |
|
23 | - * @var TBSCertificate $_tbsCertificate |
|
24 | - */ |
|
25 | - protected $_tbsCertificate; |
|
26 | - |
|
27 | - /** |
|
28 | - * Signature algorithm. |
|
29 | - * |
|
30 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
31 | - */ |
|
32 | - protected $_signatureAlgorithm; |
|
33 | - |
|
34 | - /** |
|
35 | - * Signature value. |
|
36 | - * |
|
37 | - * @var Signature $_signatureValue |
|
38 | - */ |
|
39 | - protected $_signatureValue; |
|
40 | - |
|
41 | - /** |
|
42 | - * Constructor. |
|
43 | - * |
|
44 | - * @param TBSCertificate $tbsCert |
|
45 | - * @param SignatureAlgorithmIdentifier $algo |
|
46 | - * @param Signature $signature |
|
47 | - */ |
|
48 | - public function __construct(TBSCertificate $tbsCert, |
|
49 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
50 | - { |
|
51 | - $this->_tbsCertificate = $tbsCert; |
|
52 | - $this->_signatureAlgorithm = $algo; |
|
53 | - $this->_signatureValue = $signature; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * Initialize from ASN.1. |
|
58 | - * |
|
59 | - * @param Sequence $seq |
|
60 | - * @return self |
|
61 | - */ |
|
62 | - public static function fromASN1(Sequence $seq) |
|
63 | - { |
|
64 | - $tbsCert = TBSCertificate::fromASN1($seq->at(0)->asSequence()); |
|
65 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
66 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
67 | - throw new \UnexpectedValueException( |
|
68 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
69 | - } |
|
70 | - $signature = Signature::fromSignatureData( |
|
71 | - $seq->at(2) |
|
72 | - ->asBitString() |
|
73 | - ->string(), $algo); |
|
74 | - return new self($tbsCert, $algo, $signature); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Initialize from DER. |
|
79 | - * |
|
80 | - * @param string $data |
|
81 | - * @return self |
|
82 | - */ |
|
83 | - public static function fromDER($data) |
|
84 | - { |
|
85 | - return self::fromASN1(Sequence::fromDER($data)); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Initialize from PEM. |
|
90 | - * |
|
91 | - * @param PEM $pem |
|
92 | - * @throws \UnexpectedValueException |
|
93 | - * @return self |
|
94 | - */ |
|
95 | - public static function fromPEM(PEM $pem) |
|
96 | - { |
|
97 | - if ($pem->type() != PEM::TYPE_CERTIFICATE) { |
|
98 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
99 | - } |
|
100 | - return self::fromDER($pem->data()); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Get certificate information. |
|
105 | - * |
|
106 | - * @return TBSCertificate |
|
107 | - */ |
|
108 | - public function tbsCertificate() |
|
109 | - { |
|
110 | - return $this->_tbsCertificate; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get signature algorithm. |
|
115 | - * |
|
116 | - * @return SignatureAlgorithmIdentifier |
|
117 | - */ |
|
118 | - public function signatureAlgorithm() |
|
119 | - { |
|
120 | - return $this->_signatureAlgorithm; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Get signature value. |
|
125 | - * |
|
126 | - * @return Signature |
|
127 | - */ |
|
128 | - public function signatureValue() |
|
129 | - { |
|
130 | - return $this->_signatureValue; |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Check whether certificate is self-issued. |
|
135 | - * |
|
136 | - * @return bool |
|
137 | - */ |
|
138 | - public function isSelfIssued() |
|
139 | - { |
|
140 | - return $this->_tbsCertificate->subject()->equals( |
|
141 | - $this->_tbsCertificate->issuer()); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Check whether certificate is semantically equal to another. |
|
146 | - * |
|
147 | - * @param Certificate $cert Certificate to compare to |
|
148 | - * @return bool |
|
149 | - */ |
|
150 | - public function equals(Certificate $cert) |
|
151 | - { |
|
152 | - return $this->_hasEqualSerialNumber($cert) && |
|
153 | - $this->_hasEqualPublicKey($cert) && $this->_hasEqualSubject($cert); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Check whether certificate has serial number equal to another. |
|
158 | - * |
|
159 | - * @param Certificate $cert |
|
160 | - * @return bool |
|
161 | - */ |
|
162 | - private function _hasEqualSerialNumber(Certificate $cert) |
|
163 | - { |
|
164 | - $sn1 = $this->_tbsCertificate->serialNumber(); |
|
165 | - $sn2 = $cert->_tbsCertificate->serialNumber(); |
|
166 | - return $sn1 == $sn2; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Check whether certificate has public key equal to another. |
|
171 | - * |
|
172 | - * @param Certificate $cert |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - private function _hasEqualPublicKey(Certificate $cert) |
|
176 | - { |
|
177 | - $kid1 = $this->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier(); |
|
178 | - $kid2 = $cert->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier(); |
|
179 | - return $kid1 == $kid2; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Check whether certificate has subject equal to another. |
|
184 | - * |
|
185 | - * @param Certificate $cert |
|
186 | - * @return bool |
|
187 | - */ |
|
188 | - private function _hasEqualSubject(Certificate $cert) |
|
189 | - { |
|
190 | - $dn1 = $this->_tbsCertificate->subject(); |
|
191 | - $dn2 = $cert->_tbsCertificate->subject(); |
|
192 | - return $dn1->equals($dn2); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Generate ASN.1 structure. |
|
197 | - * |
|
198 | - * @return Sequence |
|
199 | - */ |
|
200 | - public function toASN1() |
|
201 | - { |
|
202 | - return new Sequence($this->_tbsCertificate->toASN1(), |
|
203 | - $this->_signatureAlgorithm->toASN1(), |
|
204 | - $this->_signatureValue->bitString()); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get certificate as a DER. |
|
209 | - * |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function toDER() |
|
213 | - { |
|
214 | - return $this->toASN1()->toDER(); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Get certificate as a PEM. |
|
219 | - * |
|
220 | - * @return PEM |
|
221 | - */ |
|
222 | - public function toPEM() |
|
223 | - { |
|
224 | - return new PEM(PEM::TYPE_CERTIFICATE, $this->toDER()); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Verify certificate signature. |
|
229 | - * |
|
230 | - * @param PublicKeyInfo $pubkey_info Issuer's public key |
|
231 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
232 | - * @return bool True if certificate signature is valid |
|
233 | - */ |
|
234 | - public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null) |
|
235 | - { |
|
236 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
237 | - $data = $this->_tbsCertificate->toASN1()->toDER(); |
|
238 | - return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
239 | - $this->_signatureAlgorithm); |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Get certificate as a PEM formatted string. |
|
244 | - * |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - public function __toString() |
|
248 | - { |
|
249 | - return $this->toPEM()->string(); |
|
250 | - } |
|
20 | + /** |
|
21 | + * "To be signed" certificate information. |
|
22 | + * |
|
23 | + * @var TBSCertificate $_tbsCertificate |
|
24 | + */ |
|
25 | + protected $_tbsCertificate; |
|
26 | + |
|
27 | + /** |
|
28 | + * Signature algorithm. |
|
29 | + * |
|
30 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
31 | + */ |
|
32 | + protected $_signatureAlgorithm; |
|
33 | + |
|
34 | + /** |
|
35 | + * Signature value. |
|
36 | + * |
|
37 | + * @var Signature $_signatureValue |
|
38 | + */ |
|
39 | + protected $_signatureValue; |
|
40 | + |
|
41 | + /** |
|
42 | + * Constructor. |
|
43 | + * |
|
44 | + * @param TBSCertificate $tbsCert |
|
45 | + * @param SignatureAlgorithmIdentifier $algo |
|
46 | + * @param Signature $signature |
|
47 | + */ |
|
48 | + public function __construct(TBSCertificate $tbsCert, |
|
49 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
50 | + { |
|
51 | + $this->_tbsCertificate = $tbsCert; |
|
52 | + $this->_signatureAlgorithm = $algo; |
|
53 | + $this->_signatureValue = $signature; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * Initialize from ASN.1. |
|
58 | + * |
|
59 | + * @param Sequence $seq |
|
60 | + * @return self |
|
61 | + */ |
|
62 | + public static function fromASN1(Sequence $seq) |
|
63 | + { |
|
64 | + $tbsCert = TBSCertificate::fromASN1($seq->at(0)->asSequence()); |
|
65 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
66 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
67 | + throw new \UnexpectedValueException( |
|
68 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
69 | + } |
|
70 | + $signature = Signature::fromSignatureData( |
|
71 | + $seq->at(2) |
|
72 | + ->asBitString() |
|
73 | + ->string(), $algo); |
|
74 | + return new self($tbsCert, $algo, $signature); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Initialize from DER. |
|
79 | + * |
|
80 | + * @param string $data |
|
81 | + * @return self |
|
82 | + */ |
|
83 | + public static function fromDER($data) |
|
84 | + { |
|
85 | + return self::fromASN1(Sequence::fromDER($data)); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Initialize from PEM. |
|
90 | + * |
|
91 | + * @param PEM $pem |
|
92 | + * @throws \UnexpectedValueException |
|
93 | + * @return self |
|
94 | + */ |
|
95 | + public static function fromPEM(PEM $pem) |
|
96 | + { |
|
97 | + if ($pem->type() != PEM::TYPE_CERTIFICATE) { |
|
98 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
99 | + } |
|
100 | + return self::fromDER($pem->data()); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Get certificate information. |
|
105 | + * |
|
106 | + * @return TBSCertificate |
|
107 | + */ |
|
108 | + public function tbsCertificate() |
|
109 | + { |
|
110 | + return $this->_tbsCertificate; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get signature algorithm. |
|
115 | + * |
|
116 | + * @return SignatureAlgorithmIdentifier |
|
117 | + */ |
|
118 | + public function signatureAlgorithm() |
|
119 | + { |
|
120 | + return $this->_signatureAlgorithm; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Get signature value. |
|
125 | + * |
|
126 | + * @return Signature |
|
127 | + */ |
|
128 | + public function signatureValue() |
|
129 | + { |
|
130 | + return $this->_signatureValue; |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Check whether certificate is self-issued. |
|
135 | + * |
|
136 | + * @return bool |
|
137 | + */ |
|
138 | + public function isSelfIssued() |
|
139 | + { |
|
140 | + return $this->_tbsCertificate->subject()->equals( |
|
141 | + $this->_tbsCertificate->issuer()); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Check whether certificate is semantically equal to another. |
|
146 | + * |
|
147 | + * @param Certificate $cert Certificate to compare to |
|
148 | + * @return bool |
|
149 | + */ |
|
150 | + public function equals(Certificate $cert) |
|
151 | + { |
|
152 | + return $this->_hasEqualSerialNumber($cert) && |
|
153 | + $this->_hasEqualPublicKey($cert) && $this->_hasEqualSubject($cert); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Check whether certificate has serial number equal to another. |
|
158 | + * |
|
159 | + * @param Certificate $cert |
|
160 | + * @return bool |
|
161 | + */ |
|
162 | + private function _hasEqualSerialNumber(Certificate $cert) |
|
163 | + { |
|
164 | + $sn1 = $this->_tbsCertificate->serialNumber(); |
|
165 | + $sn2 = $cert->_tbsCertificate->serialNumber(); |
|
166 | + return $sn1 == $sn2; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Check whether certificate has public key equal to another. |
|
171 | + * |
|
172 | + * @param Certificate $cert |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + private function _hasEqualPublicKey(Certificate $cert) |
|
176 | + { |
|
177 | + $kid1 = $this->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier(); |
|
178 | + $kid2 = $cert->_tbsCertificate->subjectPublicKeyInfo()->keyIdentifier(); |
|
179 | + return $kid1 == $kid2; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Check whether certificate has subject equal to another. |
|
184 | + * |
|
185 | + * @param Certificate $cert |
|
186 | + * @return bool |
|
187 | + */ |
|
188 | + private function _hasEqualSubject(Certificate $cert) |
|
189 | + { |
|
190 | + $dn1 = $this->_tbsCertificate->subject(); |
|
191 | + $dn2 = $cert->_tbsCertificate->subject(); |
|
192 | + return $dn1->equals($dn2); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Generate ASN.1 structure. |
|
197 | + * |
|
198 | + * @return Sequence |
|
199 | + */ |
|
200 | + public function toASN1() |
|
201 | + { |
|
202 | + return new Sequence($this->_tbsCertificate->toASN1(), |
|
203 | + $this->_signatureAlgorithm->toASN1(), |
|
204 | + $this->_signatureValue->bitString()); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get certificate as a DER. |
|
209 | + * |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function toDER() |
|
213 | + { |
|
214 | + return $this->toASN1()->toDER(); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Get certificate as a PEM. |
|
219 | + * |
|
220 | + * @return PEM |
|
221 | + */ |
|
222 | + public function toPEM() |
|
223 | + { |
|
224 | + return new PEM(PEM::TYPE_CERTIFICATE, $this->toDER()); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Verify certificate signature. |
|
229 | + * |
|
230 | + * @param PublicKeyInfo $pubkey_info Issuer's public key |
|
231 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
232 | + * @return bool True if certificate signature is valid |
|
233 | + */ |
|
234 | + public function verify(PublicKeyInfo $pubkey_info, Crypto $crypto = null) |
|
235 | + { |
|
236 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
237 | + $data = $this->_tbsCertificate->toASN1()->toDER(); |
|
238 | + return $crypto->verify($data, $this->_signatureValue, $pubkey_info, |
|
239 | + $this->_signatureAlgorithm); |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Get certificate as a PEM formatted string. |
|
244 | + * |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + public function __toString() |
|
248 | + { |
|
249 | + return $this->toPEM()->string(); |
|
250 | + } |
|
251 | 251 | } |
@@ -11,131 +11,131 @@ |
||
11 | 11 | */ |
12 | 12 | class CertificateChain implements \Countable, \IteratorAggregate |
13 | 13 | { |
14 | - /** |
|
15 | - * List of certificates in a chain. |
|
16 | - * |
|
17 | - * @var Certificate[] |
|
18 | - */ |
|
19 | - protected $_certs; |
|
14 | + /** |
|
15 | + * List of certificates in a chain. |
|
16 | + * |
|
17 | + * @var Certificate[] |
|
18 | + */ |
|
19 | + protected $_certs; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Constructor. |
|
23 | - * |
|
24 | - * @param Certificate ...$certs List of certificates, end-entity first |
|
25 | - */ |
|
26 | - public function __construct(Certificate ...$certs) |
|
27 | - { |
|
28 | - $this->_certs = $certs; |
|
29 | - } |
|
21 | + /** |
|
22 | + * Constructor. |
|
23 | + * |
|
24 | + * @param Certificate ...$certs List of certificates, end-entity first |
|
25 | + */ |
|
26 | + public function __construct(Certificate ...$certs) |
|
27 | + { |
|
28 | + $this->_certs = $certs; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Initialize from a list of PEMs. |
|
33 | - * |
|
34 | - * @param PEM ...$pems |
|
35 | - * @return self |
|
36 | - */ |
|
37 | - public static function fromPEMs(PEM ...$pems) |
|
38 | - { |
|
39 | - $certs = array_map( |
|
40 | - function (PEM $pem) { |
|
41 | - return Certificate::fromPEM($pem); |
|
42 | - }, $pems); |
|
43 | - return new self(...$certs); |
|
44 | - } |
|
31 | + /** |
|
32 | + * Initialize from a list of PEMs. |
|
33 | + * |
|
34 | + * @param PEM ...$pems |
|
35 | + * @return self |
|
36 | + */ |
|
37 | + public static function fromPEMs(PEM ...$pems) |
|
38 | + { |
|
39 | + $certs = array_map( |
|
40 | + function (PEM $pem) { |
|
41 | + return Certificate::fromPEM($pem); |
|
42 | + }, $pems); |
|
43 | + return new self(...$certs); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Initialize from a string containing multiple PEM blocks. |
|
48 | - * |
|
49 | - * @param string $str |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public static function fromPEMString($str) |
|
53 | - { |
|
54 | - $pems = PEMBundle::fromString($str)->all(); |
|
55 | - return self::fromPEMs(...$pems); |
|
56 | - } |
|
46 | + /** |
|
47 | + * Initialize from a string containing multiple PEM blocks. |
|
48 | + * |
|
49 | + * @param string $str |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public static function fromPEMString($str) |
|
53 | + { |
|
54 | + $pems = PEMBundle::fromString($str)->all(); |
|
55 | + return self::fromPEMs(...$pems); |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Get all certificates in a chain ordered from the end-entity certificate |
|
60 | - * to the trust anchor. |
|
61 | - * |
|
62 | - * @return Certificate[] |
|
63 | - */ |
|
64 | - public function certificates() |
|
65 | - { |
|
66 | - return $this->_certs; |
|
67 | - } |
|
58 | + /** |
|
59 | + * Get all certificates in a chain ordered from the end-entity certificate |
|
60 | + * to the trust anchor. |
|
61 | + * |
|
62 | + * @return Certificate[] |
|
63 | + */ |
|
64 | + public function certificates() |
|
65 | + { |
|
66 | + return $this->_certs; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Get the end-entity certificate. |
|
71 | - * |
|
72 | - * @throws \LogicException |
|
73 | - * @return Certificate |
|
74 | - */ |
|
75 | - public function endEntityCertificate() |
|
76 | - { |
|
77 | - if (!count($this->_certs)) { |
|
78 | - throw new \LogicException("No certificates."); |
|
79 | - } |
|
80 | - return $this->_certs[0]; |
|
81 | - } |
|
69 | + /** |
|
70 | + * Get the end-entity certificate. |
|
71 | + * |
|
72 | + * @throws \LogicException |
|
73 | + * @return Certificate |
|
74 | + */ |
|
75 | + public function endEntityCertificate() |
|
76 | + { |
|
77 | + if (!count($this->_certs)) { |
|
78 | + throw new \LogicException("No certificates."); |
|
79 | + } |
|
80 | + return $this->_certs[0]; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Get the trust anchor certificate. |
|
85 | - * |
|
86 | - * @throws \LogicException |
|
87 | - * @return Certificate |
|
88 | - */ |
|
89 | - public function trustAnchorCertificate() |
|
90 | - { |
|
91 | - if (!count($this->_certs)) { |
|
92 | - throw new \LogicException("No certificates."); |
|
93 | - } |
|
94 | - return $this->_certs[count($this->_certs) - 1]; |
|
95 | - } |
|
83 | + /** |
|
84 | + * Get the trust anchor certificate. |
|
85 | + * |
|
86 | + * @throws \LogicException |
|
87 | + * @return Certificate |
|
88 | + */ |
|
89 | + public function trustAnchorCertificate() |
|
90 | + { |
|
91 | + if (!count($this->_certs)) { |
|
92 | + throw new \LogicException("No certificates."); |
|
93 | + } |
|
94 | + return $this->_certs[count($this->_certs) - 1]; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Convert certificate chain to certification path. |
|
99 | - * |
|
100 | - * @return CertificationPath |
|
101 | - */ |
|
102 | - public function certificationPath() |
|
103 | - { |
|
104 | - return CertificationPath::fromCertificateChain($this); |
|
105 | - } |
|
97 | + /** |
|
98 | + * Convert certificate chain to certification path. |
|
99 | + * |
|
100 | + * @return CertificationPath |
|
101 | + */ |
|
102 | + public function certificationPath() |
|
103 | + { |
|
104 | + return CertificationPath::fromCertificateChain($this); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * Convert certificate chain to string of PEM blocks. |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function toPEMString() |
|
113 | - { |
|
114 | - return implode("\n", |
|
115 | - array_map( |
|
116 | - function (Certificate $cert) { |
|
117 | - return $cert->toPEM()->string(); |
|
118 | - }, $this->_certs)); |
|
119 | - } |
|
107 | + /** |
|
108 | + * Convert certificate chain to string of PEM blocks. |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function toPEMString() |
|
113 | + { |
|
114 | + return implode("\n", |
|
115 | + array_map( |
|
116 | + function (Certificate $cert) { |
|
117 | + return $cert->toPEM()->string(); |
|
118 | + }, $this->_certs)); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * |
|
123 | - * @see \Countable::count() |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - public function count() |
|
127 | - { |
|
128 | - return count($this->_certs); |
|
129 | - } |
|
121 | + /** |
|
122 | + * |
|
123 | + * @see \Countable::count() |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + public function count() |
|
127 | + { |
|
128 | + return count($this->_certs); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Get iterator for certificates. |
|
133 | - * |
|
134 | - * @see \IteratorAggregate::getIterator() |
|
135 | - * @return \ArrayIterator |
|
136 | - */ |
|
137 | - public function getIterator() |
|
138 | - { |
|
139 | - return new \ArrayIterator($this->_certs); |
|
140 | - } |
|
131 | + /** |
|
132 | + * Get iterator for certificates. |
|
133 | + * |
|
134 | + * @see \IteratorAggregate::getIterator() |
|
135 | + * @return \ArrayIterator |
|
136 | + */ |
|
137 | + public function getIterator() |
|
138 | + { |
|
139 | + return new \ArrayIterator($this->_certs); |
|
140 | + } |
|
141 | 141 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | public static function fromPEMs(PEM ...$pems) |
38 | 38 | { |
39 | 39 | $certs = array_map( |
40 | - function (PEM $pem) { |
|
40 | + function(PEM $pem) { |
|
41 | 41 | return Certificate::fromPEM($pem); |
42 | 42 | }, $pems); |
43 | 43 | return new self(...$certs); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | { |
114 | 114 | return implode("\n", |
115 | 115 | array_map( |
116 | - function (Certificate $cert) { |
|
116 | + function(Certificate $cert) { |
|
117 | 117 | return $cert->toPEM()->string(); |
118 | 118 | }, $this->_certs)); |
119 | 119 | } |
@@ -16,387 +16,387 @@ |
||
16 | 16 | */ |
17 | 17 | class Extensions implements \Countable, \IteratorAggregate |
18 | 18 | { |
19 | - /** |
|
20 | - * Extensions. |
|
21 | - * |
|
22 | - * @var Extension[] $_extensions |
|
23 | - */ |
|
24 | - protected $_extensions; |
|
25 | - |
|
26 | - /** |
|
27 | - * Constructor. |
|
28 | - * |
|
29 | - * @param Extension ...$extensions Extension objects |
|
30 | - */ |
|
31 | - public function __construct(Extension ...$extensions) |
|
32 | - { |
|
33 | - $this->_extensions = array(); |
|
34 | - foreach ($extensions as $ext) { |
|
35 | - $this->_extensions[$ext->oid()] = $ext; |
|
36 | - } |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Initialize from ASN.1. |
|
41 | - * |
|
42 | - * @param Sequence $seq |
|
43 | - * @return self |
|
44 | - */ |
|
45 | - public static function fromASN1(Sequence $seq) |
|
46 | - { |
|
47 | - $extensions = array_map( |
|
48 | - function (UnspecifiedType $el) { |
|
49 | - return Extension::fromASN1($el->asSequence()); |
|
50 | - }, $seq->elements()); |
|
51 | - return new self(...$extensions); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Generate ASN.1 structure. |
|
56 | - * |
|
57 | - * @return Sequence |
|
58 | - */ |
|
59 | - public function toASN1() |
|
60 | - { |
|
61 | - $elements = array_values( |
|
62 | - array_map( |
|
63 | - function ($ext) { |
|
64 | - return $ext->toASN1(); |
|
65 | - }, $this->_extensions)); |
|
66 | - return new Sequence(...$elements); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Get self with extensions added. |
|
71 | - * |
|
72 | - * @param Extension ...$ext One or more extensions to add |
|
73 | - * @return self |
|
74 | - */ |
|
75 | - public function withExtensions(Extension ...$exts) |
|
76 | - { |
|
77 | - $obj = clone $this; |
|
78 | - foreach ($exts as $ext) { |
|
79 | - $obj->_extensions[$ext->oid()] = $ext; |
|
80 | - } |
|
81 | - return $obj; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Check whether extension is present. |
|
86 | - * |
|
87 | - * @param string $oid Extensions OID |
|
88 | - * @return bool |
|
89 | - */ |
|
90 | - public function has($oid) |
|
91 | - { |
|
92 | - return isset($this->_extensions[$oid]); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Get extension by OID. |
|
97 | - * |
|
98 | - * @param string $oid |
|
99 | - * @throws \LogicException If extension is not present |
|
100 | - * @return Extension |
|
101 | - */ |
|
102 | - public function get($oid) |
|
103 | - { |
|
104 | - if (!$this->has($oid)) { |
|
105 | - throw new \LogicException("No extension by OID $oid."); |
|
106 | - } |
|
107 | - return $this->_extensions[$oid]; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Check whether 'Authority Key Identifier' extension is present. |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
115 | - public function hasAuthorityKeyIdentifier() |
|
116 | - { |
|
117 | - return $this->has(Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Get 'Authority Key Identifier' extension. |
|
122 | - * |
|
123 | - * @throws \LogicException If extension is not present |
|
124 | - * @return \X509\Certificate\Extension\AuthorityKeyIdentifierExtension |
|
125 | - */ |
|
126 | - public function authorityKeyIdentifier() |
|
127 | - { |
|
128 | - return $this->get(Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * Check whether 'Subject Key Identifier' extension is present. |
|
133 | - * |
|
134 | - * @return bool |
|
135 | - */ |
|
136 | - public function hasSubjectKeyIdentifier() |
|
137 | - { |
|
138 | - return $this->has(Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Get 'Subject Key Identifier' extension. |
|
143 | - * |
|
144 | - * @throws \LogicException If extension is not present |
|
145 | - * @return \X509\Certificate\Extension\SubjectKeyIdentifierExtension |
|
146 | - */ |
|
147 | - public function subjectKeyIdentifier() |
|
148 | - { |
|
149 | - return $this->get(Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Check whether 'Key Usage' extension is present. |
|
154 | - * |
|
155 | - * @return bool |
|
156 | - */ |
|
157 | - public function hasKeyUsage() |
|
158 | - { |
|
159 | - return $this->has(Extension::OID_KEY_USAGE); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Get 'Key Usage' extension. |
|
164 | - * |
|
165 | - * @throws \LogicException If extension is not present |
|
166 | - * @return \X509\Certificate\Extension\KeyUsageExtension |
|
167 | - */ |
|
168 | - public function keyUsage() |
|
169 | - { |
|
170 | - return $this->get(Extension::OID_KEY_USAGE); |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Check whether 'Certificate Policies' extension is present. |
|
175 | - * |
|
176 | - * @return bool |
|
177 | - */ |
|
178 | - public function hasCertificatePolicies() |
|
179 | - { |
|
180 | - return $this->has(Extension::OID_CERTIFICATE_POLICIES); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Get 'Certificate Policies' extension. |
|
185 | - * |
|
186 | - * @throws \LogicException If extension is not present |
|
187 | - * @return \X509\Certificate\Extension\CertificatePoliciesExtension |
|
188 | - */ |
|
189 | - public function certificatePolicies() |
|
190 | - { |
|
191 | - return $this->get(Extension::OID_CERTIFICATE_POLICIES); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Check whether 'Policy Mappings' extension is present. |
|
196 | - * |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function hasPolicyMappings() |
|
200 | - { |
|
201 | - return $this->has(Extension::OID_POLICY_MAPPINGS); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Get 'Policy Mappings' extension. |
|
206 | - * |
|
207 | - * @throws \LogicException If extension is not present |
|
208 | - * @return \X509\Certificate\Extension\PolicyMappingsExtension |
|
209 | - */ |
|
210 | - public function policyMappings() |
|
211 | - { |
|
212 | - return $this->get(Extension::OID_POLICY_MAPPINGS); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Check whether 'Subject Alternative Name' extension is present. |
|
217 | - * |
|
218 | - * @return bool |
|
219 | - */ |
|
220 | - public function hasSubjectAlternativeName() |
|
221 | - { |
|
222 | - return $this->has(Extension::OID_SUBJECT_ALT_NAME); |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Get 'Subject Alternative Name' extension. |
|
227 | - * |
|
228 | - * @throws \LogicException If extension is not present |
|
229 | - * @return \X509\Certificate\Extension\SubjectAlternativeNameExtension |
|
230 | - */ |
|
231 | - public function subjectAlternativeName() |
|
232 | - { |
|
233 | - return $this->get(Extension::OID_SUBJECT_ALT_NAME); |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Check whether 'Issuer Alternative Name' extension is present. |
|
238 | - * |
|
239 | - * @return bool |
|
240 | - */ |
|
241 | - public function hasIssuerAlternativeName() |
|
242 | - { |
|
243 | - return $this->has(Extension::OID_ISSUER_ALT_NAME); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Get 'Issuer Alternative Name' extension. |
|
248 | - * |
|
249 | - * @return \X509\Certificate\Extension\IssuerAlternativeNameExtension |
|
250 | - */ |
|
251 | - public function issuerAlternativeName() |
|
252 | - { |
|
253 | - return $this->get(Extension::OID_ISSUER_ALT_NAME); |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Check whether 'Basic Constraints' extension is present. |
|
258 | - * |
|
259 | - * @return bool |
|
260 | - */ |
|
261 | - public function hasBasicConstraints() |
|
262 | - { |
|
263 | - return $this->has(Extension::OID_BASIC_CONSTRAINTS); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Get 'Basic Constraints' extension. |
|
268 | - * |
|
269 | - * @throws \LogicException If extension is not present |
|
270 | - * @return \X509\Certificate\Extension\BasicConstraintsExtension |
|
271 | - */ |
|
272 | - public function basicConstraints() |
|
273 | - { |
|
274 | - return $this->get(Extension::OID_BASIC_CONSTRAINTS); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Check whether 'Name Constraints' extension is present. |
|
279 | - * |
|
280 | - * @return bool |
|
281 | - */ |
|
282 | - public function hasNameConstraints() |
|
283 | - { |
|
284 | - return $this->has(Extension::OID_NAME_CONSTRAINTS); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Get 'Name Constraints' extension. |
|
289 | - * |
|
290 | - * @throws \LogicException If extension is not present |
|
291 | - * @return \X509\Certificate\Extension\NameConstraintsExtension |
|
292 | - */ |
|
293 | - public function nameConstraints() |
|
294 | - { |
|
295 | - return $this->get(Extension::OID_NAME_CONSTRAINTS); |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Check whether 'Policy Constraints' extension is present. |
|
300 | - * |
|
301 | - * @return bool |
|
302 | - */ |
|
303 | - public function hasPolicyConstraints() |
|
304 | - { |
|
305 | - return $this->has(Extension::OID_POLICY_CONSTRAINTS); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get 'Policy Constraints' extension. |
|
310 | - * |
|
311 | - * @throws \LogicException If extension is not present |
|
312 | - * @return \X509\Certificate\Extension\PolicyConstraintsExtension |
|
313 | - */ |
|
314 | - public function policyConstraints() |
|
315 | - { |
|
316 | - return $this->get(Extension::OID_POLICY_CONSTRAINTS); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Check whether 'Extended Key Usage' extension is present. |
|
321 | - * |
|
322 | - * @return bool |
|
323 | - */ |
|
324 | - public function hasExtendedKeyUsage() |
|
325 | - { |
|
326 | - return $this->has(Extension::OID_EXT_KEY_USAGE); |
|
327 | - } |
|
328 | - |
|
329 | - /** |
|
330 | - * Get 'Extended Key Usage' extension. |
|
331 | - * |
|
332 | - * @throws \LogicException If extension is not present |
|
333 | - * @return \X509\Certificate\Extension\ExtendedKeyUsageExtension |
|
334 | - */ |
|
335 | - public function extendedKeyUsage() |
|
336 | - { |
|
337 | - return $this->get(Extension::OID_EXT_KEY_USAGE); |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Check whether 'CRL Distribution Points' extension is present. |
|
342 | - * |
|
343 | - * @return bool |
|
344 | - */ |
|
345 | - public function hasCRLDistributionPoints() |
|
346 | - { |
|
347 | - return $this->has(Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
348 | - } |
|
349 | - |
|
350 | - /** |
|
351 | - * Get 'CRL Distribution Points' extension. |
|
352 | - * |
|
353 | - * @throws \LogicException If extension is not present |
|
354 | - * @return \X509\Certificate\Extension\CRLDistributionPointsExtension |
|
355 | - */ |
|
356 | - public function crlDistributionPoints() |
|
357 | - { |
|
358 | - return $this->get(Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
359 | - } |
|
360 | - |
|
361 | - /** |
|
362 | - * Check whether 'Inhibit anyPolicy' extension is present. |
|
363 | - * |
|
364 | - * @return bool |
|
365 | - */ |
|
366 | - public function hasInhibitAnyPolicy() |
|
367 | - { |
|
368 | - return $this->has(Extension::OID_INHIBIT_ANY_POLICY); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Get 'Inhibit anyPolicy' extension. |
|
373 | - * |
|
374 | - * @throws \LogicException If extension is not present |
|
375 | - * @return \X509\Certificate\Extension\InhibitAnyPolicyExtension |
|
376 | - */ |
|
377 | - public function inhibitAnyPolicy() |
|
378 | - { |
|
379 | - return $this->get(Extension::OID_INHIBIT_ANY_POLICY); |
|
380 | - } |
|
381 | - |
|
382 | - /** |
|
383 | - * |
|
384 | - * @see \Countable::count() |
|
385 | - * @return int |
|
386 | - */ |
|
387 | - public function count() |
|
388 | - { |
|
389 | - return count($this->_extensions); |
|
390 | - } |
|
391 | - |
|
392 | - /** |
|
393 | - * Get iterator for extensions. |
|
394 | - * |
|
395 | - * @see \IteratorAggregate::getIterator() |
|
396 | - * @return \Traversable |
|
397 | - */ |
|
398 | - public function getIterator() |
|
399 | - { |
|
400 | - return new \ArrayIterator($this->_extensions); |
|
401 | - } |
|
19 | + /** |
|
20 | + * Extensions. |
|
21 | + * |
|
22 | + * @var Extension[] $_extensions |
|
23 | + */ |
|
24 | + protected $_extensions; |
|
25 | + |
|
26 | + /** |
|
27 | + * Constructor. |
|
28 | + * |
|
29 | + * @param Extension ...$extensions Extension objects |
|
30 | + */ |
|
31 | + public function __construct(Extension ...$extensions) |
|
32 | + { |
|
33 | + $this->_extensions = array(); |
|
34 | + foreach ($extensions as $ext) { |
|
35 | + $this->_extensions[$ext->oid()] = $ext; |
|
36 | + } |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Initialize from ASN.1. |
|
41 | + * |
|
42 | + * @param Sequence $seq |
|
43 | + * @return self |
|
44 | + */ |
|
45 | + public static function fromASN1(Sequence $seq) |
|
46 | + { |
|
47 | + $extensions = array_map( |
|
48 | + function (UnspecifiedType $el) { |
|
49 | + return Extension::fromASN1($el->asSequence()); |
|
50 | + }, $seq->elements()); |
|
51 | + return new self(...$extensions); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Generate ASN.1 structure. |
|
56 | + * |
|
57 | + * @return Sequence |
|
58 | + */ |
|
59 | + public function toASN1() |
|
60 | + { |
|
61 | + $elements = array_values( |
|
62 | + array_map( |
|
63 | + function ($ext) { |
|
64 | + return $ext->toASN1(); |
|
65 | + }, $this->_extensions)); |
|
66 | + return new Sequence(...$elements); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Get self with extensions added. |
|
71 | + * |
|
72 | + * @param Extension ...$ext One or more extensions to add |
|
73 | + * @return self |
|
74 | + */ |
|
75 | + public function withExtensions(Extension ...$exts) |
|
76 | + { |
|
77 | + $obj = clone $this; |
|
78 | + foreach ($exts as $ext) { |
|
79 | + $obj->_extensions[$ext->oid()] = $ext; |
|
80 | + } |
|
81 | + return $obj; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Check whether extension is present. |
|
86 | + * |
|
87 | + * @param string $oid Extensions OID |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | + public function has($oid) |
|
91 | + { |
|
92 | + return isset($this->_extensions[$oid]); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Get extension by OID. |
|
97 | + * |
|
98 | + * @param string $oid |
|
99 | + * @throws \LogicException If extension is not present |
|
100 | + * @return Extension |
|
101 | + */ |
|
102 | + public function get($oid) |
|
103 | + { |
|
104 | + if (!$this->has($oid)) { |
|
105 | + throw new \LogicException("No extension by OID $oid."); |
|
106 | + } |
|
107 | + return $this->_extensions[$oid]; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Check whether 'Authority Key Identifier' extension is present. |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | + public function hasAuthorityKeyIdentifier() |
|
116 | + { |
|
117 | + return $this->has(Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Get 'Authority Key Identifier' extension. |
|
122 | + * |
|
123 | + * @throws \LogicException If extension is not present |
|
124 | + * @return \X509\Certificate\Extension\AuthorityKeyIdentifierExtension |
|
125 | + */ |
|
126 | + public function authorityKeyIdentifier() |
|
127 | + { |
|
128 | + return $this->get(Extension::OID_AUTHORITY_KEY_IDENTIFIER); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * Check whether 'Subject Key Identifier' extension is present. |
|
133 | + * |
|
134 | + * @return bool |
|
135 | + */ |
|
136 | + public function hasSubjectKeyIdentifier() |
|
137 | + { |
|
138 | + return $this->has(Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Get 'Subject Key Identifier' extension. |
|
143 | + * |
|
144 | + * @throws \LogicException If extension is not present |
|
145 | + * @return \X509\Certificate\Extension\SubjectKeyIdentifierExtension |
|
146 | + */ |
|
147 | + public function subjectKeyIdentifier() |
|
148 | + { |
|
149 | + return $this->get(Extension::OID_SUBJECT_KEY_IDENTIFIER); |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Check whether 'Key Usage' extension is present. |
|
154 | + * |
|
155 | + * @return bool |
|
156 | + */ |
|
157 | + public function hasKeyUsage() |
|
158 | + { |
|
159 | + return $this->has(Extension::OID_KEY_USAGE); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Get 'Key Usage' extension. |
|
164 | + * |
|
165 | + * @throws \LogicException If extension is not present |
|
166 | + * @return \X509\Certificate\Extension\KeyUsageExtension |
|
167 | + */ |
|
168 | + public function keyUsage() |
|
169 | + { |
|
170 | + return $this->get(Extension::OID_KEY_USAGE); |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Check whether 'Certificate Policies' extension is present. |
|
175 | + * |
|
176 | + * @return bool |
|
177 | + */ |
|
178 | + public function hasCertificatePolicies() |
|
179 | + { |
|
180 | + return $this->has(Extension::OID_CERTIFICATE_POLICIES); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Get 'Certificate Policies' extension. |
|
185 | + * |
|
186 | + * @throws \LogicException If extension is not present |
|
187 | + * @return \X509\Certificate\Extension\CertificatePoliciesExtension |
|
188 | + */ |
|
189 | + public function certificatePolicies() |
|
190 | + { |
|
191 | + return $this->get(Extension::OID_CERTIFICATE_POLICIES); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Check whether 'Policy Mappings' extension is present. |
|
196 | + * |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function hasPolicyMappings() |
|
200 | + { |
|
201 | + return $this->has(Extension::OID_POLICY_MAPPINGS); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Get 'Policy Mappings' extension. |
|
206 | + * |
|
207 | + * @throws \LogicException If extension is not present |
|
208 | + * @return \X509\Certificate\Extension\PolicyMappingsExtension |
|
209 | + */ |
|
210 | + public function policyMappings() |
|
211 | + { |
|
212 | + return $this->get(Extension::OID_POLICY_MAPPINGS); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Check whether 'Subject Alternative Name' extension is present. |
|
217 | + * |
|
218 | + * @return bool |
|
219 | + */ |
|
220 | + public function hasSubjectAlternativeName() |
|
221 | + { |
|
222 | + return $this->has(Extension::OID_SUBJECT_ALT_NAME); |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Get 'Subject Alternative Name' extension. |
|
227 | + * |
|
228 | + * @throws \LogicException If extension is not present |
|
229 | + * @return \X509\Certificate\Extension\SubjectAlternativeNameExtension |
|
230 | + */ |
|
231 | + public function subjectAlternativeName() |
|
232 | + { |
|
233 | + return $this->get(Extension::OID_SUBJECT_ALT_NAME); |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Check whether 'Issuer Alternative Name' extension is present. |
|
238 | + * |
|
239 | + * @return bool |
|
240 | + */ |
|
241 | + public function hasIssuerAlternativeName() |
|
242 | + { |
|
243 | + return $this->has(Extension::OID_ISSUER_ALT_NAME); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Get 'Issuer Alternative Name' extension. |
|
248 | + * |
|
249 | + * @return \X509\Certificate\Extension\IssuerAlternativeNameExtension |
|
250 | + */ |
|
251 | + public function issuerAlternativeName() |
|
252 | + { |
|
253 | + return $this->get(Extension::OID_ISSUER_ALT_NAME); |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Check whether 'Basic Constraints' extension is present. |
|
258 | + * |
|
259 | + * @return bool |
|
260 | + */ |
|
261 | + public function hasBasicConstraints() |
|
262 | + { |
|
263 | + return $this->has(Extension::OID_BASIC_CONSTRAINTS); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Get 'Basic Constraints' extension. |
|
268 | + * |
|
269 | + * @throws \LogicException If extension is not present |
|
270 | + * @return \X509\Certificate\Extension\BasicConstraintsExtension |
|
271 | + */ |
|
272 | + public function basicConstraints() |
|
273 | + { |
|
274 | + return $this->get(Extension::OID_BASIC_CONSTRAINTS); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Check whether 'Name Constraints' extension is present. |
|
279 | + * |
|
280 | + * @return bool |
|
281 | + */ |
|
282 | + public function hasNameConstraints() |
|
283 | + { |
|
284 | + return $this->has(Extension::OID_NAME_CONSTRAINTS); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Get 'Name Constraints' extension. |
|
289 | + * |
|
290 | + * @throws \LogicException If extension is not present |
|
291 | + * @return \X509\Certificate\Extension\NameConstraintsExtension |
|
292 | + */ |
|
293 | + public function nameConstraints() |
|
294 | + { |
|
295 | + return $this->get(Extension::OID_NAME_CONSTRAINTS); |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Check whether 'Policy Constraints' extension is present. |
|
300 | + * |
|
301 | + * @return bool |
|
302 | + */ |
|
303 | + public function hasPolicyConstraints() |
|
304 | + { |
|
305 | + return $this->has(Extension::OID_POLICY_CONSTRAINTS); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get 'Policy Constraints' extension. |
|
310 | + * |
|
311 | + * @throws \LogicException If extension is not present |
|
312 | + * @return \X509\Certificate\Extension\PolicyConstraintsExtension |
|
313 | + */ |
|
314 | + public function policyConstraints() |
|
315 | + { |
|
316 | + return $this->get(Extension::OID_POLICY_CONSTRAINTS); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Check whether 'Extended Key Usage' extension is present. |
|
321 | + * |
|
322 | + * @return bool |
|
323 | + */ |
|
324 | + public function hasExtendedKeyUsage() |
|
325 | + { |
|
326 | + return $this->has(Extension::OID_EXT_KEY_USAGE); |
|
327 | + } |
|
328 | + |
|
329 | + /** |
|
330 | + * Get 'Extended Key Usage' extension. |
|
331 | + * |
|
332 | + * @throws \LogicException If extension is not present |
|
333 | + * @return \X509\Certificate\Extension\ExtendedKeyUsageExtension |
|
334 | + */ |
|
335 | + public function extendedKeyUsage() |
|
336 | + { |
|
337 | + return $this->get(Extension::OID_EXT_KEY_USAGE); |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Check whether 'CRL Distribution Points' extension is present. |
|
342 | + * |
|
343 | + * @return bool |
|
344 | + */ |
|
345 | + public function hasCRLDistributionPoints() |
|
346 | + { |
|
347 | + return $this->has(Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
348 | + } |
|
349 | + |
|
350 | + /** |
|
351 | + * Get 'CRL Distribution Points' extension. |
|
352 | + * |
|
353 | + * @throws \LogicException If extension is not present |
|
354 | + * @return \X509\Certificate\Extension\CRLDistributionPointsExtension |
|
355 | + */ |
|
356 | + public function crlDistributionPoints() |
|
357 | + { |
|
358 | + return $this->get(Extension::OID_CRL_DISTRIBUTION_POINTS); |
|
359 | + } |
|
360 | + |
|
361 | + /** |
|
362 | + * Check whether 'Inhibit anyPolicy' extension is present. |
|
363 | + * |
|
364 | + * @return bool |
|
365 | + */ |
|
366 | + public function hasInhibitAnyPolicy() |
|
367 | + { |
|
368 | + return $this->has(Extension::OID_INHIBIT_ANY_POLICY); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Get 'Inhibit anyPolicy' extension. |
|
373 | + * |
|
374 | + * @throws \LogicException If extension is not present |
|
375 | + * @return \X509\Certificate\Extension\InhibitAnyPolicyExtension |
|
376 | + */ |
|
377 | + public function inhibitAnyPolicy() |
|
378 | + { |
|
379 | + return $this->get(Extension::OID_INHIBIT_ANY_POLICY); |
|
380 | + } |
|
381 | + |
|
382 | + /** |
|
383 | + * |
|
384 | + * @see \Countable::count() |
|
385 | + * @return int |
|
386 | + */ |
|
387 | + public function count() |
|
388 | + { |
|
389 | + return count($this->_extensions); |
|
390 | + } |
|
391 | + |
|
392 | + /** |
|
393 | + * Get iterator for extensions. |
|
394 | + * |
|
395 | + * @see \IteratorAggregate::getIterator() |
|
396 | + * @return \Traversable |
|
397 | + */ |
|
398 | + public function getIterator() |
|
399 | + { |
|
400 | + return new \ArrayIterator($this->_extensions); |
|
401 | + } |
|
402 | 402 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | public static function fromASN1(Sequence $seq) |
46 | 46 | { |
47 | 47 | $extensions = array_map( |
48 | - function (UnspecifiedType $el) { |
|
48 | + function(UnspecifiedType $el) { |
|
49 | 49 | return Extension::fromASN1($el->asSequence()); |
50 | 50 | }, $seq->elements()); |
51 | 51 | return new self(...$extensions); |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | { |
61 | 61 | $elements = array_values( |
62 | 62 | array_map( |
63 | - function ($ext) { |
|
63 | + function($ext) { |
|
64 | 64 | return $ext->toASN1(); |
65 | 65 | }, $this->_extensions)); |
66 | 66 | return new Sequence(...$elements); |
@@ -10,208 +10,208 @@ |
||
10 | 10 | */ |
11 | 11 | class CertificateBundle implements \Countable, \IteratorAggregate |
12 | 12 | { |
13 | - /** |
|
14 | - * Certificates. |
|
15 | - * |
|
16 | - * @var Certificate[] $_certs |
|
17 | - */ |
|
18 | - protected $_certs; |
|
13 | + /** |
|
14 | + * Certificates. |
|
15 | + * |
|
16 | + * @var Certificate[] $_certs |
|
17 | + */ |
|
18 | + protected $_certs; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Mapping from public key id to array of certificates. |
|
22 | - * |
|
23 | - * @var null|(Certificate[])[] |
|
24 | - */ |
|
25 | - private $_keyIdMap; |
|
20 | + /** |
|
21 | + * Mapping from public key id to array of certificates. |
|
22 | + * |
|
23 | + * @var null|(Certificate[])[] |
|
24 | + */ |
|
25 | + private $_keyIdMap; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Constructor. |
|
29 | - * |
|
30 | - * @param Certificate ...$certs Certificate objects |
|
31 | - */ |
|
32 | - public function __construct(Certificate ...$certs) |
|
33 | - { |
|
34 | - $this->_certs = $certs; |
|
35 | - } |
|
27 | + /** |
|
28 | + * Constructor. |
|
29 | + * |
|
30 | + * @param Certificate ...$certs Certificate objects |
|
31 | + */ |
|
32 | + public function __construct(Certificate ...$certs) |
|
33 | + { |
|
34 | + $this->_certs = $certs; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Reset internal cached variables on clone. |
|
39 | - */ |
|
40 | - public function __clone() |
|
41 | - { |
|
42 | - $this->_keyIdMap = null; |
|
43 | - } |
|
37 | + /** |
|
38 | + * Reset internal cached variables on clone. |
|
39 | + */ |
|
40 | + public function __clone() |
|
41 | + { |
|
42 | + $this->_keyIdMap = null; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Initialize from PEMs. |
|
47 | - * |
|
48 | - * @param PEM ...$pems PEM objects |
|
49 | - * @return self |
|
50 | - */ |
|
51 | - public static function fromPEMs(PEM ...$pems) |
|
52 | - { |
|
53 | - $certs = array_map( |
|
54 | - function ($pem) { |
|
55 | - return Certificate::fromPEM($pem); |
|
56 | - }, $pems); |
|
57 | - return new self(...$certs); |
|
58 | - } |
|
45 | + /** |
|
46 | + * Initialize from PEMs. |
|
47 | + * |
|
48 | + * @param PEM ...$pems PEM objects |
|
49 | + * @return self |
|
50 | + */ |
|
51 | + public static function fromPEMs(PEM ...$pems) |
|
52 | + { |
|
53 | + $certs = array_map( |
|
54 | + function ($pem) { |
|
55 | + return Certificate::fromPEM($pem); |
|
56 | + }, $pems); |
|
57 | + return new self(...$certs); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Initialize from PEM bundle. |
|
62 | - * |
|
63 | - * @param PEMBundle $pem_bundle |
|
64 | - * @return self |
|
65 | - */ |
|
66 | - public static function fromPEMBundle(PEMBundle $pem_bundle) |
|
67 | - { |
|
68 | - return self::fromPEMs(...$pem_bundle->all()); |
|
69 | - } |
|
60 | + /** |
|
61 | + * Initialize from PEM bundle. |
|
62 | + * |
|
63 | + * @param PEMBundle $pem_bundle |
|
64 | + * @return self |
|
65 | + */ |
|
66 | + public static function fromPEMBundle(PEMBundle $pem_bundle) |
|
67 | + { |
|
68 | + return self::fromPEMs(...$pem_bundle->all()); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Get self with certificates added. |
|
73 | - * |
|
74 | - * @param Certificate ...$cert |
|
75 | - * @return self |
|
76 | - */ |
|
77 | - public function withCertificates(Certificate ...$cert) |
|
78 | - { |
|
79 | - $obj = clone $this; |
|
80 | - $obj->_certs = array_merge($obj->_certs, $cert); |
|
81 | - return $obj; |
|
82 | - } |
|
71 | + /** |
|
72 | + * Get self with certificates added. |
|
73 | + * |
|
74 | + * @param Certificate ...$cert |
|
75 | + * @return self |
|
76 | + */ |
|
77 | + public function withCertificates(Certificate ...$cert) |
|
78 | + { |
|
79 | + $obj = clone $this; |
|
80 | + $obj->_certs = array_merge($obj->_certs, $cert); |
|
81 | + return $obj; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Get self with certificates from PEMBundle added. |
|
86 | - * |
|
87 | - * @param PEMBundle $pem_bundle |
|
88 | - * @return self |
|
89 | - */ |
|
90 | - public function withPEMBundle(PEMBundle $pem_bundle) |
|
91 | - { |
|
92 | - $certs = $this->_certs; |
|
93 | - foreach ($pem_bundle as $pem) { |
|
94 | - $certs[] = Certificate::fromPEM($pem); |
|
95 | - } |
|
96 | - return new self(...$certs); |
|
97 | - } |
|
84 | + /** |
|
85 | + * Get self with certificates from PEMBundle added. |
|
86 | + * |
|
87 | + * @param PEMBundle $pem_bundle |
|
88 | + * @return self |
|
89 | + */ |
|
90 | + public function withPEMBundle(PEMBundle $pem_bundle) |
|
91 | + { |
|
92 | + $certs = $this->_certs; |
|
93 | + foreach ($pem_bundle as $pem) { |
|
94 | + $certs[] = Certificate::fromPEM($pem); |
|
95 | + } |
|
96 | + return new self(...$certs); |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * Get self with single certificate from PEM added. |
|
101 | - * |
|
102 | - * @param PEM $pem |
|
103 | - * @return self |
|
104 | - */ |
|
105 | - public function withPEM(PEM $pem) |
|
106 | - { |
|
107 | - $certs = $this->_certs; |
|
108 | - $certs[] = Certificate::fromPEM($pem); |
|
109 | - return new self(...$certs); |
|
110 | - } |
|
99 | + /** |
|
100 | + * Get self with single certificate from PEM added. |
|
101 | + * |
|
102 | + * @param PEM $pem |
|
103 | + * @return self |
|
104 | + */ |
|
105 | + public function withPEM(PEM $pem) |
|
106 | + { |
|
107 | + $certs = $this->_certs; |
|
108 | + $certs[] = Certificate::fromPEM($pem); |
|
109 | + return new self(...$certs); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Check whether bundle contains a given certificate. |
|
114 | - * |
|
115 | - * @param Certificate $cert |
|
116 | - * @return bool |
|
117 | - */ |
|
118 | - public function contains(Certificate $cert) |
|
119 | - { |
|
120 | - $id = self::_getCertKeyId($cert); |
|
121 | - $map = $this->_getKeyIdMap(); |
|
122 | - if (!isset($map[$id])) { |
|
123 | - return false; |
|
124 | - } |
|
125 | - foreach ($map[$id] as $c) { |
|
126 | - /** @var Certificate $c */ |
|
127 | - if ($cert->equals($c)) { |
|
128 | - return true; |
|
129 | - } |
|
130 | - } |
|
131 | - return false; |
|
132 | - } |
|
112 | + /** |
|
113 | + * Check whether bundle contains a given certificate. |
|
114 | + * |
|
115 | + * @param Certificate $cert |
|
116 | + * @return bool |
|
117 | + */ |
|
118 | + public function contains(Certificate $cert) |
|
119 | + { |
|
120 | + $id = self::_getCertKeyId($cert); |
|
121 | + $map = $this->_getKeyIdMap(); |
|
122 | + if (!isset($map[$id])) { |
|
123 | + return false; |
|
124 | + } |
|
125 | + foreach ($map[$id] as $c) { |
|
126 | + /** @var Certificate $c */ |
|
127 | + if ($cert->equals($c)) { |
|
128 | + return true; |
|
129 | + } |
|
130 | + } |
|
131 | + return false; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * Get all certificates that have given subject key identifier. |
|
136 | - * |
|
137 | - * @param string $id |
|
138 | - * @return Certificate[] |
|
139 | - */ |
|
140 | - public function allBySubjectKeyIdentifier($id) |
|
141 | - { |
|
142 | - $map = $this->_getKeyIdMap(); |
|
143 | - if (!isset($map[$id])) { |
|
144 | - return array(); |
|
145 | - } |
|
146 | - return $map[$id]; |
|
147 | - } |
|
134 | + /** |
|
135 | + * Get all certificates that have given subject key identifier. |
|
136 | + * |
|
137 | + * @param string $id |
|
138 | + * @return Certificate[] |
|
139 | + */ |
|
140 | + public function allBySubjectKeyIdentifier($id) |
|
141 | + { |
|
142 | + $map = $this->_getKeyIdMap(); |
|
143 | + if (!isset($map[$id])) { |
|
144 | + return array(); |
|
145 | + } |
|
146 | + return $map[$id]; |
|
147 | + } |
|
148 | 148 | |
149 | - /** |
|
150 | - * Get all certificates in a bundle. |
|
151 | - * |
|
152 | - * @return Certificate[] |
|
153 | - */ |
|
154 | - public function all() |
|
155 | - { |
|
156 | - return $this->_certs; |
|
157 | - } |
|
149 | + /** |
|
150 | + * Get all certificates in a bundle. |
|
151 | + * |
|
152 | + * @return Certificate[] |
|
153 | + */ |
|
154 | + public function all() |
|
155 | + { |
|
156 | + return $this->_certs; |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Get certificate mapping by public key id. |
|
161 | - * |
|
162 | - * @return (Certificate[])[] |
|
163 | - */ |
|
164 | - private function _getKeyIdMap() |
|
165 | - { |
|
166 | - // lazily build mapping |
|
167 | - if (!isset($this->_keyIdMap)) { |
|
168 | - $this->_keyIdMap = array(); |
|
169 | - foreach ($this->_certs as $cert) { |
|
170 | - $id = self::_getCertKeyId($cert); |
|
171 | - if (!isset($this->_keyIdMap[$id])) { |
|
172 | - $this->_keyIdMap[$id] = array(); |
|
173 | - } |
|
174 | - array_push($this->_keyIdMap[$id], $cert); |
|
175 | - } |
|
176 | - } |
|
177 | - return $this->_keyIdMap; |
|
178 | - } |
|
159 | + /** |
|
160 | + * Get certificate mapping by public key id. |
|
161 | + * |
|
162 | + * @return (Certificate[])[] |
|
163 | + */ |
|
164 | + private function _getKeyIdMap() |
|
165 | + { |
|
166 | + // lazily build mapping |
|
167 | + if (!isset($this->_keyIdMap)) { |
|
168 | + $this->_keyIdMap = array(); |
|
169 | + foreach ($this->_certs as $cert) { |
|
170 | + $id = self::_getCertKeyId($cert); |
|
171 | + if (!isset($this->_keyIdMap[$id])) { |
|
172 | + $this->_keyIdMap[$id] = array(); |
|
173 | + } |
|
174 | + array_push($this->_keyIdMap[$id], $cert); |
|
175 | + } |
|
176 | + } |
|
177 | + return $this->_keyIdMap; |
|
178 | + } |
|
179 | 179 | |
180 | - /** |
|
181 | - * Get public key id for the certificate. |
|
182 | - * |
|
183 | - * @param Certificate $cert |
|
184 | - * @return string |
|
185 | - */ |
|
186 | - private static function _getCertKeyId(Certificate $cert) |
|
187 | - { |
|
188 | - $exts = $cert->tbsCertificate()->extensions(); |
|
189 | - if ($exts->hasSubjectKeyIdentifier()) { |
|
190 | - return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
191 | - } |
|
192 | - return $cert->tbsCertificate() |
|
193 | - ->subjectPublicKeyInfo() |
|
194 | - ->keyIdentifier(); |
|
195 | - } |
|
180 | + /** |
|
181 | + * Get public key id for the certificate. |
|
182 | + * |
|
183 | + * @param Certificate $cert |
|
184 | + * @return string |
|
185 | + */ |
|
186 | + private static function _getCertKeyId(Certificate $cert) |
|
187 | + { |
|
188 | + $exts = $cert->tbsCertificate()->extensions(); |
|
189 | + if ($exts->hasSubjectKeyIdentifier()) { |
|
190 | + return $exts->subjectKeyIdentifier()->keyIdentifier(); |
|
191 | + } |
|
192 | + return $cert->tbsCertificate() |
|
193 | + ->subjectPublicKeyInfo() |
|
194 | + ->keyIdentifier(); |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * |
|
199 | - * @see \Countable::count() |
|
200 | - * @return int |
|
201 | - */ |
|
202 | - public function count() |
|
203 | - { |
|
204 | - return count($this->_certs); |
|
205 | - } |
|
197 | + /** |
|
198 | + * |
|
199 | + * @see \Countable::count() |
|
200 | + * @return int |
|
201 | + */ |
|
202 | + public function count() |
|
203 | + { |
|
204 | + return count($this->_certs); |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * Get iterator for certificates. |
|
209 | - * |
|
210 | - * @see \IteratorAggregate::getIterator() |
|
211 | - * @return \ArrayIterator |
|
212 | - */ |
|
213 | - public function getIterator() |
|
214 | - { |
|
215 | - return new \ArrayIterator($this->_certs); |
|
216 | - } |
|
207 | + /** |
|
208 | + * Get iterator for certificates. |
|
209 | + * |
|
210 | + * @see \IteratorAggregate::getIterator() |
|
211 | + * @return \ArrayIterator |
|
212 | + */ |
|
213 | + public function getIterator() |
|
214 | + { |
|
215 | + return new \ArrayIterator($this->_certs); |
|
216 | + } |
|
217 | 217 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | public static function fromPEMs(PEM ...$pems) |
52 | 52 | { |
53 | 53 | $certs = array_map( |
54 | - function ($pem) { |
|
54 | + function($pem) { |
|
55 | 55 | return Certificate::fromPEM($pem); |
56 | 56 | }, $pems); |
57 | 57 | return new self(...$certs); |
@@ -14,123 +14,123 @@ |
||
14 | 14 | */ |
15 | 15 | class PolicyConstraintsExtension extends Extension |
16 | 16 | { |
17 | - /** |
|
18 | - * |
|
19 | - * @var int $_requireExplicitPolicy |
|
20 | - */ |
|
21 | - protected $_requireExplicitPolicy; |
|
17 | + /** |
|
18 | + * |
|
19 | + * @var int $_requireExplicitPolicy |
|
20 | + */ |
|
21 | + protected $_requireExplicitPolicy; |
|
22 | 22 | |
23 | - /** |
|
24 | - * |
|
25 | - * @var int $_inhibitPolicyMapping |
|
26 | - */ |
|
27 | - protected $_inhibitPolicyMapping; |
|
23 | + /** |
|
24 | + * |
|
25 | + * @var int $_inhibitPolicyMapping |
|
26 | + */ |
|
27 | + protected $_inhibitPolicyMapping; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor. |
|
31 | - * |
|
32 | - * @param bool $critical |
|
33 | - * @param int|null $require_explicit_policy |
|
34 | - * @param int|null $inhibit_policy_mapping |
|
35 | - */ |
|
36 | - public function __construct($critical, $require_explicit_policy = null, |
|
37 | - $inhibit_policy_mapping = null) |
|
38 | - { |
|
39 | - parent::__construct(self::OID_POLICY_CONSTRAINTS, $critical); |
|
40 | - $this->_requireExplicitPolicy = $require_explicit_policy; |
|
41 | - $this->_inhibitPolicyMapping = $inhibit_policy_mapping; |
|
42 | - } |
|
29 | + /** |
|
30 | + * Constructor. |
|
31 | + * |
|
32 | + * @param bool $critical |
|
33 | + * @param int|null $require_explicit_policy |
|
34 | + * @param int|null $inhibit_policy_mapping |
|
35 | + */ |
|
36 | + public function __construct($critical, $require_explicit_policy = null, |
|
37 | + $inhibit_policy_mapping = null) |
|
38 | + { |
|
39 | + parent::__construct(self::OID_POLICY_CONSTRAINTS, $critical); |
|
40 | + $this->_requireExplicitPolicy = $require_explicit_policy; |
|
41 | + $this->_inhibitPolicyMapping = $inhibit_policy_mapping; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - * @return self |
|
48 | - */ |
|
49 | - protected static function _fromDER($data, $critical) |
|
50 | - { |
|
51 | - $seq = Sequence::fromDER($data); |
|
52 | - $require_explicit_policy = null; |
|
53 | - $inhibit_policy_mapping = null; |
|
54 | - if ($seq->hasTagged(0)) { |
|
55 | - $require_explicit_policy = $seq->getTagged(0) |
|
56 | - ->asImplicit(Element::TYPE_INTEGER) |
|
57 | - ->asInteger() |
|
58 | - ->number(); |
|
59 | - } |
|
60 | - if ($seq->hasTagged(1)) { |
|
61 | - $inhibit_policy_mapping = $seq->getTagged(1) |
|
62 | - ->asImplicit(Element::TYPE_INTEGER) |
|
63 | - ->asInteger() |
|
64 | - ->number(); |
|
65 | - } |
|
66 | - return new self($critical, $require_explicit_policy, |
|
67 | - $inhibit_policy_mapping); |
|
68 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + * @return self |
|
48 | + */ |
|
49 | + protected static function _fromDER($data, $critical) |
|
50 | + { |
|
51 | + $seq = Sequence::fromDER($data); |
|
52 | + $require_explicit_policy = null; |
|
53 | + $inhibit_policy_mapping = null; |
|
54 | + if ($seq->hasTagged(0)) { |
|
55 | + $require_explicit_policy = $seq->getTagged(0) |
|
56 | + ->asImplicit(Element::TYPE_INTEGER) |
|
57 | + ->asInteger() |
|
58 | + ->number(); |
|
59 | + } |
|
60 | + if ($seq->hasTagged(1)) { |
|
61 | + $inhibit_policy_mapping = $seq->getTagged(1) |
|
62 | + ->asImplicit(Element::TYPE_INTEGER) |
|
63 | + ->asInteger() |
|
64 | + ->number(); |
|
65 | + } |
|
66 | + return new self($critical, $require_explicit_policy, |
|
67 | + $inhibit_policy_mapping); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Whether requireExplicitPolicy is present. |
|
72 | - * |
|
73 | - * @return bool |
|
74 | - */ |
|
75 | - public function hasRequireExplicitPolicy() |
|
76 | - { |
|
77 | - return isset($this->_requireExplicitPolicy); |
|
78 | - } |
|
70 | + /** |
|
71 | + * Whether requireExplicitPolicy is present. |
|
72 | + * |
|
73 | + * @return bool |
|
74 | + */ |
|
75 | + public function hasRequireExplicitPolicy() |
|
76 | + { |
|
77 | + return isset($this->_requireExplicitPolicy); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get requireExplicitPolicy. |
|
82 | - * |
|
83 | - * @throws \LogicException |
|
84 | - * @return int |
|
85 | - */ |
|
86 | - public function requireExplicitPolicy() |
|
87 | - { |
|
88 | - if (!$this->hasRequireExplicitPolicy()) { |
|
89 | - throw new \LogicException("requireExplicitPolicy not set."); |
|
90 | - } |
|
91 | - return $this->_requireExplicitPolicy; |
|
92 | - } |
|
80 | + /** |
|
81 | + * Get requireExplicitPolicy. |
|
82 | + * |
|
83 | + * @throws \LogicException |
|
84 | + * @return int |
|
85 | + */ |
|
86 | + public function requireExplicitPolicy() |
|
87 | + { |
|
88 | + if (!$this->hasRequireExplicitPolicy()) { |
|
89 | + throw new \LogicException("requireExplicitPolicy not set."); |
|
90 | + } |
|
91 | + return $this->_requireExplicitPolicy; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Whether inhibitPolicyMapping is present. |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function hasInhibitPolicyMapping() |
|
100 | - { |
|
101 | - return isset($this->_inhibitPolicyMapping); |
|
102 | - } |
|
94 | + /** |
|
95 | + * Whether inhibitPolicyMapping is present. |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function hasInhibitPolicyMapping() |
|
100 | + { |
|
101 | + return isset($this->_inhibitPolicyMapping); |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
105 | - * Get inhibitPolicyMapping. |
|
106 | - * |
|
107 | - * @throws \LogicException |
|
108 | - * @return int |
|
109 | - */ |
|
110 | - public function inhibitPolicyMapping() |
|
111 | - { |
|
112 | - if (!$this->hasInhibitPolicyMapping()) { |
|
113 | - throw new \LogicException("inhibitPolicyMapping not set."); |
|
114 | - } |
|
115 | - return $this->_inhibitPolicyMapping; |
|
116 | - } |
|
104 | + /** |
|
105 | + * Get inhibitPolicyMapping. |
|
106 | + * |
|
107 | + * @throws \LogicException |
|
108 | + * @return int |
|
109 | + */ |
|
110 | + public function inhibitPolicyMapping() |
|
111 | + { |
|
112 | + if (!$this->hasInhibitPolicyMapping()) { |
|
113 | + throw new \LogicException("inhibitPolicyMapping not set."); |
|
114 | + } |
|
115 | + return $this->_inhibitPolicyMapping; |
|
116 | + } |
|
117 | 117 | |
118 | - /** |
|
119 | - * |
|
120 | - * {@inheritdoc} |
|
121 | - * @return Sequence |
|
122 | - */ |
|
123 | - protected function _valueASN1() |
|
124 | - { |
|
125 | - $elements = array(); |
|
126 | - if (isset($this->_requireExplicitPolicy)) { |
|
127 | - $elements[] = new ImplicitlyTaggedType(0, |
|
128 | - new Integer($this->_requireExplicitPolicy)); |
|
129 | - } |
|
130 | - if (isset($this->_inhibitPolicyMapping)) { |
|
131 | - $elements[] = new ImplicitlyTaggedType(1, |
|
132 | - new Integer($this->_inhibitPolicyMapping)); |
|
133 | - } |
|
134 | - return new Sequence(...$elements); |
|
135 | - } |
|
118 | + /** |
|
119 | + * |
|
120 | + * {@inheritdoc} |
|
121 | + * @return Sequence |
|
122 | + */ |
|
123 | + protected function _valueASN1() |
|
124 | + { |
|
125 | + $elements = array(); |
|
126 | + if (isset($this->_requireExplicitPolicy)) { |
|
127 | + $elements[] = new ImplicitlyTaggedType(0, |
|
128 | + new Integer($this->_requireExplicitPolicy)); |
|
129 | + } |
|
130 | + if (isset($this->_inhibitPolicyMapping)) { |
|
131 | + $elements[] = new ImplicitlyTaggedType(1, |
|
132 | + new Integer($this->_inhibitPolicyMapping)); |
|
133 | + } |
|
134 | + return new Sequence(...$elements); |
|
135 | + } |
|
136 | 136 | } |