88use SimpleSAML \Assert \Assert ;
99use SimpleSAML \XML \Exception \InvalidDOMElementException ;
1010use SimpleSAML \XML \Exception \SchemaViolationException ;
11+ use SimpleSAML \XML \Exception \TooManyElementsException ;
12+ use SimpleSAML \XML \ExtendableElementTrait ;
13+ use SimpleSAML \XML \XsNamespace as NS ;
1114use SimpleSAML \XMLSecurity \Constants as C ;
1215use SimpleSAML \XMLSecurity \Exception \InvalidArgumentException ;
1316
17+ use function array_keys ;
18+ use function array_merge ;
19+ use function array_pop ;
20+
1421/**
1522 * Class representing a ds:SignatureMethod element.
1623 *
1724 * @package simplesamlphp/xml-security
1825 */
1926final class SignatureMethod extends AbstractDsElement
2027{
28+ use ExtendableElementTrait;
29+
30+ /** The namespace-attribute for the xs:any element */
31+ public const XS_ANY_ELT_NAMESPACE = NS ::OTHER ;
32+
33+
2134 /**
2235 * Initialize a SignatureMethod element.
2336 *
2437 * @param string $Algorithm
38+ * @param \SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength|null $hmacOutputLength
39+ * @param array<\SimpleSAML\XML\SerializableElementInterface> $children
2540 */
2641 public function __construct (
2742 protected string $ Algorithm ,
43+ protected ?HMACOutputLength $ hmacOutputLength = null ,
44+ array $ children = [],
2845 ) {
2946 Assert::validURI ($ Algorithm , SchemaViolationException::class);
3047 Assert::oneOf (
@@ -36,6 +53,8 @@ public function __construct(
3653 'Invalid signature method: %s ' ,
3754 InvalidArgumentException::class,
3855 );
56+
57+ $ this ->setElements ($ children );
3958 }
4059
4160
@@ -50,6 +69,17 @@ public function getAlgorithm(): string
5069 }
5170
5271
72+ /**
73+ * Collect the value of the hmacOutputLength-property
74+ *
75+ * @return \SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength|null
76+ */
77+ public function getHMACOutputLength (): ?HMACOutputLength
78+ {
79+ return $ this ->hmacOutputLength ;
80+ }
81+
82+
5383 /**
5484 * Convert XML into a SignatureMethod
5585 *
@@ -66,7 +96,10 @@ public static function fromXML(DOMElement $xml): static
6696
6797 $ Algorithm = SignatureMethod::getAttribute ($ xml , 'Algorithm ' );
6898
69- return new static ($ Algorithm );
99+ $ hmacOutputLength = HMACOutputLength::getChildrenOfClass ($ xml );
100+ Assert::maxCount ($ hmacOutputLength , 1 , TooManyElementsException::class);
101+
102+ return new static ($ Algorithm , array_pop ($ hmacOutputLength ), self ::getChildElementsFromXML ($ xml ));
70103 }
71104
72105
@@ -81,6 +114,12 @@ public function toXML(DOMElement $parent = null): DOMElement
81114 $ e = $ this ->instantiateParentElement ($ parent );
82115 $ e ->setAttribute ('Algorithm ' , $ this ->getAlgorithm ());
83116
117+ $ this ->getHMACOutputLength ()?->toXML($ e );
118+
119+ foreach ($ this ->getElements () as $ elt ) {
120+ $ elt ->toXML ($ e );
121+ }
122+
84123 return $ e ;
85124 }
86125}
0 commit comments