Completed
Push — master ( 42c457...7978bf )
by Joni
03:43
created

SetOfAttributes::fromASN1()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X501\ASN1\Collection;
6
7
use Sop\ASN1\Type\Constructed\Set;
8
use Sop\X501\ASN1\Attribute;
9
10
/**
11
 * Implements *Attributes* ASN.1 type as a *SET OF Attribute*.
12
 *
13
 * Used in *CertificationRequestInfo* and *OneAsymmetricKey*.
14
 *
15
 * @see https://tools.ietf.org/html/rfc2986#section-4
16
 * @see https://tools.ietf.org/html/rfc5958#section-2
17
 */
18
class SetOfAttributes extends AttributeCollection
19
{
20
    /**
21
     * Initialize from ASN.1.
22
     *
23
     * @param Set $set
24
     *
25
     * @return self
26
     */
27 1
    public static function fromASN1(Set $set): self
28
    {
29 1
        return static::_fromASN1Structure($set);
30
    }
31
32
    /**
33
     * Generate ASN.1 structure.
34
     *
35
     * @return Set
36
     */
37 2
    public function toASN1(): Set
38
    {
39 2
        $set = new Set(...array_map(
40
            function (Attribute $attr) {
41 2
                return $attr->toASN1();
42 2
            }, $this->_attributes));
43 2
        return $set->sortedSetOf();
44
    }
45
}
46