Debian Codegraph @

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

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X509\Certificate\Extension\PolicyMappings;
6
7 use SpomkyLabs\Pki\ASN1\Type\Constructed\Sequence;
8 use SpomkyLabs\Pki\ASN1\Type\Primitive\ObjectIdentifier;
9
10 /**
11 * Implements ASN.1 type containing policy mapping values to be used in 'Policy Mappings' certificate extension.
12 *
13 * @see https://tools.ietf.org/html/rfc5280#section-4.2.1.5
14 */
15 final class PolicyMapping
16 {
17 /**
18 * @param string $issuerDomainPolicy OID of the issuer policy
19 * @param string $subjectDomainPolicy OID of the subject policy
20 */
21 private function __construct(
22 private readonly string $issuerDomainPolicy,
23 private readonly string $subjectDomainPolicy
24 ) {
25 }
26
27 public static function create(string $issuerDomainPolicy, string $subjectDomainPolicy): self
28 {
29 return new self($issuerDomainPolicy, $subjectDomainPolicy);
30 }
31
32 /**
33 * Initialize from ASN.1.
34 */
35 public static function fromASN1(Sequence $seq): self
36 {
37 $issuer_policy = $seq->at(0)
38 ->asObjectIdentifier()
39 ->oid();
40 $subject_policy = $seq->at(1)
41 ->asObjectIdentifier()
42 ->oid();
43 return self::create($issuer_policy, $subject_policy);
44 }
45
46 /**
47 * Get issuer domain policy.
48 *
49 * @return string OID in dotted format
50 */
51 public function issuerDomainPolicy(): string
52 {
53 return $this->issuerDomainPolicy;
54 }
55
56 /**
57 * Get subject domain policy.
58 *
59 * @return string OID in dotted format
60 */
61 public function subjectDomainPolicy(): string
62 {
63 return $this->subjectDomainPolicy;
64 }
65
66 /**
67 * Generate ASN.1 structure.
68 */
69 public function toASN1(): Sequence
70 {
71 return Sequence::create(
72 ObjectIdentifier::create($this->issuerDomainPolicy),
73 ObjectIdentifier::create($this->subjectDomainPolicy)
74 );
75 }
76 }