X509Digest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A toXML() 0 7 1
A getDigest() 0 3 1
A fromXML() 0 8 1
A __construct() 0 9 1
A getAlgorithm() 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\Assert\Assert;
9
use SimpleSAML\XML\SchemaValidatableElementInterface;
10
use SimpleSAML\XML\SchemaValidatableElementTrait;
11
use SimpleSAML\XMLSchema\Exception\InvalidDOMElementException;
12
use SimpleSAML\XMLSchema\Type\AnyURIValue;
13
use SimpleSAML\XMLSchema\Type\Base64BinaryValue;
14
use SimpleSAML\XMLSecurity\Constants as C;
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\Constants was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException;
16
17
use function strval;
18
19
/**
20
 * Class representing a dsig11:X509Digest element.
21
 *
22
 * @package simplesaml/xml-security
23
 */
24
final class X509Digest extends AbstractDsig11Element implements SchemaValidatableElementInterface
0 ignored issues
show
Bug introduced by
The type SimpleSAML\XMLSecurity\X...1\AbstractDsig11Element was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
{
26
    use SchemaValidatableElementTrait;
27
28
29
    /**
30
     * Initialize a X509Digest element.
31
     *
32
     * @param \SimpleSAML\XMLSchema\Type\Base64BinaryValue $digest
33
     * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $algorithm
34
     */
35
    public function __construct(
36
        protected Base64BinaryValue $digest,
37
        protected AnyURIValue $algorithm,
38
    ) {
39
        Assert::oneOf(
40
            strval($algorithm),
41
            array_keys(C::$DIGEST_ALGORITHMS),
42
            'Invalid digest method: %s',
43
            InvalidArgumentException::class,
44
        );
45
    }
46
47
48
    /**
49
     * Collect the value of the digest-property
50
     *
51
     * @return \SimpleSAML\XMLSchema\Type\Base64BinaryValue
52
     */
53
    public function getDigest(): Base64BinaryValue
54
    {
55
        return $this->digest;
56
    }
57
58
59
    /**
60
     * Collect the value of the algorithm-property
61
     *
62
     * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
63
     */
64
    public function getAlgorithm(): AnyURIValue
65
    {
66
        return $this->algorithm;
67
    }
68
69
70
    /**
71
     * Convert XML into a X509Digest
72
     *
73
     * @param \DOMElement $xml The XML element we should load
74
     *
75
     * @throws \SimpleSAML\XMLSchema\Exception\InvalidDOMElementException
76
     *   If the qualified name of the supplied element is wrong
77
     */
78
    public static function fromXML(DOMElement $xml): static
79
    {
80
        Assert::same($xml->localName, 'X509Digest', InvalidDOMElementException::class);
81
        Assert::same($xml->namespaceURI, X509Digest::NS, InvalidDOMElementException::class);
82
83
        return new static(
84
            Base64BinaryValue::fromString($xml->textContent),
85
            self::getAttribute($xml, 'Algorithm', AnyURIValue::class),
86
        );
87
    }
88
89
90
    /**
91
     * Convert this X509Digest element to XML.
92
     *
93
     * @param \DOMElement|null $parent The element we should append this X509Digest element to.
94
     */
95
    public function toXML(?DOMElement $parent = null): DOMElement
96
    {
97
        $e = $this->instantiateParentElement($parent);
98
        $e->textContent = strval($this->getDigest());
99
        $e->setAttribute('Algorithm', strval($this->getAlgorithm()));
100
101
        return $e;
102
    }
103
}
104