AbstractMessage::getMinorVersion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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