Response::getRevokedOn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Ocsp;
4
5
use DateTimeImmutable;
6
7
/**
8
 * Contains the response about the revocation of a certificate.
9
 */
10
class Response
11
{
12
    /**
13
     * Certificate revocation reason: unspecified.
14
     *
15
     * @var int
16
     */
17
    const REVOCATIONREASON_UNSPECIFIED = 0;
18
19
    /**
20
     * Certificate revocation reason: key compromise.
21
     *
22
     * @var int
23
     */
24
    const REVOCATIONREASON_KEYCOMPROMISE = 1;
25
26
    /**
27
     * Certificate revocation reason: CA Compromise.
28
     *
29
     * @var int
30
     */
31
    const REVOCATIONREASON_CACOMPROMISE = 2;
32
33
    /**
34
     * Certificate revocation reason: affiliation changed.
35
     *
36
     * @var int
37
     */
38
    const REVOCATIONREASON_AFFILIATIONCHANGED = 3;
39
40
    /**
41
     * Certificate revocation reason: superseded.
42
     *
43
     * @var int
44
     */
45
    const REVOCATIONREASON_SUPERSEDED = 4;
46
47
    /**
48
     * Certificate revocation reason: cessation of operation.
49
     *
50
     * @var int
51
     */
52
    const REVOCATIONREASON_CESSATIONOFOPERATION = 5;
53
54
    /**
55
     * Certificate revocation reason: certificate hold.
56
     *
57
     * @var int
58
     */
59
    const REVOCATIONREASON_CERTIFICATEHOLD = 6;
60
61
    /**
62
     * Certificate revocation reason: remove from CRL.
63
     *
64
     * @var int
65
     */
66
    const REVOCATIONREASON_REMOVEFROMCRL = 8;
67
68
    /**
69
     * Certificate revocation reason: privilege withdrawn.
70
     *
71
     * @var int
72
     */
73
    const REVOCATIONREASON_PRIVILEGEWITHDRAWN = 9;
74
75
    /**
76
     * Certificate revocation reason: AA compromise.
77
     *
78
     * @var int
79
     */
80
    const REVOCATIONREASON_AACOMPROMISE = 10;
81
82
    /**
83
     * The most recent time at which the status being indicated is known by the responder to have been correct.
84
     *
85
     * @var \DateTimeImmutable
86
     */
87
    private $thisUpdate;
88
89
    /**
90
     * The time at which one should next check for a status change.
91
     *
92
     * @var \DateTimeImmutable|null
93
     */
94
    private $nextUpdate;
95
96
    /**
97
     * The serial number of the certificate.
98
     *
99
     * @var string
100
     */
101
    private $certificateSerialNumber;
102
103
    /**
104
     * Is the certificate revoked (NULL: unknown)?
105
     *
106
     * @var bool|null
107
     */
108
    private $revoked;
109
110
    /**
111
     * The date/time when the revocation occurred.
112
     *
113
     * @var \DateTimeImmutable|null
114
     */
115
    private $revokedOn;
116
117
    /**
118
     * The revocation reason (if revoked).
119
     *
120
     * @var int|null
121
     */
122
    private $revocationReason;
123
124
    /**
125
     * @param \DateTimeImmutable $thisUpdate
126
     * @param string $certificateSerialNumber
127
     * @param \DateTimeImmutable|null $nextUpdate
128
     */
129 2
    protected function __construct(DateTimeImmutable $thisUpdate, $certificateSerialNumber, DateTimeImmutable $nextUpdate = null)
130
    {
131 2
        $this->thisUpdate = $thisUpdate;
132 2
        $this->certificateSerialNumber = $certificateSerialNumber;
133 2
        $this->nextUpdate = $nextUpdate;
134
    }
135
136
    /**
137
     * Create a new instance when the certificate is good.
138
     *
139
     * @param \DateTimeImmutable $thisUpdate
140
     * @param string $certificateSerialNumber
141
     * @param \DateTimeImmutable|null $nextUpdate
142
     *
143
     * @return static
144
     */
145 1
    public static function good(DateTimeImmutable $thisUpdate, $certificateSerialNumber, DateTimeImmutable $nextUpdate = null)
146
    {
147 1
        $result = new static($thisUpdate, $certificateSerialNumber, $nextUpdate);
148 1
        $result->revoked = false;
149
150 1
        return $result;
151
    }
152
153
    /**
154
     * Create a new instance when the certificate is revoked.
155
     *
156
     * @param \DateTimeImmutable $thisUpdate
157
     * @param string $certificateSerialNumber
158
     * @param \DateTimeImmutable $revokedOn
159
     * @param \DateTimeImmutable|null $nextUpdate
160
     *
161
     * @return static
162
     */
163 1
    public static function revoked(DateTimeImmutable $thisUpdate, $certificateSerialNumber, DateTimeImmutable $revokedOn, $revocationReason = self::REVOCATIONREASON_UNSPECIFIED, DateTimeImmutable $nextUpdate = null)
164
    {
165 1
        $result = new static($thisUpdate, $certificateSerialNumber, $nextUpdate);
166 1
        $result->revoked = true;
167 1
        $result->revokedOn = $revokedOn;
168 1
        $result->revocationReason = (int) $revocationReason;
169
170 1
        return $result;
171
    }
172
173
    /**
174
     * Create a new instance when the certificate revocation is unknown.
175
     *
176
     * @param \DateTimeImmutable $thisUpdate
177
     * @param string $certificateSerialNumber
178
     *
179
     * @return static
180
     */
181
    public static function unknown(DateTimeImmutable $thisUpdate, $certificateSerialNumber, DateTimeImmutable $nextUpdate = null)
182
    {
183
        $result = new static($thisUpdate, $certificateSerialNumber, $nextUpdate);
184
185
        return $result;
186
    }
187
188
    /**
189
     * Get the most recent time at which the status being indicated is known by the responder to have been correct.
190
     *
191
     * @return \DateTimeImmutable
192
     */
193
    public function getThisUpdate()
194
    {
195
        return $this->thisUpdate;
196
    }
197
198
    /**
199
     * Get the serial number of the certificate.
200
     *
201
     * @return string
202
     */
203
    public function getCertificateSerialNumber()
204
    {
205
        return $this->certificateSerialNumber;
206
    }
207
208
    /**
209
     * Is the certificate revoked (NULL: unknown)?
210
     *
211
     * @return bool|null
212
     */
213 2
    public function isRevoked()
214
    {
215 2
        return $this->revoked;
216
    }
217
218
    /**
219
     * Get the revocation date/time (not null only if the certificate is revoked).
220
     *
221
     * @return \DateTimeImmutable|null
222
     */
223
    public function getRevokedOn()
224
    {
225
        return $this->revokedOn;
226
    }
227
228
    /**
229
     * Get the revocation reason (if revoked).
230
     *
231
     * @return int|null
232
     */
233
    public function getRevocationReason()
234
    {
235
        return $this->revocationReason;
236
    }
237
238
    /**
239
     * The time at which one should next check for a status change.
240
     *
241
     * @var \DateTimeImmutable|null
242
     */
243 1
    public function getNextUpdate()
244
    {
245 1
        return $this->nextUpdate;
246
    }
247
}
248