@@ -13,60 +13,60 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class TargetGroup extends Target |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Group name. |
|
| 18 | - * |
|
| 19 | - * @var GeneralName $_name |
|
| 20 | - */ |
|
| 21 | - protected $_name; |
|
| 16 | + /** |
|
| 17 | + * Group name. |
|
| 18 | + * |
|
| 19 | + * @var GeneralName $_name |
|
| 20 | + */ |
|
| 21 | + protected $_name; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Constructor. |
|
| 25 | - * |
|
| 26 | - * @param GeneralName $name |
|
| 27 | - */ |
|
| 28 | - public function __construct(GeneralName $name) |
|
| 29 | - { |
|
| 30 | - $this->_name = $name; |
|
| 31 | - $this->_type = self::TYPE_GROUP; |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Constructor. |
|
| 25 | + * |
|
| 26 | + * @param GeneralName $name |
|
| 27 | + */ |
|
| 28 | + public function __construct(GeneralName $name) |
|
| 29 | + { |
|
| 30 | + $this->_name = $name; |
|
| 31 | + $this->_type = self::TYPE_GROUP; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * @param TaggedType $el |
|
| 37 | - * @return self |
|
| 38 | - */ |
|
| 39 | - public static function fromChosenASN1(TaggedType $el) |
|
| 40 | - { |
|
| 41 | - return new self(GeneralName::fromASN1($el)); |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * @param TaggedType $el |
|
| 37 | + * @return self |
|
| 38 | + */ |
|
| 39 | + public static function fromChosenASN1(TaggedType $el) |
|
| 40 | + { |
|
| 41 | + return new self(GeneralName::fromASN1($el)); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * {@inheritdoc} |
|
| 47 | - */ |
|
| 48 | - public function string() |
|
| 49 | - { |
|
| 50 | - return $this->_name->string(); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * {@inheritdoc} |
|
| 47 | + */ |
|
| 48 | + public function string() |
|
| 49 | + { |
|
| 50 | + return $this->_name->string(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get group name. |
|
| 55 | - * |
|
| 56 | - * @return GeneralName |
|
| 57 | - */ |
|
| 58 | - public function name() |
|
| 59 | - { |
|
| 60 | - return $this->_name; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Get group name. |
|
| 55 | + * |
|
| 56 | + * @return GeneralName |
|
| 57 | + */ |
|
| 58 | + public function name() |
|
| 59 | + { |
|
| 60 | + return $this->_name; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * |
|
| 65 | - * {@inheritdoc} |
|
| 66 | - * @return ExplicitlyTaggedType |
|
| 67 | - */ |
|
| 68 | - public function toASN1() |
|
| 69 | - { |
|
| 70 | - return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * |
|
| 65 | + * {@inheritdoc} |
|
| 66 | + * @return ExplicitlyTaggedType |
|
| 67 | + */ |
|
| 68 | + public function toASN1() |
|
| 69 | + { |
|
| 70 | + return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\Certificate\Extension\Target; |
| 6 | 6 | |
@@ -13,60 +13,60 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class TargetName extends Target |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Name. |
|
| 18 | - * |
|
| 19 | - * @var GeneralName $_name |
|
| 20 | - */ |
|
| 21 | - protected $_name; |
|
| 16 | + /** |
|
| 17 | + * Name. |
|
| 18 | + * |
|
| 19 | + * @var GeneralName $_name |
|
| 20 | + */ |
|
| 21 | + protected $_name; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * Constructor. |
|
| 25 | - * |
|
| 26 | - * @param GeneralName $name |
|
| 27 | - */ |
|
| 28 | - public function __construct(GeneralName $name) |
|
| 29 | - { |
|
| 30 | - $this->_name = $name; |
|
| 31 | - $this->_type = self::TYPE_NAME; |
|
| 32 | - } |
|
| 23 | + /** |
|
| 24 | + * Constructor. |
|
| 25 | + * |
|
| 26 | + * @param GeneralName $name |
|
| 27 | + */ |
|
| 28 | + public function __construct(GeneralName $name) |
|
| 29 | + { |
|
| 30 | + $this->_name = $name; |
|
| 31 | + $this->_type = self::TYPE_NAME; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * |
|
| 36 | - * @param TaggedType $el |
|
| 37 | - * @return self |
|
| 38 | - */ |
|
| 39 | - public static function fromChosenASN1(TaggedType $el) |
|
| 40 | - { |
|
| 41 | - return new self(GeneralName::fromASN1($el)); |
|
| 42 | - } |
|
| 34 | + /** |
|
| 35 | + * |
|
| 36 | + * @param TaggedType $el |
|
| 37 | + * @return self |
|
| 38 | + */ |
|
| 39 | + public static function fromChosenASN1(TaggedType $el) |
|
| 40 | + { |
|
| 41 | + return new self(GeneralName::fromASN1($el)); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * |
|
| 46 | - * {@inheritdoc} |
|
| 47 | - */ |
|
| 48 | - public function string() |
|
| 49 | - { |
|
| 50 | - return $this->_name->string(); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * |
|
| 46 | + * {@inheritdoc} |
|
| 47 | + */ |
|
| 48 | + public function string() |
|
| 49 | + { |
|
| 50 | + return $this->_name->string(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Get name. |
|
| 55 | - * |
|
| 56 | - * @return GeneralName |
|
| 57 | - */ |
|
| 58 | - public function name() |
|
| 59 | - { |
|
| 60 | - return $this->_name; |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * Get name. |
|
| 55 | + * |
|
| 56 | + * @return GeneralName |
|
| 57 | + */ |
|
| 58 | + public function name() |
|
| 59 | + { |
|
| 60 | + return $this->_name; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * |
|
| 65 | - * {@inheritdoc} |
|
| 66 | - * @return ExplicitlyTaggedType |
|
| 67 | - */ |
|
| 68 | - public function toASN1() |
|
| 69 | - { |
|
| 70 | - return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * |
|
| 65 | + * {@inheritdoc} |
|
| 66 | + * @return ExplicitlyTaggedType |
|
| 67 | + */ |
|
| 68 | + public function toASN1() |
|
| 69 | + { |
|
| 70 | + return new ExplicitlyTaggedType($this->_type, $this->_name->toASN1()); |
|
| 71 | + } |
|
| 72 | 72 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\Certificate\Extension\Target; |
| 6 | 6 | |
@@ -11,89 +11,89 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | abstract class Target |
| 13 | 13 | { |
| 14 | - const TYPE_NAME = 0; |
|
| 15 | - const TYPE_GROUP = 1; |
|
| 16 | - const TYPE_CERT = 2; |
|
| 14 | + const TYPE_NAME = 0; |
|
| 15 | + const TYPE_GROUP = 1; |
|
| 16 | + const TYPE_CERT = 2; |
|
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Type tag. |
|
| 20 | - * |
|
| 21 | - * @var int $_type |
|
| 22 | - */ |
|
| 23 | - protected $_type; |
|
| 18 | + /** |
|
| 19 | + * Type tag. |
|
| 20 | + * |
|
| 21 | + * @var int $_type |
|
| 22 | + */ |
|
| 23 | + protected $_type; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Generate ASN.1 element. |
|
| 27 | - * |
|
| 28 | - * @return \ASN1\Element |
|
| 29 | - */ |
|
| 30 | - abstract public function toASN1(); |
|
| 25 | + /** |
|
| 26 | + * Generate ASN.1 element. |
|
| 27 | + * |
|
| 28 | + * @return \ASN1\Element |
|
| 29 | + */ |
|
| 30 | + abstract public function toASN1(); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Get string value of the target. |
|
| 34 | - * |
|
| 35 | - * @return string |
|
| 36 | - */ |
|
| 37 | - abstract public function string(); |
|
| 32 | + /** |
|
| 33 | + * Get string value of the target. |
|
| 34 | + * |
|
| 35 | + * @return string |
|
| 36 | + */ |
|
| 37 | + abstract public function string(); |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Initialize concrete object from the chosen ASN.1 element. |
|
| 41 | - * |
|
| 42 | - * @param TaggedType $el |
|
| 43 | - * @return self |
|
| 44 | - */ |
|
| 45 | - public static function fromChosenASN1(TaggedType $el) |
|
| 46 | - { |
|
| 47 | - throw new \BadMethodCallException( |
|
| 48 | - __FUNCTION__ . " must be implemented in the derived class."); |
|
| 49 | - } |
|
| 39 | + /** |
|
| 40 | + * Initialize concrete object from the chosen ASN.1 element. |
|
| 41 | + * |
|
| 42 | + * @param TaggedType $el |
|
| 43 | + * @return self |
|
| 44 | + */ |
|
| 45 | + public static function fromChosenASN1(TaggedType $el) |
|
| 46 | + { |
|
| 47 | + throw new \BadMethodCallException( |
|
| 48 | + __FUNCTION__ . " must be implemented in the derived class."); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Parse from ASN.1. |
|
| 53 | - * |
|
| 54 | - * @param TaggedType $el |
|
| 55 | - * @throws \UnexpectedValueException |
|
| 56 | - * @return self |
|
| 57 | - */ |
|
| 58 | - public static function fromASN1(TaggedType $el) |
|
| 59 | - { |
|
| 60 | - switch ($el->tag()) { |
|
| 61 | - case self::TYPE_NAME: |
|
| 62 | - return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 63 | - case self::TYPE_GROUP: |
|
| 64 | - return TargetGroup::fromChosenASN1( |
|
| 65 | - $el->asExplicit()->asTagged()); |
|
| 66 | - case self::TYPE_CERT: |
|
| 67 | - throw new \RuntimeException("targetCert not supported."); |
|
| 68 | - } |
|
| 69 | - throw new \UnexpectedValueException( |
|
| 70 | - "Target type " . $el->tag() . " not supported."); |
|
| 71 | - } |
|
| 51 | + /** |
|
| 52 | + * Parse from ASN.1. |
|
| 53 | + * |
|
| 54 | + * @param TaggedType $el |
|
| 55 | + * @throws \UnexpectedValueException |
|
| 56 | + * @return self |
|
| 57 | + */ |
|
| 58 | + public static function fromASN1(TaggedType $el) |
|
| 59 | + { |
|
| 60 | + switch ($el->tag()) { |
|
| 61 | + case self::TYPE_NAME: |
|
| 62 | + return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 63 | + case self::TYPE_GROUP: |
|
| 64 | + return TargetGroup::fromChosenASN1( |
|
| 65 | + $el->asExplicit()->asTagged()); |
|
| 66 | + case self::TYPE_CERT: |
|
| 67 | + throw new \RuntimeException("targetCert not supported."); |
|
| 68 | + } |
|
| 69 | + throw new \UnexpectedValueException( |
|
| 70 | + "Target type " . $el->tag() . " not supported."); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Get type tag. |
|
| 75 | - * |
|
| 76 | - * @return int |
|
| 77 | - */ |
|
| 78 | - public function type() |
|
| 79 | - { |
|
| 80 | - return $this->_type; |
|
| 81 | - } |
|
| 73 | + /** |
|
| 74 | + * Get type tag. |
|
| 75 | + * |
|
| 76 | + * @return int |
|
| 77 | + */ |
|
| 78 | + public function type() |
|
| 79 | + { |
|
| 80 | + return $this->_type; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Check whether target is equal to another. |
|
| 85 | - * |
|
| 86 | - * @param Target $other |
|
| 87 | - * @return bool |
|
| 88 | - */ |
|
| 89 | - public function equals(Target $other) |
|
| 90 | - { |
|
| 91 | - if ($this->_type != $other->_type) { |
|
| 92 | - return false; |
|
| 93 | - } |
|
| 94 | - if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) { |
|
| 95 | - return false; |
|
| 96 | - } |
|
| 97 | - return true; |
|
| 98 | - } |
|
| 83 | + /** |
|
| 84 | + * Check whether target is equal to another. |
|
| 85 | + * |
|
| 86 | + * @param Target $other |
|
| 87 | + * @return bool |
|
| 88 | + */ |
|
| 89 | + public function equals(Target $other) |
|
| 90 | + { |
|
| 91 | + if ($this->_type != $other->_type) { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 94 | + if ($this->toASN1()->toDER() != $other->toASN1()->toDER()) { |
|
| 95 | + return false; |
|
| 96 | + } |
|
| 97 | + return true; |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -58,13 +58,13 @@ |
||
| 58 | 58 | public static function fromASN1(TaggedType $el) |
| 59 | 59 | { |
| 60 | 60 | switch ($el->tag()) { |
| 61 | - case self::TYPE_NAME: |
|
| 62 | - return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 63 | - case self::TYPE_GROUP: |
|
| 64 | - return TargetGroup::fromChosenASN1( |
|
| 65 | - $el->asExplicit()->asTagged()); |
|
| 66 | - case self::TYPE_CERT: |
|
| 67 | - throw new \RuntimeException("targetCert not supported."); |
|
| 61 | + case self::TYPE_NAME: |
|
| 62 | + return TargetName::fromChosenASN1($el->asExplicit()->asTagged()); |
|
| 63 | + case self::TYPE_GROUP: |
|
| 64 | + return TargetGroup::fromChosenASN1( |
|
| 65 | + $el->asExplicit()->asTagged()); |
|
| 66 | + case self::TYPE_CERT: |
|
| 67 | + throw new \RuntimeException("targetCert not supported."); |
|
| 68 | 68 | } |
| 69 | 69 | throw new \UnexpectedValueException( |
| 70 | 70 | "Target type " . $el->tag() . " not supported."); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\Certificate\Extension\Target; |
| 6 | 6 | |
@@ -12,131 +12,131 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Targets implements \Countable, \IteratorAggregate |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Target elements. |
|
| 17 | - * |
|
| 18 | - * @var Target[] $_targets |
|
| 19 | - */ |
|
| 20 | - protected $_targets; |
|
| 15 | + /** |
|
| 16 | + * Target elements. |
|
| 17 | + * |
|
| 18 | + * @var Target[] $_targets |
|
| 19 | + */ |
|
| 20 | + protected $_targets; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Constructor. |
|
| 24 | - * |
|
| 25 | - * @param Target ...$targets |
|
| 26 | - */ |
|
| 27 | - public function __construct(Target ...$targets) |
|
| 28 | - { |
|
| 29 | - $this->_targets = $targets; |
|
| 30 | - } |
|
| 22 | + /** |
|
| 23 | + * Constructor. |
|
| 24 | + * |
|
| 25 | + * @param Target ...$targets |
|
| 26 | + */ |
|
| 27 | + public function __construct(Target ...$targets) |
|
| 28 | + { |
|
| 29 | + $this->_targets = $targets; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Initialize from ASN.1. |
|
| 34 | - * |
|
| 35 | - * @param Sequence $seq |
|
| 36 | - * @return self |
|
| 37 | - */ |
|
| 38 | - public static function fromASN1(Sequence $seq) |
|
| 39 | - { |
|
| 40 | - $targets = array_map( |
|
| 41 | - function (UnspecifiedType $el) { |
|
| 42 | - return Target::fromASN1($el->asTagged()); |
|
| 43 | - }, $seq->elements()); |
|
| 44 | - return new self(...$targets); |
|
| 45 | - } |
|
| 32 | + /** |
|
| 33 | + * Initialize from ASN.1. |
|
| 34 | + * |
|
| 35 | + * @param Sequence $seq |
|
| 36 | + * @return self |
|
| 37 | + */ |
|
| 38 | + public static function fromASN1(Sequence $seq) |
|
| 39 | + { |
|
| 40 | + $targets = array_map( |
|
| 41 | + function (UnspecifiedType $el) { |
|
| 42 | + return Target::fromASN1($el->asTagged()); |
|
| 43 | + }, $seq->elements()); |
|
| 44 | + return new self(...$targets); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Get all targets. |
|
| 49 | - * |
|
| 50 | - * @return Target[] |
|
| 51 | - */ |
|
| 52 | - public function all() |
|
| 53 | - { |
|
| 54 | - return $this->_targets; |
|
| 55 | - } |
|
| 47 | + /** |
|
| 48 | + * Get all targets. |
|
| 49 | + * |
|
| 50 | + * @return Target[] |
|
| 51 | + */ |
|
| 52 | + public function all() |
|
| 53 | + { |
|
| 54 | + return $this->_targets; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Get all targets of given type. |
|
| 59 | - * |
|
| 60 | - * @param int $type |
|
| 61 | - * @return Target[] |
|
| 62 | - */ |
|
| 63 | - protected function _allOfType($type) |
|
| 64 | - { |
|
| 65 | - return array_values( |
|
| 66 | - array_filter($this->_targets, |
|
| 67 | - function (Target $target) use ($type) { |
|
| 68 | - return $target->type() == $type; |
|
| 69 | - })); |
|
| 70 | - } |
|
| 57 | + /** |
|
| 58 | + * Get all targets of given type. |
|
| 59 | + * |
|
| 60 | + * @param int $type |
|
| 61 | + * @return Target[] |
|
| 62 | + */ |
|
| 63 | + protected function _allOfType($type) |
|
| 64 | + { |
|
| 65 | + return array_values( |
|
| 66 | + array_filter($this->_targets, |
|
| 67 | + function (Target $target) use ($type) { |
|
| 68 | + return $target->type() == $type; |
|
| 69 | + })); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Get all name targets. |
|
| 74 | - * |
|
| 75 | - * @return Target[] |
|
| 76 | - */ |
|
| 77 | - public function nameTargets() |
|
| 78 | - { |
|
| 79 | - return $this->_allOfType(Target::TYPE_NAME); |
|
| 80 | - } |
|
| 72 | + /** |
|
| 73 | + * Get all name targets. |
|
| 74 | + * |
|
| 75 | + * @return Target[] |
|
| 76 | + */ |
|
| 77 | + public function nameTargets() |
|
| 78 | + { |
|
| 79 | + return $this->_allOfType(Target::TYPE_NAME); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Get all group targets. |
|
| 84 | - * |
|
| 85 | - * @return Target[] |
|
| 86 | - */ |
|
| 87 | - public function groupTargets() |
|
| 88 | - { |
|
| 89 | - return $this->_allOfType(Target::TYPE_GROUP); |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Get all group targets. |
|
| 84 | + * |
|
| 85 | + * @return Target[] |
|
| 86 | + */ |
|
| 87 | + public function groupTargets() |
|
| 88 | + { |
|
| 89 | + return $this->_allOfType(Target::TYPE_GROUP); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Check whether given target is present. |
|
| 94 | - * |
|
| 95 | - * @param Target $target |
|
| 96 | - * @return boolean |
|
| 97 | - */ |
|
| 98 | - public function hasTarget(Target $target) |
|
| 99 | - { |
|
| 100 | - foreach ($this->_allOfType($target->type()) as $t) { |
|
| 101 | - if ($target->equals($t)) { |
|
| 102 | - return true; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - return false; |
|
| 106 | - } |
|
| 92 | + /** |
|
| 93 | + * Check whether given target is present. |
|
| 94 | + * |
|
| 95 | + * @param Target $target |
|
| 96 | + * @return boolean |
|
| 97 | + */ |
|
| 98 | + public function hasTarget(Target $target) |
|
| 99 | + { |
|
| 100 | + foreach ($this->_allOfType($target->type()) as $t) { |
|
| 101 | + if ($target->equals($t)) { |
|
| 102 | + return true; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + return false; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Generate ASN.1 structure. |
|
| 110 | - * |
|
| 111 | - * @return Sequence |
|
| 112 | - */ |
|
| 113 | - public function toASN1() |
|
| 114 | - { |
|
| 115 | - $elements = array_map( |
|
| 116 | - function (Target $target) { |
|
| 117 | - return $target->toASN1(); |
|
| 118 | - }, $this->_targets); |
|
| 119 | - return new Sequence(...$elements); |
|
| 120 | - } |
|
| 108 | + /** |
|
| 109 | + * Generate ASN.1 structure. |
|
| 110 | + * |
|
| 111 | + * @return Sequence |
|
| 112 | + */ |
|
| 113 | + public function toASN1() |
|
| 114 | + { |
|
| 115 | + $elements = array_map( |
|
| 116 | + function (Target $target) { |
|
| 117 | + return $target->toASN1(); |
|
| 118 | + }, $this->_targets); |
|
| 119 | + return new Sequence(...$elements); |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * |
|
| 124 | - * @see \Countable::count() |
|
| 125 | - * @return int |
|
| 126 | - */ |
|
| 127 | - public function count() |
|
| 128 | - { |
|
| 129 | - return count($this->_targets); |
|
| 130 | - } |
|
| 122 | + /** |
|
| 123 | + * |
|
| 124 | + * @see \Countable::count() |
|
| 125 | + * @return int |
|
| 126 | + */ |
|
| 127 | + public function count() |
|
| 128 | + { |
|
| 129 | + return count($this->_targets); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Get iterator for targets. |
|
| 134 | - * |
|
| 135 | - * @see \IteratorAggregate::getIterator() |
|
| 136 | - * @return \ArrayIterator |
|
| 137 | - */ |
|
| 138 | - public function getIterator() |
|
| 139 | - { |
|
| 140 | - return new \ArrayIterator($this->_targets); |
|
| 141 | - } |
|
| 132 | + /** |
|
| 133 | + * Get iterator for targets. |
|
| 134 | + * |
|
| 135 | + * @see \IteratorAggregate::getIterator() |
|
| 136 | + * @return \ArrayIterator |
|
| 137 | + */ |
|
| 138 | + public function getIterator() |
|
| 139 | + { |
|
| 140 | + return new \ArrayIterator($this->_targets); |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\Certificate\Extension\Target; |
| 6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | public static function fromASN1(Sequence $seq) |
| 41 | 41 | { |
| 42 | 42 | $targets = array_map( |
| 43 | - function (UnspecifiedType $el) { |
|
| 43 | + function(UnspecifiedType $el) { |
|
| 44 | 44 | return Target::fromASN1($el->asTagged()); |
| 45 | 45 | }, $seq->elements()); |
| 46 | 46 | return new self(...$targets); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | return array_values( |
| 68 | 68 | array_filter($this->_targets, |
| 69 | - function (Target $target) use ($type) { |
|
| 69 | + function(Target $target) use ($type) { |
|
| 70 | 70 | return $target->type() == $type; |
| 71 | 71 | })); |
| 72 | 72 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | public function toASN1() |
| 116 | 116 | { |
| 117 | 117 | $elements = array_map( |
| 118 | - function (Target $target) { |
|
| 118 | + function(Target $target) { |
|
| 119 | 119 | return $target->toASN1(); |
| 120 | 120 | }, $this->_targets); |
| 121 | 121 | return new Sequence(...$elements); |
@@ -16,172 +16,172 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class CertificationRequest |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Certification request info. |
|
| 21 | - * |
|
| 22 | - * @var CertificationRequestInfo $_certificationRequestInfo |
|
| 23 | - */ |
|
| 24 | - protected $_certificationRequestInfo; |
|
| 19 | + /** |
|
| 20 | + * Certification request info. |
|
| 21 | + * |
|
| 22 | + * @var CertificationRequestInfo $_certificationRequestInfo |
|
| 23 | + */ |
|
| 24 | + protected $_certificationRequestInfo; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Signature algorithm. |
|
| 28 | - * |
|
| 29 | - * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 30 | - */ |
|
| 31 | - protected $_signatureAlgorithm; |
|
| 26 | + /** |
|
| 27 | + * Signature algorithm. |
|
| 28 | + * |
|
| 29 | + * @var SignatureAlgorithmIdentifier $_signatureAlgorithm |
|
| 30 | + */ |
|
| 31 | + protected $_signatureAlgorithm; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Signature. |
|
| 35 | - * |
|
| 36 | - * @var Signature $_signature |
|
| 37 | - */ |
|
| 38 | - protected $_signature; |
|
| 33 | + /** |
|
| 34 | + * Signature. |
|
| 35 | + * |
|
| 36 | + * @var Signature $_signature |
|
| 37 | + */ |
|
| 38 | + protected $_signature; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor. |
|
| 42 | - * |
|
| 43 | - * @param CertificationRequestInfo $info |
|
| 44 | - * @param SignatureAlgorithmIdentifier $algo |
|
| 45 | - * @param Signature $signature |
|
| 46 | - */ |
|
| 47 | - public function __construct(CertificationRequestInfo $info, |
|
| 48 | - SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 49 | - { |
|
| 50 | - $this->_certificationRequestInfo = $info; |
|
| 51 | - $this->_signatureAlgorithm = $algo; |
|
| 52 | - $this->_signature = $signature; |
|
| 53 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor. |
|
| 42 | + * |
|
| 43 | + * @param CertificationRequestInfo $info |
|
| 44 | + * @param SignatureAlgorithmIdentifier $algo |
|
| 45 | + * @param Signature $signature |
|
| 46 | + */ |
|
| 47 | + public function __construct(CertificationRequestInfo $info, |
|
| 48 | + SignatureAlgorithmIdentifier $algo, Signature $signature) |
|
| 49 | + { |
|
| 50 | + $this->_certificationRequestInfo = $info; |
|
| 51 | + $this->_signatureAlgorithm = $algo; |
|
| 52 | + $this->_signature = $signature; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Initialize from ASN.1. |
|
| 57 | - * |
|
| 58 | - * @param Sequence $seq |
|
| 59 | - * @return self |
|
| 60 | - */ |
|
| 61 | - public static function fromASN1(Sequence $seq) |
|
| 62 | - { |
|
| 63 | - $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 64 | - $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 65 | - if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 66 | - throw new \UnexpectedValueException( |
|
| 67 | - "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 68 | - } |
|
| 69 | - $signature = Signature::fromSignatureData( |
|
| 70 | - $seq->at(2) |
|
| 71 | - ->asBitString() |
|
| 72 | - ->string(), $algo); |
|
| 73 | - return new self($info, $algo, $signature); |
|
| 74 | - } |
|
| 55 | + /** |
|
| 56 | + * Initialize from ASN.1. |
|
| 57 | + * |
|
| 58 | + * @param Sequence $seq |
|
| 59 | + * @return self |
|
| 60 | + */ |
|
| 61 | + public static function fromASN1(Sequence $seq) |
|
| 62 | + { |
|
| 63 | + $info = CertificationRequestInfo::fromASN1($seq->at(0)->asSequence()); |
|
| 64 | + $algo = AlgorithmIdentifier::fromASN1($seq->at(1)->asSequence()); |
|
| 65 | + if (!$algo instanceof SignatureAlgorithmIdentifier) { |
|
| 66 | + throw new \UnexpectedValueException( |
|
| 67 | + "Unsupported signature algorithm " . $algo->oid() . "."); |
|
| 68 | + } |
|
| 69 | + $signature = Signature::fromSignatureData( |
|
| 70 | + $seq->at(2) |
|
| 71 | + ->asBitString() |
|
| 72 | + ->string(), $algo); |
|
| 73 | + return new self($info, $algo, $signature); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Initialize from DER. |
|
| 78 | - * |
|
| 79 | - * @param string $data |
|
| 80 | - * @return self |
|
| 81 | - */ |
|
| 82 | - public static function fromDER($data) |
|
| 83 | - { |
|
| 84 | - return self::fromASN1(Sequence::fromDER($data)); |
|
| 85 | - } |
|
| 76 | + /** |
|
| 77 | + * Initialize from DER. |
|
| 78 | + * |
|
| 79 | + * @param string $data |
|
| 80 | + * @return self |
|
| 81 | + */ |
|
| 82 | + public static function fromDER($data) |
|
| 83 | + { |
|
| 84 | + return self::fromASN1(Sequence::fromDER($data)); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Initialize from PEM. |
|
| 89 | - * |
|
| 90 | - * @param PEM $pem |
|
| 91 | - * @throws \UnexpectedValueException |
|
| 92 | - * @return self |
|
| 93 | - */ |
|
| 94 | - public static function fromPEM(PEM $pem) |
|
| 95 | - { |
|
| 96 | - if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
| 97 | - throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 98 | - } |
|
| 99 | - return self::fromDER($pem->data()); |
|
| 100 | - } |
|
| 87 | + /** |
|
| 88 | + * Initialize from PEM. |
|
| 89 | + * |
|
| 90 | + * @param PEM $pem |
|
| 91 | + * @throws \UnexpectedValueException |
|
| 92 | + * @return self |
|
| 93 | + */ |
|
| 94 | + public static function fromPEM(PEM $pem) |
|
| 95 | + { |
|
| 96 | + if ($pem->type() !== PEM::TYPE_CERTIFICATE_REQUEST) { |
|
| 97 | + throw new \UnexpectedValueException("Invalid PEM type."); |
|
| 98 | + } |
|
| 99 | + return self::fromDER($pem->data()); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * Get certification request info. |
|
| 104 | - * |
|
| 105 | - * @return CertificationRequestInfo |
|
| 106 | - */ |
|
| 107 | - public function certificationRequestInfo() |
|
| 108 | - { |
|
| 109 | - return $this->_certificationRequestInfo; |
|
| 110 | - } |
|
| 102 | + /** |
|
| 103 | + * Get certification request info. |
|
| 104 | + * |
|
| 105 | + * @return CertificationRequestInfo |
|
| 106 | + */ |
|
| 107 | + public function certificationRequestInfo() |
|
| 108 | + { |
|
| 109 | + return $this->_certificationRequestInfo; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Get signature algorithm. |
|
| 114 | - * |
|
| 115 | - * @return SignatureAlgorithmIdentifier |
|
| 116 | - */ |
|
| 117 | - public function signatureAlgorithm() |
|
| 118 | - { |
|
| 119 | - return $this->_signatureAlgorithm; |
|
| 120 | - } |
|
| 112 | + /** |
|
| 113 | + * Get signature algorithm. |
|
| 114 | + * |
|
| 115 | + * @return SignatureAlgorithmIdentifier |
|
| 116 | + */ |
|
| 117 | + public function signatureAlgorithm() |
|
| 118 | + { |
|
| 119 | + return $this->_signatureAlgorithm; |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * Get signature. |
|
| 124 | - * |
|
| 125 | - * @return Signature |
|
| 126 | - */ |
|
| 127 | - public function signature() |
|
| 128 | - { |
|
| 129 | - return $this->_signature; |
|
| 130 | - } |
|
| 122 | + /** |
|
| 123 | + * Get signature. |
|
| 124 | + * |
|
| 125 | + * @return Signature |
|
| 126 | + */ |
|
| 127 | + public function signature() |
|
| 128 | + { |
|
| 129 | + return $this->_signature; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 133 | - * Generate ASN.1 structure. |
|
| 134 | - * |
|
| 135 | - * @return Sequence |
|
| 136 | - */ |
|
| 137 | - public function toASN1() |
|
| 138 | - { |
|
| 139 | - return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
| 140 | - $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
| 141 | - } |
|
| 132 | + /** |
|
| 133 | + * Generate ASN.1 structure. |
|
| 134 | + * |
|
| 135 | + * @return Sequence |
|
| 136 | + */ |
|
| 137 | + public function toASN1() |
|
| 138 | + { |
|
| 139 | + return new Sequence($this->_certificationRequestInfo->toASN1(), |
|
| 140 | + $this->_signatureAlgorithm->toASN1(), $this->_signature->bitString()); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Get certification request as a DER. |
|
| 145 | - * |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - public function toDER() |
|
| 149 | - { |
|
| 150 | - return $this->toASN1()->toDER(); |
|
| 151 | - } |
|
| 143 | + /** |
|
| 144 | + * Get certification request as a DER. |
|
| 145 | + * |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + public function toDER() |
|
| 149 | + { |
|
| 150 | + return $this->toASN1()->toDER(); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Get certification request as a PEM. |
|
| 155 | - * |
|
| 156 | - * @return PEM |
|
| 157 | - */ |
|
| 158 | - public function toPEM() |
|
| 159 | - { |
|
| 160 | - return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
| 161 | - } |
|
| 153 | + /** |
|
| 154 | + * Get certification request as a PEM. |
|
| 155 | + * |
|
| 156 | + * @return PEM |
|
| 157 | + */ |
|
| 158 | + public function toPEM() |
|
| 159 | + { |
|
| 160 | + return new PEM(PEM::TYPE_CERTIFICATE_REQUEST, $this->toDER()); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * Verify certification request signature. |
|
| 165 | - * |
|
| 166 | - * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 167 | - * @return bool True if signature matches |
|
| 168 | - */ |
|
| 169 | - public function verify(Crypto $crypto = null) |
|
| 170 | - { |
|
| 171 | - $crypto = $crypto ?: Crypto::getDefault(); |
|
| 172 | - $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
| 173 | - $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
| 174 | - return $crypto->verify($data, $this->_signature, $pk_info, |
|
| 175 | - $this->_signatureAlgorithm); |
|
| 176 | - } |
|
| 163 | + /** |
|
| 164 | + * Verify certification request signature. |
|
| 165 | + * |
|
| 166 | + * @param Crypto|null $crypto Crypto engine, use default if not set |
|
| 167 | + * @return bool True if signature matches |
|
| 168 | + */ |
|
| 169 | + public function verify(Crypto $crypto = null) |
|
| 170 | + { |
|
| 171 | + $crypto = $crypto ?: Crypto::getDefault(); |
|
| 172 | + $data = $this->_certificationRequestInfo->toASN1()->toDER(); |
|
| 173 | + $pk_info = $this->_certificationRequestInfo->subjectPKInfo(); |
|
| 174 | + return $crypto->verify($data, $this->_signature, $pk_info, |
|
| 175 | + $this->_signatureAlgorithm); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Get certification request as a PEM formatted string. |
|
| 180 | - * |
|
| 181 | - * @return string |
|
| 182 | - */ |
|
| 183 | - public function __toString() |
|
| 184 | - { |
|
| 185 | - return $this->toPEM()->string(); |
|
| 186 | - } |
|
| 178 | + /** |
|
| 179 | + * Get certification request as a PEM formatted string. |
|
| 180 | + * |
|
| 181 | + * @return string |
|
| 182 | + */ |
|
| 183 | + public function __toString() |
|
| 184 | + { |
|
| 185 | + return $this->toPEM()->string(); |
|
| 186 | + } |
|
| 187 | 187 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\CertificationRequest; |
| 6 | 6 | |
@@ -12,136 +12,136 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | trait AttributeContainer |
| 14 | 14 | { |
| 15 | - /** |
|
| 16 | - * Array of attributes. |
|
| 17 | - * |
|
| 18 | - * @var Attribute[] $_attributes |
|
| 19 | - */ |
|
| 20 | - protected $_attributes; |
|
| 15 | + /** |
|
| 16 | + * Array of attributes. |
|
| 17 | + * |
|
| 18 | + * @var Attribute[] $_attributes |
|
| 19 | + */ |
|
| 20 | + protected $_attributes; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Find first attribute of given name or OID. |
|
| 24 | - * |
|
| 25 | - * @param string $name |
|
| 26 | - * @return Attribute|null |
|
| 27 | - */ |
|
| 28 | - protected function _findFirst($name) |
|
| 29 | - { |
|
| 30 | - $oid = AttributeType::attrNameToOID($name); |
|
| 31 | - foreach ($this->_attributes as $attr) { |
|
| 32 | - if ($attr->oid() == $oid) { |
|
| 33 | - return $attr; |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - return null; |
|
| 37 | - } |
|
| 22 | + /** |
|
| 23 | + * Find first attribute of given name or OID. |
|
| 24 | + * |
|
| 25 | + * @param string $name |
|
| 26 | + * @return Attribute|null |
|
| 27 | + */ |
|
| 28 | + protected function _findFirst($name) |
|
| 29 | + { |
|
| 30 | + $oid = AttributeType::attrNameToOID($name); |
|
| 31 | + foreach ($this->_attributes as $attr) { |
|
| 32 | + if ($attr->oid() == $oid) { |
|
| 33 | + return $attr; |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + return null; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Check whether attribute is present. |
|
| 41 | - * |
|
| 42 | - * @param string $name OID or attribute name |
|
| 43 | - * @return boolean |
|
| 44 | - */ |
|
| 45 | - public function has($name) |
|
| 46 | - { |
|
| 47 | - return null !== $this->_findFirst($name); |
|
| 48 | - } |
|
| 39 | + /** |
|
| 40 | + * Check whether attribute is present. |
|
| 41 | + * |
|
| 42 | + * @param string $name OID or attribute name |
|
| 43 | + * @return boolean |
|
| 44 | + */ |
|
| 45 | + public function has($name) |
|
| 46 | + { |
|
| 47 | + return null !== $this->_findFirst($name); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Get first attribute by OID or attribute name. |
|
| 52 | - * |
|
| 53 | - * @param string $name OID or attribute name |
|
| 54 | - * @throws \OutOfBoundsException |
|
| 55 | - * @return Attribute |
|
| 56 | - */ |
|
| 57 | - public function firstOf($name) |
|
| 58 | - { |
|
| 59 | - $attr = $this->_findFirst($name); |
|
| 60 | - if (!$attr) { |
|
| 61 | - throw new \UnexpectedValueException("No $name attribute."); |
|
| 62 | - } |
|
| 63 | - return $attr; |
|
| 64 | - } |
|
| 50 | + /** |
|
| 51 | + * Get first attribute by OID or attribute name. |
|
| 52 | + * |
|
| 53 | + * @param string $name OID or attribute name |
|
| 54 | + * @throws \OutOfBoundsException |
|
| 55 | + * @return Attribute |
|
| 56 | + */ |
|
| 57 | + public function firstOf($name) |
|
| 58 | + { |
|
| 59 | + $attr = $this->_findFirst($name); |
|
| 60 | + if (!$attr) { |
|
| 61 | + throw new \UnexpectedValueException("No $name attribute."); |
|
| 62 | + } |
|
| 63 | + return $attr; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Get all attributes of given name. |
|
| 68 | - * |
|
| 69 | - * @param string $name OID or attribute name |
|
| 70 | - * @return Attribute[] |
|
| 71 | - */ |
|
| 72 | - public function allOf($name) |
|
| 73 | - { |
|
| 74 | - $oid = AttributeType::attrNameToOID($name); |
|
| 75 | - $attrs = array_filter($this->_attributes, |
|
| 76 | - function (Attribute $attr) use ($oid) { |
|
| 77 | - return $attr->oid() == $oid; |
|
| 78 | - }); |
|
| 79 | - return array_values($attrs); |
|
| 80 | - } |
|
| 66 | + /** |
|
| 67 | + * Get all attributes of given name. |
|
| 68 | + * |
|
| 69 | + * @param string $name OID or attribute name |
|
| 70 | + * @return Attribute[] |
|
| 71 | + */ |
|
| 72 | + public function allOf($name) |
|
| 73 | + { |
|
| 74 | + $oid = AttributeType::attrNameToOID($name); |
|
| 75 | + $attrs = array_filter($this->_attributes, |
|
| 76 | + function (Attribute $attr) use ($oid) { |
|
| 77 | + return $attr->oid() == $oid; |
|
| 78 | + }); |
|
| 79 | + return array_values($attrs); |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * Get all attributes. |
|
| 84 | - * |
|
| 85 | - * @return Attribute[] |
|
| 86 | - */ |
|
| 87 | - public function all() |
|
| 88 | - { |
|
| 89 | - return $this->_attributes; |
|
| 90 | - } |
|
| 82 | + /** |
|
| 83 | + * Get all attributes. |
|
| 84 | + * |
|
| 85 | + * @return Attribute[] |
|
| 86 | + */ |
|
| 87 | + public function all() |
|
| 88 | + { |
|
| 89 | + return $this->_attributes; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Get self with additional attributes added. |
|
| 94 | - * |
|
| 95 | - * @param Attribute ...$attribs |
|
| 96 | - * @return self |
|
| 97 | - */ |
|
| 98 | - public function withAdditional(Attribute ...$attribs) |
|
| 99 | - { |
|
| 100 | - $obj = clone $this; |
|
| 101 | - foreach ($attribs as $attr) { |
|
| 102 | - $obj->_attributes[] = $attr; |
|
| 103 | - } |
|
| 104 | - return $obj; |
|
| 105 | - } |
|
| 92 | + /** |
|
| 93 | + * Get self with additional attributes added. |
|
| 94 | + * |
|
| 95 | + * @param Attribute ...$attribs |
|
| 96 | + * @return self |
|
| 97 | + */ |
|
| 98 | + public function withAdditional(Attribute ...$attribs) |
|
| 99 | + { |
|
| 100 | + $obj = clone $this; |
|
| 101 | + foreach ($attribs as $attr) { |
|
| 102 | + $obj->_attributes[] = $attr; |
|
| 103 | + } |
|
| 104 | + return $obj; |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Get self with single unique attribute added. |
|
| 109 | - * |
|
| 110 | - * All previous attributes of the same type are removed. |
|
| 111 | - * |
|
| 112 | - * @param Attribute $attr |
|
| 113 | - * @return self |
|
| 114 | - */ |
|
| 115 | - public function withUnique(Attribute $attr) |
|
| 116 | - { |
|
| 117 | - $obj = clone $this; |
|
| 118 | - $obj->_attributes = array_filter($obj->_attributes, |
|
| 119 | - function (Attribute $a) use ($attr) { |
|
| 120 | - return $a->oid() != $attr->oid(); |
|
| 121 | - }); |
|
| 122 | - $obj->_attributes[] = $attr; |
|
| 123 | - return $obj; |
|
| 124 | - } |
|
| 107 | + /** |
|
| 108 | + * Get self with single unique attribute added. |
|
| 109 | + * |
|
| 110 | + * All previous attributes of the same type are removed. |
|
| 111 | + * |
|
| 112 | + * @param Attribute $attr |
|
| 113 | + * @return self |
|
| 114 | + */ |
|
| 115 | + public function withUnique(Attribute $attr) |
|
| 116 | + { |
|
| 117 | + $obj = clone $this; |
|
| 118 | + $obj->_attributes = array_filter($obj->_attributes, |
|
| 119 | + function (Attribute $a) use ($attr) { |
|
| 120 | + return $a->oid() != $attr->oid(); |
|
| 121 | + }); |
|
| 122 | + $obj->_attributes[] = $attr; |
|
| 123 | + return $obj; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * Get number of attributes. |
|
| 128 | - * |
|
| 129 | - * @see \Countable::count() |
|
| 130 | - * @return int |
|
| 131 | - */ |
|
| 132 | - public function count() |
|
| 133 | - { |
|
| 134 | - return count($this->_attributes); |
|
| 135 | - } |
|
| 126 | + /** |
|
| 127 | + * Get number of attributes. |
|
| 128 | + * |
|
| 129 | + * @see \Countable::count() |
|
| 130 | + * @return int |
|
| 131 | + */ |
|
| 132 | + public function count() |
|
| 133 | + { |
|
| 134 | + return count($this->_attributes); |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * Get iterator for attributes. |
|
| 139 | - * |
|
| 140 | - * @see \IteratorAggregate::getIterator() |
|
| 141 | - * @return \ArrayIterator |
|
| 142 | - */ |
|
| 143 | - public function getIterator() |
|
| 144 | - { |
|
| 145 | - return new \ArrayIterator($this->_attributes); |
|
| 146 | - } |
|
| 137 | + /** |
|
| 138 | + * Get iterator for attributes. |
|
| 139 | + * |
|
| 140 | + * @see \IteratorAggregate::getIterator() |
|
| 141 | + * @return \ArrayIterator |
|
| 142 | + */ |
|
| 143 | + public function getIterator() |
|
| 144 | + { |
|
| 145 | + return new \ArrayIterator($this->_attributes); |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\Feature; |
| 6 | 6 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | { |
| 76 | 76 | $oid = AttributeType::attrNameToOID($name); |
| 77 | 77 | $attrs = array_filter($this->_attributes, |
| 78 | - function (Attribute $attr) use ($oid) { |
|
| 78 | + function(Attribute $attr) use ($oid) { |
|
| 79 | 79 | return $attr->oid() == $oid; |
| 80 | 80 | }); |
| 81 | 81 | return array_values($attrs); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | { |
| 119 | 119 | $obj = clone $this; |
| 120 | 120 | $obj->_attributes = array_filter($obj->_attributes, |
| 121 | - function (Attribute $a) use ($attr) { |
|
| 121 | + function(Attribute $a) use ($attr) { |
|
| 122 | 122 | return $a->oid() != $attr->oid(); |
| 123 | 123 | }); |
| 124 | 124 | $obj->_attributes[] = $attr; |
@@ -72,9 +72,9 @@ |
||
| 72 | 72 | } |
| 73 | 73 | $tagged = $el->asTagged(); |
| 74 | 74 | switch ($tagged->tag()) { |
| 75 | - case 0: |
|
| 76 | - return V2Form::fromV2ASN1( |
|
| 77 | - $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
| 75 | + case 0: |
|
| 76 | + return V2Form::fromV2ASN1( |
|
| 77 | + $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
| 78 | 78 | } |
| 79 | 79 | throw new \UnexpectedValueException("Unsupported issuer type."); |
| 80 | 80 | } |
@@ -18,66 +18,66 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class AttCertIssuer |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Generate ASN.1 element. |
|
| 23 | - * |
|
| 24 | - * @return Element |
|
| 25 | - */ |
|
| 26 | - abstract public function toASN1(); |
|
| 21 | + /** |
|
| 22 | + * Generate ASN.1 element. |
|
| 23 | + * |
|
| 24 | + * @return Element |
|
| 25 | + */ |
|
| 26 | + abstract public function toASN1(); |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Check whether AttCertIssuer identifies given certificate. |
|
| 30 | - * |
|
| 31 | - * @param Certificate $cert |
|
| 32 | - * @return bool |
|
| 33 | - */ |
|
| 34 | - abstract public function identifiesPKC(Certificate $cert): bool; |
|
| 28 | + /** |
|
| 29 | + * Check whether AttCertIssuer identifies given certificate. |
|
| 30 | + * |
|
| 31 | + * @param Certificate $cert |
|
| 32 | + * @return bool |
|
| 33 | + */ |
|
| 34 | + abstract public function identifiesPKC(Certificate $cert): bool; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Initialize from distinguished name. |
|
| 38 | - * |
|
| 39 | - * This conforms to RFC 5755 which states that only v2Form must be used, |
|
| 40 | - * and issuerName must contain exactly one GeneralName of DirectoryName |
|
| 41 | - * type. |
|
| 42 | - * |
|
| 43 | - * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
| 44 | - * @param Name $name |
|
| 45 | - * @return self |
|
| 46 | - */ |
|
| 47 | - public static function fromName(Name $name) |
|
| 48 | - { |
|
| 49 | - return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
| 50 | - } |
|
| 36 | + /** |
|
| 37 | + * Initialize from distinguished name. |
|
| 38 | + * |
|
| 39 | + * This conforms to RFC 5755 which states that only v2Form must be used, |
|
| 40 | + * and issuerName must contain exactly one GeneralName of DirectoryName |
|
| 41 | + * type. |
|
| 42 | + * |
|
| 43 | + * @link https://tools.ietf.org/html/rfc5755#section-4.2.3 |
|
| 44 | + * @param Name $name |
|
| 45 | + * @return self |
|
| 46 | + */ |
|
| 47 | + public static function fromName(Name $name) |
|
| 48 | + { |
|
| 49 | + return new V2Form(new GeneralNames(new DirectoryName($name))); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Initialize from an issuer's public key certificate. |
|
| 54 | - * |
|
| 55 | - * @param Certificate $cert |
|
| 56 | - * @return self |
|
| 57 | - */ |
|
| 58 | - public static function fromPKC(Certificate $cert) |
|
| 59 | - { |
|
| 60 | - return self::fromName($cert->tbsCertificate()->subject()); |
|
| 61 | - } |
|
| 52 | + /** |
|
| 53 | + * Initialize from an issuer's public key certificate. |
|
| 54 | + * |
|
| 55 | + * @param Certificate $cert |
|
| 56 | + * @return self |
|
| 57 | + */ |
|
| 58 | + public static function fromPKC(Certificate $cert) |
|
| 59 | + { |
|
| 60 | + return self::fromName($cert->tbsCertificate()->subject()); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Initialize from ASN.1. |
|
| 65 | - * |
|
| 66 | - * @param UnspecifiedType $el CHOICE |
|
| 67 | - * @throws \UnexpectedValueException |
|
| 68 | - * @return self |
|
| 69 | - */ |
|
| 70 | - public static function fromASN1(UnspecifiedType $el) |
|
| 71 | - { |
|
| 72 | - if (!$el->isTagged()) { |
|
| 73 | - throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
| 74 | - } |
|
| 75 | - $tagged = $el->asTagged(); |
|
| 76 | - switch ($tagged->tag()) { |
|
| 77 | - case 0: |
|
| 78 | - return V2Form::fromV2ASN1( |
|
| 79 | - $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
| 80 | - } |
|
| 81 | - throw new \UnexpectedValueException("Unsupported issuer type."); |
|
| 82 | - } |
|
| 63 | + /** |
|
| 64 | + * Initialize from ASN.1. |
|
| 65 | + * |
|
| 66 | + * @param UnspecifiedType $el CHOICE |
|
| 67 | + * @throws \UnexpectedValueException |
|
| 68 | + * @return self |
|
| 69 | + */ |
|
| 70 | + public static function fromASN1(UnspecifiedType $el) |
|
| 71 | + { |
|
| 72 | + if (!$el->isTagged()) { |
|
| 73 | + throw new \UnexpectedValueException("v1Form issuer not supported."); |
|
| 74 | + } |
|
| 75 | + $tagged = $el->asTagged(); |
|
| 76 | + switch ($tagged->tag()) { |
|
| 77 | + case 0: |
|
| 78 | + return V2Form::fromV2ASN1( |
|
| 79 | + $tagged->asImplicit(Element::TYPE_SEQUENCE)->asSequence()); |
|
| 80 | + } |
|
| 81 | + throw new \UnexpectedValueException("Unsupported issuer type."); |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate; |
| 6 | 6 | |
@@ -10,112 +10,112 @@ |
||
| 10 | 10 | */ |
| 11 | 11 | class ACValidationConfig |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Certification path of the AC holder. |
|
| 15 | - * |
|
| 16 | - * @var CertificationPath |
|
| 17 | - */ |
|
| 18 | - protected $_holderPath; |
|
| 13 | + /** |
|
| 14 | + * Certification path of the AC holder. |
|
| 15 | + * |
|
| 16 | + * @var CertificationPath |
|
| 17 | + */ |
|
| 18 | + protected $_holderPath; |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Certification path of the AC issuer. |
|
| 22 | - * |
|
| 23 | - * @var CertificationPath |
|
| 24 | - */ |
|
| 25 | - protected $_issuerPath; |
|
| 20 | + /** |
|
| 21 | + * Certification path of the AC issuer. |
|
| 22 | + * |
|
| 23 | + * @var CertificationPath |
|
| 24 | + */ |
|
| 25 | + protected $_issuerPath; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Evaluation reference time. |
|
| 29 | - * |
|
| 30 | - * @var \DateTimeImmutable |
|
| 31 | - */ |
|
| 32 | - protected $_evalTime; |
|
| 27 | + /** |
|
| 28 | + * Evaluation reference time. |
|
| 29 | + * |
|
| 30 | + * @var \DateTimeImmutable |
|
| 31 | + */ |
|
| 32 | + protected $_evalTime; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Permitted targets. |
|
| 36 | - * |
|
| 37 | - * @var Target[] |
|
| 38 | - */ |
|
| 39 | - protected $_targets; |
|
| 34 | + /** |
|
| 35 | + * Permitted targets. |
|
| 36 | + * |
|
| 37 | + * @var Target[] |
|
| 38 | + */ |
|
| 39 | + protected $_targets; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor. |
|
| 43 | - * |
|
| 44 | - * @param CertificationPath $holder_path Certification path of the AC holder |
|
| 45 | - * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
| 46 | - */ |
|
| 47 | - public function __construct(CertificationPath $holder_path, |
|
| 48 | - CertificationPath $issuer_path) |
|
| 49 | - { |
|
| 50 | - $this->_holderPath = $holder_path; |
|
| 51 | - $this->_issuerPath = $issuer_path; |
|
| 52 | - $this->_evalTime = new \DateTimeImmutable(); |
|
| 53 | - $this->_targets = array(); |
|
| 54 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor. |
|
| 43 | + * |
|
| 44 | + * @param CertificationPath $holder_path Certification path of the AC holder |
|
| 45 | + * @param CertificationPath $issuer_path Certification path of the AC issuer |
|
| 46 | + */ |
|
| 47 | + public function __construct(CertificationPath $holder_path, |
|
| 48 | + CertificationPath $issuer_path) |
|
| 49 | + { |
|
| 50 | + $this->_holderPath = $holder_path; |
|
| 51 | + $this->_issuerPath = $issuer_path; |
|
| 52 | + $this->_evalTime = new \DateTimeImmutable(); |
|
| 53 | + $this->_targets = array(); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get certification path of the AC's holder. |
|
| 58 | - * |
|
| 59 | - * @return CertificationPath |
|
| 60 | - */ |
|
| 61 | - public function holderPath() |
|
| 62 | - { |
|
| 63 | - return $this->_holderPath; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get certification path of the AC's holder. |
|
| 58 | + * |
|
| 59 | + * @return CertificationPath |
|
| 60 | + */ |
|
| 61 | + public function holderPath() |
|
| 62 | + { |
|
| 63 | + return $this->_holderPath; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Get certification path of the AC's issuer. |
|
| 68 | - * |
|
| 69 | - * @return CertificationPath |
|
| 70 | - */ |
|
| 71 | - public function issuerPath() |
|
| 72 | - { |
|
| 73 | - return $this->_issuerPath; |
|
| 74 | - } |
|
| 66 | + /** |
|
| 67 | + * Get certification path of the AC's issuer. |
|
| 68 | + * |
|
| 69 | + * @return CertificationPath |
|
| 70 | + */ |
|
| 71 | + public function issuerPath() |
|
| 72 | + { |
|
| 73 | + return $this->_issuerPath; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Get self with given evaluation reference time. |
|
| 78 | - * |
|
| 79 | - * @param \DateTimeImmutable $dt |
|
| 80 | - * @return self |
|
| 81 | - */ |
|
| 82 | - public function withEvaluationTime(\DateTimeImmutable $dt) |
|
| 83 | - { |
|
| 84 | - $obj = clone $this; |
|
| 85 | - $obj->_evalTime = $dt; |
|
| 86 | - return $obj; |
|
| 87 | - } |
|
| 76 | + /** |
|
| 77 | + * Get self with given evaluation reference time. |
|
| 78 | + * |
|
| 79 | + * @param \DateTimeImmutable $dt |
|
| 80 | + * @return self |
|
| 81 | + */ |
|
| 82 | + public function withEvaluationTime(\DateTimeImmutable $dt) |
|
| 83 | + { |
|
| 84 | + $obj = clone $this; |
|
| 85 | + $obj->_evalTime = $dt; |
|
| 86 | + return $obj; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Get the evaluation reference time. |
|
| 91 | - * |
|
| 92 | - * @return \DateTimeImmutable |
|
| 93 | - */ |
|
| 94 | - public function evaluationTime() |
|
| 95 | - { |
|
| 96 | - return $this->_evalTime; |
|
| 97 | - } |
|
| 89 | + /** |
|
| 90 | + * Get the evaluation reference time. |
|
| 91 | + * |
|
| 92 | + * @return \DateTimeImmutable |
|
| 93 | + */ |
|
| 94 | + public function evaluationTime() |
|
| 95 | + { |
|
| 96 | + return $this->_evalTime; |
|
| 97 | + } |
|
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Get self with permitted targets. |
|
| 101 | - * |
|
| 102 | - * @param Target ...$targets |
|
| 103 | - * @return self |
|
| 104 | - */ |
|
| 105 | - public function withTargets(Target ...$targets) |
|
| 106 | - { |
|
| 107 | - $obj = clone $this; |
|
| 108 | - $obj->_targets = $targets; |
|
| 109 | - return $obj; |
|
| 110 | - } |
|
| 99 | + /** |
|
| 100 | + * Get self with permitted targets. |
|
| 101 | + * |
|
| 102 | + * @param Target ...$targets |
|
| 103 | + * @return self |
|
| 104 | + */ |
|
| 105 | + public function withTargets(Target ...$targets) |
|
| 106 | + { |
|
| 107 | + $obj = clone $this; |
|
| 108 | + $obj->_targets = $targets; |
|
| 109 | + return $obj; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * Get array of permitted targets |
|
| 114 | - * |
|
| 115 | - * @return Target[] |
|
| 116 | - */ |
|
| 117 | - public function targets() |
|
| 118 | - { |
|
| 119 | - return $this->_targets; |
|
| 120 | - } |
|
| 112 | + /** |
|
| 113 | + * Get array of permitted targets |
|
| 114 | + * |
|
| 115 | + * @return Target[] |
|
| 116 | + */ |
|
| 117 | + public function targets() |
|
| 118 | + { |
|
| 119 | + return $this->_targets; |
|
| 120 | + } |
|
| 121 | 121 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate\Validation; |
| 6 | 6 | |
@@ -11,17 +11,17 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class AccessIdentityAttributeValue extends SvceAuthInfo |
| 13 | 13 | { |
| 14 | - const OID = "1.3.6.1.5.5.7.10.2"; |
|
| 14 | + const OID = "1.3.6.1.5.5.7.10.2"; |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Constructor. |
|
| 18 | - * |
|
| 19 | - * @param GeneralName $service |
|
| 20 | - * @param GeneralName $ident |
|
| 21 | - */ |
|
| 22 | - public function __construct(GeneralName $service, GeneralName $ident) |
|
| 23 | - { |
|
| 24 | - parent::__construct($service, $ident, null); |
|
| 25 | - $this->_oid = self::OID; |
|
| 26 | - } |
|
| 16 | + /** |
|
| 17 | + * Constructor. |
|
| 18 | + * |
|
| 19 | + * @param GeneralName $service |
|
| 20 | + * @param GeneralName $ident |
|
| 21 | + */ |
|
| 22 | + public function __construct(GeneralName $service, GeneralName $ident) |
|
| 23 | + { |
|
| 24 | + parent::__construct($service, $ident, null); |
|
| 25 | + $this->_oid = self::OID; |
|
| 26 | + } |
|
| 27 | 27 | } |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -declare(strict_types=1); |
|
| 3 | +declare(strict_types = 1); |
|
| 4 | 4 | |
| 5 | 5 | namespace X509\AttributeCertificate\Attribute; |
| 6 | 6 | |