@@ -15,77 +15,77 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class PolicyMapping |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * OID of the issuer policy. |
|
| 20 | - * |
|
| 21 | - * @var string $_issuerDomainPolicy |
|
| 22 | - */ |
|
| 23 | - protected $_issuerDomainPolicy; |
|
| 18 | + /** |
|
| 19 | + * OID of the issuer policy. |
|
| 20 | + * |
|
| 21 | + * @var string $_issuerDomainPolicy |
|
| 22 | + */ |
|
| 23 | + protected $_issuerDomainPolicy; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * OID of the subject policy. |
|
| 27 | - * |
|
| 28 | - * @var string $_subjectDomainPolicy |
|
| 29 | - */ |
|
| 30 | - protected $_subjectDomainPolicy; |
|
| 25 | + /** |
|
| 26 | + * OID of the subject policy. |
|
| 27 | + * |
|
| 28 | + * @var string $_subjectDomainPolicy |
|
| 29 | + */ |
|
| 30 | + protected $_subjectDomainPolicy; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Constructor. |
|
| 34 | - * |
|
| 35 | - * @param string $issuer_policy OID of the issuer policy |
|
| 36 | - * @param string $subject_policy OID of the subject policy |
|
| 37 | - */ |
|
| 38 | - public function __construct(string $issuer_policy, string $subject_policy) |
|
| 39 | - { |
|
| 40 | - $this->_issuerDomainPolicy = $issuer_policy; |
|
| 41 | - $this->_subjectDomainPolicy = $subject_policy; |
|
| 42 | - } |
|
| 32 | + /** |
|
| 33 | + * Constructor. |
|
| 34 | + * |
|
| 35 | + * @param string $issuer_policy OID of the issuer policy |
|
| 36 | + * @param string $subject_policy OID of the subject policy |
|
| 37 | + */ |
|
| 38 | + public function __construct(string $issuer_policy, string $subject_policy) |
|
| 39 | + { |
|
| 40 | + $this->_issuerDomainPolicy = $issuer_policy; |
|
| 41 | + $this->_subjectDomainPolicy = $subject_policy; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Initialize from ASN.1. |
|
| 46 | - * |
|
| 47 | - * @param Sequence $seq |
|
| 48 | - * @return self |
|
| 49 | - */ |
|
| 50 | - public static function fromASN1(Sequence $seq): self |
|
| 51 | - { |
|
| 52 | - $issuer_policy = $seq->at(0) |
|
| 53 | - ->asObjectIdentifier() |
|
| 54 | - ->oid(); |
|
| 55 | - $subject_policy = $seq->at(1) |
|
| 56 | - ->asObjectIdentifier() |
|
| 57 | - ->oid(); |
|
| 58 | - return new self($issuer_policy, $subject_policy); |
|
| 59 | - } |
|
| 44 | + /** |
|
| 45 | + * Initialize from ASN.1. |
|
| 46 | + * |
|
| 47 | + * @param Sequence $seq |
|
| 48 | + * @return self |
|
| 49 | + */ |
|
| 50 | + public static function fromASN1(Sequence $seq): self |
|
| 51 | + { |
|
| 52 | + $issuer_policy = $seq->at(0) |
|
| 53 | + ->asObjectIdentifier() |
|
| 54 | + ->oid(); |
|
| 55 | + $subject_policy = $seq->at(1) |
|
| 56 | + ->asObjectIdentifier() |
|
| 57 | + ->oid(); |
|
| 58 | + return new self($issuer_policy, $subject_policy); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get issuer domain policy. |
|
| 63 | - * |
|
| 64 | - * @return string OID in dotted format |
|
| 65 | - */ |
|
| 66 | - public function issuerDomainPolicy(): string |
|
| 67 | - { |
|
| 68 | - return $this->_issuerDomainPolicy; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get issuer domain policy. |
|
| 63 | + * |
|
| 64 | + * @return string OID in dotted format |
|
| 65 | + */ |
|
| 66 | + public function issuerDomainPolicy(): string |
|
| 67 | + { |
|
| 68 | + return $this->_issuerDomainPolicy; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Get subject domain policy. |
|
| 73 | - * |
|
| 74 | - * @return string OID in dotted format |
|
| 75 | - */ |
|
| 76 | - public function subjectDomainPolicy(): string |
|
| 77 | - { |
|
| 78 | - return $this->_subjectDomainPolicy; |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Get subject domain policy. |
|
| 73 | + * |
|
| 74 | + * @return string OID in dotted format |
|
| 75 | + */ |
|
| 76 | + public function subjectDomainPolicy(): string |
|
| 77 | + { |
|
| 78 | + return $this->_subjectDomainPolicy; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Generate ASN.1 structure. |
|
| 83 | - * |
|
| 84 | - * @return Sequence |
|
| 85 | - */ |
|
| 86 | - public function toASN1(): Sequence |
|
| 87 | - { |
|
| 88 | - return new Sequence(new ObjectIdentifier($this->_issuerDomainPolicy), |
|
| 89 | - new ObjectIdentifier($this->_subjectDomainPolicy)); |
|
| 90 | - } |
|
| 81 | + /** |
|
| 82 | + * Generate ASN.1 structure. |
|
| 83 | + * |
|
| 84 | + * @return Sequence |
|
| 85 | + */ |
|
| 86 | + public function toASN1(): Sequence |
|
| 87 | + { |
|
| 88 | + return new Sequence(new ObjectIdentifier($this->_issuerDomainPolicy), |
|
| 89 | + new ObjectIdentifier($this->_subjectDomainPolicy)); |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -18,91 +18,91 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class GeneralSubtree |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Constraint. |
|
| 23 | - * |
|
| 24 | - * @var GeneralName |
|
| 25 | - */ |
|
| 26 | - protected $_base; |
|
| 21 | + /** |
|
| 22 | + * Constraint. |
|
| 23 | + * |
|
| 24 | + * @var GeneralName |
|
| 25 | + */ |
|
| 26 | + protected $_base; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Not used, must be zero. |
|
| 30 | - * |
|
| 31 | - * @var int $_min |
|
| 32 | - */ |
|
| 33 | - protected $_min; |
|
| 28 | + /** |
|
| 29 | + * Not used, must be zero. |
|
| 30 | + * |
|
| 31 | + * @var int $_min |
|
| 32 | + */ |
|
| 33 | + protected $_min; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Not used, must be null. |
|
| 37 | - * |
|
| 38 | - * @var int|null $_max |
|
| 39 | - */ |
|
| 40 | - protected $_max; |
|
| 35 | + /** |
|
| 36 | + * Not used, must be null. |
|
| 37 | + * |
|
| 38 | + * @var int|null $_max |
|
| 39 | + */ |
|
| 40 | + protected $_max; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor. |
|
| 44 | - * |
|
| 45 | - * @param GeneralName $base |
|
| 46 | - * @param int $min |
|
| 47 | - * @param int|null $max |
|
| 48 | - */ |
|
| 49 | - public function __construct(GeneralName $base, int $min = 0, $max = null) |
|
| 50 | - { |
|
| 51 | - $this->_base = $base; |
|
| 52 | - $this->_min = $min; |
|
| 53 | - $this->_max = $max; |
|
| 54 | - } |
|
| 42 | + /** |
|
| 43 | + * Constructor. |
|
| 44 | + * |
|
| 45 | + * @param GeneralName $base |
|
| 46 | + * @param int $min |
|
| 47 | + * @param int|null $max |
|
| 48 | + */ |
|
| 49 | + public function __construct(GeneralName $base, int $min = 0, $max = null) |
|
| 50 | + { |
|
| 51 | + $this->_base = $base; |
|
| 52 | + $this->_min = $min; |
|
| 53 | + $this->_max = $max; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Initialize from ASN.1. |
|
| 58 | - * |
|
| 59 | - * @param Sequence $seq |
|
| 60 | - * @return self |
|
| 61 | - */ |
|
| 62 | - public static function fromASN1(Sequence $seq): self |
|
| 63 | - { |
|
| 64 | - $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 65 | - $min = 0; |
|
| 66 | - $max = null; |
|
| 67 | - if ($seq->hasTagged(0)) { |
|
| 68 | - $min = $seq->getTagged(0) |
|
| 69 | - ->asImplicit(Element::TYPE_INTEGER) |
|
| 70 | - ->asInteger() |
|
| 71 | - ->intNumber(); |
|
| 72 | - } |
|
| 73 | - if ($seq->hasTagged(1)) { |
|
| 74 | - $max = $seq->getTagged(1) |
|
| 75 | - ->asImplicit(Element::TYPE_INTEGER) |
|
| 76 | - ->asInteger() |
|
| 77 | - ->intNumber(); |
|
| 78 | - } |
|
| 79 | - return new self($base, $min, $max); |
|
| 80 | - } |
|
| 56 | + /** |
|
| 57 | + * Initialize from ASN.1. |
|
| 58 | + * |
|
| 59 | + * @param Sequence $seq |
|
| 60 | + * @return self |
|
| 61 | + */ |
|
| 62 | + public static function fromASN1(Sequence $seq): self |
|
| 63 | + { |
|
| 64 | + $base = GeneralName::fromASN1($seq->at(0)->asTagged()); |
|
| 65 | + $min = 0; |
|
| 66 | + $max = null; |
|
| 67 | + if ($seq->hasTagged(0)) { |
|
| 68 | + $min = $seq->getTagged(0) |
|
| 69 | + ->asImplicit(Element::TYPE_INTEGER) |
|
| 70 | + ->asInteger() |
|
| 71 | + ->intNumber(); |
|
| 72 | + } |
|
| 73 | + if ($seq->hasTagged(1)) { |
|
| 74 | + $max = $seq->getTagged(1) |
|
| 75 | + ->asImplicit(Element::TYPE_INTEGER) |
|
| 76 | + ->asInteger() |
|
| 77 | + ->intNumber(); |
|
| 78 | + } |
|
| 79 | + return new self($base, $min, $max); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Get constraint. |
|
| 84 | - * |
|
| 85 | - * @return GeneralName |
|
| 86 | - */ |
|
| 87 | - public function base(): GeneralName |
|
| 88 | - { |
|
| 89 | - return $this->_base; |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Get constraint. |
|
| 84 | + * |
|
| 85 | + * @return GeneralName |
|
| 86 | + */ |
|
| 87 | + public function base(): GeneralName |
|
| 88 | + { |
|
| 89 | + return $this->_base; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Generate ASN.1 structure. |
|
| 94 | - * |
|
| 95 | - * @return Sequence |
|
| 96 | - */ |
|
| 97 | - public function toASN1(): Sequence |
|
| 98 | - { |
|
| 99 | - $elements = array($this->_base->toASN1()); |
|
| 100 | - if (isset($this->_min) && $this->_min != 0) { |
|
| 101 | - $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
| 102 | - } |
|
| 103 | - if (isset($this->_max)) { |
|
| 104 | - $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
| 105 | - } |
|
| 106 | - return new Sequence(...$elements); |
|
| 107 | - } |
|
| 92 | + /** |
|
| 93 | + * Generate ASN.1 structure. |
|
| 94 | + * |
|
| 95 | + * @return Sequence |
|
| 96 | + */ |
|
| 97 | + public function toASN1(): Sequence |
|
| 98 | + { |
|
| 99 | + $elements = array($this->_base->toASN1()); |
|
| 100 | + if (isset($this->_min) && $this->_min != 0) { |
|
| 101 | + $elements[] = new ImplicitlyTaggedType(0, new Integer($this->_min)); |
|
| 102 | + } |
|
| 103 | + if (isset($this->_max)) { |
|
| 104 | + $elements[] = new ImplicitlyTaggedType(1, new Integer($this->_max)); |
|
| 105 | + } |
|
| 106 | + return new Sequence(...$elements); |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -18,63 +18,63 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class DistributionPointName |
| 20 | 20 | { |
| 21 | - const TAG_FULL_NAME = 0; |
|
| 22 | - const TAG_RDN = 1; |
|
| 21 | + const TAG_FULL_NAME = 0; |
|
| 22 | + const TAG_RDN = 1; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Type. |
|
| 26 | - * |
|
| 27 | - * @var int $_tag |
|
| 28 | - */ |
|
| 29 | - protected $_tag; |
|
| 24 | + /** |
|
| 25 | + * Type. |
|
| 26 | + * |
|
| 27 | + * @var int $_tag |
|
| 28 | + */ |
|
| 29 | + protected $_tag; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Generate ASN.1 element. |
|
| 33 | - * |
|
| 34 | - * @return Element |
|
| 35 | - */ |
|
| 36 | - abstract protected function _valueASN1(); |
|
| 31 | + /** |
|
| 32 | + * Generate ASN.1 element. |
|
| 33 | + * |
|
| 34 | + * @return Element |
|
| 35 | + */ |
|
| 36 | + abstract protected function _valueASN1(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Initialize from TaggedType. |
|
| 40 | - * |
|
| 41 | - * @param TaggedType $el |
|
| 42 | - * @throws \UnexpectedValueException |
|
| 43 | - * @return self |
|
| 44 | - */ |
|
| 45 | - public static function fromTaggedType(TaggedType $el): self |
|
| 46 | - { |
|
| 47 | - switch ($el->tag()) { |
|
| 48 | - case self::TAG_FULL_NAME: |
|
| 49 | - return new FullName( |
|
| 50 | - GeneralNames::fromASN1( |
|
| 51 | - $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 52 | - case self::TAG_RDN: |
|
| 53 | - return new RelativeName( |
|
| 54 | - RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 55 | - default: |
|
| 56 | - throw new \UnexpectedValueException( |
|
| 57 | - "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 58 | - } |
|
| 59 | - } |
|
| 38 | + /** |
|
| 39 | + * Initialize from TaggedType. |
|
| 40 | + * |
|
| 41 | + * @param TaggedType $el |
|
| 42 | + * @throws \UnexpectedValueException |
|
| 43 | + * @return self |
|
| 44 | + */ |
|
| 45 | + public static function fromTaggedType(TaggedType $el): self |
|
| 46 | + { |
|
| 47 | + switch ($el->tag()) { |
|
| 48 | + case self::TAG_FULL_NAME: |
|
| 49 | + return new FullName( |
|
| 50 | + GeneralNames::fromASN1( |
|
| 51 | + $el->asImplicit(Element::TYPE_SEQUENCE)->asSequence())); |
|
| 52 | + case self::TAG_RDN: |
|
| 53 | + return new RelativeName( |
|
| 54 | + RDN::fromASN1($el->asImplicit(Element::TYPE_SET)->asSet())); |
|
| 55 | + default: |
|
| 56 | + throw new \UnexpectedValueException( |
|
| 57 | + "DistributionPointName tag " . $el->tag() . " not supported."); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get type tag. |
|
| 63 | - * |
|
| 64 | - * @return int |
|
| 65 | - */ |
|
| 66 | - public function tag(): int |
|
| 67 | - { |
|
| 68 | - return $this->_tag; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get type tag. |
|
| 63 | + * |
|
| 64 | + * @return int |
|
| 65 | + */ |
|
| 66 | + public function tag(): int |
|
| 67 | + { |
|
| 68 | + return $this->_tag; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Generate ASN.1 structure. |
|
| 73 | - * |
|
| 74 | - * @return ImplicitlyTaggedType |
|
| 75 | - */ |
|
| 76 | - public function toASN1(): ImplicitlyTaggedType |
|
| 77 | - { |
|
| 78 | - return new ImplicitlyTaggedType($this->_tag, $this->_valueASN1()); |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Generate ASN.1 structure. |
|
| 73 | + * |
|
| 74 | + * @return ImplicitlyTaggedType |
|
| 75 | + */ |
|
| 76 | + public function toASN1(): ImplicitlyTaggedType |
|
| 77 | + { |
|
| 78 | + return new ImplicitlyTaggedType($this->_tag, $this->_valueASN1()); |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -16,41 +16,41 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class RelativeName extends DistributionPointName |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Relative distinguished name. |
|
| 21 | - * |
|
| 22 | - * @var RDN $_rdn |
|
| 23 | - */ |
|
| 24 | - protected $_rdn; |
|
| 19 | + /** |
|
| 20 | + * Relative distinguished name. |
|
| 21 | + * |
|
| 22 | + * @var RDN $_rdn |
|
| 23 | + */ |
|
| 24 | + protected $_rdn; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param RDN $rdn |
|
| 30 | - */ |
|
| 31 | - public function __construct(RDN $rdn) |
|
| 32 | - { |
|
| 33 | - $this->_tag = self::TAG_RDN; |
|
| 34 | - $this->_rdn = $rdn; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param RDN $rdn |
|
| 30 | + */ |
|
| 31 | + public function __construct(RDN $rdn) |
|
| 32 | + { |
|
| 33 | + $this->_tag = self::TAG_RDN; |
|
| 34 | + $this->_rdn = $rdn; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Get RDN. |
|
| 39 | - * |
|
| 40 | - * @return RDN |
|
| 41 | - */ |
|
| 42 | - public function rdn(): RDN |
|
| 43 | - { |
|
| 44 | - return $this->_rdn; |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * Get RDN. |
|
| 39 | + * |
|
| 40 | + * @return RDN |
|
| 41 | + */ |
|
| 42 | + public function rdn(): RDN |
|
| 43 | + { |
|
| 44 | + return $this->_rdn; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * |
|
| 49 | - * {@inheritdoc} |
|
| 50 | - * @return Set |
|
| 51 | - */ |
|
| 52 | - protected function _valueASN1(): Set |
|
| 53 | - { |
|
| 54 | - return $this->_rdn->toASN1(); |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * |
|
| 49 | + * {@inheritdoc} |
|
| 50 | + * @return Set |
|
| 51 | + */ |
|
| 52 | + protected function _valueASN1(): Set |
|
| 53 | + { |
|
| 54 | + return $this->_rdn->toASN1(); |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -16,52 +16,52 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class FullName extends DistributionPointName |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Names. |
|
| 21 | - * |
|
| 22 | - * @var GeneralNames $_names |
|
| 23 | - */ |
|
| 24 | - protected $_names; |
|
| 19 | + /** |
|
| 20 | + * Names. |
|
| 21 | + * |
|
| 22 | + * @var GeneralNames $_names |
|
| 23 | + */ |
|
| 24 | + protected $_names; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Constructor. |
|
| 28 | - * |
|
| 29 | - * @param GeneralNames $names |
|
| 30 | - */ |
|
| 31 | - public function __construct(GeneralNames $names) |
|
| 32 | - { |
|
| 33 | - $this->_tag = self::TAG_FULL_NAME; |
|
| 34 | - $this->_names = $names; |
|
| 35 | - } |
|
| 26 | + /** |
|
| 27 | + * Constructor. |
|
| 28 | + * |
|
| 29 | + * @param GeneralNames $names |
|
| 30 | + */ |
|
| 31 | + public function __construct(GeneralNames $names) |
|
| 32 | + { |
|
| 33 | + $this->_tag = self::TAG_FULL_NAME; |
|
| 34 | + $this->_names = $names; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Initialize with a single URI. |
|
| 39 | - * |
|
| 40 | - * @param string $uri |
|
| 41 | - * @return self |
|
| 42 | - */ |
|
| 43 | - public static function fromURI(string $uri): self |
|
| 44 | - { |
|
| 45 | - return new self(new GeneralNames(new UniformResourceIdentifier($uri))); |
|
| 46 | - } |
|
| 37 | + /** |
|
| 38 | + * Initialize with a single URI. |
|
| 39 | + * |
|
| 40 | + * @param string $uri |
|
| 41 | + * @return self |
|
| 42 | + */ |
|
| 43 | + public static function fromURI(string $uri): self |
|
| 44 | + { |
|
| 45 | + return new self(new GeneralNames(new UniformResourceIdentifier($uri))); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Get names. |
|
| 50 | - * |
|
| 51 | - * @return GeneralNames |
|
| 52 | - */ |
|
| 53 | - public function names(): GeneralNames |
|
| 54 | - { |
|
| 55 | - return $this->_names; |
|
| 56 | - } |
|
| 48 | + /** |
|
| 49 | + * Get names. |
|
| 50 | + * |
|
| 51 | + * @return GeneralNames |
|
| 52 | + */ |
|
| 53 | + public function names(): GeneralNames |
|
| 54 | + { |
|
| 55 | + return $this->_names; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * |
|
| 60 | - * {@inheritdoc} |
|
| 61 | - * @return Sequence |
|
| 62 | - */ |
|
| 63 | - protected function _valueASN1(): Sequence |
|
| 64 | - { |
|
| 65 | - return $this->_names->toASN1(); |
|
| 66 | - } |
|
| 58 | + /** |
|
| 59 | + * |
|
| 60 | + * {@inheritdoc} |
|
| 61 | + * @return Sequence |
|
| 62 | + */ |
|
| 63 | + protected function _valueASN1(): Sequence |
|
| 64 | + { |
|
| 65 | + return $this->_names->toASN1(); |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -15,143 +15,143 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class ReasonFlags |
| 17 | 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; |
|
| 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 | 27 | |
| 28 | - /** |
|
| 29 | - * Flags. |
|
| 30 | - * |
|
| 31 | - * @var int $_flags |
|
| 32 | - */ |
|
| 33 | - protected $_flags; |
|
| 28 | + /** |
|
| 29 | + * Flags. |
|
| 30 | + * |
|
| 31 | + * @var int $_flags |
|
| 32 | + */ |
|
| 33 | + protected $_flags; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor. |
|
| 37 | - * |
|
| 38 | - * @param int $flags |
|
| 39 | - */ |
|
| 40 | - public function __construct(int $flags) |
|
| 41 | - { |
|
| 42 | - $this->_flags = $flags; |
|
| 43 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor. |
|
| 37 | + * |
|
| 38 | + * @param int $flags |
|
| 39 | + */ |
|
| 40 | + public function __construct(int $flags) |
|
| 41 | + { |
|
| 42 | + $this->_flags = $flags; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Initialize from ASN.1. |
|
| 47 | - * |
|
| 48 | - * @param BitString $bs |
|
| 49 | - * @return self |
|
| 50 | - */ |
|
| 51 | - public static function fromASN1(BitString $bs): self |
|
| 52 | - { |
|
| 53 | - return new self(Flags::fromBitString($bs, 9)->intNumber()); |
|
| 54 | - } |
|
| 45 | + /** |
|
| 46 | + * Initialize from ASN.1. |
|
| 47 | + * |
|
| 48 | + * @param BitString $bs |
|
| 49 | + * @return self |
|
| 50 | + */ |
|
| 51 | + public static function fromASN1(BitString $bs): self |
|
| 52 | + { |
|
| 53 | + return new self(Flags::fromBitString($bs, 9)->intNumber()); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Check whether keyCompromise flag is set. |
|
| 58 | - * |
|
| 59 | - * @return bool |
|
| 60 | - */ |
|
| 61 | - public function isKeyCompromise(): bool |
|
| 62 | - { |
|
| 63 | - return $this->_flagSet(self::KEY_COMPROMISE); |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Check whether keyCompromise flag is set. |
|
| 58 | + * |
|
| 59 | + * @return bool |
|
| 60 | + */ |
|
| 61 | + public function isKeyCompromise(): bool |
|
| 62 | + { |
|
| 63 | + return $this->_flagSet(self::KEY_COMPROMISE); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Check whether cACompromise flag is set. |
|
| 68 | - * |
|
| 69 | - * @return bool |
|
| 70 | - */ |
|
| 71 | - public function isCACompromise(): bool |
|
| 72 | - { |
|
| 73 | - return $this->_flagSet(self::CA_COMPROMISE); |
|
| 74 | - } |
|
| 66 | + /** |
|
| 67 | + * Check whether cACompromise flag is set. |
|
| 68 | + * |
|
| 69 | + * @return bool |
|
| 70 | + */ |
|
| 71 | + public function isCACompromise(): bool |
|
| 72 | + { |
|
| 73 | + return $this->_flagSet(self::CA_COMPROMISE); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Check whether affiliationChanged flag is set. |
|
| 78 | - * |
|
| 79 | - * @return bool |
|
| 80 | - */ |
|
| 81 | - public function isAffiliationChanged(): bool |
|
| 82 | - { |
|
| 83 | - return $this->_flagSet(self::AFFILIATION_CHANGED); |
|
| 84 | - } |
|
| 76 | + /** |
|
| 77 | + * Check whether affiliationChanged flag is set. |
|
| 78 | + * |
|
| 79 | + * @return bool |
|
| 80 | + */ |
|
| 81 | + public function isAffiliationChanged(): bool |
|
| 82 | + { |
|
| 83 | + return $this->_flagSet(self::AFFILIATION_CHANGED); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Check whether superseded flag is set. |
|
| 88 | - * |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function isSuperseded(): bool |
|
| 92 | - { |
|
| 93 | - return $this->_flagSet(self::SUPERSEDED); |
|
| 94 | - } |
|
| 86 | + /** |
|
| 87 | + * Check whether superseded flag is set. |
|
| 88 | + * |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function isSuperseded(): bool |
|
| 92 | + { |
|
| 93 | + return $this->_flagSet(self::SUPERSEDED); |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * Check whether cessationOfOperation flag is set. |
|
| 98 | - * |
|
| 99 | - * @return bool |
|
| 100 | - */ |
|
| 101 | - public function isCessationOfOperation(): bool |
|
| 102 | - { |
|
| 103 | - return $this->_flagSet(self::CESSATION_OF_OPERATION); |
|
| 104 | - } |
|
| 96 | + /** |
|
| 97 | + * Check whether cessationOfOperation flag is set. |
|
| 98 | + * |
|
| 99 | + * @return bool |
|
| 100 | + */ |
|
| 101 | + public function isCessationOfOperation(): bool |
|
| 102 | + { |
|
| 103 | + return $this->_flagSet(self::CESSATION_OF_OPERATION); |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Check whether certificateHold flag is set. |
|
| 108 | - * |
|
| 109 | - * @return bool |
|
| 110 | - */ |
|
| 111 | - public function isCertificateHold(): bool |
|
| 112 | - { |
|
| 113 | - return $this->_flagSet(self::CERTIFICATE_HOLD); |
|
| 114 | - } |
|
| 106 | + /** |
|
| 107 | + * Check whether certificateHold flag is set. |
|
| 108 | + * |
|
| 109 | + * @return bool |
|
| 110 | + */ |
|
| 111 | + public function isCertificateHold(): bool |
|
| 112 | + { |
|
| 113 | + return $this->_flagSet(self::CERTIFICATE_HOLD); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * Check whether privilegeWithdrawn flag is set. |
|
| 118 | - * |
|
| 119 | - * @return bool |
|
| 120 | - */ |
|
| 121 | - public function isPrivilegeWithdrawn(): bool |
|
| 122 | - { |
|
| 123 | - return $this->_flagSet(self::PRIVILEGE_WITHDRAWN); |
|
| 124 | - } |
|
| 116 | + /** |
|
| 117 | + * Check whether privilegeWithdrawn flag is set. |
|
| 118 | + * |
|
| 119 | + * @return bool |
|
| 120 | + */ |
|
| 121 | + public function isPrivilegeWithdrawn(): bool |
|
| 122 | + { |
|
| 123 | + return $this->_flagSet(self::PRIVILEGE_WITHDRAWN); |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * Check whether aACompromise flag is set. |
|
| 128 | - * |
|
| 129 | - * @return bool |
|
| 130 | - */ |
|
| 131 | - public function isAACompromise(): bool |
|
| 132 | - { |
|
| 133 | - return $this->_flagSet(self::AA_COMPROMISE); |
|
| 134 | - } |
|
| 126 | + /** |
|
| 127 | + * Check whether aACompromise flag is set. |
|
| 128 | + * |
|
| 129 | + * @return bool |
|
| 130 | + */ |
|
| 131 | + public function isAACompromise(): bool |
|
| 132 | + { |
|
| 133 | + return $this->_flagSet(self::AA_COMPROMISE); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Generate ASN.1 element. |
|
| 138 | - * |
|
| 139 | - * @return BitString |
|
| 140 | - */ |
|
| 141 | - public function toASN1(): BitString |
|
| 142 | - { |
|
| 143 | - $flags = new Flags($this->_flags, 9); |
|
| 144 | - return $flags->bitString()->withoutTrailingZeroes(); |
|
| 145 | - } |
|
| 136 | + /** |
|
| 137 | + * Generate ASN.1 element. |
|
| 138 | + * |
|
| 139 | + * @return BitString |
|
| 140 | + */ |
|
| 141 | + public function toASN1(): BitString |
|
| 142 | + { |
|
| 143 | + $flags = new Flags($this->_flags, 9); |
|
| 144 | + return $flags->bitString()->withoutTrailingZeroes(); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Check whether given flag is set. |
|
| 149 | - * |
|
| 150 | - * @param int $flag |
|
| 151 | - * @return boolean |
|
| 152 | - */ |
|
| 153 | - protected function _flagSet(int $flag): bool |
|
| 154 | - { |
|
| 155 | - return (bool) ($this->_flags & $flag); |
|
| 156 | - } |
|
| 147 | + /** |
|
| 148 | + * Check whether given flag is set. |
|
| 149 | + * |
|
| 150 | + * @param int $flag |
|
| 151 | + * @return boolean |
|
| 152 | + */ |
|
| 153 | + protected function _flagSet(int $flag): bool |
|
| 154 | + { |
|
| 155 | + return (bool) ($this->_flags & $flag); |
|
| 156 | + } |
|
| 157 | 157 | } |
@@ -18,215 +18,215 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class DistributionPoint |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Distribution point name. |
|
| 23 | - * |
|
| 24 | - * @var DistributionPointName $_distributionPoint |
|
| 25 | - */ |
|
| 26 | - protected $_distributionPoint; |
|
| 21 | + /** |
|
| 22 | + * Distribution point name. |
|
| 23 | + * |
|
| 24 | + * @var DistributionPointName $_distributionPoint |
|
| 25 | + */ |
|
| 26 | + protected $_distributionPoint; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Revocation reason. |
|
| 30 | - * |
|
| 31 | - * @var ReasonFlags $_reasons |
|
| 32 | - */ |
|
| 33 | - protected $_reasons; |
|
| 28 | + /** |
|
| 29 | + * Revocation reason. |
|
| 30 | + * |
|
| 31 | + * @var ReasonFlags $_reasons |
|
| 32 | + */ |
|
| 33 | + protected $_reasons; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * CRL issuer. |
|
| 37 | - * |
|
| 38 | - * @var GeneralNames $_issuer |
|
| 39 | - */ |
|
| 40 | - protected $_issuer; |
|
| 35 | + /** |
|
| 36 | + * CRL issuer. |
|
| 37 | + * |
|
| 38 | + * @var GeneralNames $_issuer |
|
| 39 | + */ |
|
| 40 | + protected $_issuer; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor. |
|
| 44 | - * |
|
| 45 | - * @param DistributionPointName $name |
|
| 46 | - * @param ReasonFlags $reasons |
|
| 47 | - * @param GeneralNames $issuer |
|
| 48 | - */ |
|
| 49 | - public function __construct(DistributionPointName $name = null, |
|
| 50 | - ReasonFlags $reasons = null, GeneralNames $issuer = null) |
|
| 51 | - { |
|
| 52 | - $this->_distributionPoint = $name; |
|
| 53 | - $this->_reasons = $reasons; |
|
| 54 | - $this->_issuer = $issuer; |
|
| 55 | - } |
|
| 42 | + /** |
|
| 43 | + * Constructor. |
|
| 44 | + * |
|
| 45 | + * @param DistributionPointName $name |
|
| 46 | + * @param ReasonFlags $reasons |
|
| 47 | + * @param GeneralNames $issuer |
|
| 48 | + */ |
|
| 49 | + public function __construct(DistributionPointName $name = null, |
|
| 50 | + ReasonFlags $reasons = null, GeneralNames $issuer = null) |
|
| 51 | + { |
|
| 52 | + $this->_distributionPoint = $name; |
|
| 53 | + $this->_reasons = $reasons; |
|
| 54 | + $this->_issuer = $issuer; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Initialize from ASN.1. |
|
| 59 | - * |
|
| 60 | - * @param Sequence $seq |
|
| 61 | - * @return self |
|
| 62 | - */ |
|
| 63 | - public static function fromASN1(Sequence $seq): self |
|
| 64 | - { |
|
| 65 | - $name = null; |
|
| 66 | - $reasons = null; |
|
| 67 | - $issuer = null; |
|
| 68 | - if ($seq->hasTagged(0)) { |
|
| 69 | - // promoted to explicit tagging because underlying type is CHOICE |
|
| 70 | - $name = DistributionPointName::fromTaggedType( |
|
| 71 | - $seq->getTagged(0) |
|
| 72 | - ->asExplicit() |
|
| 73 | - ->asTagged()); |
|
| 74 | - } |
|
| 75 | - if ($seq->hasTagged(1)) { |
|
| 76 | - $reasons = ReasonFlags::fromASN1( |
|
| 77 | - $seq->getTagged(1) |
|
| 78 | - ->asImplicit(Element::TYPE_BIT_STRING) |
|
| 79 | - ->asBitString()); |
|
| 80 | - } |
|
| 81 | - if ($seq->hasTagged(2)) { |
|
| 82 | - $issuer = GeneralNames::fromASN1( |
|
| 83 | - $seq->getTagged(2) |
|
| 84 | - ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 85 | - ->asSequence()); |
|
| 86 | - } |
|
| 87 | - return new self($name, $reasons, $issuer); |
|
| 88 | - } |
|
| 57 | + /** |
|
| 58 | + * Initialize from ASN.1. |
|
| 59 | + * |
|
| 60 | + * @param Sequence $seq |
|
| 61 | + * @return self |
|
| 62 | + */ |
|
| 63 | + public static function fromASN1(Sequence $seq): self |
|
| 64 | + { |
|
| 65 | + $name = null; |
|
| 66 | + $reasons = null; |
|
| 67 | + $issuer = null; |
|
| 68 | + if ($seq->hasTagged(0)) { |
|
| 69 | + // promoted to explicit tagging because underlying type is CHOICE |
|
| 70 | + $name = DistributionPointName::fromTaggedType( |
|
| 71 | + $seq->getTagged(0) |
|
| 72 | + ->asExplicit() |
|
| 73 | + ->asTagged()); |
|
| 74 | + } |
|
| 75 | + if ($seq->hasTagged(1)) { |
|
| 76 | + $reasons = ReasonFlags::fromASN1( |
|
| 77 | + $seq->getTagged(1) |
|
| 78 | + ->asImplicit(Element::TYPE_BIT_STRING) |
|
| 79 | + ->asBitString()); |
|
| 80 | + } |
|
| 81 | + if ($seq->hasTagged(2)) { |
|
| 82 | + $issuer = GeneralNames::fromASN1( |
|
| 83 | + $seq->getTagged(2) |
|
| 84 | + ->asImplicit(Element::TYPE_SEQUENCE) |
|
| 85 | + ->asSequence()); |
|
| 86 | + } |
|
| 87 | + return new self($name, $reasons, $issuer); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Check whether distribution point name is set. |
|
| 92 | - * |
|
| 93 | - * @return bool |
|
| 94 | - */ |
|
| 95 | - public function hasDistributionPointName(): bool |
|
| 96 | - { |
|
| 97 | - return isset($this->_distributionPoint); |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * Check whether distribution point name is set. |
|
| 92 | + * |
|
| 93 | + * @return bool |
|
| 94 | + */ |
|
| 95 | + public function hasDistributionPointName(): bool |
|
| 96 | + { |
|
| 97 | + return isset($this->_distributionPoint); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Get distribution point name. |
|
| 102 | - * |
|
| 103 | - * @throws \LogicException |
|
| 104 | - * @return DistributionPointName |
|
| 105 | - */ |
|
| 106 | - public function distributionPointName(): DistributionPointName |
|
| 107 | - { |
|
| 108 | - if (!$this->hasDistributionPointName()) { |
|
| 109 | - throw new \LogicException("distributionPoint not set."); |
|
| 110 | - } |
|
| 111 | - return $this->_distributionPoint; |
|
| 112 | - } |
|
| 100 | + /** |
|
| 101 | + * Get distribution point name. |
|
| 102 | + * |
|
| 103 | + * @throws \LogicException |
|
| 104 | + * @return DistributionPointName |
|
| 105 | + */ |
|
| 106 | + public function distributionPointName(): DistributionPointName |
|
| 107 | + { |
|
| 108 | + if (!$this->hasDistributionPointName()) { |
|
| 109 | + throw new \LogicException("distributionPoint not set."); |
|
| 110 | + } |
|
| 111 | + return $this->_distributionPoint; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Check whether distribution point name is set and it's a full name. |
|
| 116 | - * |
|
| 117 | - * @return bool |
|
| 118 | - */ |
|
| 119 | - public function hasFullName(): bool |
|
| 120 | - { |
|
| 121 | - return $this->distributionPointName()->tag() == |
|
| 122 | - DistributionPointName::TAG_FULL_NAME; |
|
| 123 | - } |
|
| 114 | + /** |
|
| 115 | + * Check whether distribution point name is set and it's a full name. |
|
| 116 | + * |
|
| 117 | + * @return bool |
|
| 118 | + */ |
|
| 119 | + public function hasFullName(): bool |
|
| 120 | + { |
|
| 121 | + return $this->distributionPointName()->tag() == |
|
| 122 | + DistributionPointName::TAG_FULL_NAME; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Get full distribution point name. |
|
| 127 | - * |
|
| 128 | - * @throws \LogicException |
|
| 129 | - * @return FullName |
|
| 130 | - */ |
|
| 131 | - public function fullName(): FullName |
|
| 132 | - { |
|
| 133 | - if (!$this->hasFullName()) { |
|
| 134 | - throw new \LogicException("fullName not set."); |
|
| 135 | - } |
|
| 136 | - return $this->_distributionPoint; |
|
| 137 | - } |
|
| 125 | + /** |
|
| 126 | + * Get full distribution point name. |
|
| 127 | + * |
|
| 128 | + * @throws \LogicException |
|
| 129 | + * @return FullName |
|
| 130 | + */ |
|
| 131 | + public function fullName(): FullName |
|
| 132 | + { |
|
| 133 | + if (!$this->hasFullName()) { |
|
| 134 | + throw new \LogicException("fullName not set."); |
|
| 135 | + } |
|
| 136 | + return $this->_distributionPoint; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Check whether distribution point name is set and it's a relative name. |
|
| 141 | - * |
|
| 142 | - * @return bool |
|
| 143 | - */ |
|
| 144 | - public function hasRelativeName(): bool |
|
| 145 | - { |
|
| 146 | - return $this->distributionPointName()->tag() == |
|
| 147 | - DistributionPointName::TAG_RDN; |
|
| 148 | - } |
|
| 139 | + /** |
|
| 140 | + * Check whether distribution point name is set and it's a relative name. |
|
| 141 | + * |
|
| 142 | + * @return bool |
|
| 143 | + */ |
|
| 144 | + public function hasRelativeName(): bool |
|
| 145 | + { |
|
| 146 | + return $this->distributionPointName()->tag() == |
|
| 147 | + DistributionPointName::TAG_RDN; |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Get relative distribution point name. |
|
| 152 | - * |
|
| 153 | - * @throws \LogicException |
|
| 154 | - * @return RelativeName |
|
| 155 | - */ |
|
| 156 | - public function relativeName(): RelativeName |
|
| 157 | - { |
|
| 158 | - if (!$this->hasRelativeName()) { |
|
| 159 | - throw new \LogicException("nameRelativeToCRLIssuer not set."); |
|
| 160 | - } |
|
| 161 | - return $this->_distributionPoint; |
|
| 162 | - } |
|
| 150 | + /** |
|
| 151 | + * Get relative distribution point name. |
|
| 152 | + * |
|
| 153 | + * @throws \LogicException |
|
| 154 | + * @return RelativeName |
|
| 155 | + */ |
|
| 156 | + public function relativeName(): RelativeName |
|
| 157 | + { |
|
| 158 | + if (!$this->hasRelativeName()) { |
|
| 159 | + throw new \LogicException("nameRelativeToCRLIssuer not set."); |
|
| 160 | + } |
|
| 161 | + return $this->_distributionPoint; |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Check whether reasons flags is set. |
|
| 166 | - * |
|
| 167 | - * @return bool |
|
| 168 | - */ |
|
| 169 | - public function hasReasons(): bool |
|
| 170 | - { |
|
| 171 | - return isset($this->_reasons); |
|
| 172 | - } |
|
| 164 | + /** |
|
| 165 | + * Check whether reasons flags is set. |
|
| 166 | + * |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + public function hasReasons(): bool |
|
| 170 | + { |
|
| 171 | + return isset($this->_reasons); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Get revocation reason flags. |
|
| 176 | - * |
|
| 177 | - * @throws \LogicException |
|
| 178 | - * @return ReasonFlags |
|
| 179 | - */ |
|
| 180 | - public function reasons(): ReasonFlags |
|
| 181 | - { |
|
| 182 | - if (!$this->hasReasons()) { |
|
| 183 | - throw new \LogicException("reasons not set."); |
|
| 184 | - } |
|
| 185 | - return $this->_reasons; |
|
| 186 | - } |
|
| 174 | + /** |
|
| 175 | + * Get revocation reason flags. |
|
| 176 | + * |
|
| 177 | + * @throws \LogicException |
|
| 178 | + * @return ReasonFlags |
|
| 179 | + */ |
|
| 180 | + public function reasons(): ReasonFlags |
|
| 181 | + { |
|
| 182 | + if (!$this->hasReasons()) { |
|
| 183 | + throw new \LogicException("reasons not set."); |
|
| 184 | + } |
|
| 185 | + return $this->_reasons; |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Check whether cRLIssuer is set. |
|
| 190 | - * |
|
| 191 | - * @return bool |
|
| 192 | - */ |
|
| 193 | - public function hasCRLIssuer(): bool |
|
| 194 | - { |
|
| 195 | - return isset($this->_issuer); |
|
| 196 | - } |
|
| 188 | + /** |
|
| 189 | + * Check whether cRLIssuer is set. |
|
| 190 | + * |
|
| 191 | + * @return bool |
|
| 192 | + */ |
|
| 193 | + public function hasCRLIssuer(): bool |
|
| 194 | + { |
|
| 195 | + return isset($this->_issuer); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - /** |
|
| 199 | - * Get CRL issuer. |
|
| 200 | - * |
|
| 201 | - * @throws \LogicException |
|
| 202 | - * @return GeneralNames |
|
| 203 | - */ |
|
| 204 | - public function crlIssuer(): GeneralNames |
|
| 205 | - { |
|
| 206 | - if (!$this->hasCRLIssuer()) { |
|
| 207 | - throw new \LogicException("crlIssuer not set."); |
|
| 208 | - } |
|
| 209 | - return $this->_issuer; |
|
| 210 | - } |
|
| 198 | + /** |
|
| 199 | + * Get CRL issuer. |
|
| 200 | + * |
|
| 201 | + * @throws \LogicException |
|
| 202 | + * @return GeneralNames |
|
| 203 | + */ |
|
| 204 | + public function crlIssuer(): GeneralNames |
|
| 205 | + { |
|
| 206 | + if (!$this->hasCRLIssuer()) { |
|
| 207 | + throw new \LogicException("crlIssuer not set."); |
|
| 208 | + } |
|
| 209 | + return $this->_issuer; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * Generate ASN.1 structure. |
|
| 214 | - * |
|
| 215 | - * @return Sequence |
|
| 216 | - */ |
|
| 217 | - public function toASN1(): Sequence |
|
| 218 | - { |
|
| 219 | - $elements = array(); |
|
| 220 | - if (isset($this->_distributionPoint)) { |
|
| 221 | - $elements[] = new ExplicitlyTaggedType(0, |
|
| 222 | - $this->_distributionPoint->toASN1()); |
|
| 223 | - } |
|
| 224 | - if (isset($this->_reasons)) { |
|
| 225 | - $elements[] = new ImplicitlyTaggedType(1, $this->_reasons->toASN1()); |
|
| 226 | - } |
|
| 227 | - if (isset($this->_issuer)) { |
|
| 228 | - $elements[] = new ImplicitlyTaggedType(2, $this->_issuer->toASN1()); |
|
| 229 | - } |
|
| 230 | - return new Sequence(...$elements); |
|
| 231 | - } |
|
| 212 | + /** |
|
| 213 | + * Generate ASN.1 structure. |
|
| 214 | + * |
|
| 215 | + * @return Sequence |
|
| 216 | + */ |
|
| 217 | + public function toASN1(): Sequence |
|
| 218 | + { |
|
| 219 | + $elements = array(); |
|
| 220 | + if (isset($this->_distributionPoint)) { |
|
| 221 | + $elements[] = new ExplicitlyTaggedType(0, |
|
| 222 | + $this->_distributionPoint->toASN1()); |
|
| 223 | + } |
|
| 224 | + if (isset($this->_reasons)) { |
|
| 225 | + $elements[] = new ImplicitlyTaggedType(1, $this->_reasons->toASN1()); |
|
| 226 | + } |
|
| 227 | + if (isset($this->_issuer)) { |
|
| 228 | + $elements[] = new ImplicitlyTaggedType(2, $this->_issuer->toASN1()); |
|
| 229 | + } |
|
| 230 | + return new Sequence(...$elements); |
|
| 231 | + } |
|
| 232 | 232 | } |
@@ -14,265 +14,265 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class PolicyNode implements \IteratorAggregate, \Countable |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * Policy OID. |
|
| 19 | - * |
|
| 20 | - * @var string |
|
| 21 | - */ |
|
| 22 | - protected $_validPolicy; |
|
| 17 | + /** |
|
| 18 | + * Policy OID. |
|
| 19 | + * |
|
| 20 | + * @var string |
|
| 21 | + */ |
|
| 22 | + protected $_validPolicy; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * List of qualifiers. |
|
| 26 | - * |
|
| 27 | - * @var \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
| 28 | - */ |
|
| 29 | - protected $_qualifiers; |
|
| 24 | + /** |
|
| 25 | + * List of qualifiers. |
|
| 26 | + * |
|
| 27 | + * @var \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
| 28 | + */ |
|
| 29 | + protected $_qualifiers; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * List of expected policy OIDs. |
|
| 33 | - * |
|
| 34 | - * @var string[] |
|
| 35 | - */ |
|
| 36 | - protected $_expectedPolicies; |
|
| 31 | + /** |
|
| 32 | + * List of expected policy OIDs. |
|
| 33 | + * |
|
| 34 | + * @var string[] |
|
| 35 | + */ |
|
| 36 | + protected $_expectedPolicies; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * List of child nodes. |
|
| 40 | - * |
|
| 41 | - * @var PolicyNode[] |
|
| 42 | - */ |
|
| 43 | - protected $_children; |
|
| 38 | + /** |
|
| 39 | + * List of child nodes. |
|
| 40 | + * |
|
| 41 | + * @var PolicyNode[] |
|
| 42 | + */ |
|
| 43 | + protected $_children; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * Reference to the parent node. |
|
| 47 | - * |
|
| 48 | - * @var PolicyNode|null |
|
| 49 | - */ |
|
| 50 | - protected $_parent; |
|
| 45 | + /** |
|
| 46 | + * Reference to the parent node. |
|
| 47 | + * |
|
| 48 | + * @var PolicyNode|null |
|
| 49 | + */ |
|
| 50 | + protected $_parent; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Constructor. |
|
| 54 | - * |
|
| 55 | - * @param string $valid_policy Policy OID |
|
| 56 | - * @param \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] $qualifiers |
|
| 57 | - * @param string[] $expected_policies |
|
| 58 | - */ |
|
| 59 | - public function __construct(string $valid_policy, array $qualifiers, |
|
| 60 | - array $expected_policies) |
|
| 61 | - { |
|
| 62 | - $this->_validPolicy = $valid_policy; |
|
| 63 | - $this->_qualifiers = $qualifiers; |
|
| 64 | - $this->_expectedPolicies = $expected_policies; |
|
| 65 | - $this->_children = array(); |
|
| 66 | - } |
|
| 52 | + /** |
|
| 53 | + * Constructor. |
|
| 54 | + * |
|
| 55 | + * @param string $valid_policy Policy OID |
|
| 56 | + * @param \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] $qualifiers |
|
| 57 | + * @param string[] $expected_policies |
|
| 58 | + */ |
|
| 59 | + public function __construct(string $valid_policy, array $qualifiers, |
|
| 60 | + array $expected_policies) |
|
| 61 | + { |
|
| 62 | + $this->_validPolicy = $valid_policy; |
|
| 63 | + $this->_qualifiers = $qualifiers; |
|
| 64 | + $this->_expectedPolicies = $expected_policies; |
|
| 65 | + $this->_children = array(); |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Create initial node for the policy tree. |
|
| 70 | - * |
|
| 71 | - * @return self |
|
| 72 | - */ |
|
| 73 | - public static function anyPolicyNode(): self |
|
| 74 | - { |
|
| 75 | - return new self(PolicyInformation::OID_ANY_POLICY, array(), |
|
| 76 | - array(PolicyInformation::OID_ANY_POLICY)); |
|
| 77 | - } |
|
| 68 | + /** |
|
| 69 | + * Create initial node for the policy tree. |
|
| 70 | + * |
|
| 71 | + * @return self |
|
| 72 | + */ |
|
| 73 | + public static function anyPolicyNode(): self |
|
| 74 | + { |
|
| 75 | + return new self(PolicyInformation::OID_ANY_POLICY, array(), |
|
| 76 | + array(PolicyInformation::OID_ANY_POLICY)); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Get the valid policy OID. |
|
| 81 | - * |
|
| 82 | - * @return string |
|
| 83 | - */ |
|
| 84 | - public function validPolicy(): string |
|
| 85 | - { |
|
| 86 | - return $this->_validPolicy; |
|
| 87 | - } |
|
| 79 | + /** |
|
| 80 | + * Get the valid policy OID. |
|
| 81 | + * |
|
| 82 | + * @return string |
|
| 83 | + */ |
|
| 84 | + public function validPolicy(): string |
|
| 85 | + { |
|
| 86 | + return $this->_validPolicy; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Check whether node has anyPolicy as a valid policy. |
|
| 91 | - * |
|
| 92 | - * @return boolean |
|
| 93 | - */ |
|
| 94 | - public function isAnyPolicy(): bool |
|
| 95 | - { |
|
| 96 | - return PolicyInformation::OID_ANY_POLICY == $this->_validPolicy; |
|
| 97 | - } |
|
| 89 | + /** |
|
| 90 | + * Check whether node has anyPolicy as a valid policy. |
|
| 91 | + * |
|
| 92 | + * @return boolean |
|
| 93 | + */ |
|
| 94 | + public function isAnyPolicy(): bool |
|
| 95 | + { |
|
| 96 | + return PolicyInformation::OID_ANY_POLICY == $this->_validPolicy; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get the qualifier set. |
|
| 101 | - * |
|
| 102 | - * @return \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
| 103 | - */ |
|
| 104 | - public function qualifiers(): array |
|
| 105 | - { |
|
| 106 | - return $this->_qualifiers; |
|
| 107 | - } |
|
| 99 | + /** |
|
| 100 | + * Get the qualifier set. |
|
| 101 | + * |
|
| 102 | + * @return \X509\Certificate\Extension\CertificatePolicy\PolicyQualifierInfo[] |
|
| 103 | + */ |
|
| 104 | + public function qualifiers(): array |
|
| 105 | + { |
|
| 106 | + return $this->_qualifiers; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Check whether node has OID as an expected policy. |
|
| 111 | - * |
|
| 112 | - * @param string $oid |
|
| 113 | - * @return boolean |
|
| 114 | - */ |
|
| 115 | - public function hasExpectedPolicy(string $oid): bool |
|
| 116 | - { |
|
| 117 | - return in_array($oid, $this->_expectedPolicies); |
|
| 118 | - } |
|
| 109 | + /** |
|
| 110 | + * Check whether node has OID as an expected policy. |
|
| 111 | + * |
|
| 112 | + * @param string $oid |
|
| 113 | + * @return boolean |
|
| 114 | + */ |
|
| 115 | + public function hasExpectedPolicy(string $oid): bool |
|
| 116 | + { |
|
| 117 | + return in_array($oid, $this->_expectedPolicies); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Get the expected policy set. |
|
| 122 | - * |
|
| 123 | - * @return string[] |
|
| 124 | - */ |
|
| 125 | - public function expectedPolicies(): array |
|
| 126 | - { |
|
| 127 | - return $this->_expectedPolicies; |
|
| 128 | - } |
|
| 120 | + /** |
|
| 121 | + * Get the expected policy set. |
|
| 122 | + * |
|
| 123 | + * @return string[] |
|
| 124 | + */ |
|
| 125 | + public function expectedPolicies(): array |
|
| 126 | + { |
|
| 127 | + return $this->_expectedPolicies; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Set expected policies. |
|
| 132 | - * |
|
| 133 | - * @param string ...$oids Policy OIDs |
|
| 134 | - */ |
|
| 135 | - public function setExpectedPolicies(string ...$oids) |
|
| 136 | - { |
|
| 137 | - $this->_expectedPolicies = $oids; |
|
| 138 | - } |
|
| 130 | + /** |
|
| 131 | + * Set expected policies. |
|
| 132 | + * |
|
| 133 | + * @param string ...$oids Policy OIDs |
|
| 134 | + */ |
|
| 135 | + public function setExpectedPolicies(string ...$oids) |
|
| 136 | + { |
|
| 137 | + $this->_expectedPolicies = $oids; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Check whether node has a child node with given valid policy OID. |
|
| 142 | - * |
|
| 143 | - * @param string $oid |
|
| 144 | - * @return boolean |
|
| 145 | - */ |
|
| 146 | - public function hasChildWithValidPolicy(string $oid): bool |
|
| 147 | - { |
|
| 148 | - foreach ($this->_children as $node) { |
|
| 149 | - if ($node->validPolicy() == $oid) { |
|
| 150 | - return true; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - return false; |
|
| 154 | - } |
|
| 140 | + /** |
|
| 141 | + * Check whether node has a child node with given valid policy OID. |
|
| 142 | + * |
|
| 143 | + * @param string $oid |
|
| 144 | + * @return boolean |
|
| 145 | + */ |
|
| 146 | + public function hasChildWithValidPolicy(string $oid): bool |
|
| 147 | + { |
|
| 148 | + foreach ($this->_children as $node) { |
|
| 149 | + if ($node->validPolicy() == $oid) { |
|
| 150 | + return true; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + return false; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Add child node. |
|
| 158 | - * |
|
| 159 | - * @param PolicyNode $node |
|
| 160 | - * @return self |
|
| 161 | - */ |
|
| 162 | - public function addChild(PolicyNode $node): self |
|
| 163 | - { |
|
| 164 | - $id = spl_object_hash($node); |
|
| 165 | - $node->_parent = $this; |
|
| 166 | - $this->_children[$id] = $node; |
|
| 167 | - return $this; |
|
| 168 | - } |
|
| 156 | + /** |
|
| 157 | + * Add child node. |
|
| 158 | + * |
|
| 159 | + * @param PolicyNode $node |
|
| 160 | + * @return self |
|
| 161 | + */ |
|
| 162 | + public function addChild(PolicyNode $node): self |
|
| 163 | + { |
|
| 164 | + $id = spl_object_hash($node); |
|
| 165 | + $node->_parent = $this; |
|
| 166 | + $this->_children[$id] = $node; |
|
| 167 | + return $this; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * Get the child nodes. |
|
| 172 | - * |
|
| 173 | - * @return PolicyNode[] |
|
| 174 | - */ |
|
| 175 | - public function children(): array |
|
| 176 | - { |
|
| 177 | - return array_values($this->_children); |
|
| 178 | - } |
|
| 170 | + /** |
|
| 171 | + * Get the child nodes. |
|
| 172 | + * |
|
| 173 | + * @return PolicyNode[] |
|
| 174 | + */ |
|
| 175 | + public function children(): array |
|
| 176 | + { |
|
| 177 | + return array_values($this->_children); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Remove this node from the tree. |
|
| 182 | - * |
|
| 183 | - * @return self The removed node |
|
| 184 | - */ |
|
| 185 | - public function remove(): self |
|
| 186 | - { |
|
| 187 | - if ($this->_parent) { |
|
| 188 | - $id = spl_object_hash($this); |
|
| 189 | - unset($this->_parent->_children[$id]); |
|
| 190 | - unset($this->_parent); |
|
| 191 | - } |
|
| 192 | - return $this; |
|
| 193 | - } |
|
| 180 | + /** |
|
| 181 | + * Remove this node from the tree. |
|
| 182 | + * |
|
| 183 | + * @return self The removed node |
|
| 184 | + */ |
|
| 185 | + public function remove(): self |
|
| 186 | + { |
|
| 187 | + if ($this->_parent) { |
|
| 188 | + $id = spl_object_hash($this); |
|
| 189 | + unset($this->_parent->_children[$id]); |
|
| 190 | + unset($this->_parent); |
|
| 191 | + } |
|
| 192 | + return $this; |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - /** |
|
| 196 | - * Check whether node has a parent. |
|
| 197 | - * |
|
| 198 | - * @return bool |
|
| 199 | - */ |
|
| 200 | - public function hasParent(): bool |
|
| 201 | - { |
|
| 202 | - return isset($this->_parent); |
|
| 203 | - } |
|
| 195 | + /** |
|
| 196 | + * Check whether node has a parent. |
|
| 197 | + * |
|
| 198 | + * @return bool |
|
| 199 | + */ |
|
| 200 | + public function hasParent(): bool |
|
| 201 | + { |
|
| 202 | + return isset($this->_parent); |
|
| 203 | + } |
|
| 204 | 204 | |
| 205 | - /** |
|
| 206 | - * Get the parent node. |
|
| 207 | - * |
|
| 208 | - * @return PolicyNode|null |
|
| 209 | - */ |
|
| 210 | - public function parent() |
|
| 211 | - { |
|
| 212 | - return $this->_parent; |
|
| 213 | - } |
|
| 205 | + /** |
|
| 206 | + * Get the parent node. |
|
| 207 | + * |
|
| 208 | + * @return PolicyNode|null |
|
| 209 | + */ |
|
| 210 | + public function parent() |
|
| 211 | + { |
|
| 212 | + return $this->_parent; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - /** |
|
| 216 | - * Get chain of parent nodes from this node's parent to the root node. |
|
| 217 | - * |
|
| 218 | - * @return PolicyNode[] |
|
| 219 | - */ |
|
| 220 | - public function parents(): array |
|
| 221 | - { |
|
| 222 | - if (!$this->_parent) { |
|
| 223 | - return array(); |
|
| 224 | - } |
|
| 225 | - $nodes = $this->_parent->parents(); |
|
| 226 | - $nodes[] = $this->_parent; |
|
| 227 | - return array_reverse($nodes); |
|
| 228 | - } |
|
| 215 | + /** |
|
| 216 | + * Get chain of parent nodes from this node's parent to the root node. |
|
| 217 | + * |
|
| 218 | + * @return PolicyNode[] |
|
| 219 | + */ |
|
| 220 | + public function parents(): array |
|
| 221 | + { |
|
| 222 | + if (!$this->_parent) { |
|
| 223 | + return array(); |
|
| 224 | + } |
|
| 225 | + $nodes = $this->_parent->parents(); |
|
| 226 | + $nodes[] = $this->_parent; |
|
| 227 | + return array_reverse($nodes); |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Walk tree from this node, applying a callback for each node. |
|
| 232 | - * |
|
| 233 | - * Nodes are traversed depth-first and callback shall be applied post-order. |
|
| 234 | - * |
|
| 235 | - * @param callable $fn |
|
| 236 | - */ |
|
| 237 | - public function walkNodes(callable $fn) |
|
| 238 | - { |
|
| 239 | - foreach ($this->_children as $node) { |
|
| 240 | - $node->walkNodes($fn); |
|
| 241 | - } |
|
| 242 | - $fn($this); |
|
| 243 | - } |
|
| 230 | + /** |
|
| 231 | + * Walk tree from this node, applying a callback for each node. |
|
| 232 | + * |
|
| 233 | + * Nodes are traversed depth-first and callback shall be applied post-order. |
|
| 234 | + * |
|
| 235 | + * @param callable $fn |
|
| 236 | + */ |
|
| 237 | + public function walkNodes(callable $fn) |
|
| 238 | + { |
|
| 239 | + foreach ($this->_children as $node) { |
|
| 240 | + $node->walkNodes($fn); |
|
| 241 | + } |
|
| 242 | + $fn($this); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Get the total number of nodes in a tree. |
|
| 247 | - * |
|
| 248 | - * @return int |
|
| 249 | - */ |
|
| 250 | - public function nodeCount(): int |
|
| 251 | - { |
|
| 252 | - $c = 1; |
|
| 253 | - foreach ($this->_children as $child) { |
|
| 254 | - $c += $child->nodeCount(); |
|
| 255 | - } |
|
| 256 | - return $c; |
|
| 257 | - } |
|
| 245 | + /** |
|
| 246 | + * Get the total number of nodes in a tree. |
|
| 247 | + * |
|
| 248 | + * @return int |
|
| 249 | + */ |
|
| 250 | + public function nodeCount(): int |
|
| 251 | + { |
|
| 252 | + $c = 1; |
|
| 253 | + foreach ($this->_children as $child) { |
|
| 254 | + $c += $child->nodeCount(); |
|
| 255 | + } |
|
| 256 | + return $c; |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Get the number of child nodes. |
|
| 261 | - * |
|
| 262 | - * @see \Countable::count() |
|
| 263 | - */ |
|
| 264 | - public function count(): int |
|
| 265 | - { |
|
| 266 | - return count($this->_children); |
|
| 267 | - } |
|
| 259 | + /** |
|
| 260 | + * Get the number of child nodes. |
|
| 261 | + * |
|
| 262 | + * @see \Countable::count() |
|
| 263 | + */ |
|
| 264 | + public function count(): int |
|
| 265 | + { |
|
| 266 | + return count($this->_children); |
|
| 267 | + } |
|
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Get iterator for the child nodes. |
|
| 271 | - * |
|
| 272 | - * @see \IteratorAggregate::getIterator() |
|
| 273 | - */ |
|
| 274 | - public function getIterator(): \ArrayIterator |
|
| 275 | - { |
|
| 276 | - return new \ArrayIterator($this->_children); |
|
| 277 | - } |
|
| 269 | + /** |
|
| 270 | + * Get iterator for the child nodes. |
|
| 271 | + * |
|
| 272 | + * @see \IteratorAggregate::getIterator() |
|
| 273 | + */ |
|
| 274 | + public function getIterator(): \ArrayIterator |
|
| 275 | + { |
|
| 276 | + return new \ArrayIterator($this->_children); |
|
| 277 | + } |
|
| 278 | 278 | } |
@@ -10,411 +10,411 @@ |
||
| 10 | 10 | |
| 11 | 11 | class PolicyTree |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Root node at depth zero. |
|
| 15 | - * |
|
| 16 | - * @var PolicyNode|null |
|
| 17 | - */ |
|
| 18 | - protected $_root; |
|
| 13 | + /** |
|
| 14 | + * Root node at depth zero. |
|
| 15 | + * |
|
| 16 | + * @var PolicyNode|null |
|
| 17 | + */ |
|
| 18 | + protected $_root; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Constructor. |
|
| 22 | - * |
|
| 23 | - * @param PolicyNode $root Initial root node |
|
| 24 | - */ |
|
| 25 | - public function __construct(PolicyNode $root) |
|
| 26 | - { |
|
| 27 | - $this->_root = $root; |
|
| 28 | - } |
|
| 20 | + /** |
|
| 21 | + * Constructor. |
|
| 22 | + * |
|
| 23 | + * @param PolicyNode $root Initial root node |
|
| 24 | + */ |
|
| 25 | + public function __construct(PolicyNode $root) |
|
| 26 | + { |
|
| 27 | + $this->_root = $root; |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Process policy information from the certificate. |
|
| 32 | - * |
|
| 33 | - * Certificate policies extension must be present. |
|
| 34 | - * |
|
| 35 | - * @param ValidatorState $state |
|
| 36 | - * @param Certificate $cert |
|
| 37 | - * @return ValidatorState |
|
| 38 | - */ |
|
| 39 | - public function processPolicies(ValidatorState $state, Certificate $cert): ValidatorState |
|
| 40 | - { |
|
| 41 | - $policies = $cert->tbsCertificate() |
|
| 42 | - ->extensions() |
|
| 43 | - ->certificatePolicies(); |
|
| 44 | - $tree = clone $this; |
|
| 45 | - // (d.1) for each policy P not equal to anyPolicy |
|
| 46 | - foreach ($policies as $policy) { |
|
| 47 | - if ($policy->isAnyPolicy()) { |
|
| 48 | - $tree->_processAnyPolicy($policy, $cert, $state); |
|
| 49 | - } else { |
|
| 50 | - $tree->_processPolicy($policy, $state); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // if whole tree is pruned |
|
| 54 | - if (!$tree->_pruneTree($state->index() - 1)) { |
|
| 55 | - return $state->withoutValidPolicyTree(); |
|
| 56 | - } |
|
| 57 | - return $state->withValidPolicyTree($tree); |
|
| 58 | - } |
|
| 30 | + /** |
|
| 31 | + * Process policy information from the certificate. |
|
| 32 | + * |
|
| 33 | + * Certificate policies extension must be present. |
|
| 34 | + * |
|
| 35 | + * @param ValidatorState $state |
|
| 36 | + * @param Certificate $cert |
|
| 37 | + * @return ValidatorState |
|
| 38 | + */ |
|
| 39 | + public function processPolicies(ValidatorState $state, Certificate $cert): ValidatorState |
|
| 40 | + { |
|
| 41 | + $policies = $cert->tbsCertificate() |
|
| 42 | + ->extensions() |
|
| 43 | + ->certificatePolicies(); |
|
| 44 | + $tree = clone $this; |
|
| 45 | + // (d.1) for each policy P not equal to anyPolicy |
|
| 46 | + foreach ($policies as $policy) { |
|
| 47 | + if ($policy->isAnyPolicy()) { |
|
| 48 | + $tree->_processAnyPolicy($policy, $cert, $state); |
|
| 49 | + } else { |
|
| 50 | + $tree->_processPolicy($policy, $state); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // if whole tree is pruned |
|
| 54 | + if (!$tree->_pruneTree($state->index() - 1)) { |
|
| 55 | + return $state->withoutValidPolicyTree(); |
|
| 56 | + } |
|
| 57 | + return $state->withValidPolicyTree($tree); |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Process policy mappings from the certificate. |
|
| 62 | - * |
|
| 63 | - * @param ValidatorState $state |
|
| 64 | - * @param Certificate $cert |
|
| 65 | - * @return ValidatorState |
|
| 66 | - */ |
|
| 67 | - public function processMappings(ValidatorState $state, Certificate $cert): ValidatorState |
|
| 68 | - { |
|
| 69 | - $tree = clone $this; |
|
| 70 | - if ($state->policyMapping() > 0) { |
|
| 71 | - $tree->_applyMappings($cert, $state); |
|
| 72 | - } else if ($state->policyMapping() == 0) { |
|
| 73 | - $tree->_deleteMappings($cert, $state); |
|
| 74 | - } |
|
| 75 | - // if whole tree is pruned |
|
| 76 | - if (!$tree->_root) { |
|
| 77 | - return $state->withoutValidPolicyTree(); |
|
| 78 | - } |
|
| 79 | - return $state->withValidPolicyTree($tree); |
|
| 80 | - } |
|
| 60 | + /** |
|
| 61 | + * Process policy mappings from the certificate. |
|
| 62 | + * |
|
| 63 | + * @param ValidatorState $state |
|
| 64 | + * @param Certificate $cert |
|
| 65 | + * @return ValidatorState |
|
| 66 | + */ |
|
| 67 | + public function processMappings(ValidatorState $state, Certificate $cert): ValidatorState |
|
| 68 | + { |
|
| 69 | + $tree = clone $this; |
|
| 70 | + if ($state->policyMapping() > 0) { |
|
| 71 | + $tree->_applyMappings($cert, $state); |
|
| 72 | + } else if ($state->policyMapping() == 0) { |
|
| 73 | + $tree->_deleteMappings($cert, $state); |
|
| 74 | + } |
|
| 75 | + // if whole tree is pruned |
|
| 76 | + if (!$tree->_root) { |
|
| 77 | + return $state->withoutValidPolicyTree(); |
|
| 78 | + } |
|
| 79 | + return $state->withValidPolicyTree($tree); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g. |
|
| 84 | - * |
|
| 85 | - * @param ValidatorState $state |
|
| 86 | - * @param array $policies |
|
| 87 | - * @return ValidatorState |
|
| 88 | - */ |
|
| 89 | - public function calculateIntersection(ValidatorState $state, array $policies): ValidatorState |
|
| 90 | - { |
|
| 91 | - $tree = clone $this; |
|
| 92 | - $valid_policy_node_set = $tree->_validPolicyNodeSet(); |
|
| 93 | - // 2. If the valid_policy of any node in the valid_policy_node_set |
|
| 94 | - // is not in the user-initial-policy-set and is not anyPolicy, |
|
| 95 | - // delete this node and all its children. |
|
| 96 | - $valid_policy_node_set = array_filter($valid_policy_node_set, |
|
| 97 | - function (PolicyNode $node) use ($policies) { |
|
| 98 | - if ($node->isAnyPolicy()) { |
|
| 99 | - return true; |
|
| 100 | - } |
|
| 101 | - if (in_array($node->validPolicy(), $policies)) { |
|
| 102 | - return true; |
|
| 103 | - } |
|
| 104 | - $node->remove(); |
|
| 105 | - return false; |
|
| 106 | - }); |
|
| 107 | - // array of valid policy OIDs |
|
| 108 | - $valid_policy_set = array_map( |
|
| 109 | - function (PolicyNode $node) { |
|
| 110 | - return $node->validPolicy(); |
|
| 111 | - }, $valid_policy_node_set); |
|
| 112 | - // 3. If the valid_policy_tree includes a node of depth n with |
|
| 113 | - // the valid_policy anyPolicy and the user-initial-policy-set |
|
| 114 | - // is not any-policy |
|
| 115 | - foreach ($tree->_nodesAtDepth($state->index()) as $node) { |
|
| 116 | - if ($node->hasParent() && $node->isAnyPolicy()) { |
|
| 117 | - // a. Set P-Q to the qualifier_set in the node of depth n |
|
| 118 | - // with valid_policy anyPolicy. |
|
| 119 | - $pq = $node->qualifiers(); |
|
| 120 | - // b. For each P-OID in the user-initial-policy-set that is not |
|
| 121 | - // the valid_policy of a node in the valid_policy_node_set, |
|
| 122 | - // create a child node whose parent is the node of depth n-1 |
|
| 123 | - // with the valid_policy anyPolicy. |
|
| 124 | - $poids = array_diff($policies, $valid_policy_set); |
|
| 125 | - foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) { |
|
| 126 | - if ($parent->isAnyPolicy()) { |
|
| 127 | - // Set the values in the child node as follows: |
|
| 128 | - // set the valid_policy to P-OID, set the qualifier_set |
|
| 129 | - // to P-Q, and set the expected_policy_set to {P-OID}. |
|
| 130 | - foreach ($poids as $poid) { |
|
| 131 | - $parent->addChild( |
|
| 132 | - new PolicyNode($poid, $pq, array($poid))); |
|
| 133 | - } |
|
| 134 | - break; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - // c. Delete the node of depth n with the |
|
| 138 | - // valid_policy anyPolicy. |
|
| 139 | - $node->remove(); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - // 4. If there is a node in the valid_policy_tree of depth n-1 or less |
|
| 143 | - // without any child nodes, delete that node. Repeat this step until |
|
| 144 | - // there are no nodes of depth n-1 or less without children. |
|
| 145 | - if (!$tree->_pruneTree($state->index() - 1)) { |
|
| 146 | - return $state->withoutValidPolicyTree(); |
|
| 147 | - } |
|
| 148 | - return $state->withValidPolicyTree($tree); |
|
| 149 | - } |
|
| 82 | + /** |
|
| 83 | + * Calculate policy intersection as specified in Wrap-Up Procedure 6.1.5.g. |
|
| 84 | + * |
|
| 85 | + * @param ValidatorState $state |
|
| 86 | + * @param array $policies |
|
| 87 | + * @return ValidatorState |
|
| 88 | + */ |
|
| 89 | + public function calculateIntersection(ValidatorState $state, array $policies): ValidatorState |
|
| 90 | + { |
|
| 91 | + $tree = clone $this; |
|
| 92 | + $valid_policy_node_set = $tree->_validPolicyNodeSet(); |
|
| 93 | + // 2. If the valid_policy of any node in the valid_policy_node_set |
|
| 94 | + // is not in the user-initial-policy-set and is not anyPolicy, |
|
| 95 | + // delete this node and all its children. |
|
| 96 | + $valid_policy_node_set = array_filter($valid_policy_node_set, |
|
| 97 | + function (PolicyNode $node) use ($policies) { |
|
| 98 | + if ($node->isAnyPolicy()) { |
|
| 99 | + return true; |
|
| 100 | + } |
|
| 101 | + if (in_array($node->validPolicy(), $policies)) { |
|
| 102 | + return true; |
|
| 103 | + } |
|
| 104 | + $node->remove(); |
|
| 105 | + return false; |
|
| 106 | + }); |
|
| 107 | + // array of valid policy OIDs |
|
| 108 | + $valid_policy_set = array_map( |
|
| 109 | + function (PolicyNode $node) { |
|
| 110 | + return $node->validPolicy(); |
|
| 111 | + }, $valid_policy_node_set); |
|
| 112 | + // 3. If the valid_policy_tree includes a node of depth n with |
|
| 113 | + // the valid_policy anyPolicy and the user-initial-policy-set |
|
| 114 | + // is not any-policy |
|
| 115 | + foreach ($tree->_nodesAtDepth($state->index()) as $node) { |
|
| 116 | + if ($node->hasParent() && $node->isAnyPolicy()) { |
|
| 117 | + // a. Set P-Q to the qualifier_set in the node of depth n |
|
| 118 | + // with valid_policy anyPolicy. |
|
| 119 | + $pq = $node->qualifiers(); |
|
| 120 | + // b. For each P-OID in the user-initial-policy-set that is not |
|
| 121 | + // the valid_policy of a node in the valid_policy_node_set, |
|
| 122 | + // create a child node whose parent is the node of depth n-1 |
|
| 123 | + // with the valid_policy anyPolicy. |
|
| 124 | + $poids = array_diff($policies, $valid_policy_set); |
|
| 125 | + foreach ($tree->_nodesAtDepth($state->index() - 1) as $parent) { |
|
| 126 | + if ($parent->isAnyPolicy()) { |
|
| 127 | + // Set the values in the child node as follows: |
|
| 128 | + // set the valid_policy to P-OID, set the qualifier_set |
|
| 129 | + // to P-Q, and set the expected_policy_set to {P-OID}. |
|
| 130 | + foreach ($poids as $poid) { |
|
| 131 | + $parent->addChild( |
|
| 132 | + new PolicyNode($poid, $pq, array($poid))); |
|
| 133 | + } |
|
| 134 | + break; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + // c. Delete the node of depth n with the |
|
| 138 | + // valid_policy anyPolicy. |
|
| 139 | + $node->remove(); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + // 4. If there is a node in the valid_policy_tree of depth n-1 or less |
|
| 143 | + // without any child nodes, delete that node. Repeat this step until |
|
| 144 | + // there are no nodes of depth n-1 or less without children. |
|
| 145 | + if (!$tree->_pruneTree($state->index() - 1)) { |
|
| 146 | + return $state->withoutValidPolicyTree(); |
|
| 147 | + } |
|
| 148 | + return $state->withValidPolicyTree($tree); |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Get policies at given policy tree depth. |
|
| 153 | - * |
|
| 154 | - * @param int $i Depth in range 1..n |
|
| 155 | - * @return PolicyInformation[] |
|
| 156 | - */ |
|
| 157 | - public function policiesAtDepth(int $i): array |
|
| 158 | - { |
|
| 159 | - $policies = array(); |
|
| 160 | - foreach ($this->_nodesAtDepth($i) as $node) { |
|
| 161 | - $policies[] = new PolicyInformation($node->validPolicy(), |
|
| 162 | - ...$node->qualifiers()); |
|
| 163 | - } |
|
| 164 | - return $policies; |
|
| 165 | - } |
|
| 151 | + /** |
|
| 152 | + * Get policies at given policy tree depth. |
|
| 153 | + * |
|
| 154 | + * @param int $i Depth in range 1..n |
|
| 155 | + * @return PolicyInformation[] |
|
| 156 | + */ |
|
| 157 | + public function policiesAtDepth(int $i): array |
|
| 158 | + { |
|
| 159 | + $policies = array(); |
|
| 160 | + foreach ($this->_nodesAtDepth($i) as $node) { |
|
| 161 | + $policies[] = new PolicyInformation($node->validPolicy(), |
|
| 162 | + ...$node->qualifiers()); |
|
| 163 | + } |
|
| 164 | + return $policies; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Process single policy information. |
|
| 169 | - * |
|
| 170 | - * @param PolicyInformation $policy |
|
| 171 | - * @param ValidatorState $state |
|
| 172 | - */ |
|
| 173 | - protected function _processPolicy(PolicyInformation $policy, |
|
| 174 | - ValidatorState $state) |
|
| 175 | - { |
|
| 176 | - $p_oid = $policy->oid(); |
|
| 177 | - $i = $state->index(); |
|
| 178 | - $match_count = 0; |
|
| 179 | - // (d.1.i) for each node of depth i-1 in the valid_policy_tree... |
|
| 180 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
| 181 | - // ...where P-OID is in the expected_policy_set |
|
| 182 | - if ($node->hasExpectedPolicy($p_oid)) { |
|
| 183 | - $node->addChild( |
|
| 184 | - new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid))); |
|
| 185 | - ++$match_count; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - // (d.1.ii) if there was no match in step (i)... |
|
| 189 | - if (!$match_count) { |
|
| 190 | - // ...and the valid_policy_tree includes a node of depth i-1 with |
|
| 191 | - // the valid_policy anyPolicy |
|
| 192 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
| 193 | - if ($node->isAnyPolicy()) { |
|
| 194 | - $node->addChild( |
|
| 195 | - new PolicyNode($p_oid, $policy->qualifiers(), |
|
| 196 | - array($p_oid))); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 167 | + /** |
|
| 168 | + * Process single policy information. |
|
| 169 | + * |
|
| 170 | + * @param PolicyInformation $policy |
|
| 171 | + * @param ValidatorState $state |
|
| 172 | + */ |
|
| 173 | + protected function _processPolicy(PolicyInformation $policy, |
|
| 174 | + ValidatorState $state) |
|
| 175 | + { |
|
| 176 | + $p_oid = $policy->oid(); |
|
| 177 | + $i = $state->index(); |
|
| 178 | + $match_count = 0; |
|
| 179 | + // (d.1.i) for each node of depth i-1 in the valid_policy_tree... |
|
| 180 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
| 181 | + // ...where P-OID is in the expected_policy_set |
|
| 182 | + if ($node->hasExpectedPolicy($p_oid)) { |
|
| 183 | + $node->addChild( |
|
| 184 | + new PolicyNode($p_oid, $policy->qualifiers(), array($p_oid))); |
|
| 185 | + ++$match_count; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + // (d.1.ii) if there was no match in step (i)... |
|
| 189 | + if (!$match_count) { |
|
| 190 | + // ...and the valid_policy_tree includes a node of depth i-1 with |
|
| 191 | + // the valid_policy anyPolicy |
|
| 192 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
| 193 | + if ($node->isAnyPolicy()) { |
|
| 194 | + $node->addChild( |
|
| 195 | + new PolicyNode($p_oid, $policy->qualifiers(), |
|
| 196 | + array($p_oid))); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 203 | - * Process anyPolicy policy information. |
|
| 204 | - * |
|
| 205 | - * @param PolicyInformation $policy |
|
| 206 | - * @param Certificate $cert |
|
| 207 | - * @param ValidatorState $state |
|
| 208 | - */ |
|
| 209 | - protected function _processAnyPolicy(PolicyInformation $policy, |
|
| 210 | - Certificate $cert, ValidatorState $state) |
|
| 211 | - { |
|
| 212 | - $i = $state->index(); |
|
| 213 | - // if (a) inhibit_anyPolicy is greater than 0 or |
|
| 214 | - // (b) i<n and the certificate is self-issued |
|
| 215 | - if (!($state->inhibitAnyPolicy() > 0 || |
|
| 216 | - ($i < $state->pathLength() && $cert->isSelfIssued()))) { |
|
| 217 | - return; |
|
| 218 | - } |
|
| 219 | - // for each node in the valid_policy_tree of depth i-1 |
|
| 220 | - foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
| 221 | - // for each value in the expected_policy_set |
|
| 222 | - foreach ($node->expectedPolicies() as $p_oid) { |
|
| 223 | - // that does not appear in a child node |
|
| 224 | - if (!$node->hasChildWithValidPolicy($p_oid)) { |
|
| 225 | - $node->addChild( |
|
| 226 | - new PolicyNode($p_oid, $policy->qualifiers(), |
|
| 227 | - array($p_oid))); |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 202 | + /** |
|
| 203 | + * Process anyPolicy policy information. |
|
| 204 | + * |
|
| 205 | + * @param PolicyInformation $policy |
|
| 206 | + * @param Certificate $cert |
|
| 207 | + * @param ValidatorState $state |
|
| 208 | + */ |
|
| 209 | + protected function _processAnyPolicy(PolicyInformation $policy, |
|
| 210 | + Certificate $cert, ValidatorState $state) |
|
| 211 | + { |
|
| 212 | + $i = $state->index(); |
|
| 213 | + // if (a) inhibit_anyPolicy is greater than 0 or |
|
| 214 | + // (b) i<n and the certificate is self-issued |
|
| 215 | + if (!($state->inhibitAnyPolicy() > 0 || |
|
| 216 | + ($i < $state->pathLength() && $cert->isSelfIssued()))) { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 219 | + // for each node in the valid_policy_tree of depth i-1 |
|
| 220 | + foreach ($this->_nodesAtDepth($i - 1) as $node) { |
|
| 221 | + // for each value in the expected_policy_set |
|
| 222 | + foreach ($node->expectedPolicies() as $p_oid) { |
|
| 223 | + // that does not appear in a child node |
|
| 224 | + if (!$node->hasChildWithValidPolicy($p_oid)) { |
|
| 225 | + $node->addChild( |
|
| 226 | + new PolicyNode($p_oid, $policy->qualifiers(), |
|
| 227 | + array($p_oid))); |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - /** |
|
| 234 | - * Apply policy mappings to the policy tree. |
|
| 235 | - * |
|
| 236 | - * @param Certificate $cert |
|
| 237 | - * @param ValidatorState $state |
|
| 238 | - */ |
|
| 239 | - protected function _applyMappings(Certificate $cert, ValidatorState $state) |
|
| 240 | - { |
|
| 241 | - $policy_mappings = $cert->tbsCertificate() |
|
| 242 | - ->extensions() |
|
| 243 | - ->policyMappings(); |
|
| 244 | - // (6.1.4. b.1.) for each node in the valid_policy_tree of depth i... |
|
| 245 | - foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) { |
|
| 246 | - $match_count = 0; |
|
| 247 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
| 248 | - // ...where ID-P is the valid_policy |
|
| 249 | - if ($node->validPolicy() == $idp) { |
|
| 250 | - // set expected_policy_set to the set of subjectDomainPolicy |
|
| 251 | - // values that are specified as equivalent to ID-P by |
|
| 252 | - // the policy mappings extension |
|
| 253 | - $node->setExpectedPolicies(...$sdps); |
|
| 254 | - ++$match_count; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - // if no node of depth i in the valid_policy_tree has |
|
| 258 | - // a valid_policy of ID-P... |
|
| 259 | - if (!$match_count) { |
|
| 260 | - $this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 233 | + /** |
|
| 234 | + * Apply policy mappings to the policy tree. |
|
| 235 | + * |
|
| 236 | + * @param Certificate $cert |
|
| 237 | + * @param ValidatorState $state |
|
| 238 | + */ |
|
| 239 | + protected function _applyMappings(Certificate $cert, ValidatorState $state) |
|
| 240 | + { |
|
| 241 | + $policy_mappings = $cert->tbsCertificate() |
|
| 242 | + ->extensions() |
|
| 243 | + ->policyMappings(); |
|
| 244 | + // (6.1.4. b.1.) for each node in the valid_policy_tree of depth i... |
|
| 245 | + foreach ($policy_mappings->flattenedMappings() as $idp => $sdps) { |
|
| 246 | + $match_count = 0; |
|
| 247 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
| 248 | + // ...where ID-P is the valid_policy |
|
| 249 | + if ($node->validPolicy() == $idp) { |
|
| 250 | + // set expected_policy_set to the set of subjectDomainPolicy |
|
| 251 | + // values that are specified as equivalent to ID-P by |
|
| 252 | + // the policy mappings extension |
|
| 253 | + $node->setExpectedPolicies(...$sdps); |
|
| 254 | + ++$match_count; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + // if no node of depth i in the valid_policy_tree has |
|
| 258 | + // a valid_policy of ID-P... |
|
| 259 | + if (!$match_count) { |
|
| 260 | + $this->_applyAnyPolicyMapping($cert, $state, $idp, $sdps); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | 264 | |
| 265 | - /** |
|
| 266 | - * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1). |
|
| 267 | - * |
|
| 268 | - * @param Certificate $cert |
|
| 269 | - * @param ValidatorState $state |
|
| 270 | - * @param string $idp OID of the issuer domain policy |
|
| 271 | - * @param array $sdps Array of subject domain policy OIDs |
|
| 272 | - */ |
|
| 273 | - protected function _applyAnyPolicyMapping(Certificate $cert, |
|
| 274 | - ValidatorState $state, $idp, array $sdps) |
|
| 275 | - { |
|
| 276 | - // (6.1.4. b.1.) ...but there is a node of depth i with |
|
| 277 | - // a valid_policy of anyPolicy |
|
| 278 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
| 279 | - if ($node->isAnyPolicy()) { |
|
| 280 | - // then generate a child node of the node of depth i-1 |
|
| 281 | - // that has a valid_policy of anyPolicy as follows... |
|
| 282 | - foreach ($this->_nodesAtDepth($state->index() - 1) as $node) { |
|
| 283 | - if ($node->isAnyPolicy()) { |
|
| 284 | - // try to fetch qualifiers of anyPolicy certificate policy |
|
| 285 | - $qualifiers = array(); |
|
| 286 | - try { |
|
| 287 | - $qualifiers = $cert->tbsCertificate() |
|
| 288 | - ->extensions() |
|
| 289 | - ->certificatePolicies() |
|
| 290 | - ->anyPolicy() |
|
| 291 | - ->qualifiers(); |
|
| 292 | - } catch (\LogicException $e) { |
|
| 293 | - // if there's no policies or no qualifiers |
|
| 294 | - } |
|
| 295 | - $node->addChild( |
|
| 296 | - new PolicyNode($idp, $qualifiers, $sdps)); |
|
| 297 | - // bail after first anyPolicy has been processed |
|
| 298 | - break; |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - // bail after first anyPolicy has been processed |
|
| 302 | - break; |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 265 | + /** |
|
| 266 | + * Apply anyPolicy mapping to the policy tree as specified in 6.1.4 (b)(1). |
|
| 267 | + * |
|
| 268 | + * @param Certificate $cert |
|
| 269 | + * @param ValidatorState $state |
|
| 270 | + * @param string $idp OID of the issuer domain policy |
|
| 271 | + * @param array $sdps Array of subject domain policy OIDs |
|
| 272 | + */ |
|
| 273 | + protected function _applyAnyPolicyMapping(Certificate $cert, |
|
| 274 | + ValidatorState $state, $idp, array $sdps) |
|
| 275 | + { |
|
| 276 | + // (6.1.4. b.1.) ...but there is a node of depth i with |
|
| 277 | + // a valid_policy of anyPolicy |
|
| 278 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
| 279 | + if ($node->isAnyPolicy()) { |
|
| 280 | + // then generate a child node of the node of depth i-1 |
|
| 281 | + // that has a valid_policy of anyPolicy as follows... |
|
| 282 | + foreach ($this->_nodesAtDepth($state->index() - 1) as $node) { |
|
| 283 | + if ($node->isAnyPolicy()) { |
|
| 284 | + // try to fetch qualifiers of anyPolicy certificate policy |
|
| 285 | + $qualifiers = array(); |
|
| 286 | + try { |
|
| 287 | + $qualifiers = $cert->tbsCertificate() |
|
| 288 | + ->extensions() |
|
| 289 | + ->certificatePolicies() |
|
| 290 | + ->anyPolicy() |
|
| 291 | + ->qualifiers(); |
|
| 292 | + } catch (\LogicException $e) { |
|
| 293 | + // if there's no policies or no qualifiers |
|
| 294 | + } |
|
| 295 | + $node->addChild( |
|
| 296 | + new PolicyNode($idp, $qualifiers, $sdps)); |
|
| 297 | + // bail after first anyPolicy has been processed |
|
| 298 | + break; |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + // bail after first anyPolicy has been processed |
|
| 302 | + break; |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * Delete nodes as specified in 6.1.4 (b)(2). |
|
| 309 | - * |
|
| 310 | - * @param Certificate $cert |
|
| 311 | - * @param ValidatorState $state |
|
| 312 | - */ |
|
| 313 | - protected function _deleteMappings(Certificate $cert, ValidatorState $state) |
|
| 314 | - { |
|
| 315 | - $idps = $cert->tbsCertificate() |
|
| 316 | - ->extensions() |
|
| 317 | - ->policyMappings() |
|
| 318 | - ->issuerDomainPolicies(); |
|
| 319 | - // delete each node of depth i in the valid_policy_tree |
|
| 320 | - // where ID-P is the valid_policy |
|
| 321 | - foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
| 322 | - if (in_array($node->validPolicy(), $idps)) { |
|
| 323 | - $node->remove(); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - $this->_pruneTree($state->index() - 1); |
|
| 327 | - } |
|
| 307 | + /** |
|
| 308 | + * Delete nodes as specified in 6.1.4 (b)(2). |
|
| 309 | + * |
|
| 310 | + * @param Certificate $cert |
|
| 311 | + * @param ValidatorState $state |
|
| 312 | + */ |
|
| 313 | + protected function _deleteMappings(Certificate $cert, ValidatorState $state) |
|
| 314 | + { |
|
| 315 | + $idps = $cert->tbsCertificate() |
|
| 316 | + ->extensions() |
|
| 317 | + ->policyMappings() |
|
| 318 | + ->issuerDomainPolicies(); |
|
| 319 | + // delete each node of depth i in the valid_policy_tree |
|
| 320 | + // where ID-P is the valid_policy |
|
| 321 | + foreach ($this->_nodesAtDepth($state->index()) as $node) { |
|
| 322 | + if (in_array($node->validPolicy(), $idps)) { |
|
| 323 | + $node->remove(); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + $this->_pruneTree($state->index() - 1); |
|
| 327 | + } |
|
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * Prune tree starting from given depth. |
|
| 331 | - * |
|
| 332 | - * @param int $depth |
|
| 333 | - * @return int The number of nodes left in a tree |
|
| 334 | - */ |
|
| 335 | - protected function _pruneTree(int $depth): int |
|
| 336 | - { |
|
| 337 | - for ($i = $depth; $i > 0; --$i) { |
|
| 338 | - foreach ($this->_nodesAtDepth($i) as $node) { |
|
| 339 | - if (!count($node)) { |
|
| 340 | - $node->remove(); |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - // if root has no children left |
|
| 345 | - if (!count($this->_root)) { |
|
| 346 | - $this->_root = null; |
|
| 347 | - return 0; |
|
| 348 | - } |
|
| 349 | - return $this->_root->nodeCount(); |
|
| 350 | - } |
|
| 329 | + /** |
|
| 330 | + * Prune tree starting from given depth. |
|
| 331 | + * |
|
| 332 | + * @param int $depth |
|
| 333 | + * @return int The number of nodes left in a tree |
|
| 334 | + */ |
|
| 335 | + protected function _pruneTree(int $depth): int |
|
| 336 | + { |
|
| 337 | + for ($i = $depth; $i > 0; --$i) { |
|
| 338 | + foreach ($this->_nodesAtDepth($i) as $node) { |
|
| 339 | + if (!count($node)) { |
|
| 340 | + $node->remove(); |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + // if root has no children left |
|
| 345 | + if (!count($this->_root)) { |
|
| 346 | + $this->_root = null; |
|
| 347 | + return 0; |
|
| 348 | + } |
|
| 349 | + return $this->_root->nodeCount(); |
|
| 350 | + } |
|
| 351 | 351 | |
| 352 | - /** |
|
| 353 | - * Get all nodes at given depth. |
|
| 354 | - * |
|
| 355 | - * @param int $i |
|
| 356 | - * @return PolicyNode[] |
|
| 357 | - */ |
|
| 358 | - protected function _nodesAtDepth(int $i): array |
|
| 359 | - { |
|
| 360 | - if (!$this->_root) { |
|
| 361 | - return array(); |
|
| 362 | - } |
|
| 363 | - $depth = 0; |
|
| 364 | - $nodes = array($this->_root); |
|
| 365 | - while ($depth < $i) { |
|
| 366 | - $nodes = self::_gatherChildren(...$nodes); |
|
| 367 | - if (!count($nodes)) { |
|
| 368 | - break; |
|
| 369 | - } |
|
| 370 | - ++$depth; |
|
| 371 | - } |
|
| 372 | - return $nodes; |
|
| 373 | - } |
|
| 352 | + /** |
|
| 353 | + * Get all nodes at given depth. |
|
| 354 | + * |
|
| 355 | + * @param int $i |
|
| 356 | + * @return PolicyNode[] |
|
| 357 | + */ |
|
| 358 | + protected function _nodesAtDepth(int $i): array |
|
| 359 | + { |
|
| 360 | + if (!$this->_root) { |
|
| 361 | + return array(); |
|
| 362 | + } |
|
| 363 | + $depth = 0; |
|
| 364 | + $nodes = array($this->_root); |
|
| 365 | + while ($depth < $i) { |
|
| 366 | + $nodes = self::_gatherChildren(...$nodes); |
|
| 367 | + if (!count($nodes)) { |
|
| 368 | + break; |
|
| 369 | + } |
|
| 370 | + ++$depth; |
|
| 371 | + } |
|
| 372 | + return $nodes; |
|
| 373 | + } |
|
| 374 | 374 | |
| 375 | - /** |
|
| 376 | - * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1. |
|
| 377 | - * |
|
| 378 | - * @return PolicyNode[] |
|
| 379 | - */ |
|
| 380 | - protected function _validPolicyNodeSet(): array |
|
| 381 | - { |
|
| 382 | - // 1. Determine the set of policy nodes whose parent nodes have |
|
| 383 | - // a valid_policy of anyPolicy. This is the valid_policy_node_set. |
|
| 384 | - $set = array(); |
|
| 385 | - if (!$this->_root) { |
|
| 386 | - return $set; |
|
| 387 | - } |
|
| 388 | - // for each node in a tree |
|
| 389 | - $this->_root->walkNodes( |
|
| 390 | - function (PolicyNode $node) use (&$set) { |
|
| 391 | - $parents = $node->parents(); |
|
| 392 | - // node has parents |
|
| 393 | - if (count($parents)) { |
|
| 394 | - // check that each ancestor is an anyPolicy node |
|
| 395 | - foreach ($parents as $ancestor) { |
|
| 396 | - if (!$ancestor->isAnyPolicy()) { |
|
| 397 | - return; |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - $set[] = $node; |
|
| 401 | - } |
|
| 402 | - }); |
|
| 403 | - return $set; |
|
| 404 | - } |
|
| 375 | + /** |
|
| 376 | + * Get the valid policy node set as specified in spec 6.1.5.(g)(iii)1. |
|
| 377 | + * |
|
| 378 | + * @return PolicyNode[] |
|
| 379 | + */ |
|
| 380 | + protected function _validPolicyNodeSet(): array |
|
| 381 | + { |
|
| 382 | + // 1. Determine the set of policy nodes whose parent nodes have |
|
| 383 | + // a valid_policy of anyPolicy. This is the valid_policy_node_set. |
|
| 384 | + $set = array(); |
|
| 385 | + if (!$this->_root) { |
|
| 386 | + return $set; |
|
| 387 | + } |
|
| 388 | + // for each node in a tree |
|
| 389 | + $this->_root->walkNodes( |
|
| 390 | + function (PolicyNode $node) use (&$set) { |
|
| 391 | + $parents = $node->parents(); |
|
| 392 | + // node has parents |
|
| 393 | + if (count($parents)) { |
|
| 394 | + // check that each ancestor is an anyPolicy node |
|
| 395 | + foreach ($parents as $ancestor) { |
|
| 396 | + if (!$ancestor->isAnyPolicy()) { |
|
| 397 | + return; |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + $set[] = $node; |
|
| 401 | + } |
|
| 402 | + }); |
|
| 403 | + return $set; |
|
| 404 | + } |
|
| 405 | 405 | |
| 406 | - /** |
|
| 407 | - * Gather all children of given nodes to a flattened array. |
|
| 408 | - * |
|
| 409 | - * @param PolicyNode ...$nodes |
|
| 410 | - * @return PolicyNode[] |
|
| 411 | - */ |
|
| 412 | - private static function _gatherChildren(PolicyNode ...$nodes): array |
|
| 413 | - { |
|
| 414 | - $children = array(); |
|
| 415 | - foreach ($nodes as $node) { |
|
| 416 | - $children = array_merge($children, $node->children()); |
|
| 417 | - } |
|
| 418 | - return $children; |
|
| 419 | - } |
|
| 406 | + /** |
|
| 407 | + * Gather all children of given nodes to a flattened array. |
|
| 408 | + * |
|
| 409 | + * @param PolicyNode ...$nodes |
|
| 410 | + * @return PolicyNode[] |
|
| 411 | + */ |
|
| 412 | + private static function _gatherChildren(PolicyNode ...$nodes): array |
|
| 413 | + { |
|
| 414 | + $children = array(); |
|
| 415 | + foreach ($nodes as $node) { |
|
| 416 | + $children = array_merge($children, $node->children()); |
|
| 417 | + } |
|
| 418 | + return $children; |
|
| 419 | + } |
|
| 420 | 420 | } |