AbstractMessage   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 9
eloc 17
c 2
b 0
f 0
dl 0
loc 126
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMajorVersion() 0 3 1
A getMinorVersion() 0 3 1
A getOriginalXML() 0 3 1
A setXML() 0 3 1
A toUnsignedXML() 0 9 1
A getIssueInstant() 0 3 1
A isMessageConstructedWithSignature() 0 3 1
A getXML() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace SimpleSAML\SAML11\XML\samlp;
6
7
use DOMElement;
8
use SimpleSAML\SAML11\Type\SAMLDateTimeValue;
9
use SimpleSAML\SAML11\XML\SignableElementTrait;
10
use SimpleSAML\SAML11\XML\SignedElementTrait;
11
use SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue;
12
use SimpleSAML\XMLSecurity\XML\SignableElementInterface;
13
use SimpleSAML\XMLSecurity\XML\SignedElementInterface;
14
15
use function strval;
16
17
/**
18
 * Base class for all SAML 1.1 messages.
19
 *
20
 * Implements what is common between the samlp:RequestAbstractType and
21
 * samlp:ResponseAbstractType element types.
22
 *
23
 * @package simplesamlphp/saml11
24
 */
25
abstract class AbstractMessage extends AbstractSamlpElement implements SignableElementInterface, SignedElementInterface
26
{
27
    use SignableElementTrait;
28
    use SignedElementTrait {
29
        SignedElementTrait::getBlacklistedAlgorithms insteadof SignableElementTrait;
30
    }
31
32
33
    /** @var bool */
34
    protected bool $messageContainedSignatureUponConstruction = false;
35
36
    /**
37
     * The original signed XML
38
     *
39
     * @var \DOMElement
40
     */
41
    protected DOMElement $xml;
42
43
44
    /**
45
     * Initialize a message.
46
     *
47
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $majorVersion
48
     * @param \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue $minorVersion
49
     * @param \SimpleSAML\SAML11\Type\SAMLDateTimeValue $issueInstant
50
     *
51
     * @throws \Exception
52
     */
53
    protected function __construct(
54
        protected NonNegativeIntegerValue $majorVersion,
55
        protected NonNegativeIntegerValue $minorVersion,
56
        protected SAMLDateTimeValue $issueInstant,
57
    ) {
58
    }
59
60
61
    /**
62
     * Retrieve the major version of this message.
63
     *
64
     * @return \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue The major version of this message
65
     */
66
    public function getMajorVersion(): NonNegativeIntegerValue
67
    {
68
        return $this->majorVersion;
69
    }
70
71
72
    /**
73
     * Retrieve the minor version of this message.
74
     *
75
     * @return \SimpleSAML\XMLSchema\Type\NonNegativeIntegerValue The minor version of this message
76
     */
77
    public function getMinorVersion(): NonNegativeIntegerValue
78
    {
79
        return $this->minorVersion;
80
    }
81
82
83
    /**
84
     * Retrieve the issue timestamp of this message.
85
     *
86
     * @return \SimpleSAML\SAML11\Type\SAMLDateTimeValue The issue timestamp of this message
87
     */
88
    public function getIssueInstant(): SAMLDateTimeValue
89
    {
90
        return $this->issueInstant;
91
    }
92
93
94
    /**
95
     * Query whether or not the message contained a signature at the root level when the object was constructed.
96
     *
97
     * @return bool
98
     */
99
    public function isMessageConstructedWithSignature(): bool
100
    {
101
        return $this->messageContainedSignatureUponConstruction;
102
    }
103
104
105
    /**
106
     * Get the XML element.
107
     *
108
     * @return \DOMElement
109
     */
110
    public function getXML(): DOMElement
111
    {
112
        return $this->xml;
113
    }
114
115
116
    /**
117
     * Set the XML element.
118
     *
119
     * @param \DOMElement $xml
120
     */
121
    protected function setXML(DOMElement $xml): void
122
    {
123
        $this->xml = $xml;
124
    }
125
126
127
    /**
128
     * @return \DOMElement
129
     */
130
    protected function getOriginalXML(): DOMElement
131
    {
132
        return $this->xml ?? $this->toUnsignedXML();
133
    }
134
135
136
    /**
137
     * Convert this message to an unsigned XML document.
138
     * This method does not sign the resulting XML document.
139
     *
140
     * @return \DOMElement The root element of the DOM tree
141
     */
142
    protected function toUnsignedXML(?DOMElement $parent = null): DOMElement
143
    {
144
        $e = $this->instantiateParentElement($parent);
145
146
        $e->setAttribute('MajorVersion', strval($this->getMajorVersion()));
147
        $e->setAttribute('MinorVersion', strval($this->getMinorVersion()));
148
        $e->setAttribute('IssueInstant', strval($this->getIssueInstant()));
149
150
        return $e;
151
    }
152
}
153