| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\Certificate; |
| 6 |
|
| 7 |
use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence; |
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
final class Validity |
| 15 |
{ |
| 16 |
private function __construct( |
| 17 |
private readonly Time $notBefore, |
| 18 |
private readonly Time $notAfter |
| 19 |
) { |
| 20 |
} |
| 21 |
|
| 22 |
public static function create(Time $notBefore, Time $notAfter): self |
| 23 |
{ |
| 24 |
return new self($notBefore, $notAfter); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public static function fromASN1(Sequence $seq): self |
| 31 |
{ |
| 32 |
$nb = Time::fromASN1($seq->at(0)->asTime()); |
| 33 |
$na = Time::fromASN1($seq->at(1)->asTime()); |
| 34 |
return self::create($nb, $na); |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
public static function fromStrings(?string $nb_date, ?string $na_date, ?string $tz = null): self |
| 45 |
{ |
| 46 |
return self::create(Time::fromString($nb_date, $tz), Time::fromString($na_date, $tz)); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
public function notBefore(): Time |
| 53 |
{ |
| 54 |
return $this->notBefore; |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
public function notAfter(): Time |
| 61 |
{ |
| 62 |
return $this->notAfter; |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
public function toASN1(): Sequence |
| 69 |
{ |
| 70 |
return Sequence::create($this->notBefore->toASN1(), $this->notAfter->toASN1()); |
| 71 |
} |
| 72 |
} |