@@ -55,15 +55,15 @@ |
||
55 | 55 | { |
56 | 56 | $octets = $el->asOctetString()->string(); |
57 | 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.'); |
|
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 | 67 | } |
68 | 68 | } |
69 | 69 |
@@ -76,43 +76,43 @@ |
||
76 | 76 | { |
77 | 77 | switch ($el->tag()) { |
78 | 78 | // otherName |
79 | - case self::TAG_OTHER_NAME: |
|
80 | - return OtherName::fromChosenASN1( |
|
81 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
82 | - // rfc822Name |
|
83 | - case self::TAG_RFC822_NAME: |
|
84 | - return RFC822Name::fromChosenASN1( |
|
85 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
86 | - // dNSName |
|
87 | - case self::TAG_DNS_NAME: |
|
88 | - return DNSName::fromChosenASN1( |
|
89 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
90 | - // x400Address |
|
91 | - case self::TAG_X400_ADDRESS: |
|
92 | - return X400Address::fromChosenASN1( |
|
93 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
94 | - // directoryName |
|
95 | - case self::TAG_DIRECTORY_NAME: |
|
96 | - // because Name is a CHOICE, albeit having only one option, |
|
97 | - // explicit tagging must be used |
|
98 | - // (see X.680 07/2002 30.6.c) |
|
99 | - return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
100 | - // ediPartyName |
|
101 | - case self::TAG_EDI_PARTY_NAME: |
|
102 | - return EDIPartyName::fromChosenASN1( |
|
103 | - $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
104 | - // uniformResourceIdentifier |
|
105 | - case self::TAG_URI: |
|
106 | - return UniformResourceIdentifier::fromChosenASN1( |
|
107 | - $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
108 | - // iPAddress |
|
109 | - case self::TAG_IP_ADDRESS: |
|
110 | - return IPAddress::fromChosenASN1( |
|
111 | - $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
112 | - // registeredID |
|
113 | - case self::TAG_REGISTERED_ID: |
|
114 | - return RegisteredID::fromChosenASN1( |
|
115 | - $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
79 | + case self::TAG_OTHER_NAME: |
|
80 | + return OtherName::fromChosenASN1( |
|
81 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
82 | + // rfc822Name |
|
83 | + case self::TAG_RFC822_NAME: |
|
84 | + return RFC822Name::fromChosenASN1( |
|
85 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
86 | + // dNSName |
|
87 | + case self::TAG_DNS_NAME: |
|
88 | + return DNSName::fromChosenASN1( |
|
89 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
90 | + // x400Address |
|
91 | + case self::TAG_X400_ADDRESS: |
|
92 | + return X400Address::fromChosenASN1( |
|
93 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
94 | + // directoryName |
|
95 | + case self::TAG_DIRECTORY_NAME: |
|
96 | + // because Name is a CHOICE, albeit having only one option, |
|
97 | + // explicit tagging must be used |
|
98 | + // (see X.680 07/2002 30.6.c) |
|
99 | + return DirectoryName::fromChosenASN1($el->asExplicit()); |
|
100 | + // ediPartyName |
|
101 | + case self::TAG_EDI_PARTY_NAME: |
|
102 | + return EDIPartyName::fromChosenASN1( |
|
103 | + $el->asImplicit(Element::TYPE_SEQUENCE)); |
|
104 | + // uniformResourceIdentifier |
|
105 | + case self::TAG_URI: |
|
106 | + return UniformResourceIdentifier::fromChosenASN1( |
|
107 | + $el->asImplicit(Element::TYPE_IA5_STRING)); |
|
108 | + // iPAddress |
|
109 | + case self::TAG_IP_ADDRESS: |
|
110 | + return IPAddress::fromChosenASN1( |
|
111 | + $el->asImplicit(Element::TYPE_OCTET_STRING)); |
|
112 | + // registeredID |
|
113 | + case self::TAG_REGISTERED_ID: |
|
114 | + return RegisteredID::fromChosenASN1( |
|
115 | + $el->asImplicit(Element::TYPE_OBJECT_IDENTIFIER)); |
|
116 | 116 | } |
117 | 117 | throw new \UnexpectedValueException( |
118 | 118 | 'GeneralName type ' . $el->tag() . ' not supported.'); |
@@ -40,16 +40,16 @@ |
||
40 | 40 | public static function fromTaggedType(TaggedType $el): self |
41 | 41 | { |
42 | 42 | switch ($el->tag()) { |
43 | - case self::TAG_FULL_NAME: |
|
44 | - return new FullName( |
|
45 | - GeneralNames::fromASN1( |
|
46 | - $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
47 | - case self::TAG_RDN: |
|
48 | - return new RelativeName( |
|
49 | - RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
50 | - default: |
|
51 | - throw new \UnexpectedValueException( |
|
52 | - 'DistributionPointName tag ' . $el->tag() . ' not supported.'); |
|
43 | + case self::TAG_FULL_NAME: |
|
44 | + return new FullName( |
|
45 | + GeneralNames::fromASN1( |
|
46 | + $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
47 | + case self::TAG_RDN: |
|
48 | + return new RelativeName( |
|
49 | + RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
50 | + default: |
|
51 | + throw new \UnexpectedValueException( |
|
52 | + 'DistributionPointName tag ' . $el->tag() . ' not supported.'); |
|
53 | 53 | } |
54 | 54 | } |
55 | 55 |
@@ -64,10 +64,10 @@ |
||
64 | 64 | { |
65 | 65 | $oid = $seq->at(0)->asObjectIdentifier()->oid(); |
66 | 66 | switch ($oid) { |
67 | - case self::OID_CPS: |
|
68 | - return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
69 | - case self::OID_UNOTICE: |
|
70 | - return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
67 | + case self::OID_CPS: |
|
68 | + return CPSQualifier::fromQualifierASN1($seq->at(1)); |
|
69 | + case self::OID_UNOTICE: |
|
70 | + return UserNoticeQualifier::fromQualifierASN1($seq->at(1)); |
|
71 | 71 | } |
72 | 72 | throw new \UnexpectedValueException("Qualifier {$oid} not supported."); |
73 | 73 | } |
@@ -97,17 +97,17 @@ |
||
97 | 97 | public function toASN1(): StringType |
98 | 98 | { |
99 | 99 | switch ($this->_tag) { |
100 | - case Element::TYPE_IA5_STRING: |
|
101 | - return new IA5String($this->_text); |
|
102 | - case Element::TYPE_VISIBLE_STRING: |
|
103 | - return new VisibleString($this->_text); |
|
104 | - case Element::TYPE_BMP_STRING: |
|
105 | - return new BMPString($this->_text); |
|
106 | - case Element::TYPE_UTF8_STRING: |
|
107 | - return new UTF8String($this->_text); |
|
108 | - default: |
|
109 | - throw new \UnexpectedValueException( |
|
110 | - 'Type ' . Element::tagToName($this->_tag) . ' not supported.'); |
|
100 | + case Element::TYPE_IA5_STRING: |
|
101 | + return new IA5String($this->_text); |
|
102 | + case Element::TYPE_VISIBLE_STRING: |
|
103 | + return new VisibleString($this->_text); |
|
104 | + case Element::TYPE_BMP_STRING: |
|
105 | + return new BMPString($this->_text); |
|
106 | + case Element::TYPE_UTF8_STRING: |
|
107 | + return new UTF8String($this->_text); |
|
108 | + default: |
|
109 | + throw new \UnexpectedValueException( |
|
110 | + 'Type ' . Element::tagToName($this->_tag) . ' not supported.'); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | } |
@@ -64,12 +64,12 @@ |
||
64 | 64 | public static function fromASN1(TaggedType $el): self |
65 | 65 | { |
66 | 66 | switch ($el->tag()) { |
67 | - case self::TYPE_NAME: |
|
68 | - return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
69 | - case self::TYPE_GROUP: |
|
70 | - return TargetGroup::fromChosenASN1($el->asExplicit()->asTagged()); |
|
71 | - case self::TYPE_CERT: |
|
72 | - throw new \RuntimeException('targetCert not supported.'); |
|
67 | + case self::TYPE_NAME: |
|
68 | + return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
69 | + case self::TYPE_GROUP: |
|
70 | + return TargetGroup::fromChosenASN1($el->asExplicit()->asTagged()); |
|
71 | + case self::TYPE_CERT: |
|
72 | + throw new \RuntimeException('targetCert not supported.'); |
|
73 | 73 | } |
74 | 74 | throw new \UnexpectedValueException( |
75 | 75 | 'Target type ' . $el->tag() . ' not supported.'); |
@@ -80,9 +80,9 @@ |
||
80 | 80 | } |
81 | 81 | $tagged = $el->asTagged(); |
82 | 82 | switch ($tagged->tag()) { |
83 | - case 0: |
|
84 | - return V2Form::fromV2ASN1( |
|
85 | - $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
83 | + case 0: |
|
84 | + return V2Form::fromV2ASN1( |
|
85 | + $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
86 | 86 | } |
87 | 87 | throw new \UnexpectedValueException('Unsupported issuer type.'); |
88 | 88 | } |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | public static function fromASN1(UnspecifiedType $el): self |
64 | 64 | { |
65 | 65 | switch ($el->tag()) { |
66 | - case Element::TYPE_OCTET_STRING: |
|
67 | - case Element::TYPE_UTF8_STRING: |
|
68 | - return new self($el->asString()->string(), $el->tag()); |
|
69 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
70 | - return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
66 | + case Element::TYPE_OCTET_STRING: |
|
67 | + case Element::TYPE_UTF8_STRING: |
|
68 | + return new self($el->asString()->string(), $el->tag()); |
|
69 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
70 | + return new self($el->asObjectIdentifier()->oid(), $el->tag()); |
|
71 | 71 | } |
72 | 72 | throw new \UnexpectedValueException( |
73 | 73 | 'Type ' . Element::tagToName($el->tag()) . ' not supported.'); |
@@ -169,12 +169,12 @@ discard block |
||
169 | 169 | public function toASN1(): Element |
170 | 170 | { |
171 | 171 | switch ($this->_type) { |
172 | - case Element::TYPE_OCTET_STRING: |
|
173 | - return new OctetString($this->_value); |
|
174 | - case Element::TYPE_UTF8_STRING: |
|
175 | - return new UTF8String($this->_value); |
|
176 | - case Element::TYPE_OBJECT_IDENTIFIER: |
|
177 | - return new ObjectIdentifier($this->_value); |
|
172 | + case Element::TYPE_OCTET_STRING: |
|
173 | + return new OctetString($this->_value); |
|
174 | + case Element::TYPE_UTF8_STRING: |
|
175 | + return new UTF8String($this->_value); |
|
176 | + case Element::TYPE_OBJECT_IDENTIFIER: |
|
177 | + return new ObjectIdentifier($this->_value); |
|
178 | 178 | } |
179 | 179 | throw new \LogicException( |
180 | 180 | 'Type ' . Element::tagToName($this->_type) . ' not supported.'); |
@@ -20,15 +20,15 @@ |
||
20 | 20 | $mask = null; |
21 | 21 | $words = unpack('n*', $octets) ?: []; |
22 | 22 | switch (count($words)) { |
23 | - case 8: |
|
24 | - $ip = self::_wordsToIPv6String($words); |
|
25 | - break; |
|
26 | - case 16: |
|
27 | - $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
28 | - $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
29 | - break; |
|
30 | - default: |
|
31 | - throw new \UnexpectedValueException('Invalid IPv6 octet length.'); |
|
23 | + case 8: |
|
24 | + $ip = self::_wordsToIPv6String($words); |
|
25 | + break; |
|
26 | + case 16: |
|
27 | + $ip = self::_wordsToIPv6String(array_slice($words, 0, 8)); |
|
28 | + $mask = self::_wordsToIPv6String(array_slice($words, 8, 8)); |
|
29 | + break; |
|
30 | + default: |
|
31 | + throw new \UnexpectedValueException('Invalid IPv6 octet length.'); |
|
32 | 32 | } |
33 | 33 | return new self($ip, $mask); |
34 | 34 | } |