Passed
Pull Request — master (#18)
by Tim
02:11
created

SignatureValue   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 34
rs 10
c 2
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validateContent() 0 4 1
A fromXML() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\XMLSecurity\XML\ds;
6
7
use DOMElement;
8
use SimpleSAML\Assert\Assert;
9
use SimpleSAML\XML\Exception\InvalidDOMElementException;
10
use SimpleSAML\XML\XMLStringElementTrait;
11
12
/**
13
 * Class representing a ds:SignatureValue element.
14
 *
15
 * @package simplesaml/xml-security
16
 */
17
final class SignatureValue extends AbstractDsElement
18
{
19
    use XMLStringElementTrait;
20
21
22
    /**
23
     * Validate the content of the element.
24
     *
25
     * @param string $content  The value to go in the XML textContent
26
     * @throws \Exception on failure
27
     * @return void
28
     */
29
    protected function validateContent(string $content): void
30
    {
31
        Assert::notEmpty($content, 'SignatureValue cannot be empty');
32
        Assert::stringPlausibleBase64($content, 'SignatureValue is not a valid Base64 encoded string');
33
    }
34
35
36
    /**
37
     * Convert XML into a SignatureValue
38
     *
39
     * @param \DOMElement $xml The XML element we should load
40
     * @return self
41
     *
42
     * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException If the qualified name of the supplied element is
43
     * wrong.
44
     */
45
    public static function fromXML(DOMElement $xml): object
46
    {
47
        Assert::same($xml->localName, 'SignatureValue', InvalidDOMElementException::class);
48
        Assert::same($xml->namespaceURI, SignatureValue::NS, InvalidDOMElementException::class);
49
50
        return new self($xml->textContent);
51
    }
52
}
53