GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AttCertIssuer::fromName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X509\AttributeCertificate;
6
7
use Sop\ASN1\Element;
8
use Sop\ASN1\Type\UnspecifiedType;
9
use Sop\X501\ASN1\Name;
10
use Sop\X509\Certificate\Certificate;
11
use Sop\X509\GeneralName\DirectoryName;
12
use Sop\X509\GeneralName\GeneralNames;
13
14
/**
15
 * Base class implementing *AttCertIssuer* ASN.1 CHOICE type.
16
 *
17
 * @see https://tools.ietf.org/html/rfc5755#section-4.1
18
 */
19
abstract class AttCertIssuer
20
{
21
    /**
22
     * Generate ASN.1 element.
23
     *
24
     * @return Element
25
     */
26
    abstract public function toASN1(): Element;
27
28
    /**
29
     * Check whether AttCertIssuer identifies given certificate.
30
     *
31
     * @param Certificate $cert
32
     *
33
     * @return bool
34
     */
35
    abstract public function identifiesPKC(Certificate $cert): bool;
36
37
    /**
38
     * Initialize from distinguished name.
39
     *
40
     * This conforms to RFC 5755 which states that only v2Form must be used,
41
     * and issuerName must contain exactly one GeneralName of DirectoryName
42
     * type.
43
     *
44
     * @see https://tools.ietf.org/html/rfc5755#section-4.2.3
45
     *
46
     * @param Name $name
47
     *
48
     * @return self
49
     */
50 3
    public static function fromName(Name $name): self
51
    {
52 3
        return new V2Form(new GeneralNames(new DirectoryName($name)));
53
    }
54
55
    /**
56
     * Initialize from an issuer's public key certificate.
57
     *
58
     * @param Certificate $cert
59
     *
60
     * @return self
61
     */
62 1
    public static function fromPKC(Certificate $cert): self
63
    {
64 1
        return self::fromName($cert->tbsCertificate()->subject());
65
    }
66
67
    /**
68
     * Initialize from ASN.1.
69
     *
70
     * @param UnspecifiedType $el CHOICE
71
     *
72
     * @throws \UnexpectedValueException
73
     *
74
     * @return self
75
     */
76 10
    public static function fromASN1(UnspecifiedType $el): self
77
    {
78 10
        if (!$el->isTagged()) {
79 1
            throw new \UnexpectedValueException('v1Form issuer not supported.');
80
        }
81 9
        $tagged = $el->asTagged();
82 9
        switch ($tagged->tag()) {
83 9
            case 0:
84 8
                return V2Form::fromV2ASN1(
85 8
                    $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence());
86
        }
87 1
        throw new \UnexpectedValueException('Unsupported issuer type.');
88
    }
89
}
90