Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/Certificate/Validity.php

raw symbols SCIP
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 * Implements *Validity* ASN.1 type.
11 *
12 * @see https://tools.ietf.org/html/rfc5280#section-4.1.2.5
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 * Initialize from ASN.1.
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 * Initialize from date strings.
39 *
40 * @param null|string $nb_date Not before date
41 * @param null|string $na_date Not after date
42 * @param null|string $tz Timezone string
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 * Get not before time.
51 */
52 public function notBefore(): Time
53 {
54 return $this->notBefore;
55 }
56
57 /**
58 * Get not after time.
59 */
60 public function notAfter(): Time
61 {
62 return $this->notAfter;
63 }
64
65 /**
66 * Generate ASN.1 structure.
67 */
68 public function toASN1(): Sequence
69 {
70 return Sequence::create($this->notBefore->toASN1(), $this->notAfter->toASN1());
71 }
72 }