@@ -16,15 +16,15 @@ |
||
16 | 16 | $mask = null; |
17 | 17 | $bytes = unpack("C*", $octets); |
18 | 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."); |
|
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 | 28 | } |
29 | 29 | return new self($ip, $mask); |
30 | 30 | } |
@@ -59,15 +59,15 @@ |
||
59 | 59 | { |
60 | 60 | $octets = $el->asOctetString()->string(); |
61 | 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."); |
|
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 | 71 | } |
72 | 72 | } |
73 | 73 |
@@ -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 | } |
@@ -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."); |
@@ -43,16 +43,16 @@ |
||
43 | 43 | public static function fromTaggedType(TaggedType $el) |
44 | 44 | { |
45 | 45 | switch ($el->tag()) { |
46 | - case self::TAG_FULL_NAME: |
|
47 | - return new FullName( |
|
48 | - GeneralNames::fromASN1( |
|
49 | - $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
50 | - case self::TAG_RDN: |
|
51 | - return new RelativeName( |
|
52 | - RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
53 | - default: |
|
54 | - throw new \UnexpectedValueException( |
|
55 | - "DistributionPointName tag " . $el->tag() . " not supported."); |
|
46 | + case self::TAG_FULL_NAME: |
|
47 | + return new FullName( |
|
48 | + GeneralNames::fromASN1( |
|
49 | + $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
50 | + case self::TAG_RDN: |
|
51 | + return new RelativeName( |
|
52 | + RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
53 | + default: |
|
54 | + throw new \UnexpectedValueException( |
|
55 | + "DistributionPointName tag " . $el->tag() . " not supported."); |
|
56 | 56 | } |
57 | 57 | } |
58 | 58 |
@@ -84,17 +84,17 @@ |
||
84 | 84 | public function toASN1() |
85 | 85 | { |
86 | 86 | switch ($this->_tag) { |
87 | - case Element::TYPE_IA5_STRING: |
|
88 | - return new IA5String($this->_text); |
|
89 | - case Element::TYPE_VISIBLE_STRING: |
|
90 | - return new VisibleString($this->_text); |
|
91 | - case Element::TYPE_BMP_STRING: |
|
92 | - return new BMPString($this->_text); |
|
93 | - case Element::TYPE_UTF8_STRING: |
|
94 | - return new UTF8String($this->_text); |
|
95 | - default: |
|
96 | - throw new \UnexpectedValueException( |
|
97 | - "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
87 | + case Element::TYPE_IA5_STRING: |
|
88 | + return new IA5String($this->_text); |
|
89 | + case Element::TYPE_VISIBLE_STRING: |
|
90 | + return new VisibleString($this->_text); |
|
91 | + case Element::TYPE_BMP_STRING: |
|
92 | + return new BMPString($this->_text); |
|
93 | + case Element::TYPE_UTF8_STRING: |
|
94 | + return new UTF8String($this->_text); |
|
95 | + default: |
|
96 | + throw new \UnexpectedValueException( |
|
97 | + "Type " . Element::tagToName($this->_tag) . " not supported."); |
|
98 | 98 | } |
99 | 99 | } |
100 | 100 |
@@ -67,10 +67,10 @@ |
||
67 | 67 | ->asObjectIdentifier() |
68 | 68 | ->oid(); |
69 | 69 | switch ($oid) { |
70 | - case self::OID_CPS: |
|
71 | - return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
72 | - case self::OID_UNOTICE: |
|
73 | - return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
70 | + case self::OID_CPS: |
|
71 | + return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
72 | + case self::OID_UNOTICE: |
|
73 | + return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
74 | 74 | } |
75 | 75 | throw new \UnexpectedValueException("Qualifier $oid not supported."); |
76 | 76 | } |
@@ -58,13 +58,13 @@ |
||
58 | 58 | public static function fromASN1(TaggedType $el) |
59 | 59 | { |
60 | 60 | switch ($el->tag()) { |
61 | - case self::TYPE_NAME: |
|
62 | - return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
63 | - case self::TYPE_GROUP: |
|
64 | - return TargetGroup::fromChosenASN1( |
|
65 | - $el->asExplicit()->asTagged()); |
|
66 | - case self::TYPE_CERT: |
|
67 | - throw new \RuntimeException("targetCert not supported."); |
|
61 | + case self::TYPE_NAME: |
|
62 | + return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
63 | + case self::TYPE_GROUP: |
|
64 | + return TargetGroup::fromChosenASN1( |
|
65 | + $el->asExplicit()->asTagged()); |
|
66 | + case self::TYPE_CERT: |
|
67 | + throw new \RuntimeException("targetCert not supported."); |
|
68 | 68 | } |
69 | 69 | throw new \UnexpectedValueException( |
70 | 70 | "Target type " . $el->tag() . " not supported."); |
@@ -87,17 +87,17 @@ |
||
87 | 87 | { |
88 | 88 | $dt = $this->_dt; |
89 | 89 | switch ($this->_type) { |
90 | - case Element::TYPE_UTC_TIME: |
|
91 | - return new UTCTime($dt); |
|
92 | - case Element::TYPE_GENERALIZED_TIME: |
|
93 | - // GeneralizedTime must not contain fractional seconds |
|
94 | - // (rfc5280 4.1.2.5.2) |
|
95 | - if ($dt->format("u") != 0) { |
|
96 | - // remove fractional seconds (round down) |
|
97 | - $dt = \DateTimeImmutable::createFromFormat("Y-m-d H:i:s", |
|
98 | - $dt->format("Y-m-d H:i:s"), $dt->getTimezone()); |
|
99 | - } |
|
100 | - return new GeneralizedTime($dt); |
|
90 | + case Element::TYPE_UTC_TIME: |
|
91 | + return new UTCTime($dt); |
|
92 | + case Element::TYPE_GENERALIZED_TIME: |
|
93 | + // GeneralizedTime must not contain fractional seconds |
|
94 | + // (rfc5280 4.1.2.5.2) |
|
95 | + if ($dt->format("u") != 0) { |
|
96 | + // remove fractional seconds (round down) |
|
97 | + $dt = \DateTimeImmutable::createFromFormat("Y-m-d H:i:s", |
|
98 | + $dt->format("Y-m-d H:i:s"), $dt->getTimezone()); |
|
99 | + } |
|
100 | + return new GeneralizedTime($dt); |
|
101 | 101 | } |
102 | 102 | throw new \UnexpectedValueException( |
103 | 103 | "Time type " . Element::tagToName($this->_type) . " not supported."); |