@@ -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 | } |
@@ -16,91 +16,91 @@ |
||
16 | 16 | */ |
17 | 17 | class GeneralSubtree |
18 | 18 | { |
19 | - /** |
|
20 | - * Constraint. |
|
21 | - * |
|
22 | - * @var GeneralName |
|
23 | - */ |
|
24 | - protected $_base; |
|
19 | + /** |
|
20 | + * Constraint. |
|
21 | + * |
|
22 | + * @var GeneralName |
|
23 | + */ |
|
24 | + protected $_base; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Not used, must be zero. |
|
28 | - * |
|
29 | - * @var int $_min |
|
30 | - */ |
|
31 | - protected $_min; |
|
26 | + /** |
|
27 | + * Not used, must be zero. |
|
28 | + * |
|
29 | + * @var int $_min |
|
30 | + */ |
|
31 | + protected $_min; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Not used, must be null. |
|
35 | - * |
|
36 | - * @var int|null $_max |
|
37 | - */ |
|
38 | - protected $_max; |
|
33 | + /** |
|
34 | + * Not used, must be null. |
|
35 | + * |
|
36 | + * @var int|null $_max |
|
37 | + */ |
|
38 | + protected $_max; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param GeneralName $base |
|
44 | - * @param int $min |
|
45 | - * @param int|null $max |
|
46 | - */ |
|
47 | - public function __construct(GeneralName $base, $min = 0, $max = null) |
|
48 | - { |
|
49 | - $this->_base = $base; |
|
50 | - $this->_min = $min; |
|
51 | - $this->_max = $max; |
|
52 | - } |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param GeneralName $base |
|
44 | + * @param int $min |
|
45 | + * @param int|null $max |
|
46 | + */ |
|
47 | + public function __construct(GeneralName $base, $min = 0, $max = null) |
|
48 | + { |
|
49 | + $this->_base = $base; |
|
50 | + $this->_min = $min; |
|
51 | + $this->_max = $max; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Initialize from ASN.1. |
|
56 | - * |
|
57 | - * @param Sequence $seq |
|
58 | - * @return self |
|
59 | - */ |
|
60 | - public static function fromASN1(Sequence $seq) |
|
61 | - { |
|
62 | - $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
63 | - $min = 0; |
|
64 | - $max = null; |
|
65 | - if ($seq->hasTagged(0)) { |
|
66 | - $min = $seq->getTagged(0) |
|
67 | - ->asImplicit(Element::TYPE_INTEGER) |
|
68 | - ->asInteger() |
|
69 | - ->number(); |
|
70 | - } |
|
71 | - if ($seq->hasTagged(1)) { |
|
72 | - $max = $seq->getTagged(1) |
|
73 | - ->asImplicit(Element::TYPE_INTEGER) |
|
74 | - ->asInteger() |
|
75 | - ->number(); |
|
76 | - } |
|
77 | - return new self($base, $min, $max); |
|
78 | - } |
|
54 | + /** |
|
55 | + * Initialize from ASN.1. |
|
56 | + * |
|
57 | + * @param Sequence $seq |
|
58 | + * @return self |
|
59 | + */ |
|
60 | + public static function fromASN1(Sequence $seq) |
|
61 | + { |
|
62 | + $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
63 | + $min = 0; |
|
64 | + $max = null; |
|
65 | + if ($seq->hasTagged(0)) { |
|
66 | + $min = $seq->getTagged(0) |
|
67 | + ->asImplicit(Element::TYPE_INTEGER) |
|
68 | + ->asInteger() |
|
69 | + ->number(); |
|
70 | + } |
|
71 | + if ($seq->hasTagged(1)) { |
|
72 | + $max = $seq->getTagged(1) |
|
73 | + ->asImplicit(Element::TYPE_INTEGER) |
|
74 | + ->asInteger() |
|
75 | + ->number(); |
|
76 | + } |
|
77 | + return new self($base, $min, $max); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Get constraint. |
|
82 | - * |
|
83 | - * @return GeneralName |
|
84 | - */ |
|
85 | - public function base() |
|
86 | - { |
|
87 | - return $this->_base; |
|
88 | - } |
|
80 | + /** |
|
81 | + * Get constraint. |
|
82 | + * |
|
83 | + * @return GeneralName |
|
84 | + */ |
|
85 | + public function base() |
|
86 | + { |
|
87 | + return $this->_base; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Generate ASN.1 structure. |
|
92 | - * |
|
93 | - * @return Sequence |
|
94 | - */ |
|
95 | - public function toASN1() |
|
96 | - { |
|
97 | - $elements = array($this->_base->toASN1()); |
|
98 | - if (isset($this->_min) && $this->_min != 0) { |
|
99 | - $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
100 | - } |
|
101 | - if (isset($this->_max)) { |
|
102 | - $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
103 | - } |
|
104 | - return new Sequence(...$elements); |
|
105 | - } |
|
90 | + /** |
|
91 | + * Generate ASN.1 structure. |
|
92 | + * |
|
93 | + * @return Sequence |
|
94 | + */ |
|
95 | + public function toASN1() |
|
96 | + { |
|
97 | + $elements = array($this->_base->toASN1()); |
|
98 | + if (isset($this->_min) && $this->_min != 0) { |
|
99 | + $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
100 | + } |
|
101 | + if (isset($this->_max)) { |
|
102 | + $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
103 | + } |
|
104 | + return new Sequence(...$elements); |
|
105 | + } |
|
106 | 106 | } |
@@ -14,114 +14,114 @@ |
||
14 | 14 | */ |
15 | 15 | class UserNoticeQualifier extends PolicyQualifierInfo |
16 | 16 | { |
17 | - /** |
|
18 | - * Explicit notice text. |
|
19 | - * |
|
20 | - * @var DisplayText $_text |
|
21 | - */ |
|
22 | - protected $_text; |
|
17 | + /** |
|
18 | + * Explicit notice text. |
|
19 | + * |
|
20 | + * @var DisplayText $_text |
|
21 | + */ |
|
22 | + protected $_text; |
|
23 | 23 | |
24 | - /** |
|
25 | - * Notice reference. |
|
26 | - * |
|
27 | - * @var NoticeReference $_ref |
|
28 | - */ |
|
29 | - protected $_ref; |
|
24 | + /** |
|
25 | + * Notice reference. |
|
26 | + * |
|
27 | + * @var NoticeReference $_ref |
|
28 | + */ |
|
29 | + protected $_ref; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor. |
|
33 | - * |
|
34 | - * @param DisplayText|null $text |
|
35 | - * @param NoticeReference|null $ref |
|
36 | - */ |
|
37 | - public function __construct(DisplayText $text = null, NoticeReference $ref = null) |
|
38 | - { |
|
39 | - $this->_oid = self::OID_UNOTICE; |
|
40 | - $this->_text = $text; |
|
41 | - $this->_ref = $ref; |
|
42 | - } |
|
31 | + /** |
|
32 | + * Constructor. |
|
33 | + * |
|
34 | + * @param DisplayText|null $text |
|
35 | + * @param NoticeReference|null $ref |
|
36 | + */ |
|
37 | + public function __construct(DisplayText $text = null, NoticeReference $ref = null) |
|
38 | + { |
|
39 | + $this->_oid = self::OID_UNOTICE; |
|
40 | + $this->_text = $text; |
|
41 | + $this->_ref = $ref; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * @param UnspecifiedType $el |
|
47 | - * @return self |
|
48 | - */ |
|
49 | - public static function fromQualifierASN1(UnspecifiedType $el) |
|
50 | - { |
|
51 | - $seq = $el->asSequence(); |
|
52 | - $ref = null; |
|
53 | - $text = null; |
|
54 | - $idx = 0; |
|
55 | - if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
56 | - $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
57 | - } |
|
58 | - if ($seq->has($idx, Element::TYPE_STRING)) { |
|
59 | - $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
60 | - } |
|
61 | - return new self($text, $ref); |
|
62 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * @param UnspecifiedType $el |
|
47 | + * @return self |
|
48 | + */ |
|
49 | + public static function fromQualifierASN1(UnspecifiedType $el) |
|
50 | + { |
|
51 | + $seq = $el->asSequence(); |
|
52 | + $ref = null; |
|
53 | + $text = null; |
|
54 | + $idx = 0; |
|
55 | + if ($seq->has($idx, Element::TYPE_SEQUENCE)) { |
|
56 | + $ref = NoticeReference::fromASN1($seq->at($idx++)->asSequence()); |
|
57 | + } |
|
58 | + if ($seq->has($idx, Element::TYPE_STRING)) { |
|
59 | + $text = DisplayText::fromASN1($seq->at($idx)->asString()); |
|
60 | + } |
|
61 | + return new self($text, $ref); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Whether explicit text is present. |
|
66 | - * |
|
67 | - * @return bool |
|
68 | - */ |
|
69 | - public function hasExplicitText() |
|
70 | - { |
|
71 | - return isset($this->_text); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Whether explicit text is present. |
|
66 | + * |
|
67 | + * @return bool |
|
68 | + */ |
|
69 | + public function hasExplicitText() |
|
70 | + { |
|
71 | + return isset($this->_text); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Get explicit text. |
|
76 | - * |
|
77 | - * @return DisplayText |
|
78 | - */ |
|
79 | - public function explicitText() |
|
80 | - { |
|
81 | - if (!$this->hasExplicitText()) { |
|
82 | - throw new \LogicException("explicitText not set."); |
|
83 | - } |
|
84 | - return $this->_text; |
|
85 | - } |
|
74 | + /** |
|
75 | + * Get explicit text. |
|
76 | + * |
|
77 | + * @return DisplayText |
|
78 | + */ |
|
79 | + public function explicitText() |
|
80 | + { |
|
81 | + if (!$this->hasExplicitText()) { |
|
82 | + throw new \LogicException("explicitText not set."); |
|
83 | + } |
|
84 | + return $this->_text; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Whether notice reference is present. |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - public function hasNoticeRef() |
|
93 | - { |
|
94 | - return isset($this->_ref); |
|
95 | - } |
|
87 | + /** |
|
88 | + * Whether notice reference is present. |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + public function hasNoticeRef() |
|
93 | + { |
|
94 | + return isset($this->_ref); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Get notice reference. |
|
99 | - * |
|
100 | - * @throws \RuntimeException |
|
101 | - * @return NoticeReference |
|
102 | - */ |
|
103 | - public function noticeRef() |
|
104 | - { |
|
105 | - if (!$this->hasNoticeRef()) { |
|
106 | - throw new \LogicException("noticeRef not set."); |
|
107 | - } |
|
108 | - return $this->_ref; |
|
109 | - } |
|
97 | + /** |
|
98 | + * Get notice reference. |
|
99 | + * |
|
100 | + * @throws \RuntimeException |
|
101 | + * @return NoticeReference |
|
102 | + */ |
|
103 | + public function noticeRef() |
|
104 | + { |
|
105 | + if (!$this->hasNoticeRef()) { |
|
106 | + throw new \LogicException("noticeRef not set."); |
|
107 | + } |
|
108 | + return $this->_ref; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * |
|
113 | - * {@inheritdoc} |
|
114 | - * @return Sequence |
|
115 | - */ |
|
116 | - protected function _qualifierASN1() |
|
117 | - { |
|
118 | - $elements = array(); |
|
119 | - if (isset($this->_ref)) { |
|
120 | - $elements[] = $this->_ref->toASN1(); |
|
121 | - } |
|
122 | - if (isset($this->_text)) { |
|
123 | - $elements[] = $this->_text->toASN1(); |
|
124 | - } |
|
125 | - return new Sequence(...$elements); |
|
126 | - } |
|
111 | + /** |
|
112 | + * |
|
113 | + * {@inheritdoc} |
|
114 | + * @return Sequence |
|
115 | + */ |
|
116 | + protected function _qualifierASN1() |
|
117 | + { |
|
118 | + $elements = array(); |
|
119 | + if (isset($this->_ref)) { |
|
120 | + $elements[] = $this->_ref->toASN1(); |
|
121 | + } |
|
122 | + if (isset($this->_text)) { |
|
123 | + $elements[] = $this->_text->toASN1(); |
|
124 | + } |
|
125 | + return new Sequence(...$elements); |
|
126 | + } |
|
127 | 127 | } |
@@ -17,93 +17,93 @@ |
||
17 | 17 | */ |
18 | 18 | class DisplayText |
19 | 19 | { |
20 | - /** |
|
21 | - * Text. |
|
22 | - * |
|
23 | - * @var string $_text |
|
24 | - */ |
|
25 | - protected $_text; |
|
20 | + /** |
|
21 | + * Text. |
|
22 | + * |
|
23 | + * @var string $_text |
|
24 | + */ |
|
25 | + protected $_text; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Element tag. |
|
29 | - * |
|
30 | - * @var int $_tag |
|
31 | - */ |
|
32 | - protected $_tag; |
|
27 | + /** |
|
28 | + * Element tag. |
|
29 | + * |
|
30 | + * @var int $_tag |
|
31 | + */ |
|
32 | + protected $_tag; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor. |
|
36 | - * |
|
37 | - * @param string $text |
|
38 | - * @param int $tag |
|
39 | - */ |
|
40 | - public function __construct($text, $tag) |
|
41 | - { |
|
42 | - $this->_text = $text; |
|
43 | - $this->_tag = $tag; |
|
44 | - } |
|
34 | + /** |
|
35 | + * Constructor. |
|
36 | + * |
|
37 | + * @param string $text |
|
38 | + * @param int $tag |
|
39 | + */ |
|
40 | + public function __construct($text, $tag) |
|
41 | + { |
|
42 | + $this->_text = $text; |
|
43 | + $this->_tag = $tag; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Initialize from ASN.1. |
|
48 | - * |
|
49 | - * @param StringType $el |
|
50 | - * @return self |
|
51 | - */ |
|
52 | - public static function fromASN1(StringType $el) |
|
53 | - { |
|
54 | - return new self($el->string(), $el->tag()); |
|
55 | - } |
|
46 | + /** |
|
47 | + * Initialize from ASN.1. |
|
48 | + * |
|
49 | + * @param StringType $el |
|
50 | + * @return self |
|
51 | + */ |
|
52 | + public static function fromASN1(StringType $el) |
|
53 | + { |
|
54 | + return new self($el->string(), $el->tag()); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Initialize from a UTF-8 string. |
|
59 | - * |
|
60 | - * @param string $str |
|
61 | - * @return self |
|
62 | - */ |
|
63 | - public static function fromString($str) |
|
64 | - { |
|
65 | - return new self($str, Element::TYPE_UTF8_STRING); |
|
66 | - } |
|
57 | + /** |
|
58 | + * Initialize from a UTF-8 string. |
|
59 | + * |
|
60 | + * @param string $str |
|
61 | + * @return self |
|
62 | + */ |
|
63 | + public static function fromString($str) |
|
64 | + { |
|
65 | + return new self($str, Element::TYPE_UTF8_STRING); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Get the text. |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function string() |
|
74 | - { |
|
75 | - return $this->_text; |
|
76 | - } |
|
68 | + /** |
|
69 | + * Get the text. |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function string() |
|
74 | + { |
|
75 | + return $this->_text; |
|
76 | + } |
|
77 | 77 | |
78 | - /** |
|
79 | - * Generate ASN.1 element. |
|
80 | - * |
|
81 | - * @throws \UnexpectedValueException |
|
82 | - * @return StringType |
|
83 | - */ |
|
84 | - public function toASN1() |
|
85 | - { |
|
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."); |
|
98 | - } |
|
99 | - } |
|
78 | + /** |
|
79 | + * Generate ASN.1 element. |
|
80 | + * |
|
81 | + * @throws \UnexpectedValueException |
|
82 | + * @return StringType |
|
83 | + */ |
|
84 | + public function toASN1() |
|
85 | + { |
|
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."); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * |
|
103 | - * @return string |
|
104 | - */ |
|
105 | - public function __toString() |
|
106 | - { |
|
107 | - return $this->string(); |
|
108 | - } |
|
101 | + /** |
|
102 | + * |
|
103 | + * @return string |
|
104 | + */ |
|
105 | + public function __toString() |
|
106 | + { |
|
107 | + return $this->string(); |
|
108 | + } |
|
109 | 109 | } |
@@ -13,60 +13,60 @@ |
||
13 | 13 | */ |
14 | 14 | class TargetGroup extends Target |
15 | 15 | { |
16 | - /** |
|
17 | - * Group name. |
|
18 | - * |
|
19 | - * @var GeneralName $_name |
|
20 | - */ |
|
21 | - protected $_name; |
|
16 | + /** |
|
17 | + * Group name. |
|
18 | + * |
|
19 | + * @var GeneralName $_name |
|
20 | + */ |
|
21 | + protected $_name; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param GeneralName $name |
|
27 | - */ |
|
28 | - public function __construct(GeneralName $name) |
|
29 | - { |
|
30 | - $this->_name = $name; |
|
31 | - $this->_type = self::TYPE_GROUP; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param GeneralName $name |
|
27 | + */ |
|
28 | + public function __construct(GeneralName $name) |
|
29 | + { |
|
30 | + $this->_name = $name; |
|
31 | + $this->_type = self::TYPE_GROUP; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @param TaggedType $el |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromChosenASN1(TaggedType $el) |
|
40 | - { |
|
41 | - return new self(GeneralName::fromASN1($el)); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param TaggedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(TaggedType $el) |
|
40 | + { |
|
41 | + return new self(GeneralName::fromASN1($el)); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return $this->_name->string(); |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return $this->_name->string(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get group name. |
|
55 | - * |
|
56 | - * @return GeneralName |
|
57 | - */ |
|
58 | - public function name() |
|
59 | - { |
|
60 | - return $this->_name; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get group name. |
|
55 | + * |
|
56 | + * @return GeneralName |
|
57 | + */ |
|
58 | + public function name() |
|
59 | + { |
|
60 | + return $this->_name; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * {@inheritdoc} |
|
66 | - * @return ExplicitlyTaggedType |
|
67 | - */ |
|
68 | - public function toASN1() |
|
69 | - { |
|
70 | - return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
71 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * {@inheritdoc} |
|
66 | + * @return ExplicitlyTaggedType |
|
67 | + */ |
|
68 | + public function toASN1() |
|
69 | + { |
|
70 | + return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
71 | + } |
|
72 | 72 | } |
@@ -13,60 +13,60 @@ |
||
13 | 13 | */ |
14 | 14 | class TargetName extends Target |
15 | 15 | { |
16 | - /** |
|
17 | - * Name. |
|
18 | - * |
|
19 | - * @var GeneralName $_name |
|
20 | - */ |
|
21 | - protected $_name; |
|
16 | + /** |
|
17 | + * Name. |
|
18 | + * |
|
19 | + * @var GeneralName $_name |
|
20 | + */ |
|
21 | + protected $_name; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor. |
|
25 | - * |
|
26 | - * @param GeneralName $name |
|
27 | - */ |
|
28 | - public function __construct(GeneralName $name) |
|
29 | - { |
|
30 | - $this->_name = $name; |
|
31 | - $this->_type = self::TYPE_NAME; |
|
32 | - } |
|
23 | + /** |
|
24 | + * Constructor. |
|
25 | + * |
|
26 | + * @param GeneralName $name |
|
27 | + */ |
|
28 | + public function __construct(GeneralName $name) |
|
29 | + { |
|
30 | + $this->_name = $name; |
|
31 | + $this->_type = self::TYPE_NAME; |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * |
|
36 | - * @param TaggedType $el |
|
37 | - * @return self |
|
38 | - */ |
|
39 | - public static function fromChosenASN1(TaggedType $el) |
|
40 | - { |
|
41 | - return new self(GeneralName::fromASN1($el)); |
|
42 | - } |
|
34 | + /** |
|
35 | + * |
|
36 | + * @param TaggedType $el |
|
37 | + * @return self |
|
38 | + */ |
|
39 | + public static function fromChosenASN1(TaggedType $el) |
|
40 | + { |
|
41 | + return new self(GeneralName::fromASN1($el)); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * |
|
46 | - * {@inheritdoc} |
|
47 | - */ |
|
48 | - public function string() |
|
49 | - { |
|
50 | - return $this->_name->string(); |
|
51 | - } |
|
44 | + /** |
|
45 | + * |
|
46 | + * {@inheritdoc} |
|
47 | + */ |
|
48 | + public function string() |
|
49 | + { |
|
50 | + return $this->_name->string(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Get name. |
|
55 | - * |
|
56 | - * @return GeneralName |
|
57 | - */ |
|
58 | - public function name() |
|
59 | - { |
|
60 | - return $this->_name; |
|
61 | - } |
|
53 | + /** |
|
54 | + * Get name. |
|
55 | + * |
|
56 | + * @return GeneralName |
|
57 | + */ |
|
58 | + public function name() |
|
59 | + { |
|
60 | + return $this->_name; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * |
|
65 | - * {@inheritdoc} |
|
66 | - * @return ExplicitlyTaggedType |
|
67 | - */ |
|
68 | - public function toASN1() |
|
69 | - { |
|
70 | - return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
71 | - } |
|
63 | + /** |
|
64 | + * |
|
65 | + * {@inheritdoc} |
|
66 | + * @return ExplicitlyTaggedType |
|
67 | + */ |
|
68 | + public function toASN1() |
|
69 | + { |
|
70 | + return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
71 | + } |
|
72 | 72 | } |
@@ -11,89 +11,89 @@ |
||
11 | 11 | */ |
12 | 12 | abstract class Target |
13 | 13 | { |
14 | - const TYPE_NAME = 0; |
|
15 | - const TYPE_GROUP = 1; |
|
16 | - const TYPE_CERT = 2; |
|
14 | + const TYPE_NAME = 0; |
|
15 | + const TYPE_GROUP = 1; |
|
16 | + const TYPE_CERT = 2; |
|
17 | 17 | |
18 | - /** |
|
19 | - * Type tag. |
|
20 | - * |
|
21 | - * @var int $_type |
|
22 | - */ |
|
23 | - protected $_type; |
|
18 | + /** |
|
19 | + * Type tag. |
|
20 | + * |
|
21 | + * @var int $_type |
|
22 | + */ |
|
23 | + protected $_type; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Generate ASN.1 element. |
|
27 | - * |
|
28 | - * @return \ASN1\Element |
|
29 | - */ |
|
30 | - abstract public function toASN1(); |
|
25 | + /** |
|
26 | + * Generate ASN.1 element. |
|
27 | + * |
|
28 | + * @return \ASN1\Element |
|
29 | + */ |
|
30 | + abstract public function toASN1(); |
|
31 | 31 | |
32 | - /** |
|
33 | - * Get string value of the target. |
|
34 | - * |
|
35 | - * @return string |
|
36 | - */ |
|
37 | - abstract public function string(); |
|
32 | + /** |
|
33 | + * Get string value of the target. |
|
34 | + * |
|
35 | + * @return string |
|
36 | + */ |
|
37 | + abstract public function string(); |
|
38 | 38 | |
39 | - /** |
|
40 | - * Initialize concrete object from the chosen ASN.1 element. |
|
41 | - * |
|
42 | - * @param TaggedType $el |
|
43 | - * @return self |
|
44 | - */ |
|
45 | - public static function fromChosenASN1(TaggedType $el) |
|
46 | - { |
|
47 | - throw new \BadMethodCallException( |
|
48 | - __FUNCTION__ . " must be implemented in the derived class."); |
|
49 | - } |
|
39 | + /** |
|
40 | + * Initialize concrete object from the chosen ASN.1 element. |
|
41 | + * |
|
42 | + * @param TaggedType $el |
|
43 | + * @return self |
|
44 | + */ |
|
45 | + public static function fromChosenASN1(TaggedType $el) |
|
46 | + { |
|
47 | + throw new \BadMethodCallException( |
|
48 | + __FUNCTION__ . " must be implemented in the derived class."); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Parse from ASN.1. |
|
53 | - * |
|
54 | - * @param TaggedType $el |
|
55 | - * @throws \UnexpectedValueException |
|
56 | - * @return self |
|
57 | - */ |
|
58 | - public static function fromASN1(TaggedType $el) |
|
59 | - { |
|
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."); |
|
68 | - } |
|
69 | - throw new \UnexpectedValueException( |
|
70 | - "Target type " . $el->tag() . " not supported."); |
|
71 | - } |
|
51 | + /** |
|
52 | + * Parse from ASN.1. |
|
53 | + * |
|
54 | + * @param TaggedType $el |
|
55 | + * @throws \UnexpectedValueException |
|
56 | + * @return self |
|
57 | + */ |
|
58 | + public static function fromASN1(TaggedType $el) |
|
59 | + { |
|
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."); |
|
68 | + } |
|
69 | + throw new \UnexpectedValueException( |
|
70 | + "Target type " . $el->tag() . " not supported."); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Get type tag. |
|
75 | - * |
|
76 | - * @return int |
|
77 | - */ |
|
78 | - public function type() |
|
79 | - { |
|
80 | - return $this->_type; |
|
81 | - } |
|
73 | + /** |
|
74 | + * Get type tag. |
|
75 | + * |
|
76 | + * @return int |
|
77 | + */ |
|
78 | + public function type() |
|
79 | + { |
|
80 | + return $this->_type; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Check whether target is equal to another. |
|
85 | - * |
|
86 | - * @param Target $other |
|
87 | - * @return bool |
|
88 | - */ |
|
89 | - public function equals(Target $other) |
|
90 | - { |
|
91 | - if ($this->_type != $other->_type) { |
|
92 | - return false; |
|
93 | - } |
|
94 | - if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) { |
|
95 | - return false; |
|
96 | - } |
|
97 | - return true; |
|
98 | - } |
|
83 | + /** |
|
84 | + * Check whether target is equal to another. |
|
85 | + * |
|
86 | + * @param Target $other |
|
87 | + * @return bool |
|
88 | + */ |
|
89 | + public function equals(Target $other) |
|
90 | + { |
|
91 | + if ($this->_type != $other->_type) { |
|
92 | + return false; |
|
93 | + } |
|
94 | + if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) { |
|
95 | + return false; |
|
96 | + } |
|
97 | + return true; |
|
98 | + } |
|
99 | 99 | } |
@@ -12,131 +12,131 @@ |
||
12 | 12 | */ |
13 | 13 | class Targets implements \Countable, \IteratorAggregate |
14 | 14 | { |
15 | - /** |
|
16 | - * Target elements. |
|
17 | - * |
|
18 | - * @var Target[] $_targets |
|
19 | - */ |
|
20 | - protected $_targets; |
|
15 | + /** |
|
16 | + * Target elements. |
|
17 | + * |
|
18 | + * @var Target[] $_targets |
|
19 | + */ |
|
20 | + protected $_targets; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Constructor. |
|
24 | - * |
|
25 | - * @param Target ...$targets |
|
26 | - */ |
|
27 | - public function __construct(Target ...$targets) |
|
28 | - { |
|
29 | - $this->_targets = $targets; |
|
30 | - } |
|
22 | + /** |
|
23 | + * Constructor. |
|
24 | + * |
|
25 | + * @param Target ...$targets |
|
26 | + */ |
|
27 | + public function __construct(Target ...$targets) |
|
28 | + { |
|
29 | + $this->_targets = $targets; |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Initialize from ASN.1. |
|
34 | - * |
|
35 | - * @param Sequence $seq |
|
36 | - * @return self |
|
37 | - */ |
|
38 | - public static function fromASN1(Sequence $seq) |
|
39 | - { |
|
40 | - $targets = array_map( |
|
41 | - function (UnspecifiedType $el) { |
|
42 | - return Target::fromASN1($el->asTagged()); |
|
43 | - }, $seq->elements()); |
|
44 | - return new self(...$targets); |
|
45 | - } |
|
32 | + /** |
|
33 | + * Initialize from ASN.1. |
|
34 | + * |
|
35 | + * @param Sequence $seq |
|
36 | + * @return self |
|
37 | + */ |
|
38 | + public static function fromASN1(Sequence $seq) |
|
39 | + { |
|
40 | + $targets = array_map( |
|
41 | + function (UnspecifiedType $el) { |
|
42 | + return Target::fromASN1($el->asTagged()); |
|
43 | + }, $seq->elements()); |
|
44 | + return new self(...$targets); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Get all targets. |
|
49 | - * |
|
50 | - * @return Target[] |
|
51 | - */ |
|
52 | - public function all() |
|
53 | - { |
|
54 | - return $this->_targets; |
|
55 | - } |
|
47 | + /** |
|
48 | + * Get all targets. |
|
49 | + * |
|
50 | + * @return Target[] |
|
51 | + */ |
|
52 | + public function all() |
|
53 | + { |
|
54 | + return $this->_targets; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get all targets of given type. |
|
59 | - * |
|
60 | - * @param int $type |
|
61 | - * @return Target[] |
|
62 | - */ |
|
63 | - protected function _allOfType($type) |
|
64 | - { |
|
65 | - return array_values( |
|
66 | - array_filter($this->_targets, |
|
67 | - function (Target $target) use ($type) { |
|
68 | - return $target->type() == $type; |
|
69 | - })); |
|
70 | - } |
|
57 | + /** |
|
58 | + * Get all targets of given type. |
|
59 | + * |
|
60 | + * @param int $type |
|
61 | + * @return Target[] |
|
62 | + */ |
|
63 | + protected function _allOfType($type) |
|
64 | + { |
|
65 | + return array_values( |
|
66 | + array_filter($this->_targets, |
|
67 | + function (Target $target) use ($type) { |
|
68 | + return $target->type() == $type; |
|
69 | + })); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Get all name targets. |
|
74 | - * |
|
75 | - * @return Target[] |
|
76 | - */ |
|
77 | - public function nameTargets() |
|
78 | - { |
|
79 | - return $this->_allOfType(Target::TYPE_NAME); |
|
80 | - } |
|
72 | + /** |
|
73 | + * Get all name targets. |
|
74 | + * |
|
75 | + * @return Target[] |
|
76 | + */ |
|
77 | + public function nameTargets() |
|
78 | + { |
|
79 | + return $this->_allOfType(Target::TYPE_NAME); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Get all group targets. |
|
84 | - * |
|
85 | - * @return Target[] |
|
86 | - */ |
|
87 | - public function groupTargets() |
|
88 | - { |
|
89 | - return $this->_allOfType(Target::TYPE_GROUP); |
|
90 | - } |
|
82 | + /** |
|
83 | + * Get all group targets. |
|
84 | + * |
|
85 | + * @return Target[] |
|
86 | + */ |
|
87 | + public function groupTargets() |
|
88 | + { |
|
89 | + return $this->_allOfType(Target::TYPE_GROUP); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Check whether given target is present. |
|
94 | - * |
|
95 | - * @param Target $target |
|
96 | - * @return boolean |
|
97 | - */ |
|
98 | - public function hasTarget(Target $target) |
|
99 | - { |
|
100 | - foreach ($this->_allOfType($target->type()) as $t) { |
|
101 | - if ($target->equals($t)) { |
|
102 | - return true; |
|
103 | - } |
|
104 | - } |
|
105 | - return false; |
|
106 | - } |
|
92 | + /** |
|
93 | + * Check whether given target is present. |
|
94 | + * |
|
95 | + * @param Target $target |
|
96 | + * @return boolean |
|
97 | + */ |
|
98 | + public function hasTarget(Target $target) |
|
99 | + { |
|
100 | + foreach ($this->_allOfType($target->type()) as $t) { |
|
101 | + if ($target->equals($t)) { |
|
102 | + return true; |
|
103 | + } |
|
104 | + } |
|
105 | + return false; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Generate ASN.1 structure. |
|
110 | - * |
|
111 | - * @return Sequence |
|
112 | - */ |
|
113 | - public function toASN1() |
|
114 | - { |
|
115 | - $elements = array_map( |
|
116 | - function (Target $target) { |
|
117 | - return $target->toASN1(); |
|
118 | - }, $this->_targets); |
|
119 | - return new Sequence(...$elements); |
|
120 | - } |
|
108 | + /** |
|
109 | + * Generate ASN.1 structure. |
|
110 | + * |
|
111 | + * @return Sequence |
|
112 | + */ |
|
113 | + public function toASN1() |
|
114 | + { |
|
115 | + $elements = array_map( |
|
116 | + function (Target $target) { |
|
117 | + return $target->toASN1(); |
|
118 | + }, $this->_targets); |
|
119 | + return new Sequence(...$elements); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * |
|
124 | - * @see \Countable::count() |
|
125 | - * @return int |
|
126 | - */ |
|
127 | - public function count() |
|
128 | - { |
|
129 | - return count($this->_targets); |
|
130 | - } |
|
122 | + /** |
|
123 | + * |
|
124 | + * @see \Countable::count() |
|
125 | + * @return int |
|
126 | + */ |
|
127 | + public function count() |
|
128 | + { |
|
129 | + return count($this->_targets); |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Get iterator for targets. |
|
134 | - * |
|
135 | - * @see \IteratorAggregate::getIterator() |
|
136 | - * @return \ArrayIterator |
|
137 | - */ |
|
138 | - public function getIterator() |
|
139 | - { |
|
140 | - return new \ArrayIterator($this->_targets); |
|
141 | - } |
|
132 | + /** |
|
133 | + * Get iterator for targets. |
|
134 | + * |
|
135 | + * @see \IteratorAggregate::getIterator() |
|
136 | + * @return \ArrayIterator |
|
137 | + */ |
|
138 | + public function getIterator() |
|
139 | + { |
|
140 | + return new \ArrayIterator($this->_targets); |
|
141 | + } |
|
142 | 142 | } |
@@ -16,172 +16,172 @@ |
||
16 | 16 | */ |
17 | 17 | class CertificationRequest |
18 | 18 | { |
19 | - /** |
|
20 | - * Certification request info. |
|
21 | - * |
|
22 | - * @var CertificationRequestInfo $_certificationRequestInfo |
|
23 | - */ |
|
24 | - protected $_certificationRequestInfo; |
|
19 | + /** |
|
20 | + * Certification request info. |
|
21 | + * |
|
22 | + * @var CertificationRequestInfo $_certificationRequestInfo |
|
23 | + */ |
|
24 | + protected $_certificationRequestInfo; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Signature algorithm. |
|
28 | - * |
|
29 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
30 | - */ |
|
31 | - protected $_signatureAlgorithm; |
|
26 | + /** |
|
27 | + * Signature algorithm. |
|
28 | + * |
|
29 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
30 | + */ |
|
31 | + protected $_signatureAlgorithm; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Signature. |
|
35 | - * |
|
36 | - * @var Signature $_signature |
|
37 | - */ |
|
38 | - protected $_signature; |
|
33 | + /** |
|
34 | + * Signature. |
|
35 | + * |
|
36 | + * @var Signature $_signature |
|
37 | + */ |
|
38 | + protected $_signature; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor. |
|
42 | - * |
|
43 | - * @param CertificationRequestInfo $info |
|
44 | - * @param SignatureAlgorithmIdentifier $algo |
|
45 | - * @param Signature $signature |
|
46 | - */ |
|
47 | - public function __construct(CertificationRequestInfo $info, |
|
48 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
49 | - { |
|
50 | - $this->_certificationRequestInfo = $info; |
|
51 | - $this->_signatureAlgorithm = $algo; |
|
52 | - $this->_signature = $signature; |
|
53 | - } |
|
40 | + /** |
|
41 | + * Constructor. |
|
42 | + * |
|
43 | + * @param CertificationRequestInfo $info |
|
44 | + * @param SignatureAlgorithmIdentifier $algo |
|
45 | + * @param Signature $signature |
|
46 | + */ |
|
47 | + public function __construct(CertificationRequestInfo $info, |
|
48 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
49 | + { |
|
50 | + $this->_certificationRequestInfo = $info; |
|
51 | + $this->_signatureAlgorithm = $algo; |
|
52 | + $this->_signature = $signature; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Initialize from ASN.1. |
|
57 | - * |
|
58 | - * @param Sequence $seq |
|
59 | - * @return self |
|
60 | - */ |
|
61 | - public static function fromASN1(Sequence $seq) |
|
62 | - { |
|
63 | - $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
64 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
65 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
66 | - throw new \UnexpectedValueException( |
|
67 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
68 | - } |
|
69 | - $signature = Signature::fromSignatureData( |
|
70 | - $seq->at(2) |
|
71 | - ->asBitString() |
|
72 | - ->string(), $algo); |
|
73 | - return new self($info, $algo, $signature); |
|
74 | - } |
|
55 | + /** |
|
56 | + * Initialize from ASN.1. |
|
57 | + * |
|
58 | + * @param Sequence $seq |
|
59 | + * @return self |
|
60 | + */ |
|
61 | + public static function fromASN1(Sequence $seq) |
|
62 | + { |
|
63 | + $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
64 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
65 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
66 | + throw new \UnexpectedValueException( |
|
67 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
68 | + } |
|
69 | + $signature = Signature::fromSignatureData( |
|
70 | + $seq->at(2) |
|
71 | + ->asBitString() |
|
72 | + ->string(), $algo); |
|
73 | + return new self($info, $algo, $signature); |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Initialize from DER. |
|
78 | - * |
|
79 | - * @param string $data |
|
80 | - * @return self |
|
81 | - */ |
|
82 | - public static function fromDER($data) |
|
83 | - { |
|
84 | - return self::fromASN1(Sequence::fromDER($data)); |
|
85 | - } |
|
76 | + /** |
|
77 | + * Initialize from DER. |
|
78 | + * |
|
79 | + * @param string $data |
|
80 | + * @return self |
|
81 | + */ |
|
82 | + public static function fromDER($data) |
|
83 | + { |
|
84 | + return self::fromASN1(Sequence::fromDER($data)); |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Initialize from PEM. |
|
89 | - * |
|
90 | - * @param PEM $pem |
|
91 | - * @throws \UnexpectedValueException |
|
92 | - * @return self |
|
93 | - */ |
|
94 | - public static function fromPEM(PEM $pem) |
|
95 | - { |
|
96 | - if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
97 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
98 | - } |
|
99 | - return self::fromDER($pem->data()); |
|
100 | - } |
|
87 | + /** |
|
88 | + * Initialize from PEM. |
|
89 | + * |
|
90 | + * @param PEM $pem |
|
91 | + * @throws \UnexpectedValueException |
|
92 | + * @return self |
|
93 | + */ |
|
94 | + public static function fromPEM(PEM $pem) |
|
95 | + { |
|
96 | + if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
97 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
98 | + } |
|
99 | + return self::fromDER($pem->data()); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Get certification request info. |
|
104 | - * |
|
105 | - * @return CertificationRequestInfo |
|
106 | - */ |
|
107 | - public function certificationRequestInfo() |
|
108 | - { |
|
109 | - return $this->_certificationRequestInfo; |
|
110 | - } |
|
102 | + /** |
|
103 | + * Get certification request info. |
|
104 | + * |
|
105 | + * @return CertificationRequestInfo |
|
106 | + */ |
|
107 | + public function certificationRequestInfo() |
|
108 | + { |
|
109 | + return $this->_certificationRequestInfo; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Get signature algorithm. |
|
114 | - * |
|
115 | - * @return SignatureAlgorithmIdentifier |
|
116 | - */ |
|
117 | - public function signatureAlgorithm() |
|
118 | - { |
|
119 | - return $this->_signatureAlgorithm; |
|
120 | - } |
|
112 | + /** |
|
113 | + * Get signature algorithm. |
|
114 | + * |
|
115 | + * @return SignatureAlgorithmIdentifier |
|
116 | + */ |
|
117 | + public function signatureAlgorithm() |
|
118 | + { |
|
119 | + return $this->_signatureAlgorithm; |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Get signature. |
|
124 | - * |
|
125 | - * @return Signature |
|
126 | - */ |
|
127 | - public function signature() |
|
128 | - { |
|
129 | - return $this->_signature; |
|
130 | - } |
|
122 | + /** |
|
123 | + * Get signature. |
|
124 | + * |
|
125 | + * @return Signature |
|
126 | + */ |
|
127 | + public function signature() |
|
128 | + { |
|
129 | + return $this->_signature; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Generate ASN.1 structure. |
|
134 | - * |
|
135 | - * @return Sequence |
|
136 | - */ |
|
137 | - public function toASN1() |
|
138 | - { |
|
139 | - return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
140 | - $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
141 | - } |
|
132 | + /** |
|
133 | + * Generate ASN.1 structure. |
|
134 | + * |
|
135 | + * @return Sequence |
|
136 | + */ |
|
137 | + public function toASN1() |
|
138 | + { |
|
139 | + return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
140 | + $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Get certification request as a DER. |
|
145 | - * |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function toDER() |
|
149 | - { |
|
150 | - return $this->toASN1()->toDER(); |
|
151 | - } |
|
143 | + /** |
|
144 | + * Get certification request as a DER. |
|
145 | + * |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function toDER() |
|
149 | + { |
|
150 | + return $this->toASN1()->toDER(); |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * Get certification request as a PEM. |
|
155 | - * |
|
156 | - * @return PEM |
|
157 | - */ |
|
158 | - public function toPEM() |
|
159 | - { |
|
160 | - return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
161 | - } |
|
153 | + /** |
|
154 | + * Get certification request as a PEM. |
|
155 | + * |
|
156 | + * @return PEM |
|
157 | + */ |
|
158 | + public function toPEM() |
|
159 | + { |
|
160 | + return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
161 | + } |
|
162 | 162 | |
163 | - /** |
|
164 | - * Verify certification request signature. |
|
165 | - * |
|
166 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
167 | - * @return bool True if signature matches |
|
168 | - */ |
|
169 | - public function verify(Crypto $crypto = null) |
|
170 | - { |
|
171 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
172 | - $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
173 | - $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
174 | - return $crypto->verify($data, $this->_signature, $pk_info, |
|
175 | - $this->_signatureAlgorithm); |
|
176 | - } |
|
163 | + /** |
|
164 | + * Verify certification request signature. |
|
165 | + * |
|
166 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
167 | + * @return bool True if signature matches |
|
168 | + */ |
|
169 | + public function verify(Crypto $crypto = null) |
|
170 | + { |
|
171 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
172 | + $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
173 | + $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
174 | + return $crypto->verify($data, $this->_signature, $pk_info, |
|
175 | + $this->_signatureAlgorithm); |
|
176 | + } |
|
177 | 177 | |
178 | - /** |
|
179 | - * Get certification request as a PEM formatted string. |
|
180 | - * |
|
181 | - * @return string |
|
182 | - */ |
|
183 | - public function __toString() |
|
184 | - { |
|
185 | - return $this->toPEM()->string(); |
|
186 | - } |
|
178 | + /** |
|
179 | + * Get certification request as a PEM formatted string. |
|
180 | + * |
|
181 | + * @return string |
|
182 | + */ |
|
183 | + public function __toString() |
|
184 | + { |
|
185 | + return $this->toPEM()->string(); |
|
186 | + } |
|
187 | 187 | } |