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.
Completed
Branch php72 (a7f01e)
by Joni
04:53
created

ObjectDigestInfo::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
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\Constructed\Sequence;
9
use Sop\ASN1\Type\Primitive\BitString;
10
use Sop\ASN1\Type\Primitive\Enumerated;
11
use Sop\ASN1\Type\Primitive\ObjectIdentifier;
12
use Sop\CryptoTypes\AlgorithmIdentifier\AlgorithmIdentifier;
13
use Sop\CryptoTypes\AlgorithmIdentifier\Feature\AlgorithmIdentifierType;
14
15
/**
16
 * Implements <i>ObjectDigestInfo</i> ASN.1 type.
17
 *
18
 * @see https://tools.ietf.org/html/rfc5755#section-4.1
19
 * @see https://tools.ietf.org/html/rfc5755#section-7.3
20
 */
21
class ObjectDigestInfo
22
{
23
    const TYPE_PUBLIC_KEY = 0;
24
    const TYPE_PUBLIC_KEY_CERT = 1;
25
    const TYPE_OTHER_OBJECT_TYPES = 2;
26
27
    /**
28
     * Object type.
29
     *
30
     * @var int
31
     */
32
    protected $_digestedObjectType;
33
34
    /**
35
     * OID of other object type.
36
     *
37
     * @var null|string
38
     */
39
    protected $_otherObjectTypeID;
40
41
    /**
42
     * Digest algorithm.
43
     *
44
     * @var AlgorithmIdentifierType
45
     */
46
    protected $_digestAlgorithm;
47
48
    /**
49
     * Object digest.
50
     *
51
     * @var BitString
52
     */
53
    protected $_objectDigest;
54
55
    /**
56
     * Constructor.
57
     *
58
     * @param int                     $type
59
     * @param AlgorithmIdentifierType $algo
60
     * @param BitString               $digest
61
     */
62 5
    public function __construct(int $type, AlgorithmIdentifierType $algo,
63
        BitString $digest)
64
    {
65 5
        $this->_digestedObjectType = $type;
66 5
        $this->_otherObjectTypeID = null;
67 5
        $this->_digestAlgorithm = $algo;
68 5
        $this->_objectDigest = $digest;
69 5
    }
70
71
    /**
72
     * Initialize from ASN.1.
73
     *
74
     * @param Sequence $seq
75
     *
76
     * @return self
77
     */
78 4
    public static function fromASN1(Sequence $seq): ObjectDigestInfo
79
    {
80 4
        $idx = 0;
81 4
        $oid = null;
82 4
        $type = $seq->at($idx++)->asEnumerated()->intNumber();
83 4
        if ($seq->has($idx, Element::TYPE_OBJECT_IDENTIFIER)) {
84 1
            $oid = $seq->at($idx++)->asObjectIdentifier()->oid();
85
        }
86 4
        $algo = AlgorithmIdentifier::fromASN1($seq->at($idx++)->asSequence());
87 4
        $digest = $seq->at($idx)->asBitString();
88 4
        $obj = new self($type, $algo, $digest);
89 4
        $obj->_otherObjectTypeID = $oid;
90 4
        return $obj;
91
    }
92
93
    /**
94
     * Generate ASN.1 structure.
95
     *
96
     * @return Sequence
97
     */
98 5
    public function toASN1(): Sequence
99
    {
100 5
        $elements = [new Enumerated($this->_digestedObjectType)];
101 5
        if (isset($this->_otherObjectTypeID)) {
102 1
            $elements[] = new ObjectIdentifier($this->_otherObjectTypeID);
1 ignored issue
show
Bug introduced by
It seems like $this->_otherObjectTypeID can also be of type null; however, parameter $oid of Sop\ASN1\Type\Primitive\...entifier::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

102
            $elements[] = new ObjectIdentifier(/** @scrutinizer ignore-type */ $this->_otherObjectTypeID);
Loading history...
103
        }
104 5
        $elements[] = $this->_digestAlgorithm->toASN1();
105 5
        $elements[] = $this->_objectDigest;
106 5
        return new Sequence(...$elements);
107
    }
108
}
109