Debian Codegraph @

lib/3rdParty/composer/spomky-labs/pki-framework/src/X501/ASN1/Collection/SetOfAttributes.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 namespace SpomkyLabs\Pki\X501\ASN1\Collection;
6
7 use SpomkyLabs\Pki\ASN1\Type\Constructed\Set;
8 use SpomkyLabs\Pki\X501\ASN1\Attribute;
9 use SpomkyLabs\Pki\X501\ASN1\AttributeValue\AttributeValue;
10
11 /**
12 * Implements *Attributes* ASN.1 type as a *SET OF Attribute*.
13 *
14 * Used in *CertificationRequestInfo* and *OneAsymmetricKey*.
15 *
16 * @see https://tools.ietf.org/html/rfc2986#section-4
17 * @see https://tools.ietf.org/html/rfc5958#section-2
18 */
19 class SetOfAttributes extends AttributeCollection
20 {
21 /**
22 * Initialize from ASN.1.
23 */
24 public static function fromASN1(Set $set): static
25 {
26 return static::_fromASN1Structure($set);
27 }
28
29 /**
30 * Initialize from attribute values.
31 *
32 * @param AttributeValue ...$values List of attribute values
33 */
34 public static function fromAttributeValues(AttributeValue ...$values): static
35 {
36 return static::create(...array_map(static fn (AttributeValue $value) => $value->toAttribute(), $values));
37 }
38
39 /**
40 * Generate ASN.1 structure.
41 */
42 public function toASN1(): Set
43 {
44 $set = Set::create(...array_map(static fn (Attribute $attr) => $attr->toASN1(), $this->_attributes));
45 return $set->sortedSetOf();
46 }
47 }