| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace SpomkyLabs\Pki\X509\Certificate\Extension\DistributionPoint; |
| 6 |
|
| 7 |
use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString; |
| 8 |
use SpomkyLabs\Pki\ASN1\Util\Flags; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
final class ReasonFlags |
| 16 |
{ |
| 17 |
|
| 18 |
final public const KEY_COMPROMISE = 0x080; |
| 19 |
|
| 20 |
final public const CA_COMPROMISE = 0x040; |
| 21 |
|
| 22 |
final public const AFFILIATION_CHANGED = 0x020; |
| 23 |
|
| 24 |
final public const SUPERSEDED = 0x010; |
| 25 |
|
| 26 |
final public const CESSATION_OF_OPERATION = 0x008; |
| 27 |
|
| 28 |
final public const CERTIFICATE_HOLD = 0x004; |
| 29 |
|
| 30 |
final public const PRIVILEGE_WITHDRAWN = 0x002; |
| 31 |
|
| 32 |
final public const AA_COMPROMISE = 0x001; |
| 33 |
|
| 34 |
private function __construct( |
| 35 |
private readonly int $flags |
| 36 |
) { |
| 37 |
} |
| 38 |
|
| 39 |
public static function create(int $flags): self |
| 40 |
{ |
| 41 |
return new self($flags); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
public static function fromASN1(BitString $bs): self |
| 48 |
{ |
| 49 |
return self::create(Flags::fromBitString($bs, 9)->intNumber()); |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
public function isKeyCompromise(): bool |
| 56 |
{ |
| 57 |
return $this->flagSet(self::KEY_COMPROMISE); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public function isCACompromise(): bool |
| 64 |
{ |
| 65 |
return $this->flagSet(self::CA_COMPROMISE); |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
public function isAffiliationChanged(): bool |
| 72 |
{ |
| 73 |
return $this->flagSet(self::AFFILIATION_CHANGED); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
public function isSuperseded(): bool |
| 80 |
{ |
| 81 |
return $this->flagSet(self::SUPERSEDED); |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
public function isCessationOfOperation(): bool |
| 88 |
{ |
| 89 |
return $this->flagSet(self::CESSATION_OF_OPERATION); |
| 90 |
} |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public function isCertificateHold(): bool |
| 96 |
{ |
| 97 |
return $this->flagSet(self::CERTIFICATE_HOLD); |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
public function isPrivilegeWithdrawn(): bool |
| 104 |
{ |
| 105 |
return $this->flagSet(self::PRIVILEGE_WITHDRAWN); |
| 106 |
} |
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
public function isAACompromise(): bool |
| 112 |
{ |
| 113 |
return $this->flagSet(self::AA_COMPROMISE); |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
public function toASN1(): BitString |
| 120 |
{ |
| 121 |
$flags = Flags::create($this->flags, 9); |
| 122 |
return $flags->bitString() |
| 123 |
->withoutTrailingZeroes(); |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
private function flagSet(int $flag): bool |
| 130 |
{ |
| 131 |
return (bool) ($this->flags & $flag); |
| 132 |
} |
| 133 |
} |