Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X509/AttributeCertificate/AttCertIssuer.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X509\AttributeCertificate;
6
7 use SpomkyLabs\Pki\ASN1\Element;
8 use SpomkyLabs\Pki\ASN1\Type\UnspecifiedType;
9 use SpomkyLabs\Pki\X501\ASN1\Name;
10 use SpomkyLabs\Pki\X509\Certificate\Certificate;
11 use SpomkyLabs\Pki\X509\GeneralName\DirectoryName;
12 use SpomkyLabs\Pki\X509\GeneralName\GeneralNames;
13 use UnexpectedValueException;
14
15 /**
16 * Base class implementing *AttCertIssuer* ASN.1 CHOICE type.
17 *
18 * @see https://tools.ietf.org/html/rfc5755#section-4.1
19 */
20 abstract class AttCertIssuer
21 {
22 /**
23 * Generate ASN.1 element.
24 */
25 abstract public function toASN1(): Element;
26
27 /**
28 * Check whether AttCertIssuer identifies given certificate.
29 */
30 abstract public function identifiesPKC(Certificate $cert): bool;
31
32 /**
33 * Initialize from distinguished name.
34 *
35 * This conforms to RFC 5755 which states that only v2Form must be used, and issuerName must contain exactly one
36 * GeneralName of DirectoryName type.
37 *
38 * @see https://tools.ietf.org/html/rfc5755#section-4.2.3
39 */
40 public static function fromName(Name $name): self
41 {
42 return V2Form::create(GeneralNames::create(DirectoryName::create($name)));
43 }
44
45 /**
46 * Initialize from an issuer's public key certificate.
47 */
48 public static function fromPKC(Certificate $cert): self
49 {
50 return self::fromName($cert->tbsCertificate()->subject());
51 }
52
53 /**
54 * Initialize from ASN.1.
55 *
56 * @param UnspecifiedType $el CHOICE
57 */
58 public static function fromASN1(UnspecifiedType $el): self
59 {
60 if (! $el->isTagged()) {
61 throw new UnexpectedValueException('v1Form issuer not supported.');
62 }
63 $tagged = $el->asTagged();
64 return match ($tagged->tag()) {
65 0 => V2Form::fromV2ASN1($tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()),
66 default => throw new UnexpectedValueException('Unsupported issuer type.'),
67 };
68 }
69 }