DEREncodedKeyValue   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 14
c 1
b 0
f 0
dl 0
loc 78
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A fromXML() 0 8 1
A __construct() 0 4 1
A toXML() 0 10 2
A getId() 0 3 1
A getValue() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\dsig11;
6
7
use DOMElement;
8
use SimpleSAML\XML\Assert\Assert;
9
use SimpleSAML\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XML\TypedTextContentTrait;
12
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
13
use SimpleSAML\XMLSchema\Type\Base64BinaryValue;
14
use SimpleSAML\XMLSchema\Type\IDValue;
15
16
use function strval;
17
18
/**
19
 * Class representing a dsig11:DEREncodedKeyValue element.
20
 *
21
 * @package simplesaml/xml-security
22
 */
23
final class DEREncodedKeyValue extends AbstractDsig11Element implements SchemaValidatableElementInterface
24
{
25
    use SchemaValidatableElementTrait;
0 ignored issues
show
introduced by
The trait SimpleSAML\XML\SchemaValidatableElementTrait requires some properties which are not provided by SimpleSAML\XMLSecurity\X...ig11\DEREncodedKeyValue: $message, $line
Loading history...
26
    use TypedTextContentTrait;
27
28
29
    /**
30
     * Initialize a DEREncodedKeyValue element.
31
     *
32
     * @param \SimpleSAML\XMLSchema\Type\Base64BinaryValue $value
33
     * @param \SimpleSAML\XMLSchema\Type\IDValue|null $Id
34
     */
35
    public function __construct(
36
        protected Base64BinaryValue $value,
37
        protected ?IDValue $Id = null,
38
    ) {
39
    }
40
41
42
    /**
43
     * Get the content for this signature value.
44
     *
45
     * @return \SimpleSAML\XMLSchema\Type\Base64BinaryValue
46
     */
47
    public function getValue(): Base64BinaryValue
48
    {
49
        return $this->value;
50
    }
51
52
53
    /**
54
     * Collect the value of the Id-property
55
     *
56
     * @return \SimpleSAML\XMLSchema\Type\IDValue|null
57
     */
58
    public function getId(): ?IDValue
59
    {
60
        return $this->Id;
61
    }
62
63
64
    /**
65
     * Convert XML into a DEREncodedKeyValue
66
     *
67
     * @param \DOMElement $xml The XML element we should load
68
     * @return static
69
     *
70
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
71
     *   If the qualified name of the supplied element is wrong
72
     */
73
    public static function fromXML(DOMElement $xml): static
74
    {
75
        Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class);
76
        Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class);
77
78
        return new static(
79
            Base64BinaryValue::fromString($xml->textContent),
80
            self::getOptionalAttribute($xml, 'Id', IDValue::class, null),
81
        );
82
    }
83
84
85
    /**
86
     * Convert this DEREncodedKeyValue element to XML.
87
     *
88
     * @param \DOMElement|null $parent The element we should append this DEREncodedKeyValue element to.
89
     * @return \DOMElement
90
     */
91
    public function toXML(?DOMElement $parent = null): DOMElement
92
    {
93
        $e = $this->instantiateParentElement($parent);
94
        $e->textContent = strval($this->getValue());
95
96
        if ($this->getId() !== null) {
97
            $e->setAttribute('Id', strval($this->getId()));
98
        }
99
100
        return $e;
101
    }
102
}
103