1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ocsp\Asn1\Element; |
4
|
|
|
|
5
|
|
|
use Ocsp\Asn1\Encoder; |
6
|
|
|
use Ocsp\Asn1\TaggableElement; |
7
|
|
|
use Ocsp\Asn1\TaggableElementTrait; |
8
|
|
|
use Ocsp\Asn1\UniversalTagID; |
9
|
|
|
use Ocsp\Exception\InvalidAsn1Value; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* ASN.1 element: OBJECT IDENTIFIER. |
13
|
|
|
*/ |
14
|
|
|
class ObjectIdentifier implements TaggableElement |
15
|
|
|
{ |
16
|
|
|
use TaggableElementTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* The string representation of the identifier. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
private $identifier; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Create a new instance. |
27
|
|
|
* |
28
|
|
|
* @param string $identifier the string representation of the identifier |
29
|
|
|
* |
30
|
|
|
* @return static |
31
|
|
|
*/ |
32
|
3 |
|
public static function create($identifier) |
33
|
|
|
{ |
34
|
3 |
|
$result = new static(); |
35
|
|
|
|
36
|
3 |
|
return $result->setIdentifier($identifier); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* {@inheritdoc} |
41
|
|
|
* |
42
|
|
|
* @see \Ocsp\Asn1\Element::getClass() |
43
|
|
|
*/ |
44
|
3 |
|
public function getClass() |
45
|
|
|
{ |
46
|
3 |
|
return static::CLASS_UNIVERSAL; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
* |
52
|
|
|
* @see \Ocsp\Asn1\Element::getTypeID() |
53
|
|
|
*/ |
54
|
3 |
|
public function getTypeID() |
55
|
|
|
{ |
56
|
3 |
|
return UniversalTagID::OBJECT_IDENTIFIER; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* {@inheritdoc} |
61
|
|
|
* |
62
|
|
|
* @see \Ocsp\Asn1\Element::isConstructed() |
63
|
|
|
*/ |
64
|
2 |
|
public function isConstructed() |
65
|
|
|
{ |
66
|
2 |
|
return false; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get the string representation of the identifier. |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
3 |
|
public function getIdentifier() |
75
|
|
|
{ |
76
|
3 |
|
return $this->identifier; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Update the string representation of the identifier. |
81
|
|
|
* |
82
|
|
|
* @param string $value |
83
|
|
|
* |
84
|
|
|
* @throws \Ocsp\Exception\InvalidAsn1Value |
85
|
|
|
* |
86
|
|
|
* @return $this |
87
|
|
|
*/ |
88
|
3 |
|
public function setIdentifier($value) |
89
|
|
|
{ |
90
|
3 |
|
$value = (string) $value; |
91
|
3 |
|
if (!preg_match('/^\d+\.\d+(\.\d+)*$/', $value)) { |
92
|
|
|
throw InvalidAsn1Value::create('Invalid object identifier'); |
93
|
|
|
} |
94
|
3 |
|
$this->identifier = $value; |
95
|
|
|
|
96
|
3 |
|
return $this; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* {@inheritdoc} |
101
|
|
|
* |
102
|
|
|
* @see \Ocsp\Asn1\Element::getEncodedValue() |
103
|
|
|
*/ |
104
|
2 |
|
public function getEncodedValue(Encoder $encoder) |
105
|
|
|
{ |
106
|
2 |
|
return $encoder->encodeIdentifier($this->getIdentifier()); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|