<?php
 declare(strict_types=1); namespace SpomkyLabs\Pki\X509\Certificate\Extension\DistributionPoint; use SpomkyLabs\Pki\ASN1\Type\Primitive\BitString; use SpomkyLabs\Pki\ASN1\Util\Flags; final class ReasonFlags { final public const KEY_COMPROMISE = 0x080; final public const CA_COMPROMISE = 0x040; final public const AFFILIATION_CHANGED = 0x020; final public const SUPERSEDED = 0x010; final public const CESSATION_OF_OPERATION = 0x008; final public const CERTIFICATE_HOLD = 0x004; final public const PRIVILEGE_WITHDRAWN = 0x002; final public const AA_COMPROMISE = 0x001; private function __construct( private readonly int $flags ) { } public static function create(int $flags): self { return new self($flags); } public static function fromASN1(BitString $bs): self { return self::create(Flags::fromBitString($bs, 9)->intNumber()); } public function isKeyCompromise(): bool { return $this->flagSet(self::KEY_COMPROMISE); } public function isCACompromise(): bool { return $this->flagSet(self::CA_COMPROMISE); } public function isAffiliationChanged(): bool { return $this->flagSet(self::AFFILIATION_CHANGED); } public function isSuperseded(): bool { return $this->flagSet(self::SUPERSEDED); } public function isCessationOfOperation(): bool { return $this->flagSet(self::CESSATION_OF_OPERATION); } public function isCertificateHold(): bool { return $this->flagSet(self::CERTIFICATE_HOLD); } public function isPrivilegeWithdrawn(): bool { return $this->flagSet(self::PRIVILEGE_WITHDRAWN); } public function isAACompromise(): bool { return $this->flagSet(self::AA_COMPROMISE); } public function toASN1(): BitString { $flags = Flags::create($this->flags, 9); return $flags->bitString() ->withoutTrailingZeroes(); } private function flagSet(int $flag): bool { return (bool) ($this->flags & $flag); } } 