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.
Test Failed
Pull Request — master (#1)
by thomas
05:34
created

AttCertIssuer::fromPKC()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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