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.

V2Form::issuerName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
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\Constructed\Sequence;
9
use Sop\ASN1\Type\Tagged\ImplicitlyTaggedType;
10
use Sop\X501\ASN1\Name;
11
use Sop\X509\Certificate\Certificate;
12
use Sop\X509\GeneralName\GeneralNames;
13
14
/**
15
 * Implements *V2Form* ASN.1 type used as a attribute certificate issuer.
16
 *
17
 * @see https://tools.ietf.org/html/rfc5755#section-4.1
18
 */
19
class V2Form extends AttCertIssuer
20
{
21
    /**
22
     * Issuer name.
23
     *
24
     * @var null|GeneralNames
25
     */
26
    protected $_issuerName;
27
28
    /**
29
     * Issuer PKC's issuer and serial.
30
     *
31
     * @var IssuerSerial
32
     */
33
    protected $_baseCertificateID;
34
35
    /**
36
     * Linked object.
37
     *
38
     * @var ObjectDigestInfo
39
     */
40
    protected $_objectDigestInfo;
41
42
    /**
43
     * Constructor.
44
     *
45
     * @param null|GeneralNames $names
46
     */
47 13
    public function __construct(?GeneralNames $names = null)
48
    {
49 13
        $this->_issuerName = $names;
50 13
        $this->_baseCertificateID = null;
51 13
        $this->_objectDigestInfo = null;
52 13
    }
53
54
    /**
55
     * Initialize from ASN.1.
56
     *
57
     * @param Sequence $seq
58
     *
59
     * @return self
60
     */
61 8
    public static function fromV2ASN1(Sequence $seq): self
62
    {
63 8
        $issuer = null;
64 8
        $cert_id = null;
65 8
        $digest_info = null;
66 8
        if ($seq->has(0, Element::TYPE_SEQUENCE)) {
67 8
            $issuer = GeneralNames::fromASN1($seq->at(0)->asSequence());
68
        }
69 8
        if ($seq->hasTagged(0)) {
70 1
            $cert_id = IssuerSerial::fromASN1(
71 1
                $seq->getTagged(0)->asImplicit(Element::TYPE_SEQUENCE)
72 1
                    ->asSequence());
73
        }
74 8
        if ($seq->hasTagged(1)) {
75 1
            $digest_info = ObjectDigestInfo::fromASN1(
76 1
                $seq->getTagged(1)->asImplicit(Element::TYPE_SEQUENCE)
77 1
                    ->asSequence());
78
        }
79 8
        $obj = new self($issuer);
80 8
        $obj->_baseCertificateID = $cert_id;
81 8
        $obj->_objectDigestInfo = $digest_info;
82 8
        return $obj;
83
    }
84
85
    /**
86
     * Check whether issuer name is set.
87
     *
88
     * @return bool
89
     */
90 3
    public function hasIssuerName(): bool
91
    {
92 3
        return isset($this->_issuerName);
93
    }
94
95
    /**
96
     * Get issuer name.
97
     *
98
     * @throws \LogicException If not set
99
     *
100
     * @return GeneralNames
101
     */
102 3
    public function issuerName(): GeneralNames
103
    {
104 3
        if (!$this->hasIssuerName()) {
105 1
            throw new \LogicException('issuerName not set.');
106
        }
107 2
        return $this->_issuerName;
108
    }
109
110
    /**
111
     * Get DN of the issuer.
112
     *
113
     * This is a convenience method conforming to RFC 5755, which states
114
     * that Issuer must contain only one non-empty distinguished name.
115
     *
116
     * @return Name
117
     */
118 1
    public function name(): Name
119
    {
120 1
        return $this->issuerName()->firstDN();
121
    }
122
123
    /**
124
     * {@inheritdoc}
125
     */
126 21
    public function toASN1(): Element
127
    {
128 21
        $elements = [];
129 21
        if (isset($this->_issuerName)) {
130 21
            $elements[] = $this->_issuerName->toASN1();
131
        }
132 21
        if (isset($this->_baseCertificateID)) {
133 1
            $elements[] = new ImplicitlyTaggedType(0,
134 1
                $this->_baseCertificateID->toASN1());
135
        }
136 21
        if (isset($this->_objectDigestInfo)) {
137 1
            $elements[] = new ImplicitlyTaggedType(1,
138 1
                $this->_objectDigestInfo->toASN1());
139
        }
140 21
        return new ImplicitlyTaggedType(0, new Sequence(...$elements));
141
    }
142
143
    /**
144
     * {@inheritdoc}
145
     */
146 13
    public function identifiesPKC(Certificate $cert): bool
147
    {
148 13
        $name = $this->_issuerName->firstDN();
149 13
        if (!$cert->tbsCertificate()->subject()->equals($name)) {
150 3
            return false;
151
        }
152 10
        return true;
153
    }
154
}
155