ReasonFlags::isCessationOfOperation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
nc 1
cc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace X509\Certificate\Extension\DistributionPoint;
6
7
use ASN1\Type\Primitive\BitString;
8
use ASN1\Util\Flags;
9
10
/**
11
 * Implements <i>ReasonFlags</i> ASN.1 type used by
12
 * 'CRL Distribution Points' certificate extension.
13
 *
14
 * @link https://tools.ietf.org/html/rfc5280#section-4.2.1.13
15
 */
16
class ReasonFlags
17
{
18
    // const UNUSED = 0x100;
19
    const KEY_COMPROMISE = 0x080;
20
    const CA_COMPROMISE = 0x040;
21
    const AFFILIATION_CHANGED = 0x020;
22
    const SUPERSEDED = 0x010;
23
    const CESSATION_OF_OPERATION = 0x008;
24
    const CERTIFICATE_HOLD = 0x004;
25
    const PRIVILEGE_WITHDRAWN = 0x002;
26
    const AA_COMPROMISE = 0x001;
27
    
28
    /**
29
     * Flags.
30
     *
31
     * @var int $_flags
32
     */
33
    protected $_flags;
34
    
35
    /**
36
     * Constructor.
37
     *
38
     * @param int $flags
39
     */
40 15
    public function __construct(int $flags)
41
    {
42 15
        $this->_flags = $flags;
43 15
    }
44
    
45
    /**
46
     * Initialize from ASN.1.
47
     *
48
     * @param BitString $bs
49
     * @return self
50
     */
51 12
    public static function fromASN1(BitString $bs): self
52
    {
53 12
        return new self(Flags::fromBitString($bs, 9)->intNumber());
54
    }
55
    
56
    /**
57
     * Check whether keyCompromise flag is set.
58
     *
59
     * @return bool
60
     */
61 3
    public function isKeyCompromise(): bool
62
    {
63 3
        return $this->_flagSet(self::KEY_COMPROMISE);
64
    }
65
    
66
    /**
67
     * Check whether cACompromise flag is set.
68
     *
69
     * @return bool
70
     */
71 3
    public function isCACompromise(): bool
72
    {
73 3
        return $this->_flagSet(self::CA_COMPROMISE);
74
    }
75
    
76
    /**
77
     * Check whether affiliationChanged flag is set.
78
     *
79
     * @return bool
80
     */
81 3
    public function isAffiliationChanged(): bool
82
    {
83 3
        return $this->_flagSet(self::AFFILIATION_CHANGED);
84
    }
85
    
86
    /**
87
     * Check whether superseded flag is set.
88
     *
89
     * @return bool
90
     */
91 3
    public function isSuperseded(): bool
92
    {
93 3
        return $this->_flagSet(self::SUPERSEDED);
94
    }
95
    
96
    /**
97
     * Check whether cessationOfOperation flag is set.
98
     *
99
     * @return bool
100
     */
101 3
    public function isCessationOfOperation(): bool
102
    {
103 3
        return $this->_flagSet(self::CESSATION_OF_OPERATION);
104
    }
105
    
106
    /**
107
     * Check whether certificateHold flag is set.
108
     *
109
     * @return bool
110
     */
111 3
    public function isCertificateHold(): bool
112
    {
113 3
        return $this->_flagSet(self::CERTIFICATE_HOLD);
114
    }
115
    
116
    /**
117
     * Check whether privilegeWithdrawn flag is set.
118
     *
119
     * @return bool
120
     */
121 4
    public function isPrivilegeWithdrawn(): bool
122
    {
123 4
        return $this->_flagSet(self::PRIVILEGE_WITHDRAWN);
124
    }
125
    
126
    /**
127
     * Check whether aACompromise flag is set.
128
     *
129
     * @return bool
130
     */
131 3
    public function isAACompromise(): bool
132
    {
133 3
        return $this->_flagSet(self::AA_COMPROMISE);
134
    }
135
    
136
    /**
137
     * Generate ASN.1 element.
138
     *
139
     * @return BitString
140
     */
141 18
    public function toASN1(): BitString
142
    {
143 18
        $flags = new Flags($this->_flags, 9);
144 18
        return $flags->bitString()->withoutTrailingZeroes();
145
    }
146
    
147
    /**
148
     * Check whether given flag is set.
149
     *
150
     * @param int $flag
151
     * @return boolean
152
     */
153 11
    protected function _flagSet(int $flag): bool
154
    {
155 11
        return (bool) ($this->_flags & $flag);
156
    }
157
}
158