55namespace SimpleSAML \XMLSecurity \XML \ds ;
66
77use DOMElement ;
8+ use SimpleSAML \XML \Exception \InvalidDOMElementException ;
89use SimpleSAML \XMLSecurity \Constants as C ;
910use SimpleSAML \XMLSecurity \XML \ec \InclusiveNamespaces ;
1011use Webmozart \Assert \Assert ;
@@ -26,14 +27,14 @@ class Transform extends AbstractDsElement
2627 /**
2728 * An XPath object.
2829 *
29- * @var XPath|null
30+ * @var \SimpleSAML\XMLSecurity\XML\ds\ XPath|null
3031 */
3132 protected ?XPath $ xpath = null ;
3233
3334 /**
3435 * An InclusiveNamespaces object.
3536 *
36- * @var InclusiveNamespaces|null
37+ * @var \SimpleSAML\XMLSecurity\XML\ec\ InclusiveNamespaces|null
3738 */
3839 protected ?InclusiveNamespaces $ inclusiveNamespaces = null ;
3940
@@ -42,8 +43,8 @@ class Transform extends AbstractDsElement
4243 * Initialize the Transform element.
4344 *
4445 * @param string $algorithm
45- * @param XPath|null $xpath
46- * @param InclusiveNamespaces|null $prefixes
46+ * @param \SimpleSAML\XMLSecurity\XML\ds\ XPath|null $xpath
47+ * @param \SimpleSAML\XMLSecurity\XML\ec\ InclusiveNamespaces|null $prefixes
4748 */
4849 public function __construct (
4950 string $ algorithm ,
@@ -81,7 +82,7 @@ private function setAlgorithm(string $algorithm): void
8182 /**
8283 * Get the XPath associated with this transform.
8384 *
84- * @return XPath|null
85+ * @return \SimpleSAML\XMLSecurity\XML\ds\ XPath|null
8586 */
8687 public function getXPath (): ?XPath
8788 {
@@ -92,14 +93,15 @@ public function getXPath(): ?XPath
9293 /**
9394 * Set and validate the XPath object.
9495 *
95- * @param XPath|null $XPath
96+ * @param \SimpleSAML\XMLSecurity\XML\ds\ XPath|null $XPath
9697 */
9798 private function setXPath (?XPath $ xpath ): void
9899 {
99100 if ($ xpath === null ) {
100101 return ;
101102 }
102- Assert::eq (
103+
104+ Assert::nullOrEq (
103105 $ this ->algorithm ,
104106 C::XPATH_URI ,
105107 'Transform algorithm " ' . C::XPATH_URI . '" required if XPath provided. '
@@ -111,7 +113,7 @@ private function setXPath(?XPath $xpath): void
111113 /**
112114 * Get the InclusiveNamespaces associated with this transform.
113115 *
114- * @return InclusiveNamespaces|null
116+ * @return \SimpleSAML\XMLSecurity\XML\ec\ InclusiveNamespaces|null
115117 */
116118 public function getInclusiveNamespaces (): ?InclusiveNamespaces
117119 {
@@ -122,13 +124,14 @@ public function getInclusiveNamespaces(): ?InclusiveNamespaces
122124 /**
123125 * Set and validate the InclusiveNamespaces object.
124126 *
125- * @param InclusiveNamespaces|null $inclusiveNamespaces
127+ * @param \SimpleSAML\XMLSecurity\XML\ec\ InclusiveNamespaces|null $inclusiveNamespaces
126128 */
127129 private function setInclusiveNamespaces (?InclusiveNamespaces $ inclusiveNamespaces )
128130 {
129131 if ($ inclusiveNamespaces === null ) {
130132 return ;
131133 }
134+
132135 Assert::oneOf (
133136 $ this ->algorithm ,
134137 [
@@ -138,6 +141,7 @@ private function setInclusiveNamespaces(?InclusiveNamespaces $inclusiveNamespace
138141 'Transform algorithm " ' . C::C14N_EXCLUSIVE_WITH_COMMENTS . '" or " ' .
139142 C::C14N_EXCLUSIVE_WITHOUT_COMMENTS . '" required if InclusiveNamespaces provided. '
140143 );
144+
141145 $ this ->inclusiveNamespaces = $ inclusiveNamespaces ;
142146 }
143147
@@ -150,6 +154,9 @@ private function setInclusiveNamespaces(?InclusiveNamespaces $inclusiveNamespace
150154 */
151155 public static function fromXML (DOMElement $ xml ): object
152156 {
157+ Assert::same ($ xml ->localName , 'Transform ' , InvalidDOMElementException::class);
158+ Assert::same ($ xml ->namespaceURI , Transform::NS , InvalidDOMElementException::class);
159+
153160 $ alg = self ::getAttribute ($ xml , 'Algorithm ' );
154161 $ xpath = XPath::getChildrenOfClass ($ xml );
155162 Assert::maxCount ($ xpath , 1 , 'Only one XPath element supported per Transform. ' );
0 commit comments