1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
4
|
|
|
|
5
|
|
|
namespace Sop\X509\AttributeCertificate; |
6
|
|
|
|
7
|
|
|
use Sop\ASN1\Type\Constructed\Sequence; |
8
|
|
|
use Sop\ASN1\Type\Primitive\GeneralizedTime; |
9
|
|
|
use Sop\X509\Feature\DateTimeHelper; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Implements *AttCertValidityPeriod* ASN.1 type. |
13
|
|
|
* |
14
|
|
|
* @see https://tools.ietf.org/html/rfc5755#section-4.1 |
15
|
|
|
*/ |
16
|
|
|
class AttCertValidityPeriod |
17
|
|
|
{ |
18
|
|
|
use DateTimeHelper; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Not before time. |
22
|
|
|
* |
23
|
|
|
* @var \DateTimeImmutable |
24
|
|
|
*/ |
25
|
|
|
protected $_notBeforeTime; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Not after time. |
29
|
|
|
* |
30
|
|
|
* @var \DateTimeImmutable |
31
|
|
|
*/ |
32
|
|
|
protected $_notAfterTime; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Constructor. |
36
|
|
|
* |
37
|
|
|
* @param \DateTimeImmutable $nb |
38
|
|
|
* @param \DateTimeImmutable $na |
39
|
|
|
*/ |
40
|
9 |
|
public function __construct(\DateTimeImmutable $nb, \DateTimeImmutable $na) |
41
|
|
|
{ |
42
|
9 |
|
$this->_notBeforeTime = $nb; |
43
|
9 |
|
$this->_notAfterTime = $na; |
44
|
9 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Initialize from ASN.1. |
48
|
|
|
* |
49
|
|
|
* @param Sequence $seq |
50
|
|
|
* |
51
|
|
|
* @return self |
52
|
|
|
*/ |
53
|
6 |
|
public static function fromASN1(Sequence $seq): self |
54
|
|
|
{ |
55
|
6 |
|
$nb = $seq->at(0)->asGeneralizedTime()->dateTime(); |
56
|
6 |
|
$na = $seq->at(1)->asGeneralizedTime()->dateTime(); |
57
|
6 |
|
return new self($nb, $na); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Initialize from date strings. |
62
|
|
|
* |
63
|
|
|
* @param null|string $nb_date Not before date |
64
|
|
|
* @param null|string $na_date Not after date |
65
|
|
|
* @param null|string $tz Timezone string |
66
|
|
|
* |
67
|
|
|
* @return self |
68
|
|
|
*/ |
69
|
2 |
|
public static function fromStrings(?string $nb_date, ?string $na_date, |
70
|
|
|
?string $tz = null): self |
71
|
|
|
{ |
72
|
2 |
|
$nb = self::_createDateTime($nb_date, $tz); |
73
|
2 |
|
$na = self::_createDateTime($na_date, $tz); |
74
|
2 |
|
return new self($nb, $na); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Get not before time. |
79
|
|
|
* |
80
|
|
|
* @return \DateTimeImmutable |
81
|
|
|
*/ |
82
|
7 |
|
public function notBeforeTime(): \DateTimeImmutable |
83
|
|
|
{ |
84
|
7 |
|
return $this->_notBeforeTime; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Get not after time. |
89
|
|
|
* |
90
|
|
|
* @return \DateTimeImmutable |
91
|
|
|
*/ |
92
|
6 |
|
public function notAfterTime(): \DateTimeImmutable |
93
|
|
|
{ |
94
|
6 |
|
return $this->_notAfterTime; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Generate ASN.1 structure. |
99
|
|
|
* |
100
|
|
|
* @return Sequence |
101
|
|
|
*/ |
102
|
20 |
|
public function toASN1(): Sequence |
103
|
|
|
{ |
104
|
20 |
|
return new Sequence(new GeneralizedTime($this->_notBeforeTime), |
105
|
20 |
|
new GeneralizedTime($this->_notAfterTime)); |
106
|
|
|
} |
107
|
|
|
} |
108
|
|
|
|