Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/Certificate/Extension/CertificatePolicy/PolicyQualifierInfo.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X509\Certificate\Extension\CertificatePolicy;
6
7 use SpomkyLabs\Pki\ASN1\Element;
8 use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
9 use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier;
10 use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
11 use UnexpectedValueException;
12
13 /**
14 * Base class for *PolicyQualifierInfo* ASN.1 types used by 'Certificate Policies' certificate extension.
15 *
16 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.4
17 */
18 abstract class PolicyQualifierInfo
19 {
20 /**
21 * OID for the CPS Pointer qualifier.
22 *
23 * @var string
24 */
25 public const OID_CPS = '1.3.6.1.5.5.7.2.1';
26
27 /**
28 * OID for the user notice qualifier.
29 *
30 * @var string
31 */
32 public const OID_UNOTICE = '1.3.6.1.5.5.7.2.2';
33
34 protected function __construct(
35 protected string $oid
36 ) {
37 }
38
39 /**
40 * Initialize from qualifier ASN.1 element.
41 */
42 abstract public static function fromQualifierASN1(UnspecifiedType $el): self;
43
44 /**
45 * Initialize from ASN.1.
46 */
47 public static function fromASN1(Sequence $seq): self
48 {
49 $oid = $seq->at(0)
50 ->asObjectIdentifier()
51 ->oid();
52 return match ($oid) {
53 self::OID_CPS => CPSQualifier::fromQualifierASN1($seq->at(1)),
54 self::OID_UNOTICE => UserNoticeQualifier::fromQualifierASN1($seq->at(1)),
55 default => throw new UnexpectedValueException("Qualifier {$oid} not supported."),
56 };
57 }
58
59 /**
60 * Get qualifier identifier.
61 */
62 public function oid(): string
63 {
64 return $this->oid;
65 }
66
67 /**
68 * Generate ASN.1 structure.
69 */
70 public function toASN1(): Sequence
71 {
72 return Sequence::create(ObjectIdentifier::create($this->oid), $this->qualifierASN1());
73 }
74
75 /**
76 * Generate ASN.1 for the 'qualifier' field.
77 */
78 abstract protected function qualifierASN1(): Element;
79 }