@@ -14,16 +14,16 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class TitleValue extends DirectoryString |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Constructor. |
|
| 19 | - * |
|
| 20 | - * @param string $value String value |
|
| 21 | - * @param int $string_tag Syntax choice |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $value, |
|
| 24 | - int $string_tag = DirectoryString::UTF8) |
|
| 25 | - { |
|
| 26 | - $this->_oid = AttributeType::OID_TITLE; |
|
| 27 | - parent::__construct($value, $string_tag); |
|
| 28 | - } |
|
| 17 | + /** |
|
| 18 | + * Constructor. |
|
| 19 | + * |
|
| 20 | + * @param string $value String value |
|
| 21 | + * @param int $string_tag Syntax choice |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $value, |
|
| 24 | + int $string_tag = DirectoryString::UTF8) |
|
| 25 | + { |
|
| 26 | + $this->_oid = AttributeType::OID_TITLE; |
|
| 27 | + parent::__construct($value, $string_tag); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -25,156 +25,156 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | abstract class DirectoryString extends AttributeValue |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * Teletex string syntax. |
|
| 30 | - * |
|
| 31 | - * @var int |
|
| 32 | - */ |
|
| 33 | - const TELETEX = Element::TYPE_T61_STRING; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Printable string syntax. |
|
| 37 | - * |
|
| 38 | - * @var int |
|
| 39 | - */ |
|
| 40 | - const PRINTABLE = Element::TYPE_PRINTABLE_STRING; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * BMP string syntax. |
|
| 44 | - * |
|
| 45 | - * @var int |
|
| 46 | - */ |
|
| 47 | - const BMP = Element::TYPE_BMP_STRING; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Universal string syntax. |
|
| 51 | - * |
|
| 52 | - * @var int |
|
| 53 | - */ |
|
| 54 | - const UNIVERSAL = Element::TYPE_UNIVERSAL_STRING; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * UTF-8 string syntax. |
|
| 58 | - * |
|
| 59 | - * @var int |
|
| 60 | - */ |
|
| 61 | - const UTF8 = Element::TYPE_UTF8_STRING; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Mapping from syntax enumeration to ASN.1 class name. |
|
| 65 | - * |
|
| 66 | - * @internal |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - const MAP_TAG_TO_CLASS = [ |
|
| 71 | - self::TELETEX => T61String::class, |
|
| 72 | - self::PRINTABLE => PrintableString::class, |
|
| 73 | - self::UNIVERSAL => UniversalString::class, |
|
| 74 | - self::UTF8 => UTF8String::class, |
|
| 75 | - self::BMP => BMPString::class, |
|
| 76 | - ]; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * ASN.1 type tag for the chosen syntax. |
|
| 80 | - * |
|
| 81 | - * @var int |
|
| 82 | - */ |
|
| 83 | - protected $_stringTag; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * String value. |
|
| 87 | - * |
|
| 88 | - * @var string |
|
| 89 | - */ |
|
| 90 | - protected $_string; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Constructor. |
|
| 94 | - * |
|
| 95 | - * @param string $value String value |
|
| 96 | - * @param int $string_tag Syntax choice |
|
| 97 | - */ |
|
| 98 | - public function __construct(string $value, int $string_tag) |
|
| 99 | - { |
|
| 100 | - $this->_string = $value; |
|
| 101 | - $this->_stringTag = $string_tag; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * {@inheritdoc} |
|
| 106 | - * |
|
| 107 | - * @return self |
|
| 108 | - */ |
|
| 109 | - public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 110 | - { |
|
| 111 | - $tag = $el->tag(); |
|
| 112 | - self::_tagToASN1Class($tag); |
|
| 113 | - return new static($el->asString()->string(), $tag); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * {@inheritdoc} |
|
| 118 | - */ |
|
| 119 | - public function toASN1(): Element |
|
| 120 | - { |
|
| 121 | - $cls = self::_tagToASN1Class($this->_stringTag); |
|
| 122 | - return new $cls($this->_string); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * {@inheritdoc} |
|
| 127 | - */ |
|
| 128 | - public function stringValue(): string |
|
| 129 | - { |
|
| 130 | - return $this->_string; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * {@inheritdoc} |
|
| 135 | - */ |
|
| 136 | - public function equalityMatchingRule(): MatchingRule |
|
| 137 | - { |
|
| 138 | - return new CaseIgnoreMatch($this->_stringTag); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * {@inheritdoc} |
|
| 143 | - */ |
|
| 144 | - public function rfc2253String(): string |
|
| 145 | - { |
|
| 146 | - // TeletexString is encoded as binary |
|
| 147 | - if (self::TELETEX == $this->_stringTag) { |
|
| 148 | - return $this->_transcodedString(); |
|
| 149 | - } |
|
| 150 | - return DNParser::escapeString($this->_transcodedString()); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * {@inheritdoc} |
|
| 155 | - */ |
|
| 156 | - protected function _transcodedString(): string |
|
| 157 | - { |
|
| 158 | - $step = new TranscodeStep($this->_stringTag); |
|
| 159 | - return $step->apply($this->_string); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get ASN.1 class name for given DirectoryString type tag. |
|
| 164 | - * |
|
| 165 | - * @param int $tag |
|
| 166 | - * |
|
| 167 | - * @throws \UnexpectedValueException |
|
| 168 | - * |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 171 | - private static function _tagToASN1Class(int $tag): string |
|
| 172 | - { |
|
| 173 | - if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) { |
|
| 174 | - throw new \UnexpectedValueException( |
|
| 175 | - 'Type ' . Element::tagToName($tag) . |
|
| 176 | - ' is not valid DirectoryString.'); |
|
| 177 | - } |
|
| 178 | - return self::MAP_TAG_TO_CLASS[$tag]; |
|
| 179 | - } |
|
| 28 | + /** |
|
| 29 | + * Teletex string syntax. |
|
| 30 | + * |
|
| 31 | + * @var int |
|
| 32 | + */ |
|
| 33 | + const TELETEX = Element::TYPE_T61_STRING; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Printable string syntax. |
|
| 37 | + * |
|
| 38 | + * @var int |
|
| 39 | + */ |
|
| 40 | + const PRINTABLE = Element::TYPE_PRINTABLE_STRING; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * BMP string syntax. |
|
| 44 | + * |
|
| 45 | + * @var int |
|
| 46 | + */ |
|
| 47 | + const BMP = Element::TYPE_BMP_STRING; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Universal string syntax. |
|
| 51 | + * |
|
| 52 | + * @var int |
|
| 53 | + */ |
|
| 54 | + const UNIVERSAL = Element::TYPE_UNIVERSAL_STRING; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * UTF-8 string syntax. |
|
| 58 | + * |
|
| 59 | + * @var int |
|
| 60 | + */ |
|
| 61 | + const UTF8 = Element::TYPE_UTF8_STRING; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Mapping from syntax enumeration to ASN.1 class name. |
|
| 65 | + * |
|
| 66 | + * @internal |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + const MAP_TAG_TO_CLASS = [ |
|
| 71 | + self::TELETEX => T61String::class, |
|
| 72 | + self::PRINTABLE => PrintableString::class, |
|
| 73 | + self::UNIVERSAL => UniversalString::class, |
|
| 74 | + self::UTF8 => UTF8String::class, |
|
| 75 | + self::BMP => BMPString::class, |
|
| 76 | + ]; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * ASN.1 type tag for the chosen syntax. |
|
| 80 | + * |
|
| 81 | + * @var int |
|
| 82 | + */ |
|
| 83 | + protected $_stringTag; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * String value. |
|
| 87 | + * |
|
| 88 | + * @var string |
|
| 89 | + */ |
|
| 90 | + protected $_string; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Constructor. |
|
| 94 | + * |
|
| 95 | + * @param string $value String value |
|
| 96 | + * @param int $string_tag Syntax choice |
|
| 97 | + */ |
|
| 98 | + public function __construct(string $value, int $string_tag) |
|
| 99 | + { |
|
| 100 | + $this->_string = $value; |
|
| 101 | + $this->_stringTag = $string_tag; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * {@inheritdoc} |
|
| 106 | + * |
|
| 107 | + * @return self |
|
| 108 | + */ |
|
| 109 | + public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 110 | + { |
|
| 111 | + $tag = $el->tag(); |
|
| 112 | + self::_tagToASN1Class($tag); |
|
| 113 | + return new static($el->asString()->string(), $tag); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * {@inheritdoc} |
|
| 118 | + */ |
|
| 119 | + public function toASN1(): Element |
|
| 120 | + { |
|
| 121 | + $cls = self::_tagToASN1Class($this->_stringTag); |
|
| 122 | + return new $cls($this->_string); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * {@inheritdoc} |
|
| 127 | + */ |
|
| 128 | + public function stringValue(): string |
|
| 129 | + { |
|
| 130 | + return $this->_string; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * {@inheritdoc} |
|
| 135 | + */ |
|
| 136 | + public function equalityMatchingRule(): MatchingRule |
|
| 137 | + { |
|
| 138 | + return new CaseIgnoreMatch($this->_stringTag); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * {@inheritdoc} |
|
| 143 | + */ |
|
| 144 | + public function rfc2253String(): string |
|
| 145 | + { |
|
| 146 | + // TeletexString is encoded as binary |
|
| 147 | + if (self::TELETEX == $this->_stringTag) { |
|
| 148 | + return $this->_transcodedString(); |
|
| 149 | + } |
|
| 150 | + return DNParser::escapeString($this->_transcodedString()); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * {@inheritdoc} |
|
| 155 | + */ |
|
| 156 | + protected function _transcodedString(): string |
|
| 157 | + { |
|
| 158 | + $step = new TranscodeStep($this->_stringTag); |
|
| 159 | + return $step->apply($this->_string); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get ASN.1 class name for given DirectoryString type tag. |
|
| 164 | + * |
|
| 165 | + * @param int $tag |
|
| 166 | + * |
|
| 167 | + * @throws \UnexpectedValueException |
|
| 168 | + * |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | + private static function _tagToASN1Class(int $tag): string |
|
| 172 | + { |
|
| 173 | + if (!array_key_exists($tag, self::MAP_TAG_TO_CLASS)) { |
|
| 174 | + throw new \UnexpectedValueException( |
|
| 175 | + 'Type ' . Element::tagToName($tag) . |
|
| 176 | + ' is not valid DirectoryString.'); |
|
| 177 | + } |
|
| 178 | + return self::MAP_TAG_TO_CLASS[$tag]; |
|
| 179 | + } |
|
| 180 | 180 | } |
@@ -17,72 +17,72 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | abstract class PrintableStringValue extends AttributeValue |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * String value. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $_string; |
|
| 20 | + /** |
|
| 21 | + * String value. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $_string; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Constructor. |
|
| 29 | - * |
|
| 30 | - * @param string $value String value |
|
| 31 | - */ |
|
| 32 | - public function __construct(string $value) |
|
| 33 | - { |
|
| 34 | - $this->_string = $value; |
|
| 35 | - } |
|
| 27 | + /** |
|
| 28 | + * Constructor. |
|
| 29 | + * |
|
| 30 | + * @param string $value String value |
|
| 31 | + */ |
|
| 32 | + public function __construct(string $value) |
|
| 33 | + { |
|
| 34 | + $this->_string = $value; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * {@inheritdoc} |
|
| 39 | - * |
|
| 40 | - * @return self |
|
| 41 | - */ |
|
| 42 | - public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 43 | - { |
|
| 44 | - return new static($el->asPrintableString()->string()); |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * {@inheritdoc} |
|
| 39 | + * |
|
| 40 | + * @return self |
|
| 41 | + */ |
|
| 42 | + public static function fromASN1(UnspecifiedType $el): AttributeValue |
|
| 43 | + { |
|
| 44 | + return new static($el->asPrintableString()->string()); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritdoc} |
|
| 49 | - */ |
|
| 50 | - public function toASN1(): Element |
|
| 51 | - { |
|
| 52 | - return new PrintableString($this->_string); |
|
| 53 | - } |
|
| 47 | + /** |
|
| 48 | + * {@inheritdoc} |
|
| 49 | + */ |
|
| 50 | + public function toASN1(): Element |
|
| 51 | + { |
|
| 52 | + return new PrintableString($this->_string); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * {@inheritdoc} |
|
| 57 | - */ |
|
| 58 | - public function stringValue(): string |
|
| 59 | - { |
|
| 60 | - return $this->_string; |
|
| 61 | - } |
|
| 55 | + /** |
|
| 56 | + * {@inheritdoc} |
|
| 57 | + */ |
|
| 58 | + public function stringValue(): string |
|
| 59 | + { |
|
| 60 | + return $this->_string; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * {@inheritdoc} |
|
| 65 | - */ |
|
| 66 | - public function equalityMatchingRule(): MatchingRule |
|
| 67 | - { |
|
| 68 | - // default to caseIgnoreMatch |
|
| 69 | - return new CaseIgnoreMatch(Element::TYPE_PRINTABLE_STRING); |
|
| 70 | - } |
|
| 63 | + /** |
|
| 64 | + * {@inheritdoc} |
|
| 65 | + */ |
|
| 66 | + public function equalityMatchingRule(): MatchingRule |
|
| 67 | + { |
|
| 68 | + // default to caseIgnoreMatch |
|
| 69 | + return new CaseIgnoreMatch(Element::TYPE_PRINTABLE_STRING); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * {@inheritdoc} |
|
| 74 | - */ |
|
| 75 | - public function rfc2253String(): string |
|
| 76 | - { |
|
| 77 | - return DNParser::escapeString($this->_transcodedString()); |
|
| 78 | - } |
|
| 72 | + /** |
|
| 73 | + * {@inheritdoc} |
|
| 74 | + */ |
|
| 75 | + public function rfc2253String(): string |
|
| 76 | + { |
|
| 77 | + return DNParser::escapeString($this->_transcodedString()); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * {@inheritdoc} |
|
| 82 | - */ |
|
| 83 | - protected function _transcodedString(): string |
|
| 84 | - { |
|
| 85 | - // PrintableString maps directly to UTF-8 |
|
| 86 | - return $this->_string; |
|
| 87 | - } |
|
| 80 | + /** |
|
| 81 | + * {@inheritdoc} |
|
| 82 | + */ |
|
| 83 | + protected function _transcodedString(): string |
|
| 84 | + { |
|
| 85 | + // PrintableString maps directly to UTF-8 |
|
| 86 | + return $this->_string; |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -14,16 +14,16 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class SurnameValue extends DirectoryString |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Constructor. |
|
| 19 | - * |
|
| 20 | - * @param string $value String value |
|
| 21 | - * @param int $string_tag Syntax choice |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $value, |
|
| 24 | - int $string_tag = DirectoryString::UTF8) |
|
| 25 | - { |
|
| 26 | - $this->_oid = AttributeType::OID_SURNAME; |
|
| 27 | - parent::__construct($value, $string_tag); |
|
| 28 | - } |
|
| 17 | + /** |
|
| 18 | + * Constructor. |
|
| 19 | + * |
|
| 20 | + * @param string $value String value |
|
| 21 | + * @param int $string_tag Syntax choice |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $value, |
|
| 24 | + int $string_tag = DirectoryString::UTF8) |
|
| 25 | + { |
|
| 26 | + $this->_oid = AttributeType::OID_SURNAME; |
|
| 27 | + parent::__construct($value, $string_tag); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -13,63 +13,63 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class UnknownAttributeValue extends AttributeValue |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * ASN.1 element. |
|
| 18 | - * |
|
| 19 | - * @var Element |
|
| 20 | - */ |
|
| 21 | - protected $_element; |
|
| 16 | + /** |
|
| 17 | + * ASN.1 element. |
|
| 18 | + * |
|
| 19 | + * @var Element |
|
| 20 | + */ |
|
| 21 | + protected $_element; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Constructor. |
|
| 25 | - * |
|
| 26 | - * @param string $oid |
|
| 27 | - * @param Element $el |
|
| 28 | - */ |
|
| 29 | - public function __construct(string $oid, Element $el) |
|
| 30 | - { |
|
| 31 | - $this->_oid = $oid; |
|
| 32 | - $this->_element = $el; |
|
| 33 | - } |
|
| 23 | + /** |
|
| 24 | + * Constructor. |
|
| 25 | + * |
|
| 26 | + * @param string $oid |
|
| 27 | + * @param Element $el |
|
| 28 | + */ |
|
| 29 | + public function __construct(string $oid, Element $el) |
|
| 30 | + { |
|
| 31 | + $this->_oid = $oid; |
|
| 32 | + $this->_element = $el; |
|
| 33 | + } |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * {@inheritdoc} |
|
| 37 | - */ |
|
| 38 | - public function toASN1(): Element |
|
| 39 | - { |
|
| 40 | - return $this->_element; |
|
| 41 | - } |
|
| 35 | + /** |
|
| 36 | + * {@inheritdoc} |
|
| 37 | + */ |
|
| 38 | + public function toASN1(): Element |
|
| 39 | + { |
|
| 40 | + return $this->_element; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * {@inheritdoc} |
|
| 45 | - */ |
|
| 46 | - public function stringValue(): string |
|
| 47 | - { |
|
| 48 | - // return DER encoding as a hexstring |
|
| 49 | - return '#' . bin2hex($this->_element->toDER()); |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * {@inheritdoc} |
|
| 45 | + */ |
|
| 46 | + public function stringValue(): string |
|
| 47 | + { |
|
| 48 | + // return DER encoding as a hexstring |
|
| 49 | + return '#' . bin2hex($this->_element->toDER()); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritdoc} |
|
| 54 | - */ |
|
| 55 | - public function equalityMatchingRule(): MatchingRule |
|
| 56 | - { |
|
| 57 | - return new BinaryMatch(); |
|
| 58 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritdoc} |
|
| 54 | + */ |
|
| 55 | + public function equalityMatchingRule(): MatchingRule |
|
| 56 | + { |
|
| 57 | + return new BinaryMatch(); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * {@inheritdoc} |
|
| 62 | - */ |
|
| 63 | - public function rfc2253String(): string |
|
| 64 | - { |
|
| 65 | - return $this->stringValue(); |
|
| 66 | - } |
|
| 60 | + /** |
|
| 61 | + * {@inheritdoc} |
|
| 62 | + */ |
|
| 63 | + public function rfc2253String(): string |
|
| 64 | + { |
|
| 65 | + return $this->stringValue(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * {@inheritdoc} |
|
| 70 | - */ |
|
| 71 | - protected function _transcodedString(): string |
|
| 72 | - { |
|
| 73 | - return $this->stringValue(); |
|
| 74 | - } |
|
| 68 | + /** |
|
| 69 | + * {@inheritdoc} |
|
| 70 | + */ |
|
| 71 | + protected function _transcodedString(): string |
|
| 72 | + { |
|
| 73 | + return $this->stringValue(); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -14,16 +14,16 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class PseudonymValue extends DirectoryString |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Constructor. |
|
| 19 | - * |
|
| 20 | - * @param string $value String value |
|
| 21 | - * @param int $string_tag Syntax choice |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $value, |
|
| 24 | - int $string_tag = DirectoryString::UTF8) |
|
| 25 | - { |
|
| 26 | - $this->_oid = AttributeType::OID_PSEUDONYM; |
|
| 27 | - parent::__construct($value, $string_tag); |
|
| 28 | - } |
|
| 17 | + /** |
|
| 18 | + * Constructor. |
|
| 19 | + * |
|
| 20 | + * @param string $value String value |
|
| 21 | + * @param int $string_tag Syntax choice |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $value, |
|
| 24 | + int $string_tag = DirectoryString::UTF8) |
|
| 25 | + { |
|
| 26 | + $this->_oid = AttributeType::OID_PSEUDONYM; |
|
| 27 | + parent::__construct($value, $string_tag); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -14,16 +14,16 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class StateOrProvinceNameValue extends DirectoryString |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Constructor. |
|
| 19 | - * |
|
| 20 | - * @param string $value String value |
|
| 21 | - * @param int $string_tag Syntax choice |
|
| 22 | - */ |
|
| 23 | - public function __construct(string $value, |
|
| 24 | - int $string_tag = DirectoryString::UTF8) |
|
| 25 | - { |
|
| 26 | - $this->_oid = AttributeType::OID_STATE_OR_PROVINCE_NAME; |
|
| 27 | - parent::__construct($value, $string_tag); |
|
| 28 | - } |
|
| 17 | + /** |
|
| 18 | + * Constructor. |
|
| 19 | + * |
|
| 20 | + * @param string $value String value |
|
| 21 | + * @param int $string_tag Syntax choice |
|
| 22 | + */ |
|
| 23 | + public function __construct(string $value, |
|
| 24 | + int $string_tag = DirectoryString::UTF8) |
|
| 25 | + { |
|
| 26 | + $this->_oid = AttributeType::OID_STATE_OR_PROVINCE_NAME; |
|
| 27 | + parent::__construct($value, $string_tag); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -11,30 +11,30 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | trait TypedAttribute |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Attribute type. |
|
| 16 | - * |
|
| 17 | - * @var AttributeType |
|
| 18 | - */ |
|
| 19 | - protected $_type; |
|
| 14 | + /** |
|
| 15 | + * Attribute type. |
|
| 16 | + * |
|
| 17 | + * @var AttributeType |
|
| 18 | + */ |
|
| 19 | + protected $_type; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Get attribute type. |
|
| 23 | - * |
|
| 24 | - * @return AttributeType |
|
| 25 | - */ |
|
| 26 | - public function type(): AttributeType |
|
| 27 | - { |
|
| 28 | - return $this->_type; |
|
| 29 | - } |
|
| 21 | + /** |
|
| 22 | + * Get attribute type. |
|
| 23 | + * |
|
| 24 | + * @return AttributeType |
|
| 25 | + */ |
|
| 26 | + public function type(): AttributeType |
|
| 27 | + { |
|
| 28 | + return $this->_type; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Get OID of the attribute. |
|
| 33 | - * |
|
| 34 | - * @return string |
|
| 35 | - */ |
|
| 36 | - public function oid(): string |
|
| 37 | - { |
|
| 38 | - return $this->_type->oid(); |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * Get OID of the attribute. |
|
| 33 | + * |
|
| 34 | + * @return string |
|
| 35 | + */ |
|
| 36 | + public function oid(): string |
|
| 37 | + { |
|
| 38 | + return $this->_type->oid(); |
|
| 39 | + } |
|
| 40 | 40 | } |
@@ -15,173 +15,173 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class RDN implements \Countable, \IteratorAggregate |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Attributes. |
|
| 20 | - * |
|
| 21 | - * @var AttributeTypeAndValue[] |
|
| 22 | - */ |
|
| 23 | - protected $_attribs; |
|
| 18 | + /** |
|
| 19 | + * Attributes. |
|
| 20 | + * |
|
| 21 | + * @var AttributeTypeAndValue[] |
|
| 22 | + */ |
|
| 23 | + protected $_attribs; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Constructor. |
|
| 27 | - * |
|
| 28 | - * @param AttributeTypeAndValue ...$attribs One or more attributes |
|
| 29 | - */ |
|
| 30 | - public function __construct(AttributeTypeAndValue ...$attribs) |
|
| 31 | - { |
|
| 32 | - if (!count($attribs)) { |
|
| 33 | - throw new \UnexpectedValueException( |
|
| 34 | - 'RDN must have at least one AttributeTypeAndValue.'); |
|
| 35 | - } |
|
| 36 | - $this->_attribs = $attribs; |
|
| 37 | - } |
|
| 25 | + /** |
|
| 26 | + * Constructor. |
|
| 27 | + * |
|
| 28 | + * @param AttributeTypeAndValue ...$attribs One or more attributes |
|
| 29 | + */ |
|
| 30 | + public function __construct(AttributeTypeAndValue ...$attribs) |
|
| 31 | + { |
|
| 32 | + if (!count($attribs)) { |
|
| 33 | + throw new \UnexpectedValueException( |
|
| 34 | + 'RDN must have at least one AttributeTypeAndValue.'); |
|
| 35 | + } |
|
| 36 | + $this->_attribs = $attribs; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @return string |
|
| 41 | - */ |
|
| 42 | - public function __toString() |
|
| 43 | - { |
|
| 44 | - return $this->toString(); |
|
| 45 | - } |
|
| 39 | + /** |
|
| 40 | + * @return string |
|
| 41 | + */ |
|
| 42 | + public function __toString() |
|
| 43 | + { |
|
| 44 | + return $this->toString(); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Convenience method to initialize RDN from AttributeValue objects. |
|
| 49 | - * |
|
| 50 | - * @param AttributeValue ...$values One or more attributes |
|
| 51 | - * |
|
| 52 | - * @return self |
|
| 53 | - */ |
|
| 54 | - public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 55 | - { |
|
| 56 | - $attribs = array_map( |
|
| 57 | - function (AttributeValue $value) { |
|
| 58 | - return new AttributeTypeAndValue( |
|
| 59 | - new AttributeType($value->oid()), $value); |
|
| 60 | - }, $values); |
|
| 61 | - return new self(...$attribs); |
|
| 62 | - } |
|
| 47 | + /** |
|
| 48 | + * Convenience method to initialize RDN from AttributeValue objects. |
|
| 49 | + * |
|
| 50 | + * @param AttributeValue ...$values One or more attributes |
|
| 51 | + * |
|
| 52 | + * @return self |
|
| 53 | + */ |
|
| 54 | + public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 55 | + { |
|
| 56 | + $attribs = array_map( |
|
| 57 | + function (AttributeValue $value) { |
|
| 58 | + return new AttributeTypeAndValue( |
|
| 59 | + new AttributeType($value->oid()), $value); |
|
| 60 | + }, $values); |
|
| 61 | + return new self(...$attribs); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Initialize from ASN.1. |
|
| 66 | - * |
|
| 67 | - * @param Set $set |
|
| 68 | - * |
|
| 69 | - * @return self |
|
| 70 | - */ |
|
| 71 | - public static function fromASN1(Set $set): self |
|
| 72 | - { |
|
| 73 | - $attribs = array_map( |
|
| 74 | - function (UnspecifiedType $el) { |
|
| 75 | - return AttributeTypeAndValue::fromASN1($el->asSequence()); |
|
| 76 | - }, $set->elements()); |
|
| 77 | - return new self(...$attribs); |
|
| 78 | - } |
|
| 64 | + /** |
|
| 65 | + * Initialize from ASN.1. |
|
| 66 | + * |
|
| 67 | + * @param Set $set |
|
| 68 | + * |
|
| 69 | + * @return self |
|
| 70 | + */ |
|
| 71 | + public static function fromASN1(Set $set): self |
|
| 72 | + { |
|
| 73 | + $attribs = array_map( |
|
| 74 | + function (UnspecifiedType $el) { |
|
| 75 | + return AttributeTypeAndValue::fromASN1($el->asSequence()); |
|
| 76 | + }, $set->elements()); |
|
| 77 | + return new self(...$attribs); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Generate ASN.1 structure. |
|
| 82 | - * |
|
| 83 | - * @return Set |
|
| 84 | - */ |
|
| 85 | - public function toASN1(): Set |
|
| 86 | - { |
|
| 87 | - $elements = array_map( |
|
| 88 | - function (AttributeTypeAndValue $tv) { |
|
| 89 | - return $tv->toASN1(); |
|
| 90 | - }, $this->_attribs); |
|
| 91 | - $set = new Set(...$elements); |
|
| 92 | - return $set->sortedSetOf(); |
|
| 93 | - } |
|
| 80 | + /** |
|
| 81 | + * Generate ASN.1 structure. |
|
| 82 | + * |
|
| 83 | + * @return Set |
|
| 84 | + */ |
|
| 85 | + public function toASN1(): Set |
|
| 86 | + { |
|
| 87 | + $elements = array_map( |
|
| 88 | + function (AttributeTypeAndValue $tv) { |
|
| 89 | + return $tv->toASN1(); |
|
| 90 | + }, $this->_attribs); |
|
| 91 | + $set = new Set(...$elements); |
|
| 92 | + return $set->sortedSetOf(); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Get name-component string conforming to RFC 2253. |
|
| 97 | - * |
|
| 98 | - * @see https://tools.ietf.org/html/rfc2253#section-2.2 |
|
| 99 | - * |
|
| 100 | - * @return string |
|
| 101 | - */ |
|
| 102 | - public function toString(): string |
|
| 103 | - { |
|
| 104 | - $parts = array_map( |
|
| 105 | - function (AttributeTypeAndValue $tv) { |
|
| 106 | - return $tv->toString(); |
|
| 107 | - }, $this->_attribs); |
|
| 108 | - return implode('+', $parts); |
|
| 109 | - } |
|
| 95 | + /** |
|
| 96 | + * Get name-component string conforming to RFC 2253. |
|
| 97 | + * |
|
| 98 | + * @see https://tools.ietf.org/html/rfc2253#section-2.2 |
|
| 99 | + * |
|
| 100 | + * @return string |
|
| 101 | + */ |
|
| 102 | + public function toString(): string |
|
| 103 | + { |
|
| 104 | + $parts = array_map( |
|
| 105 | + function (AttributeTypeAndValue $tv) { |
|
| 106 | + return $tv->toString(); |
|
| 107 | + }, $this->_attribs); |
|
| 108 | + return implode('+', $parts); |
|
| 109 | + } |
|
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Check whether RDN is semantically equal to other. |
|
| 113 | - * |
|
| 114 | - * @param RDN $other Object to compare to |
|
| 115 | - * |
|
| 116 | - * @return bool |
|
| 117 | - */ |
|
| 118 | - public function equals(RDN $other): bool |
|
| 119 | - { |
|
| 120 | - // if attribute count doesn't match |
|
| 121 | - if (count($this) != count($other)) { |
|
| 122 | - return false; |
|
| 123 | - } |
|
| 124 | - $attribs1 = $this->_attribs; |
|
| 125 | - $attribs2 = $other->_attribs; |
|
| 126 | - // if there's multiple attributes, sort using SET OF rules |
|
| 127 | - if (count($attribs1) > 1) { |
|
| 128 | - $attribs1 = self::fromASN1($this->toASN1())->_attribs; |
|
| 129 | - $attribs2 = self::fromASN1($other->toASN1())->_attribs; |
|
| 130 | - } |
|
| 131 | - for ($i = count($attribs1) - 1; $i >= 0; --$i) { |
|
| 132 | - $tv1 = $attribs1[$i]; |
|
| 133 | - $tv2 = $attribs2[$i]; |
|
| 134 | - if (!$tv1->equals($tv2)) { |
|
| 135 | - return false; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - return true; |
|
| 139 | - } |
|
| 111 | + /** |
|
| 112 | + * Check whether RDN is semantically equal to other. |
|
| 113 | + * |
|
| 114 | + * @param RDN $other Object to compare to |
|
| 115 | + * |
|
| 116 | + * @return bool |
|
| 117 | + */ |
|
| 118 | + public function equals(RDN $other): bool |
|
| 119 | + { |
|
| 120 | + // if attribute count doesn't match |
|
| 121 | + if (count($this) != count($other)) { |
|
| 122 | + return false; |
|
| 123 | + } |
|
| 124 | + $attribs1 = $this->_attribs; |
|
| 125 | + $attribs2 = $other->_attribs; |
|
| 126 | + // if there's multiple attributes, sort using SET OF rules |
|
| 127 | + if (count($attribs1) > 1) { |
|
| 128 | + $attribs1 = self::fromASN1($this->toASN1())->_attribs; |
|
| 129 | + $attribs2 = self::fromASN1($other->toASN1())->_attribs; |
|
| 130 | + } |
|
| 131 | + for ($i = count($attribs1) - 1; $i >= 0; --$i) { |
|
| 132 | + $tv1 = $attribs1[$i]; |
|
| 133 | + $tv2 = $attribs2[$i]; |
|
| 134 | + if (!$tv1->equals($tv2)) { |
|
| 135 | + return false; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + return true; |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Get all AttributeTypeAndValue objects. |
|
| 143 | - * |
|
| 144 | - * @return AttributeTypeAndValue[] |
|
| 145 | - */ |
|
| 146 | - public function all(): array |
|
| 147 | - { |
|
| 148 | - return $this->_attribs; |
|
| 149 | - } |
|
| 141 | + /** |
|
| 142 | + * Get all AttributeTypeAndValue objects. |
|
| 143 | + * |
|
| 144 | + * @return AttributeTypeAndValue[] |
|
| 145 | + */ |
|
| 146 | + public function all(): array |
|
| 147 | + { |
|
| 148 | + return $this->_attribs; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Get all AttributeTypeAndValue objects of the given attribute type. |
|
| 153 | - * |
|
| 154 | - * @param string $name Attribute OID or name |
|
| 155 | - * |
|
| 156 | - * @return AttributeTypeAndValue[] |
|
| 157 | - */ |
|
| 158 | - public function allOf(string $name): array |
|
| 159 | - { |
|
| 160 | - $oid = AttributeType::attrNameToOID($name); |
|
| 161 | - $attribs = array_filter($this->_attribs, |
|
| 162 | - function (AttributeTypeAndValue $tv) use ($oid) { |
|
| 163 | - return $tv->oid() == $oid; |
|
| 164 | - }); |
|
| 165 | - return array_values($attribs); |
|
| 166 | - } |
|
| 151 | + /** |
|
| 152 | + * Get all AttributeTypeAndValue objects of the given attribute type. |
|
| 153 | + * |
|
| 154 | + * @param string $name Attribute OID or name |
|
| 155 | + * |
|
| 156 | + * @return AttributeTypeAndValue[] |
|
| 157 | + */ |
|
| 158 | + public function allOf(string $name): array |
|
| 159 | + { |
|
| 160 | + $oid = AttributeType::attrNameToOID($name); |
|
| 161 | + $attribs = array_filter($this->_attribs, |
|
| 162 | + function (AttributeTypeAndValue $tv) use ($oid) { |
|
| 163 | + return $tv->oid() == $oid; |
|
| 164 | + }); |
|
| 165 | + return array_values($attribs); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * @see \Countable::count() |
|
| 170 | - * |
|
| 171 | - * @return int |
|
| 172 | - */ |
|
| 173 | - public function count(): int |
|
| 174 | - { |
|
| 175 | - return count($this->_attribs); |
|
| 176 | - } |
|
| 168 | + /** |
|
| 169 | + * @see \Countable::count() |
|
| 170 | + * |
|
| 171 | + * @return int |
|
| 172 | + */ |
|
| 173 | + public function count(): int |
|
| 174 | + { |
|
| 175 | + return count($this->_attribs); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * @see \IteratorAggregate::getIterator() |
|
| 180 | - * |
|
| 181 | - * @return \ArrayIterator |
|
| 182 | - */ |
|
| 183 | - public function getIterator(): \ArrayIterator |
|
| 184 | - { |
|
| 185 | - return new \ArrayIterator($this->_attribs); |
|
| 186 | - } |
|
| 178 | + /** |
|
| 179 | + * @see \IteratorAggregate::getIterator() |
|
| 180 | + * |
|
| 181 | + * @return \ArrayIterator |
|
| 182 | + */ |
|
| 183 | + public function getIterator(): \ArrayIterator |
|
| 184 | + { |
|
| 185 | + return new \ArrayIterator($this->_attribs); |
|
| 186 | + } |
|
| 187 | 187 | } |