1 | <?php |
||
17 | { |
||
18 | use TypedAttribute; |
||
19 | |||
20 | /** |
||
21 | * Attribute value. |
||
22 | * |
||
23 | * @var AttributeValue |
||
24 | */ |
||
25 | protected $_value; |
||
26 | |||
27 | /** |
||
28 | * Constructor. |
||
29 | * |
||
30 | * @param AttributeType $type Attribute type |
||
31 | * @param AttributeValue $value Attribute value |
||
32 | */ |
||
33 | 42 | public function __construct(AttributeType $type, AttributeValue $value) |
|
34 | { |
||
35 | 42 | $this->_type = $type; |
|
36 | 42 | $this->_value = $value; |
|
37 | 42 | } |
|
38 | |||
39 | /** |
||
40 | * @return string |
||
41 | */ |
||
42 | 1 | public function __toString() |
|
45 | } |
||
46 | |||
47 | /** |
||
48 | * Initialize from ASN.1. |
||
49 | * |
||
50 | * @param Sequence $seq |
||
51 | * |
||
52 | * @return self |
||
53 | */ |
||
54 | 5 | public static function fromASN1(Sequence $seq): self |
|
55 | { |
||
56 | 5 | $type = AttributeType::fromASN1($seq->at(0)->asObjectIdentifier()); |
|
57 | 5 | $value = AttributeValue::fromASN1ByOID($type->oid(), $seq->at(1)); |
|
58 | 5 | return new self($type, $value); |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Convenience method to initialize from attribute value. |
||
63 | * |
||
64 | * @param AttributeValue $value Attribute value |
||
65 | * |
||
66 | * @return self |
||
67 | */ |
||
68 | 2 | public static function fromAttributeValue(AttributeValue $value): self |
|
69 | { |
||
70 | 2 | return new self(new AttributeType($value->oid()), $value); |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * Get attribute value. |
||
75 | * |
||
76 | * @return AttributeValue |
||
77 | */ |
||
78 | 2 | public function value(): AttributeValue |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Generate ASN.1 structure. |
||
85 | * |
||
86 | * @return Sequence |
||
87 | */ |
||
88 | 5 | public function toASN1(): Sequence |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * Get attributeTypeAndValue string conforming to RFC 2253. |
||
95 | * |
||
96 | * @see https://tools.ietf.org/html/rfc2253#section-2.3 |
||
97 | * |
||
98 | * @return string |
||
99 | */ |
||
100 | 17 | public function toString(): string |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Check whether attribute is semantically equal to other. |
||
107 | * |
||
108 | * @param AttributeTypeAndValue $other Object to compare to |
||
109 | * |
||
110 | * @return bool |
||
111 | */ |
||
112 | 21 | public function equals(AttributeTypeAndValue $other): bool |
|
129 |