@@ -19,110 +19,110 @@ |
||
19 | 19 | */ |
20 | 20 | abstract class IPAddress extends GeneralName |
21 | 21 | { |
22 | - /** |
|
23 | - * IP address. |
|
24 | - * |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - protected $_ip; |
|
22 | + /** |
|
23 | + * IP address. |
|
24 | + * |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + protected $_ip; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Subnet mask. |
|
31 | - * |
|
32 | - * @var null|string |
|
33 | - */ |
|
34 | - protected $_mask; |
|
29 | + /** |
|
30 | + * Subnet mask. |
|
31 | + * |
|
32 | + * @var null|string |
|
33 | + */ |
|
34 | + protected $_mask; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor. |
|
38 | - * |
|
39 | - * @param string $ip |
|
40 | - * @param null|string $mask |
|
41 | - */ |
|
42 | - public function __construct(string $ip, ?string $mask = null) |
|
43 | - { |
|
44 | - $this->_tag = self::TAG_IP_ADDRESS; |
|
45 | - $this->_ip = $ip; |
|
46 | - $this->_mask = $mask; |
|
47 | - } |
|
36 | + /** |
|
37 | + * Constructor. |
|
38 | + * |
|
39 | + * @param string $ip |
|
40 | + * @param null|string $mask |
|
41 | + */ |
|
42 | + public function __construct(string $ip, ?string $mask = null) |
|
43 | + { |
|
44 | + $this->_tag = self::TAG_IP_ADDRESS; |
|
45 | + $this->_ip = $ip; |
|
46 | + $this->_mask = $mask; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritdoc} |
|
51 | - * |
|
52 | - * @return self |
|
53 | - */ |
|
54 | - public static function fromChosenASN1(UnspecifiedType $el): GeneralName |
|
55 | - { |
|
56 | - $octets = $el->asOctetString()->string(); |
|
57 | - switch (strlen($octets)) { |
|
58 | - case 4: |
|
59 | - case 8: |
|
60 | - return IPv4Address::fromOctets($octets); |
|
61 | - case 16: |
|
62 | - case 32: |
|
63 | - return IPv6Address::fromOctets($octets); |
|
64 | - default: |
|
65 | - throw new \UnexpectedValueException( |
|
66 | - 'Invalid octet length for IP address.'); |
|
67 | - } |
|
68 | - } |
|
49 | + /** |
|
50 | + * {@inheritdoc} |
|
51 | + * |
|
52 | + * @return self |
|
53 | + */ |
|
54 | + public static function fromChosenASN1(UnspecifiedType $el): GeneralName |
|
55 | + { |
|
56 | + $octets = $el->asOctetString()->string(); |
|
57 | + switch (strlen($octets)) { |
|
58 | + case 4: |
|
59 | + case 8: |
|
60 | + return IPv4Address::fromOctets($octets); |
|
61 | + case 16: |
|
62 | + case 32: |
|
63 | + return IPv6Address::fromOctets($octets); |
|
64 | + default: |
|
65 | + throw new \UnexpectedValueException( |
|
66 | + 'Invalid octet length for IP address.'); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritdoc} |
|
72 | - */ |
|
73 | - public function string(): string |
|
74 | - { |
|
75 | - return $this->_ip . (isset($this->_mask) ? '/' . $this->_mask : ''); |
|
76 | - } |
|
70 | + /** |
|
71 | + * {@inheritdoc} |
|
72 | + */ |
|
73 | + public function string(): string |
|
74 | + { |
|
75 | + return $this->_ip . (isset($this->_mask) ? '/' . $this->_mask : ''); |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Get IP address as a string. |
|
80 | - * |
|
81 | - * @return string |
|
82 | - */ |
|
83 | - public function address(): string |
|
84 | - { |
|
85 | - return $this->_ip; |
|
86 | - } |
|
78 | + /** |
|
79 | + * Get IP address as a string. |
|
80 | + * |
|
81 | + * @return string |
|
82 | + */ |
|
83 | + public function address(): string |
|
84 | + { |
|
85 | + return $this->_ip; |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Check whether mask is present. |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public function hasMask(): bool |
|
94 | - { |
|
95 | - return isset($this->_mask); |
|
96 | - } |
|
88 | + /** |
|
89 | + * Check whether mask is present. |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public function hasMask(): bool |
|
94 | + { |
|
95 | + return isset($this->_mask); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * Get subnet mask as a string. |
|
100 | - * |
|
101 | - * @throws \LogicException If not set |
|
102 | - * |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function mask(): string |
|
106 | - { |
|
107 | - if (!$this->hasMask()) { |
|
108 | - throw new \LogicException('mask is not set.'); |
|
109 | - } |
|
110 | - return $this->_mask; |
|
111 | - } |
|
98 | + /** |
|
99 | + * Get subnet mask as a string. |
|
100 | + * |
|
101 | + * @throws \LogicException If not set |
|
102 | + * |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function mask(): string |
|
106 | + { |
|
107 | + if (!$this->hasMask()) { |
|
108 | + throw new \LogicException('mask is not set.'); |
|
109 | + } |
|
110 | + return $this->_mask; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get octet representation of the IP address. |
|
115 | - * |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - abstract protected function _octets(): string; |
|
113 | + /** |
|
114 | + * Get octet representation of the IP address. |
|
115 | + * |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + abstract protected function _octets(): string; |
|
119 | 119 | |
120 | - /** |
|
121 | - * {@inheritdoc} |
|
122 | - */ |
|
123 | - protected function _choiceASN1(): TaggedType |
|
124 | - { |
|
125 | - return new ImplicitlyTaggedType($this->_tag, |
|
126 | - new OctetString($this->_octets())); |
|
127 | - } |
|
120 | + /** |
|
121 | + * {@inheritdoc} |
|
122 | + */ |
|
123 | + protected function _choiceASN1(): TaggedType |
|
124 | + { |
|
125 | + return new ImplicitlyTaggedType($this->_tag, |
|
126 | + new OctetString($this->_octets())); |
|
127 | + } |
|
128 | 128 | } |