| 1 | <?php |
||
| 19 | class DistributionPoint |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * Distribution point name. |
||
| 23 | * |
||
| 24 | * @var null|DistributionPointName |
||
| 25 | */ |
||
| 26 | protected $_distributionPoint; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Revocation reason. |
||
| 30 | * |
||
| 31 | * @var null|ReasonFlags |
||
| 32 | */ |
||
| 33 | protected $_reasons; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * CRL issuer. |
||
| 37 | * |
||
| 38 | * @var null|GeneralNames |
||
| 39 | */ |
||
| 40 | protected $_issuer; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Constructor. |
||
| 44 | * |
||
| 45 | * @param null|DistributionPointName $name |
||
| 46 | * @param null|ReasonFlags $reasons |
||
| 47 | * @param null|GeneralNames $issuer |
||
| 48 | */ |
||
| 49 | 17 | public function __construct(?DistributionPointName $name = null, |
|
| 50 | ?ReasonFlags $reasons = null, ?GeneralNames $issuer = null) |
||
| 51 | { |
||
| 52 | 17 | $this->_distributionPoint = $name; |
|
| 53 | 17 | $this->_reasons = $reasons; |
|
| 54 | 17 | $this->_issuer = $issuer; |
|
| 55 | 17 | } |
|
| 56 | |||
| 57 | /** |
||
| 58 | * Initialize from ASN.1. |
||
| 59 | * |
||
| 60 | * @param Sequence $seq |
||
| 61 | * |
||
| 62 | * @return self |
||
| 63 | */ |
||
| 64 | 12 | public static function fromASN1(Sequence $seq): self |
|
| 65 | { |
||
| 66 | 12 | $name = null; |
|
| 67 | 12 | $reasons = null; |
|
| 68 | 12 | $issuer = null; |
|
| 69 | 12 | if ($seq->hasTagged(0)) { |
|
| 70 | // promoted to explicit tagging because underlying type is CHOICE |
||
| 71 | 12 | $name = DistributionPointName::fromTaggedType( |
|
| 72 | 12 | $seq->getTagged(0)->asExplicit()->asTagged()); |
|
| 73 | } |
||
| 74 | 12 | if ($seq->hasTagged(1)) { |
|
| 75 | 11 | $reasons = ReasonFlags::fromASN1( |
|
| 76 | 11 | $seq->getTagged(1)->asImplicit(Element::TYPE_BIT_STRING) |
|
| 77 | 11 | ->asBitString()); |
|
| 78 | } |
||
| 79 | 12 | if ($seq->hasTagged(2)) { |
|
| 80 | 11 | $issuer = GeneralNames::fromASN1( |
|
| 81 | 11 | $seq->getTagged(2)->asImplicit(Element::TYPE_SEQUENCE) |
|
| 82 | 11 | ->asSequence()); |
|
| 83 | } |
||
| 84 | 12 | return new self($name, $reasons, $issuer); |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Check whether distribution point name is set. |
||
| 89 | * |
||
| 90 | * @return bool |
||
| 91 | */ |
||
| 92 | 9 | public function hasDistributionPointName(): bool |
|
| 93 | { |
||
| 94 | 9 | return isset($this->_distributionPoint); |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get distribution point name. |
||
| 99 | * |
||
| 100 | * @throws \LogicException If not set |
||
| 101 | * |
||
| 102 | * @return DistributionPointName |
||
| 103 | */ |
||
| 104 | 9 | public function distributionPointName(): DistributionPointName |
|
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Check whether distribution point name is set and it's a full name. |
||
| 114 | * |
||
| 115 | * @return bool |
||
| 116 | */ |
||
| 117 | 3 | public function hasFullName(): bool |
|
| 118 | { |
||
| 119 | 3 | return DistributionPointName::TAG_FULL_NAME === |
|
| 120 | 3 | $this->distributionPointName()->tag(); |
|
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Get full distribution point name. |
||
| 125 | * |
||
| 126 | * @throws \LogicException If not set |
||
| 127 | * |
||
| 128 | * @return FullName |
||
| 129 | */ |
||
| 130 | 3 | public function fullName(): FullName |
|
| 131 | { |
||
| 132 | 3 | if (!$this->hasFullName()) { |
|
| 133 | 1 | throw new \LogicException('fullName not set.'); |
|
| 134 | } |
||
| 135 | 2 | return $this->_distributionPoint; |
|
|
1 ignored issue
–
show
|
|||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Check whether distribution point name is set and it's a relative name. |
||
| 140 | * |
||
| 141 | * @return bool |
||
| 142 | */ |
||
| 143 | 2 | public function hasRelativeName(): bool |
|
| 144 | { |
||
| 145 | 2 | return DistributionPointName::TAG_RDN === |
|
| 146 | 2 | $this->distributionPointName()->tag(); |
|
| 147 | } |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Get relative distribution point name. |
||
| 151 | * |
||
| 152 | * @throws \LogicException If not set |
||
| 153 | * |
||
| 154 | * @return RelativeName |
||
| 155 | */ |
||
| 156 | 2 | public function relativeName(): RelativeName |
|
| 157 | { |
||
| 158 | 2 | if (!$this->hasRelativeName()) { |
|
| 159 | 1 | throw new \LogicException('nameRelativeToCRLIssuer not set.'); |
|
| 160 | } |
||
| 161 | 1 | return $this->_distributionPoint; |
|
|
1 ignored issue
–
show
|
|||
| 162 | } |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Check whether reasons flags is set. |
||
| 166 | * |
||
| 167 | * @return bool |
||
| 168 | */ |
||
| 169 | 5 | public function hasReasons(): bool |
|
| 170 | { |
||
| 171 | 5 | return isset($this->_reasons); |
|
| 172 | } |
||
| 173 | |||
| 174 | /** |
||
| 175 | * Get revocation reason flags. |
||
| 176 | * |
||
| 177 | * @throws \LogicException If not set |
||
| 178 | * |
||
| 179 | * @return ReasonFlags |
||
| 180 | */ |
||
| 181 | 5 | public function reasons(): ReasonFlags |
|
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Check whether cRLIssuer is set. |
||
| 191 | * |
||
| 192 | * @return bool |
||
| 193 | */ |
||
| 194 | 5 | public function hasCRLIssuer(): bool |
|
| 195 | { |
||
| 196 | 5 | return isset($this->_issuer); |
|
| 197 | } |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Get CRL issuer. |
||
| 201 | * |
||
| 202 | * @throws \LogicException If not set |
||
| 203 | * |
||
| 204 | * @return GeneralNames |
||
| 205 | */ |
||
| 206 | 5 | public function crlIssuer(): GeneralNames |
|
| 207 | { |
||
| 208 | 5 | if (!$this->hasCRLIssuer()) { |
|
| 209 | 1 | throw new \LogicException('crlIssuer not set.'); |
|
| 210 | } |
||
| 211 | 4 | return $this->_issuer; |
|
|
1 ignored issue
–
show
|
|||
| 212 | } |
||
| 213 | |||
| 214 | /** |
||
| 215 | * Generate ASN.1 structure. |
||
| 216 | * |
||
| 217 | * @return Sequence |
||
| 218 | */ |
||
| 219 | 18 | public function toASN1(): Sequence |
|
| 233 | } |
||
| 234 | } |
||
| 235 |