@@ -15,16 +15,16 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class CommonNameValue extends DirectoryString |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $value String value |
|
| 22 | - * @param int $string_tag Syntax choice |
|
| 23 | - */ |
|
| 24 | - public function __construct(string $value, |
|
| 25 | - int $string_tag = DirectoryString::UTF8) |
|
| 26 | - { |
|
| 27 | - $this->_oid = AttributeType::OID_COMMON_NAME; |
|
| 28 | - parent::__construct($value, $string_tag); |
|
| 29 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $value String value |
|
| 22 | + * @param int $string_tag Syntax choice |
|
| 23 | + */ |
|
| 24 | + public function __construct(string $value, |
|
| 25 | + int $string_tag = DirectoryString::UTF8) |
|
| 26 | + { |
|
| 27 | + $this->_oid = AttributeType::OID_COMMON_NAME; |
|
| 28 | + parent::__construct($value, $string_tag); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -12,73 +12,73 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class UnknownAttributeValue extends AttributeValue |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * ASN.1 element. |
|
| 17 | - * |
|
| 18 | - * @var Element $_element |
|
| 19 | - */ |
|
| 20 | - protected $_element; |
|
| 15 | + /** |
|
| 16 | + * ASN.1 element. |
|
| 17 | + * |
|
| 18 | + * @var Element $_element |
|
| 19 | + */ |
|
| 20 | + protected $_element; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Constructor. |
|
| 24 | - * |
|
| 25 | - * @param string $oid |
|
| 26 | - * @param Element $el |
|
| 27 | - */ |
|
| 28 | - public function __construct(string $oid, Element $el) |
|
| 29 | - { |
|
| 30 | - $this->_oid = $oid; |
|
| 31 | - $this->_element = $el; |
|
| 32 | - } |
|
| 22 | + /** |
|
| 23 | + * Constructor. |
|
| 24 | + * |
|
| 25 | + * @param string $oid |
|
| 26 | + * @param Element $el |
|
| 27 | + */ |
|
| 28 | + public function __construct(string $oid, Element $el) |
|
| 29 | + { |
|
| 30 | + $this->_oid = $oid; |
|
| 31 | + $this->_element = $el; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
| 37 | - * @return Element |
|
| 38 | - */ |
|
| 39 | - public function toASN1(): Element |
|
| 40 | - { |
|
| 41 | - return $this->_element; |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * @see \X501\ASN1\AttributeValue\AttributeValue::toASN1() |
|
| 37 | + * @return Element |
|
| 38 | + */ |
|
| 39 | + public function toASN1(): Element |
|
| 40 | + { |
|
| 41 | + return $this->_element; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - public function stringValue(): string |
|
| 50 | - { |
|
| 51 | - // return DER encoding as a hexstring |
|
| 52 | - return "#" . bin2hex($this->_element->toDER()); |
|
| 53 | - } |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * @see \X501\ASN1\AttributeValue\AttributeValue::stringValue() |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + public function stringValue(): string |
|
| 50 | + { |
|
| 51 | + // return DER encoding as a hexstring |
|
| 52 | + return "#" . bin2hex($this->_element->toDER()); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * |
|
| 57 | - * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
| 58 | - * @return BinaryMatch |
|
| 59 | - */ |
|
| 60 | - public function equalityMatchingRule() |
|
| 61 | - { |
|
| 62 | - return new BinaryMatch(); |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * |
|
| 57 | + * @see \X501\ASN1\AttributeValue\AttributeValue::equalityMatchingRule() |
|
| 58 | + * @return BinaryMatch |
|
| 59 | + */ |
|
| 60 | + public function equalityMatchingRule() |
|
| 61 | + { |
|
| 62 | + return new BinaryMatch(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * |
|
| 67 | - * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
| 68 | - * @return string |
|
| 69 | - */ |
|
| 70 | - public function rfc2253String(): string |
|
| 71 | - { |
|
| 72 | - return $this->stringValue(); |
|
| 73 | - } |
|
| 65 | + /** |
|
| 66 | + * |
|
| 67 | + * @see \X501\ASN1\AttributeValue\AttributeValue::rfc2253String() |
|
| 68 | + * @return string |
|
| 69 | + */ |
|
| 70 | + public function rfc2253String(): string |
|
| 71 | + { |
|
| 72 | + return $this->stringValue(); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * |
|
| 77 | - * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - protected function _transcodedString(): string |
|
| 81 | - { |
|
| 82 | - return $this->stringValue(); |
|
| 83 | - } |
|
| 75 | + /** |
|
| 76 | + * |
|
| 77 | + * @see \X501\ASN1\AttributeValue\AttributeValue::_transcodedString() |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + protected function _transcodedString(): string |
|
| 81 | + { |
|
| 82 | + return $this->stringValue(); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -15,16 +15,16 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class TitleValue extends DirectoryString |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * Constructor. |
|
| 20 | - * |
|
| 21 | - * @param string $value String value |
|
| 22 | - * @param int $string_tag Syntax choice |
|
| 23 | - */ |
|
| 24 | - public function __construct(string $value, |
|
| 25 | - int $string_tag = DirectoryString::UTF8) |
|
| 26 | - { |
|
| 27 | - $this->_oid = AttributeType::OID_TITLE; |
|
| 28 | - parent::__construct($value, $string_tag); |
|
| 29 | - } |
|
| 18 | + /** |
|
| 19 | + * Constructor. |
|
| 20 | + * |
|
| 21 | + * @param string $value String value |
|
| 22 | + * @param int $string_tag Syntax choice |
|
| 23 | + */ |
|
| 24 | + public function __construct(string $value, |
|
| 25 | + int $string_tag = DirectoryString::UTF8) |
|
| 26 | + { |
|
| 27 | + $this->_oid = AttributeType::OID_TITLE; |
|
| 28 | + parent::__construct($value, $string_tag); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -18,157 +18,157 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Attribute implements \Countable, \IteratorAggregate |
| 20 | 20 | { |
| 21 | - use TypedAttribute; |
|
| 21 | + use TypedAttribute; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Attribute values. |
|
| 25 | - * |
|
| 26 | - * @var AttributeValue[] |
|
| 27 | - */ |
|
| 28 | - protected $_values; |
|
| 23 | + /** |
|
| 24 | + * Attribute values. |
|
| 25 | + * |
|
| 26 | + * @var AttributeValue[] |
|
| 27 | + */ |
|
| 28 | + protected $_values; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor. |
|
| 32 | - * |
|
| 33 | - * @param AttributeType $type Attribute type |
|
| 34 | - * @param AttributeValue ...$values Attribute values |
|
| 35 | - */ |
|
| 36 | - public function __construct(AttributeType $type, AttributeValue ...$values) |
|
| 37 | - { |
|
| 38 | - // check that attribute values have correct oid |
|
| 39 | - array_walk($values, |
|
| 40 | - function (AttributeValue $value) use ($type) { |
|
| 41 | - if ($value->oid() != $type->oid()) { |
|
| 42 | - throw new \LogicException("Attribute OID mismatch."); |
|
| 43 | - } |
|
| 44 | - }); |
|
| 45 | - $this->_type = $type; |
|
| 46 | - $this->_values = $values; |
|
| 47 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor. |
|
| 32 | + * |
|
| 33 | + * @param AttributeType $type Attribute type |
|
| 34 | + * @param AttributeValue ...$values Attribute values |
|
| 35 | + */ |
|
| 36 | + public function __construct(AttributeType $type, AttributeValue ...$values) |
|
| 37 | + { |
|
| 38 | + // check that attribute values have correct oid |
|
| 39 | + array_walk($values, |
|
| 40 | + function (AttributeValue $value) use ($type) { |
|
| 41 | + if ($value->oid() != $type->oid()) { |
|
| 42 | + throw new \LogicException("Attribute OID mismatch."); |
|
| 43 | + } |
|
| 44 | + }); |
|
| 45 | + $this->_type = $type; |
|
| 46 | + $this->_values = $values; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Initialize from ASN.1. |
|
| 51 | - * |
|
| 52 | - * @param Sequence $seq |
|
| 53 | - * @return self |
|
| 54 | - */ |
|
| 55 | - public static function fromASN1(Sequence $seq): self |
|
| 56 | - { |
|
| 57 | - $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier()); |
|
| 58 | - $values = array_map( |
|
| 59 | - function (UnspecifiedType $el) use ($type) { |
|
| 60 | - return AttributeValue::fromASN1ByOID($type->oid(), $el); |
|
| 61 | - }, $seq->at(1) |
|
| 62 | - ->asSet() |
|
| 63 | - ->elements()); |
|
| 64 | - return new self($type, ...$values); |
|
| 65 | - } |
|
| 49 | + /** |
|
| 50 | + * Initialize from ASN.1. |
|
| 51 | + * |
|
| 52 | + * @param Sequence $seq |
|
| 53 | + * @return self |
|
| 54 | + */ |
|
| 55 | + public static function fromASN1(Sequence $seq): self |
|
| 56 | + { |
|
| 57 | + $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier()); |
|
| 58 | + $values = array_map( |
|
| 59 | + function (UnspecifiedType $el) use ($type) { |
|
| 60 | + return AttributeValue::fromASN1ByOID($type->oid(), $el); |
|
| 61 | + }, $seq->at(1) |
|
| 62 | + ->asSet() |
|
| 63 | + ->elements()); |
|
| 64 | + return new self($type, ...$values); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Convenience method to initialize from attribute values. |
|
| 69 | - * |
|
| 70 | - * @param AttributeValue ...$values One or more values |
|
| 71 | - * @throws \LogicException |
|
| 72 | - * @return self |
|
| 73 | - */ |
|
| 74 | - public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 75 | - { |
|
| 76 | - // we need at least one value to determine OID |
|
| 77 | - if (!count($values)) { |
|
| 78 | - throw new \LogicException("No values."); |
|
| 79 | - } |
|
| 80 | - $oid = reset($values)->oid(); |
|
| 81 | - return new self(new AttributeType($oid), ...$values); |
|
| 82 | - } |
|
| 67 | + /** |
|
| 68 | + * Convenience method to initialize from attribute values. |
|
| 69 | + * |
|
| 70 | + * @param AttributeValue ...$values One or more values |
|
| 71 | + * @throws \LogicException |
|
| 72 | + * @return self |
|
| 73 | + */ |
|
| 74 | + public static function fromAttributeValues(AttributeValue ...$values): self |
|
| 75 | + { |
|
| 76 | + // we need at least one value to determine OID |
|
| 77 | + if (!count($values)) { |
|
| 78 | + throw new \LogicException("No values."); |
|
| 79 | + } |
|
| 80 | + $oid = reset($values)->oid(); |
|
| 81 | + return new self(new AttributeType($oid), ...$values); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Get first value of the attribute. |
|
| 86 | - * |
|
| 87 | - * @throws \LogicException |
|
| 88 | - * @return AttributeValue |
|
| 89 | - */ |
|
| 90 | - public function first(): AttributeValue |
|
| 91 | - { |
|
| 92 | - if (!count($this->_values)) { |
|
| 93 | - throw new \LogicException("Attribute contains no values."); |
|
| 94 | - } |
|
| 95 | - return $this->_values[0]; |
|
| 96 | - } |
|
| 84 | + /** |
|
| 85 | + * Get first value of the attribute. |
|
| 86 | + * |
|
| 87 | + * @throws \LogicException |
|
| 88 | + * @return AttributeValue |
|
| 89 | + */ |
|
| 90 | + public function first(): AttributeValue |
|
| 91 | + { |
|
| 92 | + if (!count($this->_values)) { |
|
| 93 | + throw new \LogicException("Attribute contains no values."); |
|
| 94 | + } |
|
| 95 | + return $this->_values[0]; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Get all values. |
|
| 100 | - * |
|
| 101 | - * @return AttributeValue[] |
|
| 102 | - */ |
|
| 103 | - public function values(): array |
|
| 104 | - { |
|
| 105 | - return $this->_values; |
|
| 106 | - } |
|
| 98 | + /** |
|
| 99 | + * Get all values. |
|
| 100 | + * |
|
| 101 | + * @return AttributeValue[] |
|
| 102 | + */ |
|
| 103 | + public function values(): array |
|
| 104 | + { |
|
| 105 | + return $this->_values; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Generate ASN.1 structure. |
|
| 110 | - * |
|
| 111 | - * @return Sequence |
|
| 112 | - */ |
|
| 113 | - public function toASN1(): Sequence |
|
| 114 | - { |
|
| 115 | - $values = array_map( |
|
| 116 | - function (AttributeValue $value) { |
|
| 117 | - return $value->toASN1(); |
|
| 118 | - }, $this->_values); |
|
| 119 | - $valueset = new Set(...$values); |
|
| 120 | - return new Sequence($this->_type->toASN1(), $valueset->sortedSetOf()); |
|
| 121 | - } |
|
| 108 | + /** |
|
| 109 | + * Generate ASN.1 structure. |
|
| 110 | + * |
|
| 111 | + * @return Sequence |
|
| 112 | + */ |
|
| 113 | + public function toASN1(): Sequence |
|
| 114 | + { |
|
| 115 | + $values = array_map( |
|
| 116 | + function (AttributeValue $value) { |
|
| 117 | + return $value->toASN1(); |
|
| 118 | + }, $this->_values); |
|
| 119 | + $valueset = new Set(...$values); |
|
| 120 | + return new Sequence($this->_type->toASN1(), $valueset->sortedSetOf()); |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Cast attribute values to another AttributeValue class. |
|
| 125 | - * |
|
| 126 | - * This method is generally used to cast UnknownAttributeValue values |
|
| 127 | - * to specific objects when class is declared outside this package. |
|
| 128 | - * |
|
| 129 | - * The new class must be derived from AttributeValue and have the same OID |
|
| 130 | - * as current attribute values. |
|
| 131 | - * |
|
| 132 | - * @param string $cls AttributeValue class name |
|
| 133 | - * @throws \LogicException |
|
| 134 | - * @return self |
|
| 135 | - */ |
|
| 136 | - public function castValues(string $cls): self |
|
| 137 | - { |
|
| 138 | - $refl = new \ReflectionClass($cls); |
|
| 139 | - if (!$refl->isSubclassOf(AttributeValue::class)) { |
|
| 140 | - throw new \LogicException( |
|
| 141 | - "$cls must be derived from " . AttributeValue::class . "."); |
|
| 142 | - } |
|
| 143 | - $oid = $this->oid(); |
|
| 144 | - $values = array_map( |
|
| 145 | - function (AttributeValue $value) use ($cls, $oid) { |
|
| 146 | - $value = $cls::fromSelf($value); |
|
| 147 | - if ($value->oid() != $oid) { |
|
| 148 | - throw new \LogicException("Attribute OID mismatch."); |
|
| 149 | - } |
|
| 150 | - return $value; |
|
| 151 | - }, $this->_values); |
|
| 152 | - return self::fromAttributeValues(...$values); |
|
| 153 | - } |
|
| 123 | + /** |
|
| 124 | + * Cast attribute values to another AttributeValue class. |
|
| 125 | + * |
|
| 126 | + * This method is generally used to cast UnknownAttributeValue values |
|
| 127 | + * to specific objects when class is declared outside this package. |
|
| 128 | + * |
|
| 129 | + * The new class must be derived from AttributeValue and have the same OID |
|
| 130 | + * as current attribute values. |
|
| 131 | + * |
|
| 132 | + * @param string $cls AttributeValue class name |
|
| 133 | + * @throws \LogicException |
|
| 134 | + * @return self |
|
| 135 | + */ |
|
| 136 | + public function castValues(string $cls): self |
|
| 137 | + { |
|
| 138 | + $refl = new \ReflectionClass($cls); |
|
| 139 | + if (!$refl->isSubclassOf(AttributeValue::class)) { |
|
| 140 | + throw new \LogicException( |
|
| 141 | + "$cls must be derived from " . AttributeValue::class . "."); |
|
| 142 | + } |
|
| 143 | + $oid = $this->oid(); |
|
| 144 | + $values = array_map( |
|
| 145 | + function (AttributeValue $value) use ($cls, $oid) { |
|
| 146 | + $value = $cls::fromSelf($value); |
|
| 147 | + if ($value->oid() != $oid) { |
|
| 148 | + throw new \LogicException("Attribute OID mismatch."); |
|
| 149 | + } |
|
| 150 | + return $value; |
|
| 151 | + }, $this->_values); |
|
| 152 | + return self::fromAttributeValues(...$values); |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * |
|
| 157 | - * @see \Countable::count() |
|
| 158 | - * @return int |
|
| 159 | - */ |
|
| 160 | - public function count(): int |
|
| 161 | - { |
|
| 162 | - return count($this->_values); |
|
| 163 | - } |
|
| 155 | + /** |
|
| 156 | + * |
|
| 157 | + * @see \Countable::count() |
|
| 158 | + * @return int |
|
| 159 | + */ |
|
| 160 | + public function count(): int |
|
| 161 | + { |
|
| 162 | + return count($this->_values); |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * |
|
| 167 | - * @see \IteratorAggregate::getIterator() |
|
| 168 | - * @return \ArrayIterator |
|
| 169 | - */ |
|
| 170 | - public function getIterator(): \ArrayIterator |
|
| 171 | - { |
|
| 172 | - return new \ArrayIterator($this->_values); |
|
| 173 | - } |
|
| 165 | + /** |
|
| 166 | + * |
|
| 167 | + * @see \IteratorAggregate::getIterator() |
|
| 168 | + * @return \ArrayIterator |
|
| 169 | + */ |
|
| 170 | + public function getIterator(): \ArrayIterator |
|
| 171 | + { |
|
| 172 | + return new \ArrayIterator($this->_values); |
|
| 173 | + } |
|
| 174 | 174 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | // check that attribute values have correct oid |
| 39 | 39 | array_walk($values, |
| 40 | - function (AttributeValue $value) use ($type) { |
|
| 40 | + function(AttributeValue $value) use ($type) { |
|
| 41 | 41 | if ($value->oid() != $type->oid()) { |
| 42 | 42 | throw new \LogicException("Attribute OID mismatch."); |
| 43 | 43 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | { |
| 57 | 57 | $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier()); |
| 58 | 58 | $values = array_map( |
| 59 | - function (UnspecifiedType $el) use ($type) { |
|
| 59 | + function(UnspecifiedType $el) use ($type) { |
|
| 60 | 60 | return AttributeValue::fromASN1ByOID($type->oid(), $el); |
| 61 | 61 | }, $seq->at(1) |
| 62 | 62 | ->asSet() |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | public function toASN1(): Sequence |
| 114 | 114 | { |
| 115 | 115 | $values = array_map( |
| 116 | - function (AttributeValue $value) { |
|
| 116 | + function(AttributeValue $value) { |
|
| 117 | 117 | return $value->toASN1(); |
| 118 | 118 | }, $this->_values); |
| 119 | 119 | $valueset = new Set(...$values); |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | $oid = $this->oid(); |
| 144 | 144 | $values = array_map( |
| 145 | - function (AttributeValue $value) use ($cls, $oid) { |
|
| 145 | + function(AttributeValue $value) use ($cls, $oid) { |
|
| 146 | 146 | $value = $cls::fromSelf($value); |
| 147 | 147 | if ($value->oid() != $oid) { |
| 148 | 148 | throw new \LogicException("Attribute OID mismatch."); |