@@ -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 | } |
@@ -11,14 +11,14 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | abstract class MatchingRule |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * Compare attribute value to assertion. |
|
| 16 | - * |
|
| 17 | - * @param mixed $assertion Value to assert |
|
| 18 | - * @param mixed $value Attribute value |
|
| 19 | - * |
|
| 20 | - * @return null|bool True if value matches. Null shall be returned if match |
|
| 21 | - * evaluates to Undefined. |
|
| 22 | - */ |
|
| 23 | - abstract public function compare($assertion, $value): ?bool; |
|
| 14 | + /** |
|
| 15 | + * Compare attribute value to assertion. |
|
| 16 | + * |
|
| 17 | + * @param mixed $assertion Value to assert |
|
| 18 | + * @param mixed $value Attribute value |
|
| 19 | + * |
|
| 20 | + * @return null|bool True if value matches. Null shall be returned if match |
|
| 21 | + * evaluates to Undefined. |
|
| 22 | + */ |
|
| 23 | + abstract public function compare($assertion, $value): ?bool; |
|
| 24 | 24 | } |
@@ -15,414 +15,414 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class DNParser |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * RFC 2253 special characters. |
|
| 20 | - * |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - const SPECIAL_CHARS = ',=+<>#;'; |
|
| 18 | + /** |
|
| 19 | + * RFC 2253 special characters. |
|
| 20 | + * |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + const SPECIAL_CHARS = ',=+<>#;'; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * DN string. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - private $_dn; |
|
| 25 | + /** |
|
| 26 | + * DN string. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + private $_dn; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * DN string length. |
|
| 34 | - * |
|
| 35 | - * @var int |
|
| 36 | - */ |
|
| 37 | - private $_len; |
|
| 32 | + /** |
|
| 33 | + * DN string length. |
|
| 34 | + * |
|
| 35 | + * @var int |
|
| 36 | + */ |
|
| 37 | + private $_len; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Constructor. |
|
| 41 | - * |
|
| 42 | - * @param string $dn Distinguised name |
|
| 43 | - */ |
|
| 44 | - protected function __construct(string $dn) |
|
| 45 | - { |
|
| 46 | - $this->_dn = $dn; |
|
| 47 | - $this->_len = strlen($dn); |
|
| 48 | - } |
|
| 39 | + /** |
|
| 40 | + * Constructor. |
|
| 41 | + * |
|
| 42 | + * @param string $dn Distinguised name |
|
| 43 | + */ |
|
| 44 | + protected function __construct(string $dn) |
|
| 45 | + { |
|
| 46 | + $this->_dn = $dn; |
|
| 47 | + $this->_len = strlen($dn); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Parse distinguished name string to name-components. |
|
| 52 | - * |
|
| 53 | - * @param string $dn |
|
| 54 | - * |
|
| 55 | - * @return array |
|
| 56 | - */ |
|
| 57 | - public static function parseString(string $dn): array |
|
| 58 | - { |
|
| 59 | - $parser = new self($dn); |
|
| 60 | - return $parser->parse(); |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * Parse distinguished name string to name-components. |
|
| 52 | + * |
|
| 53 | + * @param string $dn |
|
| 54 | + * |
|
| 55 | + * @return array |
|
| 56 | + */ |
|
| 57 | + public static function parseString(string $dn): array |
|
| 58 | + { |
|
| 59 | + $parser = new self($dn); |
|
| 60 | + return $parser->parse(); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Escape a AttributeValue string conforming to RFC 2253. |
|
| 65 | - * |
|
| 66 | - * @see https://tools.ietf.org/html/rfc2253#section-2.4 |
|
| 67 | - * |
|
| 68 | - * @param string $str |
|
| 69 | - * |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 72 | - public static function escapeString(string $str): string |
|
| 73 | - { |
|
| 74 | - // one of the characters ",", "+", """, "\", "<", ">" or ";" |
|
| 75 | - $str = preg_replace('/([,\+"\\\<\>;])/u', '\\\\$1', $str); |
|
| 76 | - // a space character occurring at the end of the string |
|
| 77 | - $str = preg_replace('/( )$/u', '\\\\$1', $str); |
|
| 78 | - // a space or "#" character occurring at the beginning of the string |
|
| 79 | - $str = preg_replace('/^([ #])/u', '\\\\$1', $str); |
|
| 80 | - // implementation specific special characters |
|
| 81 | - $str = preg_replace_callback('/([\pC])/u', |
|
| 82 | - function ($m) { |
|
| 83 | - $octets = str_split(bin2hex($m[1]), 2); |
|
| 84 | - return implode('', |
|
| 85 | - array_map( |
|
| 86 | - function ($octet) { |
|
| 87 | - return '\\' . strtoupper($octet); |
|
| 88 | - }, $octets)); |
|
| 89 | - }, $str); |
|
| 90 | - return $str; |
|
| 91 | - } |
|
| 63 | + /** |
|
| 64 | + * Escape a AttributeValue string conforming to RFC 2253. |
|
| 65 | + * |
|
| 66 | + * @see https://tools.ietf.org/html/rfc2253#section-2.4 |
|
| 67 | + * |
|
| 68 | + * @param string $str |
|
| 69 | + * |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | + public static function escapeString(string $str): string |
|
| 73 | + { |
|
| 74 | + // one of the characters ",", "+", """, "\", "<", ">" or ";" |
|
| 75 | + $str = preg_replace('/([,\+"\\\<\>;])/u', '\\\\$1', $str); |
|
| 76 | + // a space character occurring at the end of the string |
|
| 77 | + $str = preg_replace('/( )$/u', '\\\\$1', $str); |
|
| 78 | + // a space or "#" character occurring at the beginning of the string |
|
| 79 | + $str = preg_replace('/^([ #])/u', '\\\\$1', $str); |
|
| 80 | + // implementation specific special characters |
|
| 81 | + $str = preg_replace_callback('/([\pC])/u', |
|
| 82 | + function ($m) { |
|
| 83 | + $octets = str_split(bin2hex($m[1]), 2); |
|
| 84 | + return implode('', |
|
| 85 | + array_map( |
|
| 86 | + function ($octet) { |
|
| 87 | + return '\\' . strtoupper($octet); |
|
| 88 | + }, $octets)); |
|
| 89 | + }, $str); |
|
| 90 | + return $str; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Parse DN to name-components. |
|
| 95 | - * |
|
| 96 | - * @throws \RuntimeException |
|
| 97 | - * |
|
| 98 | - * @return array |
|
| 99 | - */ |
|
| 100 | - protected function parse(): array |
|
| 101 | - { |
|
| 102 | - $offset = 0; |
|
| 103 | - $name = $this->_parseName($offset); |
|
| 104 | - if ($offset < $this->_len) { |
|
| 105 | - $remains = substr($this->_dn, $offset); |
|
| 106 | - throw new \UnexpectedValueException( |
|
| 107 | - 'Parser finished before the end of string' . |
|
| 108 | - ", remaining: '{$remains}'."); |
|
| 109 | - } |
|
| 110 | - return $name; |
|
| 111 | - } |
|
| 93 | + /** |
|
| 94 | + * Parse DN to name-components. |
|
| 95 | + * |
|
| 96 | + * @throws \RuntimeException |
|
| 97 | + * |
|
| 98 | + * @return array |
|
| 99 | + */ |
|
| 100 | + protected function parse(): array |
|
| 101 | + { |
|
| 102 | + $offset = 0; |
|
| 103 | + $name = $this->_parseName($offset); |
|
| 104 | + if ($offset < $this->_len) { |
|
| 105 | + $remains = substr($this->_dn, $offset); |
|
| 106 | + throw new \UnexpectedValueException( |
|
| 107 | + 'Parser finished before the end of string' . |
|
| 108 | + ", remaining: '{$remains}'."); |
|
| 109 | + } |
|
| 110 | + return $name; |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Parse 'name'. |
|
| 115 | - * |
|
| 116 | - * name-component *("," name-component) |
|
| 117 | - * |
|
| 118 | - * @param int $offset |
|
| 119 | - * |
|
| 120 | - * @return array Array of name-components |
|
| 121 | - */ |
|
| 122 | - private function _parseName(int &$offset): array |
|
| 123 | - { |
|
| 124 | - $idx = $offset; |
|
| 125 | - $names = []; |
|
| 126 | - while ($idx < $this->_len) { |
|
| 127 | - $names[] = $this->_parseNameComponent($idx); |
|
| 128 | - if ($idx >= $this->_len) { |
|
| 129 | - break; |
|
| 130 | - } |
|
| 131 | - $this->_skipWs($idx); |
|
| 132 | - if (',' != $this->_dn[$idx] && ';' != $this->_dn[$idx]) { |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - ++$idx; |
|
| 136 | - $this->_skipWs($idx); |
|
| 137 | - } |
|
| 138 | - $offset = $idx; |
|
| 139 | - return array_reverse($names); |
|
| 140 | - } |
|
| 113 | + /** |
|
| 114 | + * Parse 'name'. |
|
| 115 | + * |
|
| 116 | + * name-component *("," name-component) |
|
| 117 | + * |
|
| 118 | + * @param int $offset |
|
| 119 | + * |
|
| 120 | + * @return array Array of name-components |
|
| 121 | + */ |
|
| 122 | + private function _parseName(int &$offset): array |
|
| 123 | + { |
|
| 124 | + $idx = $offset; |
|
| 125 | + $names = []; |
|
| 126 | + while ($idx < $this->_len) { |
|
| 127 | + $names[] = $this->_parseNameComponent($idx); |
|
| 128 | + if ($idx >= $this->_len) { |
|
| 129 | + break; |
|
| 130 | + } |
|
| 131 | + $this->_skipWs($idx); |
|
| 132 | + if (',' != $this->_dn[$idx] && ';' != $this->_dn[$idx]) { |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + ++$idx; |
|
| 136 | + $this->_skipWs($idx); |
|
| 137 | + } |
|
| 138 | + $offset = $idx; |
|
| 139 | + return array_reverse($names); |
|
| 140 | + } |
|
| 141 | 141 | |
| 142 | - /** |
|
| 143 | - * Parse 'name-component'. |
|
| 144 | - * |
|
| 145 | - * attributeTypeAndValue *("+" attributeTypeAndValue) |
|
| 146 | - * |
|
| 147 | - * @param int $offset |
|
| 148 | - * |
|
| 149 | - * @return array Array of [type, value] tuples |
|
| 150 | - */ |
|
| 151 | - private function _parseNameComponent(int &$offset): array |
|
| 152 | - { |
|
| 153 | - $idx = $offset; |
|
| 154 | - $tvpairs = []; |
|
| 155 | - while ($idx < $this->_len) { |
|
| 156 | - $tvpairs[] = $this->_parseAttrTypeAndValue($idx); |
|
| 157 | - $this->_skipWs($idx); |
|
| 158 | - if ($idx >= $this->_len || '+' != $this->_dn[$idx]) { |
|
| 159 | - break; |
|
| 160 | - } |
|
| 161 | - ++$idx; |
|
| 162 | - $this->_skipWs($idx); |
|
| 163 | - } |
|
| 164 | - $offset = $idx; |
|
| 165 | - return $tvpairs; |
|
| 166 | - } |
|
| 142 | + /** |
|
| 143 | + * Parse 'name-component'. |
|
| 144 | + * |
|
| 145 | + * attributeTypeAndValue *("+" attributeTypeAndValue) |
|
| 146 | + * |
|
| 147 | + * @param int $offset |
|
| 148 | + * |
|
| 149 | + * @return array Array of [type, value] tuples |
|
| 150 | + */ |
|
| 151 | + private function _parseNameComponent(int &$offset): array |
|
| 152 | + { |
|
| 153 | + $idx = $offset; |
|
| 154 | + $tvpairs = []; |
|
| 155 | + while ($idx < $this->_len) { |
|
| 156 | + $tvpairs[] = $this->_parseAttrTypeAndValue($idx); |
|
| 157 | + $this->_skipWs($idx); |
|
| 158 | + if ($idx >= $this->_len || '+' != $this->_dn[$idx]) { |
|
| 159 | + break; |
|
| 160 | + } |
|
| 161 | + ++$idx; |
|
| 162 | + $this->_skipWs($idx); |
|
| 163 | + } |
|
| 164 | + $offset = $idx; |
|
| 165 | + return $tvpairs; |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 169 | - * Parse 'attributeTypeAndValue'. |
|
| 170 | - * |
|
| 171 | - * attributeType "=" attributeValue |
|
| 172 | - * |
|
| 173 | - * @param int $offset |
|
| 174 | - * |
|
| 175 | - * @throws \UnexpectedValueException |
|
| 176 | - * |
|
| 177 | - * @return array A tuple of [type, value]. Value may be either a string or |
|
| 178 | - * an Element, if it's encoded as hexstring. |
|
| 179 | - */ |
|
| 180 | - private function _parseAttrTypeAndValue(int &$offset): array |
|
| 181 | - { |
|
| 182 | - $idx = $offset; |
|
| 183 | - $type = $this->_parseAttrType($idx); |
|
| 184 | - $this->_skipWs($idx); |
|
| 185 | - if ($idx >= $this->_len || '=' != $this->_dn[$idx++]) { |
|
| 186 | - throw new \UnexpectedValueException('Invalid type and value pair.'); |
|
| 187 | - } |
|
| 188 | - $this->_skipWs($idx); |
|
| 189 | - // hexstring |
|
| 190 | - if ($idx < $this->_len && '#' == $this->_dn[$idx]) { |
|
| 191 | - ++$idx; |
|
| 192 | - $data = $this->_parseAttrHexValue($idx); |
|
| 193 | - try { |
|
| 194 | - $value = Element::fromDER($data); |
|
| 195 | - } catch (DecodeException $e) { |
|
| 196 | - throw new \UnexpectedValueException( |
|
| 197 | - 'Invalid DER encoding from hexstring.', 0, $e); |
|
| 198 | - } |
|
| 199 | - } else { |
|
| 200 | - $value = $this->_parseAttrStringValue($idx); |
|
| 201 | - } |
|
| 202 | - $offset = $idx; |
|
| 203 | - return [$type, $value]; |
|
| 204 | - } |
|
| 168 | + /** |
|
| 169 | + * Parse 'attributeTypeAndValue'. |
|
| 170 | + * |
|
| 171 | + * attributeType "=" attributeValue |
|
| 172 | + * |
|
| 173 | + * @param int $offset |
|
| 174 | + * |
|
| 175 | + * @throws \UnexpectedValueException |
|
| 176 | + * |
|
| 177 | + * @return array A tuple of [type, value]. Value may be either a string or |
|
| 178 | + * an Element, if it's encoded as hexstring. |
|
| 179 | + */ |
|
| 180 | + private function _parseAttrTypeAndValue(int &$offset): array |
|
| 181 | + { |
|
| 182 | + $idx = $offset; |
|
| 183 | + $type = $this->_parseAttrType($idx); |
|
| 184 | + $this->_skipWs($idx); |
|
| 185 | + if ($idx >= $this->_len || '=' != $this->_dn[$idx++]) { |
|
| 186 | + throw new \UnexpectedValueException('Invalid type and value pair.'); |
|
| 187 | + } |
|
| 188 | + $this->_skipWs($idx); |
|
| 189 | + // hexstring |
|
| 190 | + if ($idx < $this->_len && '#' == $this->_dn[$idx]) { |
|
| 191 | + ++$idx; |
|
| 192 | + $data = $this->_parseAttrHexValue($idx); |
|
| 193 | + try { |
|
| 194 | + $value = Element::fromDER($data); |
|
| 195 | + } catch (DecodeException $e) { |
|
| 196 | + throw new \UnexpectedValueException( |
|
| 197 | + 'Invalid DER encoding from hexstring.', 0, $e); |
|
| 198 | + } |
|
| 199 | + } else { |
|
| 200 | + $value = $this->_parseAttrStringValue($idx); |
|
| 201 | + } |
|
| 202 | + $offset = $idx; |
|
| 203 | + return [$type, $value]; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Parse 'attributeType'. |
|
| 208 | - * |
|
| 209 | - * (ALPHA 1*keychar) / oid |
|
| 210 | - * |
|
| 211 | - * @param int $offset |
|
| 212 | - * |
|
| 213 | - * @throws \UnexpectedValueException |
|
| 214 | - * |
|
| 215 | - * @return string |
|
| 216 | - */ |
|
| 217 | - private function _parseAttrType(int &$offset): string |
|
| 218 | - { |
|
| 219 | - $idx = $offset; |
|
| 220 | - // dotted OID |
|
| 221 | - $type = $this->_regexMatch('/^(?:oid\.)?([0-9]+(?:\.[0-9]+)*)/i', $idx); |
|
| 222 | - if (null === $type) { |
|
| 223 | - // name |
|
| 224 | - $type = $this->_regexMatch('/^[a-z][a-z0-9\-]*/i', $idx); |
|
| 225 | - if (null === $type) { |
|
| 226 | - throw new \UnexpectedValueException('Invalid attribute type.'); |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - $offset = $idx; |
|
| 230 | - return $type; |
|
| 231 | - } |
|
| 206 | + /** |
|
| 207 | + * Parse 'attributeType'. |
|
| 208 | + * |
|
| 209 | + * (ALPHA 1*keychar) / oid |
|
| 210 | + * |
|
| 211 | + * @param int $offset |
|
| 212 | + * |
|
| 213 | + * @throws \UnexpectedValueException |
|
| 214 | + * |
|
| 215 | + * @return string |
|
| 216 | + */ |
|
| 217 | + private function _parseAttrType(int &$offset): string |
|
| 218 | + { |
|
| 219 | + $idx = $offset; |
|
| 220 | + // dotted OID |
|
| 221 | + $type = $this->_regexMatch('/^(?:oid\.)?([0-9]+(?:\.[0-9]+)*)/i', $idx); |
|
| 222 | + if (null === $type) { |
|
| 223 | + // name |
|
| 224 | + $type = $this->_regexMatch('/^[a-z][a-z0-9\-]*/i', $idx); |
|
| 225 | + if (null === $type) { |
|
| 226 | + throw new \UnexpectedValueException('Invalid attribute type.'); |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + $offset = $idx; |
|
| 230 | + return $type; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Parse 'attributeValue' of string type. |
|
| 235 | - * |
|
| 236 | - * @param int $offset |
|
| 237 | - * |
|
| 238 | - * @throws \UnexpectedValueException |
|
| 239 | - * |
|
| 240 | - * @return string |
|
| 241 | - */ |
|
| 242 | - private function _parseAttrStringValue(int &$offset): string |
|
| 243 | - { |
|
| 244 | - $idx = $offset; |
|
| 245 | - if ($idx >= $this->_len) { |
|
| 246 | - return ''; |
|
| 247 | - } |
|
| 248 | - if ('"' == $this->_dn[$idx]) { // quoted string |
|
| 249 | - $val = $this->_parseQuotedAttrString($idx); |
|
| 250 | - } else { // string |
|
| 251 | - $val = $this->_parseAttrString($idx); |
|
| 252 | - } |
|
| 253 | - $offset = $idx; |
|
| 254 | - return $val; |
|
| 255 | - } |
|
| 233 | + /** |
|
| 234 | + * Parse 'attributeValue' of string type. |
|
| 235 | + * |
|
| 236 | + * @param int $offset |
|
| 237 | + * |
|
| 238 | + * @throws \UnexpectedValueException |
|
| 239 | + * |
|
| 240 | + * @return string |
|
| 241 | + */ |
|
| 242 | + private function _parseAttrStringValue(int &$offset): string |
|
| 243 | + { |
|
| 244 | + $idx = $offset; |
|
| 245 | + if ($idx >= $this->_len) { |
|
| 246 | + return ''; |
|
| 247 | + } |
|
| 248 | + if ('"' == $this->_dn[$idx]) { // quoted string |
|
| 249 | + $val = $this->_parseQuotedAttrString($idx); |
|
| 250 | + } else { // string |
|
| 251 | + $val = $this->_parseAttrString($idx); |
|
| 252 | + } |
|
| 253 | + $offset = $idx; |
|
| 254 | + return $val; |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * Parse plain 'attributeValue' string. |
|
| 259 | - * |
|
| 260 | - * @param int $offset |
|
| 261 | - * |
|
| 262 | - * @throws \UnexpectedValueException |
|
| 263 | - * |
|
| 264 | - * @return string |
|
| 265 | - */ |
|
| 266 | - private function _parseAttrString(int &$offset): string |
|
| 267 | - { |
|
| 268 | - $idx = $offset; |
|
| 269 | - $val = ''; |
|
| 270 | - $wsidx = null; |
|
| 271 | - while ($idx < $this->_len) { |
|
| 272 | - $c = $this->_dn[$idx]; |
|
| 273 | - // pair (escape sequence) |
|
| 274 | - if ('\\' == $c) { |
|
| 275 | - ++$idx; |
|
| 276 | - $val .= $this->_parsePairAfterSlash($idx); |
|
| 277 | - $wsidx = null; |
|
| 278 | - continue; |
|
| 279 | - } |
|
| 280 | - if ('"' == $c) { |
|
| 281 | - throw new \UnexpectedValueException('Unexpected quotation.'); |
|
| 282 | - } |
|
| 283 | - if (false !== strpos(self::SPECIAL_CHARS, $c)) { |
|
| 284 | - break; |
|
| 285 | - } |
|
| 286 | - // keep track of the first consecutive whitespace |
|
| 287 | - if (' ' == $c) { |
|
| 288 | - if (null === $wsidx) { |
|
| 289 | - $wsidx = $idx; |
|
| 290 | - } |
|
| 291 | - } else { |
|
| 292 | - $wsidx = null; |
|
| 293 | - } |
|
| 294 | - // stringchar |
|
| 295 | - $val .= $c; |
|
| 296 | - ++$idx; |
|
| 297 | - } |
|
| 298 | - // if there was non-escaped whitespace in the end of the value |
|
| 299 | - if (null !== $wsidx) { |
|
| 300 | - $val = substr($val, 0, -($idx - $wsidx)); |
|
| 301 | - } |
|
| 302 | - $offset = $idx; |
|
| 303 | - return $val; |
|
| 304 | - } |
|
| 257 | + /** |
|
| 258 | + * Parse plain 'attributeValue' string. |
|
| 259 | + * |
|
| 260 | + * @param int $offset |
|
| 261 | + * |
|
| 262 | + * @throws \UnexpectedValueException |
|
| 263 | + * |
|
| 264 | + * @return string |
|
| 265 | + */ |
|
| 266 | + private function _parseAttrString(int &$offset): string |
|
| 267 | + { |
|
| 268 | + $idx = $offset; |
|
| 269 | + $val = ''; |
|
| 270 | + $wsidx = null; |
|
| 271 | + while ($idx < $this->_len) { |
|
| 272 | + $c = $this->_dn[$idx]; |
|
| 273 | + // pair (escape sequence) |
|
| 274 | + if ('\\' == $c) { |
|
| 275 | + ++$idx; |
|
| 276 | + $val .= $this->_parsePairAfterSlash($idx); |
|
| 277 | + $wsidx = null; |
|
| 278 | + continue; |
|
| 279 | + } |
|
| 280 | + if ('"' == $c) { |
|
| 281 | + throw new \UnexpectedValueException('Unexpected quotation.'); |
|
| 282 | + } |
|
| 283 | + if (false !== strpos(self::SPECIAL_CHARS, $c)) { |
|
| 284 | + break; |
|
| 285 | + } |
|
| 286 | + // keep track of the first consecutive whitespace |
|
| 287 | + if (' ' == $c) { |
|
| 288 | + if (null === $wsidx) { |
|
| 289 | + $wsidx = $idx; |
|
| 290 | + } |
|
| 291 | + } else { |
|
| 292 | + $wsidx = null; |
|
| 293 | + } |
|
| 294 | + // stringchar |
|
| 295 | + $val .= $c; |
|
| 296 | + ++$idx; |
|
| 297 | + } |
|
| 298 | + // if there was non-escaped whitespace in the end of the value |
|
| 299 | + if (null !== $wsidx) { |
|
| 300 | + $val = substr($val, 0, -($idx - $wsidx)); |
|
| 301 | + } |
|
| 302 | + $offset = $idx; |
|
| 303 | + return $val; |
|
| 304 | + } |
|
| 305 | 305 | |
| 306 | - /** |
|
| 307 | - * Parse quoted 'attributeValue' string. |
|
| 308 | - * |
|
| 309 | - * @param int $offset Offset to starting quote |
|
| 310 | - * |
|
| 311 | - * @throws \UnexpectedValueException |
|
| 312 | - * |
|
| 313 | - * @return string |
|
| 314 | - */ |
|
| 315 | - private function _parseQuotedAttrString(int &$offset): string |
|
| 316 | - { |
|
| 317 | - $idx = $offset + 1; |
|
| 318 | - $val = ''; |
|
| 319 | - while ($idx < $this->_len) { |
|
| 320 | - $c = $this->_dn[$idx]; |
|
| 321 | - if ('\\' == $c) { // pair |
|
| 322 | - ++$idx; |
|
| 323 | - $val .= $this->_parsePairAfterSlash($idx); |
|
| 324 | - continue; |
|
| 325 | - } |
|
| 326 | - if ('"' == $c) { |
|
| 327 | - ++$idx; |
|
| 328 | - break; |
|
| 329 | - } |
|
| 330 | - $val .= $c; |
|
| 331 | - ++$idx; |
|
| 332 | - } |
|
| 333 | - $offset = $idx; |
|
| 334 | - return $val; |
|
| 335 | - } |
|
| 306 | + /** |
|
| 307 | + * Parse quoted 'attributeValue' string. |
|
| 308 | + * |
|
| 309 | + * @param int $offset Offset to starting quote |
|
| 310 | + * |
|
| 311 | + * @throws \UnexpectedValueException |
|
| 312 | + * |
|
| 313 | + * @return string |
|
| 314 | + */ |
|
| 315 | + private function _parseQuotedAttrString(int &$offset): string |
|
| 316 | + { |
|
| 317 | + $idx = $offset + 1; |
|
| 318 | + $val = ''; |
|
| 319 | + while ($idx < $this->_len) { |
|
| 320 | + $c = $this->_dn[$idx]; |
|
| 321 | + if ('\\' == $c) { // pair |
|
| 322 | + ++$idx; |
|
| 323 | + $val .= $this->_parsePairAfterSlash($idx); |
|
| 324 | + continue; |
|
| 325 | + } |
|
| 326 | + if ('"' == $c) { |
|
| 327 | + ++$idx; |
|
| 328 | + break; |
|
| 329 | + } |
|
| 330 | + $val .= $c; |
|
| 331 | + ++$idx; |
|
| 332 | + } |
|
| 333 | + $offset = $idx; |
|
| 334 | + return $val; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - /** |
|
| 338 | - * Parse 'attributeValue' of binary type. |
|
| 339 | - * |
|
| 340 | - * @param int $offset |
|
| 341 | - * |
|
| 342 | - * @throws \UnexpectedValueException |
|
| 343 | - * |
|
| 344 | - * @return string |
|
| 345 | - */ |
|
| 346 | - private function _parseAttrHexValue(int &$offset): string |
|
| 347 | - { |
|
| 348 | - $idx = $offset; |
|
| 349 | - $hexstr = $this->_regexMatch('/^(?:[0-9a-f]{2})+/i', $idx); |
|
| 350 | - if (null === $hexstr) { |
|
| 351 | - throw new \UnexpectedValueException('Invalid hexstring.'); |
|
| 352 | - } |
|
| 353 | - $data = hex2bin($hexstr); |
|
| 354 | - $offset = $idx; |
|
| 355 | - return $data; |
|
| 356 | - } |
|
| 337 | + /** |
|
| 338 | + * Parse 'attributeValue' of binary type. |
|
| 339 | + * |
|
| 340 | + * @param int $offset |
|
| 341 | + * |
|
| 342 | + * @throws \UnexpectedValueException |
|
| 343 | + * |
|
| 344 | + * @return string |
|
| 345 | + */ |
|
| 346 | + private function _parseAttrHexValue(int &$offset): string |
|
| 347 | + { |
|
| 348 | + $idx = $offset; |
|
| 349 | + $hexstr = $this->_regexMatch('/^(?:[0-9a-f]{2})+/i', $idx); |
|
| 350 | + if (null === $hexstr) { |
|
| 351 | + throw new \UnexpectedValueException('Invalid hexstring.'); |
|
| 352 | + } |
|
| 353 | + $data = hex2bin($hexstr); |
|
| 354 | + $offset = $idx; |
|
| 355 | + return $data; |
|
| 356 | + } |
|
| 357 | 357 | |
| 358 | - /** |
|
| 359 | - * Parse 'pair' after leading slash. |
|
| 360 | - * |
|
| 361 | - * @param int $offset |
|
| 362 | - * |
|
| 363 | - * @throws \UnexpectedValueException |
|
| 364 | - * |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 367 | - private function _parsePairAfterSlash(int &$offset): string |
|
| 368 | - { |
|
| 369 | - $idx = $offset; |
|
| 370 | - if ($idx >= $this->_len) { |
|
| 371 | - throw new \UnexpectedValueException( |
|
| 372 | - 'Unexpected end of escape sequence.'); |
|
| 373 | - } |
|
| 374 | - $c = $this->_dn[$idx++]; |
|
| 375 | - // special | \ | " | SPACE |
|
| 376 | - if (false !== strpos(self::SPECIAL_CHARS . '\\" ', $c)) { |
|
| 377 | - $val = $c; |
|
| 378 | - } else { // hexpair |
|
| 379 | - if ($idx >= $this->_len) { |
|
| 380 | - throw new \UnexpectedValueException('Unexpected end of hexpair.'); |
|
| 381 | - } |
|
| 382 | - $val = @hex2bin($c . $this->_dn[$idx++]); |
|
| 383 | - if (false === $val) { |
|
| 384 | - throw new \UnexpectedValueException('Invalid hexpair.'); |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - $offset = $idx; |
|
| 388 | - return $val; |
|
| 389 | - } |
|
| 358 | + /** |
|
| 359 | + * Parse 'pair' after leading slash. |
|
| 360 | + * |
|
| 361 | + * @param int $offset |
|
| 362 | + * |
|
| 363 | + * @throws \UnexpectedValueException |
|
| 364 | + * |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | + private function _parsePairAfterSlash(int &$offset): string |
|
| 368 | + { |
|
| 369 | + $idx = $offset; |
|
| 370 | + if ($idx >= $this->_len) { |
|
| 371 | + throw new \UnexpectedValueException( |
|
| 372 | + 'Unexpected end of escape sequence.'); |
|
| 373 | + } |
|
| 374 | + $c = $this->_dn[$idx++]; |
|
| 375 | + // special | \ | " | SPACE |
|
| 376 | + if (false !== strpos(self::SPECIAL_CHARS . '\\" ', $c)) { |
|
| 377 | + $val = $c; |
|
| 378 | + } else { // hexpair |
|
| 379 | + if ($idx >= $this->_len) { |
|
| 380 | + throw new \UnexpectedValueException('Unexpected end of hexpair.'); |
|
| 381 | + } |
|
| 382 | + $val = @hex2bin($c . $this->_dn[$idx++]); |
|
| 383 | + if (false === $val) { |
|
| 384 | + throw new \UnexpectedValueException('Invalid hexpair.'); |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + $offset = $idx; |
|
| 388 | + return $val; |
|
| 389 | + } |
|
| 390 | 390 | |
| 391 | - /** |
|
| 392 | - * Match DN to pattern and extract the last capture group. |
|
| 393 | - * |
|
| 394 | - * Updates offset to fully matched pattern. |
|
| 395 | - * |
|
| 396 | - * @param string $pattern |
|
| 397 | - * @param int $offset |
|
| 398 | - * |
|
| 399 | - * @return null|string Null if pattern doesn't match |
|
| 400 | - */ |
|
| 401 | - private function _regexMatch(string $pattern, int &$offset): ?string |
|
| 402 | - { |
|
| 403 | - $idx = $offset; |
|
| 404 | - if (!preg_match($pattern, substr($this->_dn, $idx), $match)) { |
|
| 405 | - return null; |
|
| 406 | - } |
|
| 407 | - $idx += strlen($match[0]); |
|
| 408 | - $offset = $idx; |
|
| 409 | - return end($match); |
|
| 410 | - } |
|
| 391 | + /** |
|
| 392 | + * Match DN to pattern and extract the last capture group. |
|
| 393 | + * |
|
| 394 | + * Updates offset to fully matched pattern. |
|
| 395 | + * |
|
| 396 | + * @param string $pattern |
|
| 397 | + * @param int $offset |
|
| 398 | + * |
|
| 399 | + * @return null|string Null if pattern doesn't match |
|
| 400 | + */ |
|
| 401 | + private function _regexMatch(string $pattern, int &$offset): ?string |
|
| 402 | + { |
|
| 403 | + $idx = $offset; |
|
| 404 | + if (!preg_match($pattern, substr($this->_dn, $idx), $match)) { |
|
| 405 | + return null; |
|
| 406 | + } |
|
| 407 | + $idx += strlen($match[0]); |
|
| 408 | + $offset = $idx; |
|
| 409 | + return end($match); |
|
| 410 | + } |
|
| 411 | 411 | |
| 412 | - /** |
|
| 413 | - * Skip consecutive spaces. |
|
| 414 | - * |
|
| 415 | - * @param int $offset |
|
| 416 | - */ |
|
| 417 | - private function _skipWs(int &$offset): void |
|
| 418 | - { |
|
| 419 | - $idx = $offset; |
|
| 420 | - while ($idx < $this->_len) { |
|
| 421 | - if (' ' != $this->_dn[$idx]) { |
|
| 422 | - break; |
|
| 423 | - } |
|
| 424 | - ++$idx; |
|
| 425 | - } |
|
| 426 | - $offset = $idx; |
|
| 427 | - } |
|
| 412 | + /** |
|
| 413 | + * Skip consecutive spaces. |
|
| 414 | + * |
|
| 415 | + * @param int $offset |
|
| 416 | + */ |
|
| 417 | + private function _skipWs(int &$offset): void |
|
| 418 | + { |
|
| 419 | + $idx = $offset; |
|
| 420 | + while ($idx < $this->_len) { |
|
| 421 | + if (' ' != $this->_dn[$idx]) { |
|
| 422 | + break; |
|
| 423 | + } |
|
| 424 | + ++$idx; |
|
| 425 | + } |
|
| 426 | + $offset = $idx; |
|
| 427 | + } |
|
| 428 | 428 | } |
@@ -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 | } |
@@ -20,208 +20,208 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class Name implements \Countable, \IteratorAggregate |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * Relative distinguished name components. |
|
| 25 | - * |
|
| 26 | - * @var RDN[] |
|
| 27 | - */ |
|
| 28 | - protected $_rdns; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Constructor. |
|
| 32 | - * |
|
| 33 | - * @param RDN ...$rdns RDN components |
|
| 34 | - */ |
|
| 35 | - public function __construct(RDN ...$rdns) |
|
| 36 | - { |
|
| 37 | - $this->_rdns = $rdns; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - public function __toString() |
|
| 44 | - { |
|
| 45 | - return $this->toString(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Initialize from ASN.1. |
|
| 50 | - * |
|
| 51 | - * @param Sequence $seq |
|
| 52 | - * |
|
| 53 | - * @return self |
|
| 54 | - */ |
|
| 55 | - public static function fromASN1(Sequence $seq): self |
|
| 56 | - { |
|
| 57 | - $rdns = array_map( |
|
| 58 | - function (UnspecifiedType $el) { |
|
| 59 | - return RDN::fromASN1($el->asSet()); |
|
| 60 | - }, $seq->elements()); |
|
| 61 | - return new self(...$rdns); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Initialize from distinguished name string. |
|
| 66 | - * |
|
| 67 | - * @see https://tools.ietf.org/html/rfc1779 |
|
| 68 | - * |
|
| 69 | - * @param string $str |
|
| 70 | - * |
|
| 71 | - * @return self |
|
| 72 | - */ |
|
| 73 | - public static function fromString(string $str): self |
|
| 74 | - { |
|
| 75 | - $rdns = []; |
|
| 76 | - foreach (DNParser::parseString($str) as $nameComponent) { |
|
| 77 | - $attribs = []; |
|
| 78 | - foreach ($nameComponent as [$name, $val]) { |
|
| 79 | - $type = AttributeType::fromName($name); |
|
| 80 | - // hexstrings are parsed to ASN.1 elements |
|
| 81 | - if ($val instanceof Element) { |
|
| 82 | - $el = $val; |
|
| 83 | - } else { |
|
| 84 | - $el = AttributeType::asn1StringForType($type->oid(), $val); |
|
| 85 | - } |
|
| 86 | - $value = AttributeValue::fromASN1ByOID($type->oid(), |
|
| 87 | - $el->asUnspecified()); |
|
| 88 | - $attribs[] = new AttributeTypeAndValue($type, $value); |
|
| 89 | - } |
|
| 90 | - $rdns[] = new RDN(...$attribs); |
|
| 91 | - } |
|
| 92 | - return new self(...$rdns); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Generate ASN.1 structure. |
|
| 97 | - * |
|
| 98 | - * @return Sequence |
|
| 99 | - */ |
|
| 100 | - public function toASN1(): Sequence |
|
| 101 | - { |
|
| 102 | - $elements = array_map( |
|
| 103 | - function (RDN $rdn) { |
|
| 104 | - return $rdn->toASN1(); |
|
| 105 | - }, $this->_rdns); |
|
| 106 | - return new Sequence(...$elements); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Get distinguised name string conforming to RFC 2253. |
|
| 111 | - * |
|
| 112 | - * @see https://tools.ietf.org/html/rfc2253#section-2.1 |
|
| 113 | - * |
|
| 114 | - * @return string |
|
| 115 | - */ |
|
| 116 | - public function toString(): string |
|
| 117 | - { |
|
| 118 | - $parts = array_map( |
|
| 119 | - function (RDN $rdn) { |
|
| 120 | - return $rdn->toString(); |
|
| 121 | - }, array_reverse($this->_rdns)); |
|
| 122 | - return implode(',', $parts); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Whether name is semantically equal to other. |
|
| 127 | - * |
|
| 128 | - * Comparison conforms to RFC 4518 string preparation algorithm. |
|
| 129 | - * |
|
| 130 | - * @see https://tools.ietf.org/html/rfc4518 |
|
| 131 | - * |
|
| 132 | - * @param Name $other Object to compare to |
|
| 133 | - * |
|
| 134 | - * @return bool |
|
| 135 | - */ |
|
| 136 | - public function equals(Name $other): bool |
|
| 137 | - { |
|
| 138 | - // if RDN count doesn't match |
|
| 139 | - if (count($this) !== count($other)) { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 142 | - for ($i = count($this) - 1; $i >= 0; --$i) { |
|
| 143 | - $rdn1 = $this->_rdns[$i]; |
|
| 144 | - $rdn2 = $other->_rdns[$i]; |
|
| 145 | - if (!$rdn1->equals($rdn2)) { |
|
| 146 | - return false; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - return true; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Get all RDN objects. |
|
| 154 | - * |
|
| 155 | - * @return RDN[] |
|
| 156 | - */ |
|
| 157 | - public function all(): array |
|
| 158 | - { |
|
| 159 | - return $this->_rdns; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Get the first AttributeValue of given type. |
|
| 164 | - * |
|
| 165 | - * Relative name components shall be traversed in encoding order, which is |
|
| 166 | - * reversed in regards to the string representation. |
|
| 167 | - * Multi-valued RDN with multiple attributes of the requested type is |
|
| 168 | - * ambiguous and shall throw an exception. |
|
| 169 | - * |
|
| 170 | - * @param string $name Attribute OID or name |
|
| 171 | - * |
|
| 172 | - * @throws \RuntimeException If attribute cannot be resolved |
|
| 173 | - * |
|
| 174 | - * @return AttributeValue |
|
| 175 | - */ |
|
| 176 | - public function firstValueOf(string $name): AttributeValue |
|
| 177 | - { |
|
| 178 | - $oid = AttributeType::attrNameToOID($name); |
|
| 179 | - foreach ($this->_rdns as $rdn) { |
|
| 180 | - $tvs = $rdn->allOf($oid); |
|
| 181 | - if (count($tvs) > 1) { |
|
| 182 | - throw new \RangeException("RDN with multiple {$name} attributes."); |
|
| 183 | - } |
|
| 184 | - if (1 === count($tvs)) { |
|
| 185 | - return $tvs[0]->value(); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - throw new \RangeException("Attribute {$name} not found."); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * @see \Countable::count() |
|
| 193 | - * |
|
| 194 | - * @return int |
|
| 195 | - */ |
|
| 196 | - public function count(): int |
|
| 197 | - { |
|
| 198 | - return count($this->_rdns); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * Get the number of attributes of given type. |
|
| 203 | - * |
|
| 204 | - * @param string $name Attribute OID or name |
|
| 205 | - * |
|
| 206 | - * @return int |
|
| 207 | - */ |
|
| 208 | - public function countOfType(string $name): int |
|
| 209 | - { |
|
| 210 | - $oid = AttributeType::attrNameToOID($name); |
|
| 211 | - return (int) array_sum( |
|
| 212 | - array_map( |
|
| 213 | - function (RDN $rdn) use ($oid): int { |
|
| 214 | - return count($rdn->allOf($oid)); |
|
| 215 | - }, $this->_rdns)); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * @see \IteratorAggregate::getIterator() |
|
| 220 | - * |
|
| 221 | - * @return \ArrayIterator |
|
| 222 | - */ |
|
| 223 | - public function getIterator(): \ArrayIterator |
|
| 224 | - { |
|
| 225 | - return new \ArrayIterator($this->_rdns); |
|
| 226 | - } |
|
| 23 | + /** |
|
| 24 | + * Relative distinguished name components. |
|
| 25 | + * |
|
| 26 | + * @var RDN[] |
|
| 27 | + */ |
|
| 28 | + protected $_rdns; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Constructor. |
|
| 32 | + * |
|
| 33 | + * @param RDN ...$rdns RDN components |
|
| 34 | + */ |
|
| 35 | + public function __construct(RDN ...$rdns) |
|
| 36 | + { |
|
| 37 | + $this->_rdns = $rdns; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + public function __toString() |
|
| 44 | + { |
|
| 45 | + return $this->toString(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Initialize from ASN.1. |
|
| 50 | + * |
|
| 51 | + * @param Sequence $seq |
|
| 52 | + * |
|
| 53 | + * @return self |
|
| 54 | + */ |
|
| 55 | + public static function fromASN1(Sequence $seq): self |
|
| 56 | + { |
|
| 57 | + $rdns = array_map( |
|
| 58 | + function (UnspecifiedType $el) { |
|
| 59 | + return RDN::fromASN1($el->asSet()); |
|
| 60 | + }, $seq->elements()); |
|
| 61 | + return new self(...$rdns); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Initialize from distinguished name string. |
|
| 66 | + * |
|
| 67 | + * @see https://tools.ietf.org/html/rfc1779 |
|
| 68 | + * |
|
| 69 | + * @param string $str |
|
| 70 | + * |
|
| 71 | + * @return self |
|
| 72 | + */ |
|
| 73 | + public static function fromString(string $str): self |
|
| 74 | + { |
|
| 75 | + $rdns = []; |
|
| 76 | + foreach (DNParser::parseString($str) as $nameComponent) { |
|
| 77 | + $attribs = []; |
|
| 78 | + foreach ($nameComponent as [$name, $val]) { |
|
| 79 | + $type = AttributeType::fromName($name); |
|
| 80 | + // hexstrings are parsed to ASN.1 elements |
|
| 81 | + if ($val instanceof Element) { |
|
| 82 | + $el = $val; |
|
| 83 | + } else { |
|
| 84 | + $el = AttributeType::asn1StringForType($type->oid(), $val); |
|
| 85 | + } |
|
| 86 | + $value = AttributeValue::fromASN1ByOID($type->oid(), |
|
| 87 | + $el->asUnspecified()); |
|
| 88 | + $attribs[] = new AttributeTypeAndValue($type, $value); |
|
| 89 | + } |
|
| 90 | + $rdns[] = new RDN(...$attribs); |
|
| 91 | + } |
|
| 92 | + return new self(...$rdns); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Generate ASN.1 structure. |
|
| 97 | + * |
|
| 98 | + * @return Sequence |
|
| 99 | + */ |
|
| 100 | + public function toASN1(): Sequence |
|
| 101 | + { |
|
| 102 | + $elements = array_map( |
|
| 103 | + function (RDN $rdn) { |
|
| 104 | + return $rdn->toASN1(); |
|
| 105 | + }, $this->_rdns); |
|
| 106 | + return new Sequence(...$elements); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Get distinguised name string conforming to RFC 2253. |
|
| 111 | + * |
|
| 112 | + * @see https://tools.ietf.org/html/rfc2253#section-2.1 |
|
| 113 | + * |
|
| 114 | + * @return string |
|
| 115 | + */ |
|
| 116 | + public function toString(): string |
|
| 117 | + { |
|
| 118 | + $parts = array_map( |
|
| 119 | + function (RDN $rdn) { |
|
| 120 | + return $rdn->toString(); |
|
| 121 | + }, array_reverse($this->_rdns)); |
|
| 122 | + return implode(',', $parts); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Whether name is semantically equal to other. |
|
| 127 | + * |
|
| 128 | + * Comparison conforms to RFC 4518 string preparation algorithm. |
|
| 129 | + * |
|
| 130 | + * @see https://tools.ietf.org/html/rfc4518 |
|
| 131 | + * |
|
| 132 | + * @param Name $other Object to compare to |
|
| 133 | + * |
|
| 134 | + * @return bool |
|
| 135 | + */ |
|
| 136 | + public function equals(Name $other): bool |
|
| 137 | + { |
|
| 138 | + // if RDN count doesn't match |
|
| 139 | + if (count($this) !== count($other)) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | + for ($i = count($this) - 1; $i >= 0; --$i) { |
|
| 143 | + $rdn1 = $this->_rdns[$i]; |
|
| 144 | + $rdn2 = $other->_rdns[$i]; |
|
| 145 | + if (!$rdn1->equals($rdn2)) { |
|
| 146 | + return false; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + return true; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Get all RDN objects. |
|
| 154 | + * |
|
| 155 | + * @return RDN[] |
|
| 156 | + */ |
|
| 157 | + public function all(): array |
|
| 158 | + { |
|
| 159 | + return $this->_rdns; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Get the first AttributeValue of given type. |
|
| 164 | + * |
|
| 165 | + * Relative name components shall be traversed in encoding order, which is |
|
| 166 | + * reversed in regards to the string representation. |
|
| 167 | + * Multi-valued RDN with multiple attributes of the requested type is |
|
| 168 | + * ambiguous and shall throw an exception. |
|
| 169 | + * |
|
| 170 | + * @param string $name Attribute OID or name |
|
| 171 | + * |
|
| 172 | + * @throws \RuntimeException If attribute cannot be resolved |
|
| 173 | + * |
|
| 174 | + * @return AttributeValue |
|
| 175 | + */ |
|
| 176 | + public function firstValueOf(string $name): AttributeValue |
|
| 177 | + { |
|
| 178 | + $oid = AttributeType::attrNameToOID($name); |
|
| 179 | + foreach ($this->_rdns as $rdn) { |
|
| 180 | + $tvs = $rdn->allOf($oid); |
|
| 181 | + if (count($tvs) > 1) { |
|
| 182 | + throw new \RangeException("RDN with multiple {$name} attributes."); |
|
| 183 | + } |
|
| 184 | + if (1 === count($tvs)) { |
|
| 185 | + return $tvs[0]->value(); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + throw new \RangeException("Attribute {$name} not found."); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * @see \Countable::count() |
|
| 193 | + * |
|
| 194 | + * @return int |
|
| 195 | + */ |
|
| 196 | + public function count(): int |
|
| 197 | + { |
|
| 198 | + return count($this->_rdns); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * Get the number of attributes of given type. |
|
| 203 | + * |
|
| 204 | + * @param string $name Attribute OID or name |
|
| 205 | + * |
|
| 206 | + * @return int |
|
| 207 | + */ |
|
| 208 | + public function countOfType(string $name): int |
|
| 209 | + { |
|
| 210 | + $oid = AttributeType::attrNameToOID($name); |
|
| 211 | + return (int) array_sum( |
|
| 212 | + array_map( |
|
| 213 | + function (RDN $rdn) use ($oid): int { |
|
| 214 | + return count($rdn->allOf($oid)); |
|
| 215 | + }, $this->_rdns)); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * @see \IteratorAggregate::getIterator() |
|
| 220 | + * |
|
| 221 | + * @return \ArrayIterator |
|
| 222 | + */ |
|
| 223 | + public function getIterator(): \ArrayIterator |
|
| 224 | + { |
|
| 225 | + return new \ArrayIterator($this->_rdns); |
|
| 226 | + } |
|
| 227 | 227 | } |
@@ -17,441 +17,441 @@ |
||
| 17 | 17 | */ |
| 18 | 18 | class AttributeType |
| 19 | 19 | { |
| 20 | - // OID's from 2.5.4 arc |
|
| 21 | - const OID_OBJECT_CLASS = '2.5.4.0'; |
|
| 22 | - const OID_ALIASED_ENTRY_NAME = '2.5.4.1'; |
|
| 23 | - const OID_KNOWLEDGE_INFORMATION = '2.5.4.2'; |
|
| 24 | - const OID_COMMON_NAME = '2.5.4.3'; |
|
| 25 | - const OID_SURNAME = '2.5.4.4'; |
|
| 26 | - const OID_SERIAL_NUMBER = '2.5.4.5'; |
|
| 27 | - const OID_COUNTRY_NAME = '2.5.4.6'; |
|
| 28 | - const OID_LOCALITY_NAME = '2.5.4.7'; |
|
| 29 | - const OID_STATE_OR_PROVINCE_NAME = '2.5.4.8'; |
|
| 30 | - const OID_STREET_ADDRESS = '2.5.4.9'; |
|
| 31 | - const OID_ORGANIZATION_NAME = '2.5.4.10'; |
|
| 32 | - const OID_ORGANIZATIONAL_UNIT_NAME = '2.5.4.11'; |
|
| 33 | - const OID_TITLE = '2.5.4.12'; |
|
| 34 | - const OID_DESCRIPTION = '2.5.4.13'; |
|
| 35 | - const OID_SEARCH_GUIDE = '2.5.4.14'; |
|
| 36 | - const OID_BUSINESS_CATEGORY = '2.5.4.15'; |
|
| 37 | - const OID_POSTAL_ADDRESS = '2.5.4.16'; |
|
| 38 | - const OID_POSTAL_CODE = '2.5.4.17'; |
|
| 39 | - const OID_POST_OFFICE_BOX = '2.5.4.18'; |
|
| 40 | - const OID_PHYSICAL_DELIVERY_OFFICE_NAME = '2.5.4.19'; |
|
| 41 | - const OID_TELEPHONE_NUMBER = '2.5.4.20'; |
|
| 42 | - const OID_TELEX_NUMBER = '2.5.4.21'; |
|
| 43 | - const OID_TELETEX_TERMINAL_IDENTIFIER = '2.5.4.22'; |
|
| 44 | - const OID_FACSIMILE_TELEPHONE_NUMBER = '2.5.4.23'; |
|
| 45 | - const OID_X121_ADDRESS = '2.5.4.24'; |
|
| 46 | - const OID_INTERNATIONAL_ISDN_NUMBER = '2.5.4.25'; |
|
| 47 | - const OID_REGISTERED_ADDRESS = '2.5.4.26'; |
|
| 48 | - const OID_DESTINATION_INDICATOR = '2.5.4.27'; |
|
| 49 | - const OID_PREFERRED_DELIVERY_METHOD = '2.5.4.28'; |
|
| 50 | - const OID_PRESENTATION_ADDRESS = '2.5.4.29'; |
|
| 51 | - const OID_SUPPORTED_APPLICATION_CONTEXT = '2.5.4.30'; |
|
| 52 | - const OID_MEMBER = '2.5.4.31'; |
|
| 53 | - const OID_OWNER = '2.5.4.32'; |
|
| 54 | - const OID_ROLE_OCCUPANT = '2.5.4.33'; |
|
| 55 | - const OID_SEE_ALSO = '2.5.4.34'; |
|
| 56 | - const OID_USER_PASSWORD = '2.5.4.35'; |
|
| 57 | - const OID_USER_CERTIFICATE = '2.5.4.36'; |
|
| 58 | - const OID_CA_CERTIFICATE = '2.5.4.37'; |
|
| 59 | - const OID_AUTHORITY_REVOCATION_LIST = '2.5.4.38'; |
|
| 60 | - const OID_CERTIFICATE_REVOCATION_LIST = '2.5.4.39'; |
|
| 61 | - const OID_CROSS_CERTIFICATE_PAIR = '2.5.4.40'; |
|
| 62 | - const OID_NAME = '2.5.4.41'; |
|
| 63 | - const OID_GIVEN_NAME = '2.5.4.42'; |
|
| 64 | - const OID_INITIALS = '2.5.4.43'; |
|
| 65 | - const OID_GENERATION_QUALIFIER = '2.5.4.44'; |
|
| 66 | - const OID_UNIQUE_IDENTIFIER = '2.5.4.45'; |
|
| 67 | - const OID_DN_QUALIFIER = '2.5.4.46'; |
|
| 68 | - const OID_ENHANCED_SEARCH_GUIDE = '2.5.4.47'; |
|
| 69 | - const OID_PROTOCOL_INFORMATION = '2.5.4.48'; |
|
| 70 | - const OID_DISTINGUISHED_NAME = '2.5.4.49'; |
|
| 71 | - const OID_UNIQUE_MEMBER = '2.5.4.50'; |
|
| 72 | - const OID_HOUSE_IDENTIFIER = '2.5.4.51'; |
|
| 73 | - const OID_SUPPORTED_ALGORITHMS = '2.5.4.52'; |
|
| 74 | - const OID_DELTA_REVOCATION_LIST = '2.5.4.53'; |
|
| 75 | - const OID_DMD_NAME = '2.5.4.54'; |
|
| 76 | - const OID_CLEARANCE = '2.5.4.55'; |
|
| 77 | - const OID_DEFAULT_DIR_QOP = '2.5.4.56'; |
|
| 78 | - const OID_ATTRIBUTE_INTEGRITY_INFO = '2.5.4.57'; |
|
| 79 | - const OID_ATTRIBUTE_CERTIFICATE = '2.5.4.58'; |
|
| 80 | - const OID_ATTRIBUTE_CERTIFICATE_REVOCATION_LIST = '2.5.4.59'; |
|
| 81 | - const OID_CONF_KEY_INFO = '2.5.4.60'; |
|
| 82 | - const OID_AA_CERTIFICATE = '2.5.4.61'; |
|
| 83 | - const OID_ATTRIBUTE_DESCRIPTOR_CERTIFICATE = '2.5.4.62'; |
|
| 84 | - const OID_ATTRIBUTE_AUTHORITY_REVOCATION_LIST = '2.5.4.63'; |
|
| 85 | - const OID_FAMILY_INFORMATION = '2.5.4.64'; |
|
| 86 | - const OID_PSEUDONYM = '2.5.4.65'; |
|
| 87 | - const OID_COMMUNICATIONS_SERVICE = '2.5.4.66'; |
|
| 88 | - const OID_COMMUNICATIONS_NETWORK = '2.5.4.67'; |
|
| 89 | - const OID_CERTIFICATION_PRACTICE_STMT = '2.5.4.68'; |
|
| 90 | - const OID_CERTIFICATE_POLICY = '2.5.4.69'; |
|
| 91 | - const OID_PKI_PATH = '2.5.4.70'; |
|
| 92 | - const OID_PRIV_POLICY = '2.5.4.71'; |
|
| 93 | - const OID_ROLE = '2.5.4.72'; |
|
| 94 | - const OID_DELEGATION_PATH = '2.5.4.73'; |
|
| 95 | - const OID_PROT_PRIV_POLICY = '2.5.4.74'; |
|
| 96 | - const OID_XML_PRIVILEGE_INFO = '2.5.4.75'; |
|
| 97 | - const OID_XML_PRIV_POLICY = '2.5.4.76'; |
|
| 98 | - const OID_UUID_PAIR = '2.5.4.77'; |
|
| 99 | - const OID_TAG_OID = '2.5.4.78'; |
|
| 100 | - const OID_UII_FORMAT = '2.5.4.79'; |
|
| 101 | - const OID_UII_IN_URH = '2.5.4.80'; |
|
| 102 | - const OID_CONTENT_URL = '2.5.4.81'; |
|
| 103 | - const OID_PERMISSION = '2.5.4.82'; |
|
| 104 | - const OID_URI = '2.5.4.83'; |
|
| 105 | - const OID_PWD_ATTRIBUTE = '2.5.4.84'; |
|
| 106 | - const OID_USER_PWD = '2.5.4.85'; |
|
| 107 | - const OID_URN = '2.5.4.86'; |
|
| 108 | - const OID_URL = '2.5.4.87'; |
|
| 109 | - const OID_UTM_COORDINATES = '2.5.4.88'; |
|
| 110 | - const OID_URNC = '2.5.4.89'; |
|
| 111 | - const OID_UII = '2.5.4.90'; |
|
| 112 | - const OID_EPC = '2.5.4.91'; |
|
| 113 | - const OID_TAG_AFI = '2.5.4.92'; |
|
| 114 | - const OID_EPC_FORMAT = '2.5.4.93'; |
|
| 115 | - const OID_EPC_IN_URN = '2.5.4.94'; |
|
| 116 | - const OID_LDAP_URL = '2.5.4.95'; |
|
| 117 | - const OID_TAG_LOCATION = '2.5.4.96'; |
|
| 118 | - const OID_ORGANIZATION_IDENTIFIER = '2.5.4.97'; |
|
| 20 | + // OID's from 2.5.4 arc |
|
| 21 | + const OID_OBJECT_CLASS = '2.5.4.0'; |
|
| 22 | + const OID_ALIASED_ENTRY_NAME = '2.5.4.1'; |
|
| 23 | + const OID_KNOWLEDGE_INFORMATION = '2.5.4.2'; |
|
| 24 | + const OID_COMMON_NAME = '2.5.4.3'; |
|
| 25 | + const OID_SURNAME = '2.5.4.4'; |
|
| 26 | + const OID_SERIAL_NUMBER = '2.5.4.5'; |
|
| 27 | + const OID_COUNTRY_NAME = '2.5.4.6'; |
|
| 28 | + const OID_LOCALITY_NAME = '2.5.4.7'; |
|
| 29 | + const OID_STATE_OR_PROVINCE_NAME = '2.5.4.8'; |
|
| 30 | + const OID_STREET_ADDRESS = '2.5.4.9'; |
|
| 31 | + const OID_ORGANIZATION_NAME = '2.5.4.10'; |
|
| 32 | + const OID_ORGANIZATIONAL_UNIT_NAME = '2.5.4.11'; |
|
| 33 | + const OID_TITLE = '2.5.4.12'; |
|
| 34 | + const OID_DESCRIPTION = '2.5.4.13'; |
|
| 35 | + const OID_SEARCH_GUIDE = '2.5.4.14'; |
|
| 36 | + const OID_BUSINESS_CATEGORY = '2.5.4.15'; |
|
| 37 | + const OID_POSTAL_ADDRESS = '2.5.4.16'; |
|
| 38 | + const OID_POSTAL_CODE = '2.5.4.17'; |
|
| 39 | + const OID_POST_OFFICE_BOX = '2.5.4.18'; |
|
| 40 | + const OID_PHYSICAL_DELIVERY_OFFICE_NAME = '2.5.4.19'; |
|
| 41 | + const OID_TELEPHONE_NUMBER = '2.5.4.20'; |
|
| 42 | + const OID_TELEX_NUMBER = '2.5.4.21'; |
|
| 43 | + const OID_TELETEX_TERMINAL_IDENTIFIER = '2.5.4.22'; |
|
| 44 | + const OID_FACSIMILE_TELEPHONE_NUMBER = '2.5.4.23'; |
|
| 45 | + const OID_X121_ADDRESS = '2.5.4.24'; |
|
| 46 | + const OID_INTERNATIONAL_ISDN_NUMBER = '2.5.4.25'; |
|
| 47 | + const OID_REGISTERED_ADDRESS = '2.5.4.26'; |
|
| 48 | + const OID_DESTINATION_INDICATOR = '2.5.4.27'; |
|
| 49 | + const OID_PREFERRED_DELIVERY_METHOD = '2.5.4.28'; |
|
| 50 | + const OID_PRESENTATION_ADDRESS = '2.5.4.29'; |
|
| 51 | + const OID_SUPPORTED_APPLICATION_CONTEXT = '2.5.4.30'; |
|
| 52 | + const OID_MEMBER = '2.5.4.31'; |
|
| 53 | + const OID_OWNER = '2.5.4.32'; |
|
| 54 | + const OID_ROLE_OCCUPANT = '2.5.4.33'; |
|
| 55 | + const OID_SEE_ALSO = '2.5.4.34'; |
|
| 56 | + const OID_USER_PASSWORD = '2.5.4.35'; |
|
| 57 | + const OID_USER_CERTIFICATE = '2.5.4.36'; |
|
| 58 | + const OID_CA_CERTIFICATE = '2.5.4.37'; |
|
| 59 | + const OID_AUTHORITY_REVOCATION_LIST = '2.5.4.38'; |
|
| 60 | + const OID_CERTIFICATE_REVOCATION_LIST = '2.5.4.39'; |
|
| 61 | + const OID_CROSS_CERTIFICATE_PAIR = '2.5.4.40'; |
|
| 62 | + const OID_NAME = '2.5.4.41'; |
|
| 63 | + const OID_GIVEN_NAME = '2.5.4.42'; |
|
| 64 | + const OID_INITIALS = '2.5.4.43'; |
|
| 65 | + const OID_GENERATION_QUALIFIER = '2.5.4.44'; |
|
| 66 | + const OID_UNIQUE_IDENTIFIER = '2.5.4.45'; |
|
| 67 | + const OID_DN_QUALIFIER = '2.5.4.46'; |
|
| 68 | + const OID_ENHANCED_SEARCH_GUIDE = '2.5.4.47'; |
|
| 69 | + const OID_PROTOCOL_INFORMATION = '2.5.4.48'; |
|
| 70 | + const OID_DISTINGUISHED_NAME = '2.5.4.49'; |
|
| 71 | + const OID_UNIQUE_MEMBER = '2.5.4.50'; |
|
| 72 | + const OID_HOUSE_IDENTIFIER = '2.5.4.51'; |
|
| 73 | + const OID_SUPPORTED_ALGORITHMS = '2.5.4.52'; |
|
| 74 | + const OID_DELTA_REVOCATION_LIST = '2.5.4.53'; |
|
| 75 | + const OID_DMD_NAME = '2.5.4.54'; |
|
| 76 | + const OID_CLEARANCE = '2.5.4.55'; |
|
| 77 | + const OID_DEFAULT_DIR_QOP = '2.5.4.56'; |
|
| 78 | + const OID_ATTRIBUTE_INTEGRITY_INFO = '2.5.4.57'; |
|
| 79 | + const OID_ATTRIBUTE_CERTIFICATE = '2.5.4.58'; |
|
| 80 | + const OID_ATTRIBUTE_CERTIFICATE_REVOCATION_LIST = '2.5.4.59'; |
|
| 81 | + const OID_CONF_KEY_INFO = '2.5.4.60'; |
|
| 82 | + const OID_AA_CERTIFICATE = '2.5.4.61'; |
|
| 83 | + const OID_ATTRIBUTE_DESCRIPTOR_CERTIFICATE = '2.5.4.62'; |
|
| 84 | + const OID_ATTRIBUTE_AUTHORITY_REVOCATION_LIST = '2.5.4.63'; |
|
| 85 | + const OID_FAMILY_INFORMATION = '2.5.4.64'; |
|
| 86 | + const OID_PSEUDONYM = '2.5.4.65'; |
|
| 87 | + const OID_COMMUNICATIONS_SERVICE = '2.5.4.66'; |
|
| 88 | + const OID_COMMUNICATIONS_NETWORK = '2.5.4.67'; |
|
| 89 | + const OID_CERTIFICATION_PRACTICE_STMT = '2.5.4.68'; |
|
| 90 | + const OID_CERTIFICATE_POLICY = '2.5.4.69'; |
|
| 91 | + const OID_PKI_PATH = '2.5.4.70'; |
|
| 92 | + const OID_PRIV_POLICY = '2.5.4.71'; |
|
| 93 | + const OID_ROLE = '2.5.4.72'; |
|
| 94 | + const OID_DELEGATION_PATH = '2.5.4.73'; |
|
| 95 | + const OID_PROT_PRIV_POLICY = '2.5.4.74'; |
|
| 96 | + const OID_XML_PRIVILEGE_INFO = '2.5.4.75'; |
|
| 97 | + const OID_XML_PRIV_POLICY = '2.5.4.76'; |
|
| 98 | + const OID_UUID_PAIR = '2.5.4.77'; |
|
| 99 | + const OID_TAG_OID = '2.5.4.78'; |
|
| 100 | + const OID_UII_FORMAT = '2.5.4.79'; |
|
| 101 | + const OID_UII_IN_URH = '2.5.4.80'; |
|
| 102 | + const OID_CONTENT_URL = '2.5.4.81'; |
|
| 103 | + const OID_PERMISSION = '2.5.4.82'; |
|
| 104 | + const OID_URI = '2.5.4.83'; |
|
| 105 | + const OID_PWD_ATTRIBUTE = '2.5.4.84'; |
|
| 106 | + const OID_USER_PWD = '2.5.4.85'; |
|
| 107 | + const OID_URN = '2.5.4.86'; |
|
| 108 | + const OID_URL = '2.5.4.87'; |
|
| 109 | + const OID_UTM_COORDINATES = '2.5.4.88'; |
|
| 110 | + const OID_URNC = '2.5.4.89'; |
|
| 111 | + const OID_UII = '2.5.4.90'; |
|
| 112 | + const OID_EPC = '2.5.4.91'; |
|
| 113 | + const OID_TAG_AFI = '2.5.4.92'; |
|
| 114 | + const OID_EPC_FORMAT = '2.5.4.93'; |
|
| 115 | + const OID_EPC_IN_URN = '2.5.4.94'; |
|
| 116 | + const OID_LDAP_URL = '2.5.4.95'; |
|
| 117 | + const OID_TAG_LOCATION = '2.5.4.96'; |
|
| 118 | + const OID_ORGANIZATION_IDENTIFIER = '2.5.4.97'; |
|
| 119 | 119 | |
| 120 | - // Miscellany attribute OID's |
|
| 121 | - const OID_CLEARANCE_X501 = '2.5.1.5.55'; |
|
| 120 | + // Miscellany attribute OID's |
|
| 121 | + const OID_CLEARANCE_X501 = '2.5.1.5.55'; |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Default ASN.1 string types for attributes. |
|
| 125 | - * |
|
| 126 | - * Attributes not mapped here shall use UTF8String as a default type. |
|
| 127 | - * |
|
| 128 | - * @internal |
|
| 129 | - * |
|
| 130 | - * @var array |
|
| 131 | - */ |
|
| 132 | - const MAP_ATTR_TO_STR_TYPE = [ |
|
| 133 | - self::OID_DN_QUALIFIER => Element::TYPE_PRINTABLE_STRING, |
|
| 134 | - self::OID_COUNTRY_NAME => Element::TYPE_PRINTABLE_STRING, |
|
| 135 | - self::OID_SERIAL_NUMBER => Element::TYPE_PRINTABLE_STRING, |
|
| 136 | - ]; |
|
| 123 | + /** |
|
| 124 | + * Default ASN.1 string types for attributes. |
|
| 125 | + * |
|
| 126 | + * Attributes not mapped here shall use UTF8String as a default type. |
|
| 127 | + * |
|
| 128 | + * @internal |
|
| 129 | + * |
|
| 130 | + * @var array |
|
| 131 | + */ |
|
| 132 | + const MAP_ATTR_TO_STR_TYPE = [ |
|
| 133 | + self::OID_DN_QUALIFIER => Element::TYPE_PRINTABLE_STRING, |
|
| 134 | + self::OID_COUNTRY_NAME => Element::TYPE_PRINTABLE_STRING, |
|
| 135 | + self::OID_SERIAL_NUMBER => Element::TYPE_PRINTABLE_STRING, |
|
| 136 | + ]; |
|
| 137 | 137 | |
| 138 | - /** |
|
| 139 | - * OID to attribute names mapping. |
|
| 140 | - * |
|
| 141 | - * First name is the primary name. If there's more than one name, others may |
|
| 142 | - * be used as an alias. |
|
| 143 | - * |
|
| 144 | - * Generated using ldap-attribs.py. |
|
| 145 | - * |
|
| 146 | - * @internal |
|
| 147 | - * |
|
| 148 | - * @var array |
|
| 149 | - */ |
|
| 150 | - const MAP_OID_TO_NAME = [ |
|
| 151 | - '0.9.2342.19200300.100.1.1' => ['uid', 'userid'], |
|
| 152 | - '0.9.2342.19200300.100.1.2' => ['textEncodedORAddress'], |
|
| 153 | - '0.9.2342.19200300.100.1.3' => ['mail', 'rfc822Mailbox'], |
|
| 154 | - '0.9.2342.19200300.100.1.4' => ['info'], |
|
| 155 | - '0.9.2342.19200300.100.1.5' => ['drink', 'favouriteDrink'], |
|
| 156 | - '0.9.2342.19200300.100.1.6' => ['roomNumber'], |
|
| 157 | - '0.9.2342.19200300.100.1.7' => ['photo'], |
|
| 158 | - '0.9.2342.19200300.100.1.8' => ['userClass'], |
|
| 159 | - '0.9.2342.19200300.100.1.9' => ['host'], |
|
| 160 | - '0.9.2342.19200300.100.1.10' => ['manager'], |
|
| 161 | - '0.9.2342.19200300.100.1.11' => ['documentIdentifier'], |
|
| 162 | - '0.9.2342.19200300.100.1.12' => ['documentTitle'], |
|
| 163 | - '0.9.2342.19200300.100.1.13' => ['documentVersion'], |
|
| 164 | - '0.9.2342.19200300.100.1.14' => ['documentAuthor'], |
|
| 165 | - '0.9.2342.19200300.100.1.15' => ['documentLocation'], |
|
| 166 | - '0.9.2342.19200300.100.1.20' => ['homePhone', 'homeTelephoneNumber'], |
|
| 167 | - '0.9.2342.19200300.100.1.21' => ['secretary'], |
|
| 168 | - '0.9.2342.19200300.100.1.22' => ['otherMailbox'], |
|
| 169 | - '0.9.2342.19200300.100.1.25' => ['dc', 'domainComponent'], |
|
| 170 | - '0.9.2342.19200300.100.1.26' => ['aRecord'], |
|
| 171 | - '0.9.2342.19200300.100.1.27' => ['mDRecord'], |
|
| 172 | - '0.9.2342.19200300.100.1.28' => ['mXRecord'], |
|
| 173 | - '0.9.2342.19200300.100.1.29' => ['nSRecord'], |
|
| 174 | - '0.9.2342.19200300.100.1.30' => ['sOARecord'], |
|
| 175 | - '0.9.2342.19200300.100.1.31' => ['cNAMERecord'], |
|
| 176 | - '0.9.2342.19200300.100.1.37' => ['associatedDomain'], |
|
| 177 | - '0.9.2342.19200300.100.1.38' => ['associatedName'], |
|
| 178 | - '0.9.2342.19200300.100.1.39' => ['homePostalAddress'], |
|
| 179 | - '0.9.2342.19200300.100.1.40' => ['personalTitle'], |
|
| 180 | - '0.9.2342.19200300.100.1.41' => ['mobile', 'mobileTelephoneNumber'], |
|
| 181 | - '0.9.2342.19200300.100.1.42' => ['pager', 'pagerTelephoneNumber'], |
|
| 182 | - '0.9.2342.19200300.100.1.43' => ['co', 'friendlyCountryName'], |
|
| 183 | - '0.9.2342.19200300.100.1.44' => ['uniqueIdentifier'], |
|
| 184 | - '0.9.2342.19200300.100.1.45' => ['organizationalStatus'], |
|
| 185 | - '0.9.2342.19200300.100.1.46' => ['janetMailbox'], |
|
| 186 | - '0.9.2342.19200300.100.1.47' => ['mailPreferenceOption'], |
|
| 187 | - '0.9.2342.19200300.100.1.48' => ['buildingName'], |
|
| 188 | - '0.9.2342.19200300.100.1.49' => ['dSAQuality'], |
|
| 189 | - '0.9.2342.19200300.100.1.50' => ['singleLevelQuality'], |
|
| 190 | - '0.9.2342.19200300.100.1.51' => ['subtreeMinimumQuality'], |
|
| 191 | - '0.9.2342.19200300.100.1.52' => ['subtreeMaximumQuality'], |
|
| 192 | - '0.9.2342.19200300.100.1.53' => ['personalSignature'], |
|
| 193 | - '0.9.2342.19200300.100.1.54' => ['dITRedirect'], |
|
| 194 | - '0.9.2342.19200300.100.1.55' => ['audio'], |
|
| 195 | - '0.9.2342.19200300.100.1.56' => ['documentPublisher'], |
|
| 196 | - '0.9.2342.19200300.100.1.60' => ['jpegPhoto'], |
|
| 197 | - '1.2.840.113549.1.9.1' => ['email', 'emailAddress', 'pkcs9email'], |
|
| 198 | - '1.2.840.113556.1.2.102' => ['memberOf'], |
|
| 199 | - '1.3.6.1.1.1.1.0' => ['uidNumber'], |
|
| 200 | - '1.3.6.1.1.1.1.1' => ['gidNumber'], |
|
| 201 | - '1.3.6.1.1.1.1.2' => ['gecos'], |
|
| 202 | - '1.3.6.1.1.1.1.3' => ['homeDirectory'], |
|
| 203 | - '1.3.6.1.1.1.1.4' => ['loginShell'], |
|
| 204 | - '1.3.6.1.1.1.1.5' => ['shadowLastChange'], |
|
| 205 | - '1.3.6.1.1.1.1.6' => ['shadowMin'], |
|
| 206 | - '1.3.6.1.1.1.1.7' => ['shadowMax'], |
|
| 207 | - '1.3.6.1.1.1.1.8' => ['shadowWarning'], |
|
| 208 | - '1.3.6.1.1.1.1.9' => ['shadowInactive'], |
|
| 209 | - '1.3.6.1.1.1.1.10' => ['shadowExpire'], |
|
| 210 | - '1.3.6.1.1.1.1.11' => ['shadowFlag'], |
|
| 211 | - '1.3.6.1.1.1.1.12' => ['memberUid'], |
|
| 212 | - '1.3.6.1.1.1.1.13' => ['memberNisNetgroup'], |
|
| 213 | - '1.3.6.1.1.1.1.14' => ['nisNetgroupTriple'], |
|
| 214 | - '1.3.6.1.1.1.1.15' => ['ipServicePort'], |
|
| 215 | - '1.3.6.1.1.1.1.16' => ['ipServiceProtocol'], |
|
| 216 | - '1.3.6.1.1.1.1.17' => ['ipProtocolNumber'], |
|
| 217 | - '1.3.6.1.1.1.1.18' => ['oncRpcNumber'], |
|
| 218 | - '1.3.6.1.1.1.1.19' => ['ipHostNumber'], |
|
| 219 | - '1.3.6.1.1.1.1.20' => ['ipNetworkNumber'], |
|
| 220 | - '1.3.6.1.1.1.1.21' => ['ipNetmaskNumber'], |
|
| 221 | - '1.3.6.1.1.1.1.22' => ['macAddress'], |
|
| 222 | - '1.3.6.1.1.1.1.23' => ['bootParameter'], |
|
| 223 | - '1.3.6.1.1.1.1.24' => ['bootFile'], |
|
| 224 | - '1.3.6.1.1.1.1.26' => ['nisMapName'], |
|
| 225 | - '1.3.6.1.1.1.1.27' => ['nisMapEntry'], |
|
| 226 | - '1.3.6.1.1.4' => ['vendorName'], |
|
| 227 | - '1.3.6.1.1.5' => ['vendorVersion'], |
|
| 228 | - '1.3.6.1.1.16.4' => ['entryUUID'], |
|
| 229 | - '1.3.6.1.1.20' => ['entryDN'], |
|
| 230 | - '2.5.4.0' => ['objectClass'], |
|
| 231 | - '2.5.4.1' => ['aliasedObjectName', 'aliasedEntryName'], |
|
| 232 | - '2.5.4.2' => ['knowledgeInformation'], |
|
| 233 | - '2.5.4.3' => ['cn', 'commonName'], |
|
| 234 | - '2.5.4.4' => ['sn', 'surname'], |
|
| 235 | - '2.5.4.5' => ['serialNumber'], |
|
| 236 | - '2.5.4.6' => ['c', 'countryName'], |
|
| 237 | - '2.5.4.7' => ['l', 'localityName'], |
|
| 238 | - '2.5.4.8' => ['st', 'stateOrProvinceName'], |
|
| 239 | - '2.5.4.9' => ['street', 'streetAddress'], |
|
| 240 | - '2.5.4.10' => ['o', 'organizationName'], |
|
| 241 | - '2.5.4.11' => ['ou', 'organizationalUnitName'], |
|
| 242 | - '2.5.4.12' => ['title'], |
|
| 243 | - '2.5.4.13' => ['description'], |
|
| 244 | - '2.5.4.14' => ['searchGuide'], |
|
| 245 | - '2.5.4.15' => ['businessCategory'], |
|
| 246 | - '2.5.4.16' => ['postalAddress'], |
|
| 247 | - '2.5.4.17' => ['postalCode'], |
|
| 248 | - '2.5.4.18' => ['postOfficeBox'], |
|
| 249 | - '2.5.4.19' => ['physicalDeliveryOfficeName'], |
|
| 250 | - '2.5.4.20' => ['telephoneNumber'], |
|
| 251 | - '2.5.4.21' => ['telexNumber'], |
|
| 252 | - '2.5.4.22' => ['teletexTerminalIdentifier'], |
|
| 253 | - '2.5.4.23' => ['facsimileTelephoneNumber', 'fax'], |
|
| 254 | - '2.5.4.24' => ['x121Address'], |
|
| 255 | - '2.5.4.25' => ['internationaliSDNNumber'], |
|
| 256 | - '2.5.4.26' => ['registeredAddress'], |
|
| 257 | - '2.5.4.27' => ['destinationIndicator'], |
|
| 258 | - '2.5.4.28' => ['preferredDeliveryMethod'], |
|
| 259 | - '2.5.4.29' => ['presentationAddress'], |
|
| 260 | - '2.5.4.30' => ['supportedApplicationContext'], |
|
| 261 | - '2.5.4.31' => ['member'], |
|
| 262 | - '2.5.4.32' => ['owner'], |
|
| 263 | - '2.5.4.33' => ['roleOccupant'], |
|
| 264 | - '2.5.4.34' => ['seeAlso'], |
|
| 265 | - '2.5.4.35' => ['userPassword'], |
|
| 266 | - '2.5.4.36' => ['userCertificate'], |
|
| 267 | - '2.5.4.37' => ['cACertificate'], |
|
| 268 | - '2.5.4.38' => ['authorityRevocationList'], |
|
| 269 | - '2.5.4.39' => ['certificateRevocationList'], |
|
| 270 | - '2.5.4.40' => ['crossCertificatePair'], |
|
| 271 | - '2.5.4.41' => ['name'], |
|
| 272 | - '2.5.4.42' => ['givenName', 'gn'], |
|
| 273 | - '2.5.4.43' => ['initials'], |
|
| 274 | - '2.5.4.44' => ['generationQualifier'], |
|
| 275 | - '2.5.4.45' => ['x500UniqueIdentifier'], |
|
| 276 | - '2.5.4.46' => ['dnQualifier'], |
|
| 277 | - '2.5.4.47' => ['enhancedSearchGuide'], |
|
| 278 | - '2.5.4.48' => ['protocolInformation'], |
|
| 279 | - '2.5.4.49' => ['distinguishedName'], |
|
| 280 | - '2.5.4.50' => ['uniqueMember'], |
|
| 281 | - '2.5.4.51' => ['houseIdentifier'], |
|
| 282 | - '2.5.4.52' => ['supportedAlgorithms'], |
|
| 283 | - '2.5.4.53' => ['deltaRevocationList'], |
|
| 284 | - '2.5.4.54' => ['dmdName'], |
|
| 285 | - '2.5.4.65' => ['pseudonym'], |
|
| 286 | - '2.5.18.1' => ['createTimestamp'], |
|
| 287 | - '2.5.18.2' => ['modifyTimestamp'], |
|
| 288 | - '2.5.18.3' => ['creatorsName'], |
|
| 289 | - '2.5.18.4' => ['modifiersName'], |
|
| 290 | - '2.5.18.5' => ['administrativeRole'], |
|
| 291 | - '2.5.18.6' => ['subtreeSpecification'], |
|
| 292 | - '2.5.18.9' => ['hasSubordinates'], |
|
| 293 | - '2.5.18.10' => ['subschemaSubentry'], |
|
| 294 | - '2.5.21.1' => ['dITStructureRules'], |
|
| 295 | - '2.5.21.2' => ['dITContentRules'], |
|
| 296 | - '2.5.21.4' => ['matchingRules'], |
|
| 297 | - '2.5.21.5' => ['attributeTypes'], |
|
| 298 | - '2.5.21.6' => ['objectClasses'], |
|
| 299 | - '2.5.21.7' => ['nameForms'], |
|
| 300 | - '2.5.21.8' => ['matchingRuleUse'], |
|
| 301 | - '2.5.21.9' => ['structuralObjectClass'], |
|
| 302 | - '2.16.840.1.113730.3.1.1' => ['carLicense'], |
|
| 303 | - '2.16.840.1.113730.3.1.2' => ['departmentNumber'], |
|
| 304 | - '2.16.840.1.113730.3.1.3' => ['employeeNumber'], |
|
| 305 | - '2.16.840.1.113730.3.1.4' => ['employeeType'], |
|
| 306 | - '2.16.840.1.113730.3.1.34' => ['ref'], |
|
| 307 | - '2.16.840.1.113730.3.1.39' => ['preferredLanguage'], |
|
| 308 | - '2.16.840.1.113730.3.1.40' => ['userSMIMECertificate'], |
|
| 309 | - '2.16.840.1.113730.3.1.216' => ['userPKCS12'], |
|
| 310 | - '2.16.840.1.113730.3.1.241' => ['displayName'], |
|
| 311 | - ]; |
|
| 138 | + /** |
|
| 139 | + * OID to attribute names mapping. |
|
| 140 | + * |
|
| 141 | + * First name is the primary name. If there's more than one name, others may |
|
| 142 | + * be used as an alias. |
|
| 143 | + * |
|
| 144 | + * Generated using ldap-attribs.py. |
|
| 145 | + * |
|
| 146 | + * @internal |
|
| 147 | + * |
|
| 148 | + * @var array |
|
| 149 | + */ |
|
| 150 | + const MAP_OID_TO_NAME = [ |
|
| 151 | + '0.9.2342.19200300.100.1.1' => ['uid', 'userid'], |
|
| 152 | + '0.9.2342.19200300.100.1.2' => ['textEncodedORAddress'], |
|
| 153 | + '0.9.2342.19200300.100.1.3' => ['mail', 'rfc822Mailbox'], |
|
| 154 | + '0.9.2342.19200300.100.1.4' => ['info'], |
|
| 155 | + '0.9.2342.19200300.100.1.5' => ['drink', 'favouriteDrink'], |
|
| 156 | + '0.9.2342.19200300.100.1.6' => ['roomNumber'], |
|
| 157 | + '0.9.2342.19200300.100.1.7' => ['photo'], |
|
| 158 | + '0.9.2342.19200300.100.1.8' => ['userClass'], |
|
| 159 | + '0.9.2342.19200300.100.1.9' => ['host'], |
|
| 160 | + '0.9.2342.19200300.100.1.10' => ['manager'], |
|
| 161 | + '0.9.2342.19200300.100.1.11' => ['documentIdentifier'], |
|
| 162 | + '0.9.2342.19200300.100.1.12' => ['documentTitle'], |
|
| 163 | + '0.9.2342.19200300.100.1.13' => ['documentVersion'], |
|
| 164 | + '0.9.2342.19200300.100.1.14' => ['documentAuthor'], |
|
| 165 | + '0.9.2342.19200300.100.1.15' => ['documentLocation'], |
|
| 166 | + '0.9.2342.19200300.100.1.20' => ['homePhone', 'homeTelephoneNumber'], |
|
| 167 | + '0.9.2342.19200300.100.1.21' => ['secretary'], |
|
| 168 | + '0.9.2342.19200300.100.1.22' => ['otherMailbox'], |
|
| 169 | + '0.9.2342.19200300.100.1.25' => ['dc', 'domainComponent'], |
|
| 170 | + '0.9.2342.19200300.100.1.26' => ['aRecord'], |
|
| 171 | + '0.9.2342.19200300.100.1.27' => ['mDRecord'], |
|
| 172 | + '0.9.2342.19200300.100.1.28' => ['mXRecord'], |
|
| 173 | + '0.9.2342.19200300.100.1.29' => ['nSRecord'], |
|
| 174 | + '0.9.2342.19200300.100.1.30' => ['sOARecord'], |
|
| 175 | + '0.9.2342.19200300.100.1.31' => ['cNAMERecord'], |
|
| 176 | + '0.9.2342.19200300.100.1.37' => ['associatedDomain'], |
|
| 177 | + '0.9.2342.19200300.100.1.38' => ['associatedName'], |
|
| 178 | + '0.9.2342.19200300.100.1.39' => ['homePostalAddress'], |
|
| 179 | + '0.9.2342.19200300.100.1.40' => ['personalTitle'], |
|
| 180 | + '0.9.2342.19200300.100.1.41' => ['mobile', 'mobileTelephoneNumber'], |
|
| 181 | + '0.9.2342.19200300.100.1.42' => ['pager', 'pagerTelephoneNumber'], |
|
| 182 | + '0.9.2342.19200300.100.1.43' => ['co', 'friendlyCountryName'], |
|
| 183 | + '0.9.2342.19200300.100.1.44' => ['uniqueIdentifier'], |
|
| 184 | + '0.9.2342.19200300.100.1.45' => ['organizationalStatus'], |
|
| 185 | + '0.9.2342.19200300.100.1.46' => ['janetMailbox'], |
|
| 186 | + '0.9.2342.19200300.100.1.47' => ['mailPreferenceOption'], |
|
| 187 | + '0.9.2342.19200300.100.1.48' => ['buildingName'], |
|
| 188 | + '0.9.2342.19200300.100.1.49' => ['dSAQuality'], |
|
| 189 | + '0.9.2342.19200300.100.1.50' => ['singleLevelQuality'], |
|
| 190 | + '0.9.2342.19200300.100.1.51' => ['subtreeMinimumQuality'], |
|
| 191 | + '0.9.2342.19200300.100.1.52' => ['subtreeMaximumQuality'], |
|
| 192 | + '0.9.2342.19200300.100.1.53' => ['personalSignature'], |
|
| 193 | + '0.9.2342.19200300.100.1.54' => ['dITRedirect'], |
|
| 194 | + '0.9.2342.19200300.100.1.55' => ['audio'], |
|
| 195 | + '0.9.2342.19200300.100.1.56' => ['documentPublisher'], |
|
| 196 | + '0.9.2342.19200300.100.1.60' => ['jpegPhoto'], |
|
| 197 | + '1.2.840.113549.1.9.1' => ['email', 'emailAddress', 'pkcs9email'], |
|
| 198 | + '1.2.840.113556.1.2.102' => ['memberOf'], |
|
| 199 | + '1.3.6.1.1.1.1.0' => ['uidNumber'], |
|
| 200 | + '1.3.6.1.1.1.1.1' => ['gidNumber'], |
|
| 201 | + '1.3.6.1.1.1.1.2' => ['gecos'], |
|
| 202 | + '1.3.6.1.1.1.1.3' => ['homeDirectory'], |
|
| 203 | + '1.3.6.1.1.1.1.4' => ['loginShell'], |
|
| 204 | + '1.3.6.1.1.1.1.5' => ['shadowLastChange'], |
|
| 205 | + '1.3.6.1.1.1.1.6' => ['shadowMin'], |
|
| 206 | + '1.3.6.1.1.1.1.7' => ['shadowMax'], |
|
| 207 | + '1.3.6.1.1.1.1.8' => ['shadowWarning'], |
|
| 208 | + '1.3.6.1.1.1.1.9' => ['shadowInactive'], |
|
| 209 | + '1.3.6.1.1.1.1.10' => ['shadowExpire'], |
|
| 210 | + '1.3.6.1.1.1.1.11' => ['shadowFlag'], |
|
| 211 | + '1.3.6.1.1.1.1.12' => ['memberUid'], |
|
| 212 | + '1.3.6.1.1.1.1.13' => ['memberNisNetgroup'], |
|
| 213 | + '1.3.6.1.1.1.1.14' => ['nisNetgroupTriple'], |
|
| 214 | + '1.3.6.1.1.1.1.15' => ['ipServicePort'], |
|
| 215 | + '1.3.6.1.1.1.1.16' => ['ipServiceProtocol'], |
|
| 216 | + '1.3.6.1.1.1.1.17' => ['ipProtocolNumber'], |
|
| 217 | + '1.3.6.1.1.1.1.18' => ['oncRpcNumber'], |
|
| 218 | + '1.3.6.1.1.1.1.19' => ['ipHostNumber'], |
|
| 219 | + '1.3.6.1.1.1.1.20' => ['ipNetworkNumber'], |
|
| 220 | + '1.3.6.1.1.1.1.21' => ['ipNetmaskNumber'], |
|
| 221 | + '1.3.6.1.1.1.1.22' => ['macAddress'], |
|
| 222 | + '1.3.6.1.1.1.1.23' => ['bootParameter'], |
|
| 223 | + '1.3.6.1.1.1.1.24' => ['bootFile'], |
|
| 224 | + '1.3.6.1.1.1.1.26' => ['nisMapName'], |
|
| 225 | + '1.3.6.1.1.1.1.27' => ['nisMapEntry'], |
|
| 226 | + '1.3.6.1.1.4' => ['vendorName'], |
|
| 227 | + '1.3.6.1.1.5' => ['vendorVersion'], |
|
| 228 | + '1.3.6.1.1.16.4' => ['entryUUID'], |
|
| 229 | + '1.3.6.1.1.20' => ['entryDN'], |
|
| 230 | + '2.5.4.0' => ['objectClass'], |
|
| 231 | + '2.5.4.1' => ['aliasedObjectName', 'aliasedEntryName'], |
|
| 232 | + '2.5.4.2' => ['knowledgeInformation'], |
|
| 233 | + '2.5.4.3' => ['cn', 'commonName'], |
|
| 234 | + '2.5.4.4' => ['sn', 'surname'], |
|
| 235 | + '2.5.4.5' => ['serialNumber'], |
|
| 236 | + '2.5.4.6' => ['c', 'countryName'], |
|
| 237 | + '2.5.4.7' => ['l', 'localityName'], |
|
| 238 | + '2.5.4.8' => ['st', 'stateOrProvinceName'], |
|
| 239 | + '2.5.4.9' => ['street', 'streetAddress'], |
|
| 240 | + '2.5.4.10' => ['o', 'organizationName'], |
|
| 241 | + '2.5.4.11' => ['ou', 'organizationalUnitName'], |
|
| 242 | + '2.5.4.12' => ['title'], |
|
| 243 | + '2.5.4.13' => ['description'], |
|
| 244 | + '2.5.4.14' => ['searchGuide'], |
|
| 245 | + '2.5.4.15' => ['businessCategory'], |
|
| 246 | + '2.5.4.16' => ['postalAddress'], |
|
| 247 | + '2.5.4.17' => ['postalCode'], |
|
| 248 | + '2.5.4.18' => ['postOfficeBox'], |
|
| 249 | + '2.5.4.19' => ['physicalDeliveryOfficeName'], |
|
| 250 | + '2.5.4.20' => ['telephoneNumber'], |
|
| 251 | + '2.5.4.21' => ['telexNumber'], |
|
| 252 | + '2.5.4.22' => ['teletexTerminalIdentifier'], |
|
| 253 | + '2.5.4.23' => ['facsimileTelephoneNumber', 'fax'], |
|
| 254 | + '2.5.4.24' => ['x121Address'], |
|
| 255 | + '2.5.4.25' => ['internationaliSDNNumber'], |
|
| 256 | + '2.5.4.26' => ['registeredAddress'], |
|
| 257 | + '2.5.4.27' => ['destinationIndicator'], |
|
| 258 | + '2.5.4.28' => ['preferredDeliveryMethod'], |
|
| 259 | + '2.5.4.29' => ['presentationAddress'], |
|
| 260 | + '2.5.4.30' => ['supportedApplicationContext'], |
|
| 261 | + '2.5.4.31' => ['member'], |
|
| 262 | + '2.5.4.32' => ['owner'], |
|
| 263 | + '2.5.4.33' => ['roleOccupant'], |
|
| 264 | + '2.5.4.34' => ['seeAlso'], |
|
| 265 | + '2.5.4.35' => ['userPassword'], |
|
| 266 | + '2.5.4.36' => ['userCertificate'], |
|
| 267 | + '2.5.4.37' => ['cACertificate'], |
|
| 268 | + '2.5.4.38' => ['authorityRevocationList'], |
|
| 269 | + '2.5.4.39' => ['certificateRevocationList'], |
|
| 270 | + '2.5.4.40' => ['crossCertificatePair'], |
|
| 271 | + '2.5.4.41' => ['name'], |
|
| 272 | + '2.5.4.42' => ['givenName', 'gn'], |
|
| 273 | + '2.5.4.43' => ['initials'], |
|
| 274 | + '2.5.4.44' => ['generationQualifier'], |
|
| 275 | + '2.5.4.45' => ['x500UniqueIdentifier'], |
|
| 276 | + '2.5.4.46' => ['dnQualifier'], |
|
| 277 | + '2.5.4.47' => ['enhancedSearchGuide'], |
|
| 278 | + '2.5.4.48' => ['protocolInformation'], |
|
| 279 | + '2.5.4.49' => ['distinguishedName'], |
|
| 280 | + '2.5.4.50' => ['uniqueMember'], |
|
| 281 | + '2.5.4.51' => ['houseIdentifier'], |
|
| 282 | + '2.5.4.52' => ['supportedAlgorithms'], |
|
| 283 | + '2.5.4.53' => ['deltaRevocationList'], |
|
| 284 | + '2.5.4.54' => ['dmdName'], |
|
| 285 | + '2.5.4.65' => ['pseudonym'], |
|
| 286 | + '2.5.18.1' => ['createTimestamp'], |
|
| 287 | + '2.5.18.2' => ['modifyTimestamp'], |
|
| 288 | + '2.5.18.3' => ['creatorsName'], |
|
| 289 | + '2.5.18.4' => ['modifiersName'], |
|
| 290 | + '2.5.18.5' => ['administrativeRole'], |
|
| 291 | + '2.5.18.6' => ['subtreeSpecification'], |
|
| 292 | + '2.5.18.9' => ['hasSubordinates'], |
|
| 293 | + '2.5.18.10' => ['subschemaSubentry'], |
|
| 294 | + '2.5.21.1' => ['dITStructureRules'], |
|
| 295 | + '2.5.21.2' => ['dITContentRules'], |
|
| 296 | + '2.5.21.4' => ['matchingRules'], |
|
| 297 | + '2.5.21.5' => ['attributeTypes'], |
|
| 298 | + '2.5.21.6' => ['objectClasses'], |
|
| 299 | + '2.5.21.7' => ['nameForms'], |
|
| 300 | + '2.5.21.8' => ['matchingRuleUse'], |
|
| 301 | + '2.5.21.9' => ['structuralObjectClass'], |
|
| 302 | + '2.16.840.1.113730.3.1.1' => ['carLicense'], |
|
| 303 | + '2.16.840.1.113730.3.1.2' => ['departmentNumber'], |
|
| 304 | + '2.16.840.1.113730.3.1.3' => ['employeeNumber'], |
|
| 305 | + '2.16.840.1.113730.3.1.4' => ['employeeType'], |
|
| 306 | + '2.16.840.1.113730.3.1.34' => ['ref'], |
|
| 307 | + '2.16.840.1.113730.3.1.39' => ['preferredLanguage'], |
|
| 308 | + '2.16.840.1.113730.3.1.40' => ['userSMIMECertificate'], |
|
| 309 | + '2.16.840.1.113730.3.1.216' => ['userPKCS12'], |
|
| 310 | + '2.16.840.1.113730.3.1.241' => ['displayName'], |
|
| 311 | + ]; |
|
| 312 | 312 | |
| 313 | - /** |
|
| 314 | - * OID of the attribute. |
|
| 315 | - * |
|
| 316 | - * @var string |
|
| 317 | - */ |
|
| 318 | - protected $_oid; |
|
| 313 | + /** |
|
| 314 | + * OID of the attribute. |
|
| 315 | + * |
|
| 316 | + * @var string |
|
| 317 | + */ |
|
| 318 | + protected $_oid; |
|
| 319 | 319 | |
| 320 | - /** |
|
| 321 | - * Constructor. |
|
| 322 | - * |
|
| 323 | - * @param string $oid OID in dotted format |
|
| 324 | - */ |
|
| 325 | - public function __construct(string $oid) |
|
| 326 | - { |
|
| 327 | - $this->_oid = $oid; |
|
| 328 | - } |
|
| 320 | + /** |
|
| 321 | + * Constructor. |
|
| 322 | + * |
|
| 323 | + * @param string $oid OID in dotted format |
|
| 324 | + */ |
|
| 325 | + public function __construct(string $oid) |
|
| 326 | + { |
|
| 327 | + $this->_oid = $oid; |
|
| 328 | + } |
|
| 329 | 329 | |
| 330 | - /** |
|
| 331 | - * Initialize from ASN.1. |
|
| 332 | - * |
|
| 333 | - * @param ObjectIdentifier $oi |
|
| 334 | - * |
|
| 335 | - * @return self |
|
| 336 | - */ |
|
| 337 | - public static function fromASN1(ObjectIdentifier $oi): self |
|
| 338 | - { |
|
| 339 | - return new self($oi->oid()); |
|
| 340 | - } |
|
| 330 | + /** |
|
| 331 | + * Initialize from ASN.1. |
|
| 332 | + * |
|
| 333 | + * @param ObjectIdentifier $oi |
|
| 334 | + * |
|
| 335 | + * @return self |
|
| 336 | + */ |
|
| 337 | + public static function fromASN1(ObjectIdentifier $oi): self |
|
| 338 | + { |
|
| 339 | + return new self($oi->oid()); |
|
| 340 | + } |
|
| 341 | 341 | |
| 342 | - /** |
|
| 343 | - * Initialize from attribute name. |
|
| 344 | - * |
|
| 345 | - * @param string $name |
|
| 346 | - * |
|
| 347 | - * @return self |
|
| 348 | - */ |
|
| 349 | - public static function fromName(string $name): self |
|
| 350 | - { |
|
| 351 | - $oid = self::attrNameToOID($name); |
|
| 352 | - return new self($oid); |
|
| 353 | - } |
|
| 342 | + /** |
|
| 343 | + * Initialize from attribute name. |
|
| 344 | + * |
|
| 345 | + * @param string $name |
|
| 346 | + * |
|
| 347 | + * @return self |
|
| 348 | + */ |
|
| 349 | + public static function fromName(string $name): self |
|
| 350 | + { |
|
| 351 | + $oid = self::attrNameToOID($name); |
|
| 352 | + return new self($oid); |
|
| 353 | + } |
|
| 354 | 354 | |
| 355 | - /** |
|
| 356 | - * Get OID of the attribute. |
|
| 357 | - * |
|
| 358 | - * @return string OID in dotted format |
|
| 359 | - */ |
|
| 360 | - public function oid(): string |
|
| 361 | - { |
|
| 362 | - return $this->_oid; |
|
| 363 | - } |
|
| 355 | + /** |
|
| 356 | + * Get OID of the attribute. |
|
| 357 | + * |
|
| 358 | + * @return string OID in dotted format |
|
| 359 | + */ |
|
| 360 | + public function oid(): string |
|
| 361 | + { |
|
| 362 | + return $this->_oid; |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Get name of the attribute. |
|
| 367 | - * |
|
| 368 | - * @return string |
|
| 369 | - */ |
|
| 370 | - public function typeName(): string |
|
| 371 | - { |
|
| 372 | - if (array_key_exists($this->_oid, self::MAP_OID_TO_NAME)) { |
|
| 373 | - return self::MAP_OID_TO_NAME[$this->_oid][0]; |
|
| 374 | - } |
|
| 375 | - return $this->_oid; |
|
| 376 | - } |
|
| 365 | + /** |
|
| 366 | + * Get name of the attribute. |
|
| 367 | + * |
|
| 368 | + * @return string |
|
| 369 | + */ |
|
| 370 | + public function typeName(): string |
|
| 371 | + { |
|
| 372 | + if (array_key_exists($this->_oid, self::MAP_OID_TO_NAME)) { |
|
| 373 | + return self::MAP_OID_TO_NAME[$this->_oid][0]; |
|
| 374 | + } |
|
| 375 | + return $this->_oid; |
|
| 376 | + } |
|
| 377 | 377 | |
| 378 | - /** |
|
| 379 | - * Generate ASN.1 element. |
|
| 380 | - * |
|
| 381 | - * @return ObjectIdentifier |
|
| 382 | - */ |
|
| 383 | - public function toASN1(): ObjectIdentifier |
|
| 384 | - { |
|
| 385 | - return new ObjectIdentifier($this->_oid); |
|
| 386 | - } |
|
| 378 | + /** |
|
| 379 | + * Generate ASN.1 element. |
|
| 380 | + * |
|
| 381 | + * @return ObjectIdentifier |
|
| 382 | + */ |
|
| 383 | + public function toASN1(): ObjectIdentifier |
|
| 384 | + { |
|
| 385 | + return new ObjectIdentifier($this->_oid); |
|
| 386 | + } |
|
| 387 | 387 | |
| 388 | - /** |
|
| 389 | - * Convert attribute name to OID. |
|
| 390 | - * |
|
| 391 | - * @param string $name Primary attribute name or an alias |
|
| 392 | - * |
|
| 393 | - * @throws \OutOfBoundsException |
|
| 394 | - * |
|
| 395 | - * @return string OID in dotted format |
|
| 396 | - */ |
|
| 397 | - public static function attrNameToOID(string $name): string |
|
| 398 | - { |
|
| 399 | - // if already in OID form |
|
| 400 | - if (preg_match('/^[0-9]+(?:\.[0-9]+)*$/', $name)) { |
|
| 401 | - return $name; |
|
| 402 | - } |
|
| 403 | - $map = self::_oidReverseMap(); |
|
| 404 | - $k = strtolower($name); |
|
| 405 | - if (!isset($map[$k])) { |
|
| 406 | - throw new \OutOfBoundsException("No OID for {$name}."); |
|
| 407 | - } |
|
| 408 | - return $map[$k]; |
|
| 409 | - } |
|
| 388 | + /** |
|
| 389 | + * Convert attribute name to OID. |
|
| 390 | + * |
|
| 391 | + * @param string $name Primary attribute name or an alias |
|
| 392 | + * |
|
| 393 | + * @throws \OutOfBoundsException |
|
| 394 | + * |
|
| 395 | + * @return string OID in dotted format |
|
| 396 | + */ |
|
| 397 | + public static function attrNameToOID(string $name): string |
|
| 398 | + { |
|
| 399 | + // if already in OID form |
|
| 400 | + if (preg_match('/^[0-9]+(?:\.[0-9]+)*$/', $name)) { |
|
| 401 | + return $name; |
|
| 402 | + } |
|
| 403 | + $map = self::_oidReverseMap(); |
|
| 404 | + $k = strtolower($name); |
|
| 405 | + if (!isset($map[$k])) { |
|
| 406 | + throw new \OutOfBoundsException("No OID for {$name}."); |
|
| 407 | + } |
|
| 408 | + return $map[$k]; |
|
| 409 | + } |
|
| 410 | 410 | |
| 411 | - /** |
|
| 412 | - * Get ASN.1 string for given attribute type. |
|
| 413 | - * |
|
| 414 | - * @param string $oid Attribute OID |
|
| 415 | - * @param string $str String |
|
| 416 | - * |
|
| 417 | - * @throws \LogicException |
|
| 418 | - * |
|
| 419 | - * @return StringType |
|
| 420 | - */ |
|
| 421 | - public static function asn1StringForType(string $oid, string $str): StringType |
|
| 422 | - { |
|
| 423 | - if (!array_key_exists($oid, self::MAP_ATTR_TO_STR_TYPE)) { |
|
| 424 | - return new UTF8String($str); |
|
| 425 | - } |
|
| 426 | - switch (self::MAP_ATTR_TO_STR_TYPE[$oid]) { |
|
| 427 | - case Element::TYPE_PRINTABLE_STRING: |
|
| 428 | - return new PrintableString($str); |
|
| 429 | - // @codeCoverageIgnoreStart |
|
| 430 | - default: |
|
| 431 | - // only reachable during development |
|
| 432 | - throw new \LogicException(); |
|
| 433 | - } |
|
| 434 | - // @codeCoverageIgnoreEnd |
|
| 435 | - } |
|
| 411 | + /** |
|
| 412 | + * Get ASN.1 string for given attribute type. |
|
| 413 | + * |
|
| 414 | + * @param string $oid Attribute OID |
|
| 415 | + * @param string $str String |
|
| 416 | + * |
|
| 417 | + * @throws \LogicException |
|
| 418 | + * |
|
| 419 | + * @return StringType |
|
| 420 | + */ |
|
| 421 | + public static function asn1StringForType(string $oid, string $str): StringType |
|
| 422 | + { |
|
| 423 | + if (!array_key_exists($oid, self::MAP_ATTR_TO_STR_TYPE)) { |
|
| 424 | + return new UTF8String($str); |
|
| 425 | + } |
|
| 426 | + switch (self::MAP_ATTR_TO_STR_TYPE[$oid]) { |
|
| 427 | + case Element::TYPE_PRINTABLE_STRING: |
|
| 428 | + return new PrintableString($str); |
|
| 429 | + // @codeCoverageIgnoreStart |
|
| 430 | + default: |
|
| 431 | + // only reachable during development |
|
| 432 | + throw new \LogicException(); |
|
| 433 | + } |
|
| 434 | + // @codeCoverageIgnoreEnd |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - /** |
|
| 438 | - * Get name to OID lookup map. |
|
| 439 | - * |
|
| 440 | - * @return array |
|
| 441 | - */ |
|
| 442 | - private static function _oidReverseMap(): array |
|
| 443 | - { |
|
| 444 | - static $map; |
|
| 445 | - if (!isset($map)) { |
|
| 446 | - $map = []; |
|
| 447 | - // for each attribute type |
|
| 448 | - foreach (self::MAP_OID_TO_NAME as $oid => $names) { |
|
| 449 | - // for primary name and aliases |
|
| 450 | - foreach ($names as $name) { |
|
| 451 | - $map[strtolower($name)] = $oid; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - return $map; |
|
| 456 | - } |
|
| 437 | + /** |
|
| 438 | + * Get name to OID lookup map. |
|
| 439 | + * |
|
| 440 | + * @return array |
|
| 441 | + */ |
|
| 442 | + private static function _oidReverseMap(): array |
|
| 443 | + { |
|
| 444 | + static $map; |
|
| 445 | + if (!isset($map)) { |
|
| 446 | + $map = []; |
|
| 447 | + // for each attribute type |
|
| 448 | + foreach (self::MAP_OID_TO_NAME as $oid => $names) { |
|
| 449 | + // for primary name and aliases |
|
| 450 | + foreach ($names as $name) { |
|
| 451 | + $map[strtolower($name)] = $oid; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + return $map; |
|
| 456 | + } |
|
| 457 | 457 | } |