SignatureValue   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 74
rs 10
c 2
b 0
f 0
wmc 6

5 Methods

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