@@ -4,42 +4,42 @@ |
||
4 | 4 | |
5 | 5 | class IPv4Address 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 | - $bytes = unpack("C*", $octets); |
|
18 | - switch (count($bytes)) { |
|
19 | - case 4: |
|
20 | - $ip = implode(".", $bytes); |
|
21 | - break; |
|
22 | - case 8: |
|
23 | - $ip = implode(".", array_slice($bytes, 0, 4)); |
|
24 | - $mask = implode(".", array_slice($bytes, 4, 4)); |
|
25 | - break; |
|
26 | - default: |
|
27 | - throw new \UnexpectedValueException("Invalid IPv4 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 | + $bytes = unpack("C*", $octets); |
|
18 | + switch (count($bytes)) { |
|
19 | + case 4: |
|
20 | + $ip = implode(".", $bytes); |
|
21 | + break; |
|
22 | + case 8: |
|
23 | + $ip = implode(".", array_slice($bytes, 0, 4)); |
|
24 | + $mask = implode(".", array_slice($bytes, 4, 4)); |
|
25 | + break; |
|
26 | + default: |
|
27 | + throw new \UnexpectedValueException("Invalid IPv4 octet length."); |
|
28 | + } |
|
29 | + return new self($ip, $mask); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * {@inheritdoc} |
|
35 | - */ |
|
36 | - protected function _octets() |
|
37 | - { |
|
38 | - $bytes = array_map("intval", explode(".", $this->_ip)); |
|
39 | - if (isset($this->_mask)) { |
|
40 | - $bytes = array_merge($bytes, |
|
41 | - array_map("intval", explode(".", $this->_mask))); |
|
42 | - } |
|
43 | - return pack("C*", ...$bytes); |
|
44 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * {@inheritdoc} |
|
35 | + */ |
|
36 | + protected function _octets() |
|
37 | + { |
|
38 | + $bytes = array_map("intval", explode(".", $this->_ip)); |
|
39 | + if (isset($this->_mask)) { |
|
40 | + $bytes = array_merge($bytes, |
|
41 | + array_map("intval", explode(".", $this->_mask))); |
|
42 | + } |
|
43 | + return pack("C*", ...$bytes); |
|
44 | + } |
|
45 | 45 | } |
@@ -16,97 +16,97 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class IPAddress extends GeneralName |
18 | 18 | { |
19 | - /** |
|
20 | - * IP address. |
|
21 | - * |
|
22 | - * @var string $_ip |
|
23 | - */ |
|
24 | - protected $_ip; |
|
19 | + /** |
|
20 | + * IP address. |
|
21 | + * |
|
22 | + * @var string $_ip |
|
23 | + */ |
|
24 | + protected $_ip; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Subnet mask. |
|
28 | - * |
|
29 | - * @var string|null $_mask |
|
30 | - */ |
|
31 | - protected $_mask; |
|
26 | + /** |
|
27 | + * Subnet mask. |
|
28 | + * |
|
29 | + * @var string|null $_mask |
|
30 | + */ |
|
31 | + protected $_mask; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Get octet representation of the IP address. |
|
35 | - * |
|
36 | - * @return string |
|
37 | - */ |
|
38 | - abstract protected function _octets(); |
|
33 | + /** |
|
34 | + * Get octet representation of the IP address. |
|
35 | + * |
|
36 | + * @return string |
|
37 | + */ |
|
38 | + abstract protected function _octets(); |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param string $ip |
|
44 | - * @param string|null $mask |
|
45 | - */ |
|
46 | - public function __construct($ip, $mask = null) |
|
47 | - { |
|
48 | - $this->_tag = self::TAG_IP_ADDRESS; |
|
49 | - $this->_ip = $ip; |
|
50 | - $this->_mask = $mask; |
|
51 | - } |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param string $ip |
|
44 | + * @param string|null $mask |
|
45 | + */ |
|
46 | + public function __construct($ip, $mask = null) |
|
47 | + { |
|
48 | + $this->_tag = self::TAG_IP_ADDRESS; |
|
49 | + $this->_ip = $ip; |
|
50 | + $this->_mask = $mask; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * @param UnspecifiedType $el |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
59 | - { |
|
60 | - $octets = $el->asOctetString()->string(); |
|
61 | - switch (strlen($octets)) { |
|
62 | - case 4: |
|
63 | - case 8: |
|
64 | - return IPv4Address::fromOctets($octets); |
|
65 | - case 16: |
|
66 | - case 32: |
|
67 | - return IPv6Address::fromOctets($octets); |
|
68 | - default: |
|
69 | - throw new \UnexpectedValueException( |
|
70 | - "Invalid octet length for IP address."); |
|
71 | - } |
|
72 | - } |
|
53 | + /** |
|
54 | + * |
|
55 | + * @param UnspecifiedType $el |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
59 | + { |
|
60 | + $octets = $el->asOctetString()->string(); |
|
61 | + switch (strlen($octets)) { |
|
62 | + case 4: |
|
63 | + case 8: |
|
64 | + return IPv4Address::fromOctets($octets); |
|
65 | + case 16: |
|
66 | + case 32: |
|
67 | + return IPv6Address::fromOctets($octets); |
|
68 | + default: |
|
69 | + throw new \UnexpectedValueException( |
|
70 | + "Invalid octet length for IP address."); |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * |
|
76 | - * {@inheritdoc} |
|
77 | - */ |
|
78 | - public function string() |
|
79 | - { |
|
80 | - return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
81 | - } |
|
74 | + /** |
|
75 | + * |
|
76 | + * {@inheritdoc} |
|
77 | + */ |
|
78 | + public function string() |
|
79 | + { |
|
80 | + return $this->_ip . (isset($this->_mask) ? "/" . $this->_mask : ""); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Get IP address as a string. |
|
85 | - * |
|
86 | - * @return string |
|
87 | - */ |
|
88 | - public function address() |
|
89 | - { |
|
90 | - return $this->_ip; |
|
91 | - } |
|
83 | + /** |
|
84 | + * Get IP address as a string. |
|
85 | + * |
|
86 | + * @return string |
|
87 | + */ |
|
88 | + public function address() |
|
89 | + { |
|
90 | + return $this->_ip; |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * Get subnet mask as a string. |
|
95 | - * |
|
96 | - * @return string |
|
97 | - */ |
|
98 | - public function mask() |
|
99 | - { |
|
100 | - return $this->_mask; |
|
101 | - } |
|
93 | + /** |
|
94 | + * Get subnet mask as a string. |
|
95 | + * |
|
96 | + * @return string |
|
97 | + */ |
|
98 | + public function mask() |
|
99 | + { |
|
100 | + return $this->_mask; |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * |
|
105 | - * {@inheritdoc} |
|
106 | - */ |
|
107 | - protected function _choiceASN1() |
|
108 | - { |
|
109 | - return new ImplicitlyTaggedType($this->_tag, |
|
110 | - new OctetString($this->_octets())); |
|
111 | - } |
|
103 | + /** |
|
104 | + * |
|
105 | + * {@inheritdoc} |
|
106 | + */ |
|
107 | + protected function _choiceASN1() |
|
108 | + { |
|
109 | + return new ImplicitlyTaggedType($this->_tag, |
|
110 | + new OctetString($this->_octets())); |
|
111 | + } |
|
112 | 112 | } |
@@ -14,59 +14,59 @@ |
||
14 | 14 | */ |
15 | 15 | class UniformResourceIdentifier extends GeneralName |
16 | 16 | { |
17 | - /** |
|
18 | - * URI. |
|
19 | - * |
|
20 | - * @var string $_uri |
|
21 | - */ |
|
22 | - protected $_uri; |
|
17 | + /** |
|
18 | + * URI. |
|
19 | + * |
|
20 | + * @var string $_uri |
|
21 | + */ |
|
22 | + protected $_uri; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - * |
|
27 | - * @param string $uri |
|
28 | - */ |
|
29 | - public function __construct($uri) |
|
30 | - { |
|
31 | - $this->_tag = self::TAG_URI; |
|
32 | - $this->_uri = $uri; |
|
33 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + * |
|
27 | + * @param string $uri |
|
28 | + */ |
|
29 | + public function __construct($uri) |
|
30 | + { |
|
31 | + $this->_tag = self::TAG_URI; |
|
32 | + $this->_uri = $uri; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * |
|
37 | - * @param UnspecifiedType $el |
|
38 | - * @return self |
|
39 | - */ |
|
40 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
41 | - { |
|
42 | - return new self($el->asIA5String()->string()); |
|
43 | - } |
|
35 | + /** |
|
36 | + * |
|
37 | + * @param UnspecifiedType $el |
|
38 | + * @return self |
|
39 | + */ |
|
40 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
41 | + { |
|
42 | + return new self($el->asIA5String()->string()); |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * |
|
47 | - * {@inheritdoc} |
|
48 | - */ |
|
49 | - public function string() |
|
50 | - { |
|
51 | - return $this->_uri; |
|
52 | - } |
|
45 | + /** |
|
46 | + * |
|
47 | + * {@inheritdoc} |
|
48 | + */ |
|
49 | + public function string() |
|
50 | + { |
|
51 | + return $this->_uri; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Get URI. |
|
56 | - * |
|
57 | - * @return string |
|
58 | - */ |
|
59 | - public function uri() |
|
60 | - { |
|
61 | - return $this->_uri; |
|
62 | - } |
|
54 | + /** |
|
55 | + * Get URI. |
|
56 | + * |
|
57 | + * @return string |
|
58 | + */ |
|
59 | + public function uri() |
|
60 | + { |
|
61 | + return $this->_uri; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * |
|
66 | - * {@inheritdoc} |
|
67 | - */ |
|
68 | - protected function _choiceASN1() |
|
69 | - { |
|
70 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
71 | - } |
|
64 | + /** |
|
65 | + * |
|
66 | + * {@inheritdoc} |
|
67 | + */ |
|
68 | + protected function _choiceASN1() |
|
69 | + { |
|
70 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_uri)); |
|
71 | + } |
|
72 | 72 | } |
@@ -13,59 +13,59 @@ |
||
13 | 13 | */ |
14 | 14 | class DNSName extends GeneralName |
15 | 15 | { |
16 | - /** |
|
17 | - * DNS name. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - protected $_name; |
|
16 | + /** |
|
17 | + * DNS name. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + protected $_name; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param string $name Domain name |
|
27 | - */ |
|
28 | - public function __construct($name) |
|
29 | - { |
|
30 | - $this->_tag = self::TAG_DNS_NAME; |
|
31 | - $this->_name = $name; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param string $name Domain name |
|
27 | + */ |
|
28 | + public function __construct($name) |
|
29 | + { |
|
30 | + $this->_tag = self::TAG_DNS_NAME; |
|
31 | + $this->_name = $name; |
|
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->asIA5String()->string()); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param UnspecifiedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | + { |
|
41 | + return new self($el->asIA5String()->string()); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return $this->_name; |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return $this->_name; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get DNS name. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function name() |
|
59 | - { |
|
60 | - return $this->_name; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get DNS name. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function name() |
|
59 | + { |
|
60 | + return $this->_name; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - protected function _choiceASN1() |
|
68 | - { |
|
69 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name)); |
|
70 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + protected function _choiceASN1() |
|
68 | + { |
|
69 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_name)); |
|
70 | + } |
|
71 | 71 | } |
@@ -15,47 +15,47 @@ |
||
15 | 15 | */ |
16 | 16 | class EDIPartyName extends GeneralName |
17 | 17 | { |
18 | - /** |
|
19 | - * |
|
20 | - * @var \ASN1\Element |
|
21 | - */ |
|
22 | - protected $_element; |
|
18 | + /** |
|
19 | + * |
|
20 | + * @var \ASN1\Element |
|
21 | + */ |
|
22 | + protected $_element; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - */ |
|
27 | - protected function __construct() |
|
28 | - { |
|
29 | - $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
30 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + */ |
|
27 | + protected function __construct() |
|
28 | + { |
|
29 | + $this->_tag = self::TAG_EDI_PARTY_NAME; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @param UnspecifiedType $el |
|
35 | - * @return self |
|
36 | - */ |
|
37 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | - { |
|
39 | - $obj = new self(); |
|
40 | - $obj->_element = $el->asSequence(); |
|
41 | - return $obj; |
|
42 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * @param UnspecifiedType $el |
|
35 | + * @return self |
|
36 | + */ |
|
37 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | + { |
|
39 | + $obj = new self(); |
|
40 | + $obj->_element = $el->asSequence(); |
|
41 | + return $obj; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return bin2hex($this->_element->toDER()); |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return bin2hex($this->_element->toDER()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - protected function _choiceASN1() |
|
58 | - { |
|
59 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | - } |
|
53 | + /** |
|
54 | + * |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + protected function _choiceASN1() |
|
58 | + { |
|
59 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | + } |
|
61 | 61 | } |
@@ -15,183 +15,183 @@ |
||
15 | 15 | */ |
16 | 16 | class GeneralNames implements \Countable, \IteratorAggregate |
17 | 17 | { |
18 | - /** |
|
19 | - * GeneralName objects. |
|
20 | - * |
|
21 | - * @var GeneralName[] $_names |
|
22 | - */ |
|
23 | - protected $_names; |
|
18 | + /** |
|
19 | + * GeneralName objects. |
|
20 | + * |
|
21 | + * @var GeneralName[] $_names |
|
22 | + */ |
|
23 | + protected $_names; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param GeneralName ...$names One or more GeneralName objects |
|
29 | - */ |
|
30 | - public function __construct(GeneralName ...$names) |
|
31 | - { |
|
32 | - $this->_names = $names; |
|
33 | - } |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param GeneralName ...$names One or more GeneralName objects |
|
29 | + */ |
|
30 | + public function __construct(GeneralName ...$names) |
|
31 | + { |
|
32 | + $this->_names = $names; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * Initialize from ASN.1. |
|
37 | - * |
|
38 | - * @param Sequence $seq |
|
39 | - * @throws \UnexpectedValueException |
|
40 | - * @return self |
|
41 | - */ |
|
42 | - public static function fromASN1(Sequence $seq) |
|
43 | - { |
|
44 | - if (!count($seq)) { |
|
45 | - throw new \UnexpectedValueException( |
|
46 | - "GeneralNames must have at least one GeneralName."); |
|
47 | - } |
|
48 | - $names = array_map( |
|
49 | - function (UnspecifiedType $el) { |
|
50 | - return GeneralName::fromASN1($el->asTagged()); |
|
51 | - }, $seq->elements()); |
|
52 | - return new self(...$names); |
|
53 | - } |
|
35 | + /** |
|
36 | + * Initialize from ASN.1. |
|
37 | + * |
|
38 | + * @param Sequence $seq |
|
39 | + * @throws \UnexpectedValueException |
|
40 | + * @return self |
|
41 | + */ |
|
42 | + public static function fromASN1(Sequence $seq) |
|
43 | + { |
|
44 | + if (!count($seq)) { |
|
45 | + throw new \UnexpectedValueException( |
|
46 | + "GeneralNames must have at least one GeneralName."); |
|
47 | + } |
|
48 | + $names = array_map( |
|
49 | + function (UnspecifiedType $el) { |
|
50 | + return GeneralName::fromASN1($el->asTagged()); |
|
51 | + }, $seq->elements()); |
|
52 | + return new self(...$names); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Find first GeneralName by given tag. |
|
57 | - * |
|
58 | - * @param int $tag |
|
59 | - * @return GeneralName|null |
|
60 | - */ |
|
61 | - protected function _findFirst($tag) |
|
62 | - { |
|
63 | - foreach ($this->_names as $name) { |
|
64 | - if ($name->tag() == $tag) { |
|
65 | - return $name; |
|
66 | - } |
|
67 | - } |
|
68 | - return null; |
|
69 | - } |
|
55 | + /** |
|
56 | + * Find first GeneralName by given tag. |
|
57 | + * |
|
58 | + * @param int $tag |
|
59 | + * @return GeneralName|null |
|
60 | + */ |
|
61 | + protected function _findFirst($tag) |
|
62 | + { |
|
63 | + foreach ($this->_names as $name) { |
|
64 | + if ($name->tag() == $tag) { |
|
65 | + return $name; |
|
66 | + } |
|
67 | + } |
|
68 | + return null; |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Check whether GeneralNames contains a GeneralName of given type. |
|
73 | - * |
|
74 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
75 | - * @return bool |
|
76 | - */ |
|
77 | - public function has($tag) |
|
78 | - { |
|
79 | - return null !== $this->_findFirst($tag); |
|
80 | - } |
|
71 | + /** |
|
72 | + * Check whether GeneralNames contains a GeneralName of given type. |
|
73 | + * |
|
74 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
75 | + * @return bool |
|
76 | + */ |
|
77 | + public function has($tag) |
|
78 | + { |
|
79 | + return null !== $this->_findFirst($tag); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Get first GeneralName of given type. |
|
84 | - * |
|
85 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
86 | - * @throws \OutOfBoundsException |
|
87 | - * @return GeneralName |
|
88 | - */ |
|
89 | - public function firstOf($tag) |
|
90 | - { |
|
91 | - $name = $this->_findFirst($tag); |
|
92 | - if (!$name) { |
|
93 | - throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
94 | - } |
|
95 | - return $name; |
|
96 | - } |
|
82 | + /** |
|
83 | + * Get first GeneralName of given type. |
|
84 | + * |
|
85 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
86 | + * @throws \OutOfBoundsException |
|
87 | + * @return GeneralName |
|
88 | + */ |
|
89 | + public function firstOf($tag) |
|
90 | + { |
|
91 | + $name = $this->_findFirst($tag); |
|
92 | + if (!$name) { |
|
93 | + throw new \UnexpectedValueException("No GeneralName by tag $tag."); |
|
94 | + } |
|
95 | + return $name; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get all GeneralName objects of given type. |
|
100 | - * |
|
101 | - * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
102 | - * @return GeneralName[] |
|
103 | - */ |
|
104 | - public function allOf($tag) |
|
105 | - { |
|
106 | - $names = array_filter($this->_names, |
|
107 | - function (GeneralName $name) use ($tag) { |
|
108 | - return $name->tag() == $tag; |
|
109 | - }); |
|
110 | - return array_values($names); |
|
111 | - } |
|
98 | + /** |
|
99 | + * Get all GeneralName objects of given type. |
|
100 | + * |
|
101 | + * @param int $tag One of <code>GeneralName::TAG_*</code> enumerations |
|
102 | + * @return GeneralName[] |
|
103 | + */ |
|
104 | + public function allOf($tag) |
|
105 | + { |
|
106 | + $names = array_filter($this->_names, |
|
107 | + function (GeneralName $name) use ($tag) { |
|
108 | + return $name->tag() == $tag; |
|
109 | + }); |
|
110 | + return array_values($names); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get value of the first 'dNSName' type. |
|
115 | - * |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function firstDNS() |
|
119 | - { |
|
120 | - $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
121 | - if (!$gn instanceof DNSName) { |
|
122 | - throw new \RuntimeException( |
|
123 | - DNSName::class . " expected, got " . get_class($gn)); |
|
124 | - } |
|
125 | - return $gn->name(); |
|
126 | - } |
|
113 | + /** |
|
114 | + * Get value of the first 'dNSName' type. |
|
115 | + * |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function firstDNS() |
|
119 | + { |
|
120 | + $gn = $this->firstOf(GeneralName::TAG_DNS_NAME); |
|
121 | + if (!$gn instanceof DNSName) { |
|
122 | + throw new \RuntimeException( |
|
123 | + DNSName::class . " expected, got " . get_class($gn)); |
|
124 | + } |
|
125 | + return $gn->name(); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Get value of the first 'directoryName' type. |
|
130 | - * |
|
131 | - * @return \X501\ASN1\Name |
|
132 | - */ |
|
133 | - public function firstDN() |
|
134 | - { |
|
135 | - $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
136 | - if (!$gn instanceof DirectoryName) { |
|
137 | - throw new \RuntimeException( |
|
138 | - DirectoryName::class . " expected, got " . get_class($gn)); |
|
139 | - } |
|
140 | - return $gn->dn(); |
|
141 | - } |
|
128 | + /** |
|
129 | + * Get value of the first 'directoryName' type. |
|
130 | + * |
|
131 | + * @return \X501\ASN1\Name |
|
132 | + */ |
|
133 | + public function firstDN() |
|
134 | + { |
|
135 | + $gn = $this->firstOf(GeneralName::TAG_DIRECTORY_NAME); |
|
136 | + if (!$gn instanceof DirectoryName) { |
|
137 | + throw new \RuntimeException( |
|
138 | + DirectoryName::class . " expected, got " . get_class($gn)); |
|
139 | + } |
|
140 | + return $gn->dn(); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Get value of the first 'uniformResourceIdentifier' type. |
|
145 | - * |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function firstURI() |
|
149 | - { |
|
150 | - $gn = $this->firstOf(GeneralName::TAG_URI); |
|
151 | - if (!$gn instanceof UniformResourceIdentifier) { |
|
152 | - throw new \RuntimeException( |
|
153 | - UniformResourceIdentifier::class . " expected, got " . |
|
154 | - get_class($gn)); |
|
155 | - } |
|
156 | - return $gn->uri(); |
|
157 | - } |
|
143 | + /** |
|
144 | + * Get value of the first 'uniformResourceIdentifier' type. |
|
145 | + * |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function firstURI() |
|
149 | + { |
|
150 | + $gn = $this->firstOf(GeneralName::TAG_URI); |
|
151 | + if (!$gn instanceof UniformResourceIdentifier) { |
|
152 | + throw new \RuntimeException( |
|
153 | + UniformResourceIdentifier::class . " expected, got " . |
|
154 | + get_class($gn)); |
|
155 | + } |
|
156 | + return $gn->uri(); |
|
157 | + } |
|
158 | 158 | |
159 | - /** |
|
160 | - * Generate ASN.1 structure. |
|
161 | - * |
|
162 | - * @return Sequence |
|
163 | - */ |
|
164 | - public function toASN1() |
|
165 | - { |
|
166 | - if (!count($this->_names)) { |
|
167 | - throw new \LogicException( |
|
168 | - "GeneralNames must have at least one GeneralName."); |
|
169 | - } |
|
170 | - $elements = array_map( |
|
171 | - function (GeneralName $name) { |
|
172 | - return $name->toASN1(); |
|
173 | - }, $this->_names); |
|
174 | - return new Sequence(...$elements); |
|
175 | - } |
|
159 | + /** |
|
160 | + * Generate ASN.1 structure. |
|
161 | + * |
|
162 | + * @return Sequence |
|
163 | + */ |
|
164 | + public function toASN1() |
|
165 | + { |
|
166 | + if (!count($this->_names)) { |
|
167 | + throw new \LogicException( |
|
168 | + "GeneralNames must have at least one GeneralName."); |
|
169 | + } |
|
170 | + $elements = array_map( |
|
171 | + function (GeneralName $name) { |
|
172 | + return $name->toASN1(); |
|
173 | + }, $this->_names); |
|
174 | + return new Sequence(...$elements); |
|
175 | + } |
|
176 | 176 | |
177 | - /** |
|
178 | - * |
|
179 | - * @see \Countable::count() |
|
180 | - * @return int |
|
181 | - */ |
|
182 | - public function count() |
|
183 | - { |
|
184 | - return count($this->_names); |
|
185 | - } |
|
177 | + /** |
|
178 | + * |
|
179 | + * @see \Countable::count() |
|
180 | + * @return int |
|
181 | + */ |
|
182 | + public function count() |
|
183 | + { |
|
184 | + return count($this->_names); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Get iterator for GeneralName objects. |
|
189 | - * |
|
190 | - * @see \IteratorAggregate::getIterator() |
|
191 | - * @return \ArrayIterator |
|
192 | - */ |
|
193 | - public function getIterator() |
|
194 | - { |
|
195 | - return new \ArrayIterator($this->_names); |
|
196 | - } |
|
187 | + /** |
|
188 | + * Get iterator for GeneralName objects. |
|
189 | + * |
|
190 | + * @see \IteratorAggregate::getIterator() |
|
191 | + * @return \ArrayIterator |
|
192 | + */ |
|
193 | + public function getIterator() |
|
194 | + { |
|
195 | + return new \ArrayIterator($this->_names); |
|
196 | + } |
|
197 | 197 | } |
@@ -13,59 +13,59 @@ |
||
13 | 13 | */ |
14 | 14 | class RFC822Name extends GeneralName |
15 | 15 | { |
16 | - /** |
|
17 | - * Email. |
|
18 | - * |
|
19 | - * @var string $_email |
|
20 | - */ |
|
21 | - protected $_email; |
|
16 | + /** |
|
17 | + * Email. |
|
18 | + * |
|
19 | + * @var string $_email |
|
20 | + */ |
|
21 | + protected $_email; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param string $email |
|
27 | - */ |
|
28 | - public function __construct($email) |
|
29 | - { |
|
30 | - $this->_tag = self::TAG_RFC822_NAME; |
|
31 | - $this->_email = $email; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param string $email |
|
27 | + */ |
|
28 | + public function __construct($email) |
|
29 | + { |
|
30 | + $this->_tag = self::TAG_RFC822_NAME; |
|
31 | + $this->_email = $email; |
|
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->asIA5String()->string()); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param UnspecifiedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
40 | + { |
|
41 | + return new self($el->asIA5String()->string()); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return $this->_email; |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return $this->_email; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get email. |
|
55 | - * |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function email() |
|
59 | - { |
|
60 | - return $this->_email; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get email. |
|
55 | + * |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function email() |
|
59 | + { |
|
60 | + return $this->_email; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * {@inheritdoc} |
|
66 | - */ |
|
67 | - protected function _choiceASN1() |
|
68 | - { |
|
69 | - return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
70 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * {@inheritdoc} |
|
66 | + */ |
|
67 | + protected function _choiceASN1() |
|
68 | + { |
|
69 | + return new ImplicitlyTaggedType($this->_tag, new IA5String($this->_email)); |
|
70 | + } |
|
71 | 71 | } |
@@ -16,82 +16,82 @@ |
||
16 | 16 | */ |
17 | 17 | class OtherName extends GeneralName |
18 | 18 | { |
19 | - /** |
|
20 | - * Type OID. |
|
21 | - * |
|
22 | - * @var string $_type |
|
23 | - */ |
|
24 | - protected $_type; |
|
19 | + /** |
|
20 | + * Type OID. |
|
21 | + * |
|
22 | + * @var string $_type |
|
23 | + */ |
|
24 | + protected $_type; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Value. |
|
28 | - * |
|
29 | - * @var Element $_element |
|
30 | - */ |
|
31 | - protected $_element; |
|
26 | + /** |
|
27 | + * Value. |
|
28 | + * |
|
29 | + * @var Element $_element |
|
30 | + */ |
|
31 | + protected $_element; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor. |
|
35 | - * |
|
36 | - * @param string $type_id OID |
|
37 | - * @param Element $el |
|
38 | - */ |
|
39 | - public function __construct($type_id, Element $el) |
|
40 | - { |
|
41 | - $this->_tag = self::TAG_OTHER_NAME; |
|
42 | - $this->_type = $type_id; |
|
43 | - $this->_element = $el; |
|
44 | - } |
|
33 | + /** |
|
34 | + * Constructor. |
|
35 | + * |
|
36 | + * @param string $type_id OID |
|
37 | + * @param Element $el |
|
38 | + */ |
|
39 | + public function __construct($type_id, Element $el) |
|
40 | + { |
|
41 | + $this->_tag = self::TAG_OTHER_NAME; |
|
42 | + $this->_type = $type_id; |
|
43 | + $this->_element = $el; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * |
|
48 | - * @param UnspecifiedType $el |
|
49 | - * @return self |
|
50 | - */ |
|
51 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
52 | - { |
|
53 | - $seq = $el->asSequence(); |
|
54 | - $type_id = $seq->at(0) |
|
55 | - ->asObjectIdentifier() |
|
56 | - ->oid(); |
|
57 | - $value = $seq->getTagged(0) |
|
58 | - ->asExplicit() |
|
59 | - ->asElement(); |
|
60 | - return new self($type_id, $value); |
|
61 | - } |
|
62 | - public function string() |
|
63 | - { |
|
64 | - return $this->_type . "/#" . bin2hex($this->_element->toDER()); |
|
65 | - } |
|
46 | + /** |
|
47 | + * |
|
48 | + * @param UnspecifiedType $el |
|
49 | + * @return self |
|
50 | + */ |
|
51 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
52 | + { |
|
53 | + $seq = $el->asSequence(); |
|
54 | + $type_id = $seq->at(0) |
|
55 | + ->asObjectIdentifier() |
|
56 | + ->oid(); |
|
57 | + $value = $seq->getTagged(0) |
|
58 | + ->asExplicit() |
|
59 | + ->asElement(); |
|
60 | + return new self($type_id, $value); |
|
61 | + } |
|
62 | + public function string() |
|
63 | + { |
|
64 | + return $this->_type . "/#" . bin2hex($this->_element->toDER()); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Get type OID. |
|
69 | - * |
|
70 | - * @return string |
|
71 | - */ |
|
72 | - public function type() |
|
73 | - { |
|
74 | - return $this->_type; |
|
75 | - } |
|
67 | + /** |
|
68 | + * Get type OID. |
|
69 | + * |
|
70 | + * @return string |
|
71 | + */ |
|
72 | + public function type() |
|
73 | + { |
|
74 | + return $this->_type; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Get value element. |
|
79 | - * |
|
80 | - * @return Element |
|
81 | - */ |
|
82 | - public function value() |
|
83 | - { |
|
84 | - return $this->_element; |
|
85 | - } |
|
77 | + /** |
|
78 | + * Get value element. |
|
79 | + * |
|
80 | + * @return Element |
|
81 | + */ |
|
82 | + public function value() |
|
83 | + { |
|
84 | + return $this->_element; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * |
|
89 | - * {@inheritdoc} |
|
90 | - */ |
|
91 | - protected function _choiceASN1() |
|
92 | - { |
|
93 | - return new ImplicitlyTaggedType($this->_tag, |
|
94 | - new Sequence(new ObjectIdentifier($this->_type), |
|
95 | - new ExplicitlyTaggedType(0, $this->_element))); |
|
96 | - } |
|
87 | + /** |
|
88 | + * |
|
89 | + * {@inheritdoc} |
|
90 | + */ |
|
91 | + protected function _choiceASN1() |
|
92 | + { |
|
93 | + return new ImplicitlyTaggedType($this->_tag, |
|
94 | + new Sequence(new ObjectIdentifier($this->_type), |
|
95 | + new ExplicitlyTaggedType(0, $this->_element))); |
|
96 | + } |
|
97 | 97 | } |
@@ -15,47 +15,47 @@ |
||
15 | 15 | */ |
16 | 16 | class X400Address extends GeneralName |
17 | 17 | { |
18 | - /** |
|
19 | - * |
|
20 | - * @var \ASN1\Element |
|
21 | - */ |
|
22 | - protected $_element; |
|
18 | + /** |
|
19 | + * |
|
20 | + * @var \ASN1\Element |
|
21 | + */ |
|
22 | + protected $_element; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - */ |
|
27 | - protected function __construct() |
|
28 | - { |
|
29 | - $this->_tag = self::TAG_X400_ADDRESS; |
|
30 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + */ |
|
27 | + protected function __construct() |
|
28 | + { |
|
29 | + $this->_tag = self::TAG_X400_ADDRESS; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * |
|
34 | - * @param UnspecifiedType $el |
|
35 | - * @return self |
|
36 | - */ |
|
37 | - public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | - { |
|
39 | - $obj = new self(); |
|
40 | - $obj->_element = $el->asSequence(); |
|
41 | - return $obj; |
|
42 | - } |
|
32 | + /** |
|
33 | + * |
|
34 | + * @param UnspecifiedType $el |
|
35 | + * @return self |
|
36 | + */ |
|
37 | + public static function fromChosenASN1(UnspecifiedType $el) |
|
38 | + { |
|
39 | + $obj = new self(); |
|
40 | + $obj->_element = $el->asSequence(); |
|
41 | + return $obj; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return bin2hex($this->_element->toDER()); |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return bin2hex($this->_element->toDER()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * |
|
55 | - * {@inheritdoc} |
|
56 | - */ |
|
57 | - protected function _choiceASN1() |
|
58 | - { |
|
59 | - return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | - } |
|
53 | + /** |
|
54 | + * |
|
55 | + * {@inheritdoc} |
|
56 | + */ |
|
57 | + protected function _choiceASN1() |
|
58 | + { |
|
59 | + return new ImplicitlyTaggedType($this->_tag, $this->_element); |
|
60 | + } |
|
61 | 61 | } |