66
77use DOMElement ;
88use SimpleSAML \WSSecurity \Assert \Assert ;
9- use SimpleSAML \XML \Exception \InvalidDOMElementException ;
10- use SimpleSAML \XML \Exception \SchemaViolationException ;
119use SimpleSAML \XML \ExtendableAttributesTrait ;
12- use SimpleSAML \XML \{SchemaValidatableElementInterface , SchemaValidatableElementTrait };
13- use SimpleSAML \XML \XsNamespace as NS ;
10+ use SimpleSAML \XML \SchemaValidatableElementInterface ;
11+ use SimpleSAML \XML \SchemaValidatableElementTrait ;
12+ use SimpleSAML \XMLSchema \Exception \InvalidDOMElementException ;
13+ use SimpleSAML \XMLSchema \Exception \SchemaViolationException ;
14+ use SimpleSAML \XMLSchema \Type \AnyURIValue ;
15+ use SimpleSAML \XMLSchema \Type \Base64BinaryValue ;
16+ use SimpleSAML \XMLSchema \XML \Constants \NS ;
1417
1518use function str_replace ;
1619
@@ -31,47 +34,43 @@ final class PolicyReference extends AbstractWspElement implements SchemaValidata
3134 /**
3235 * Initialize a wsp:PolicyReference
3336 *
34- * @param string $URI
35- * @param string |null $Digest
36- * @param string $DigestAlgorithm
37+ * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $URI
38+ * @param \SimpleSAML\XMLSchema\Type\Base64BinaryValue |null $Digest
39+ * @param \SimpleSAML\XMLSchema\Type\AnyURIValue $DigestAlgorithm
3740 * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes
3841 */
3942 public function __construct (
40- protected string $ URI ,
41- protected ?string $ Digest = null ,
42- protected ?string $ DigestAlgorithm = ' http://schemas.xmlsoap.org/ws/2004/09/policy/Sha1Exc ' ,
43+ protected AnyURIValue $ URI ,
44+ protected ?Base64BinaryValue $ Digest = null ,
45+ protected ?AnyURIValue $ DigestAlgorithm = null ,
4346 array $ namespacedAttributes = [],
4447 ) {
45- Assert::validURI ($ URI , SchemaViolationException::class);
46- Assert::nullOrValidBase64 ($ Digest , SchemaViolationException::class);
47- Assert::nullOrValidURI ($ DigestAlgorithm , SchemaViolationException::class);
48-
4948 $ this ->setAttributesNS ($ namespacedAttributes );
5049 }
5150
5251
5352 /**
54- * @return string
53+ * @return \SimpleSAML\XMLSchema\Type\AnyURIValue
5554 */
56- public function getURI (): string
55+ public function getURI (): AnyURIValue
5756 {
5857 return $ this ->URI ;
5958 }
6059
6160
6261 /**
63- * @return string |null
62+ * @return \SimpleSAML\XMLSchema\Type\Base64BinaryValue |null
6463 */
65- public function getDigest (): ?string
64+ public function getDigest (): ?Base64BinaryValue
6665 {
67- return $ this ->Digest ? str_replace ([ "\f" , "\r" , "\n" , "\t" , "\v" , ' ' ], '' , $ this -> Digest ) : null ;
66+ return $ this ->Digest ;
6867 }
6968
7069
7170 /**
72- * @return string |null
71+ * @return \SimpleSAML\XMLSchema\Type\AnyURIValue |null
7372 */
74- public function getDigestAlgorithm (): ?string
73+ public function getDigestAlgorithm (): ?AnyURIValue
7574 {
7675 return $ this ->DigestAlgorithm ;
7776 }
@@ -83,7 +82,7 @@ public function getDigestAlgorithm(): ?string
8382 * @param \DOMElement $xml The XML element we should load
8483 * @return static
8584 *
86- * @throws \SimpleSAML\XML \Exception\InvalidDOMElementException
85+ * @throws \SimpleSAML\XMLSchema \Exception\InvalidDOMElementException
8786 * If the qualified name of the supplied element is wrong
8887 */
8988 public static function fromXML (DOMElement $ xml ): static
@@ -108,9 +107,9 @@ public static function fromXML(DOMElement $xml): static
108107 }
109108
110109 return new static (
111- self ::getAttribute ($ xml , 'URI ' ),
112- self ::getOptionalAttribute ($ xml , 'Digest ' , null ),
113- self ::getOptionalAttribute ($ xml , 'DigestAlgorithm ' , null ),
110+ self ::getAttribute ($ xml , 'URI ' , AnyURIValue::class ),
111+ self ::getOptionalAttribute ($ xml , 'Digest ' , Base64BinaryValue::class, null ),
112+ self ::getOptionalAttribute ($ xml , 'DigestAlgorithm ' , AnyURIValue::class, null ),
114113 $ namespacedAttributes ,
115114 );
116115 }
@@ -125,14 +124,14 @@ public static function fromXML(DOMElement $xml): static
125124 public function toXML (?DOMElement $ parent = null ): DOMElement
126125 {
127126 $ e = $ this ->instantiateParentElement ($ parent );
128- $ e ->setAttribute ('URI ' , $ this ->getURI ());
127+ $ e ->setAttribute ('URI ' , $ this ->getURI ()-> getValue () );
129128
130129 if ($ this ->getDigest () !== null ) {
131- $ e ->setAttribute ('Digest ' , $ this ->getDigest ());
130+ $ e ->setAttribute ('Digest ' , $ this ->getDigest ()-> getValue () );
132131 }
133132
134133 if ($ this ->getDigestAlgorithm () !== null ) {
135- $ e ->setAttribute ('DigestAlgorithm ' , $ this ->getDigestAlgorithm ());
134+ $ e ->setAttribute ('DigestAlgorithm ' , $ this ->getDigestAlgorithm ()-> getValue () );
136135 }
137136
138137 foreach ($ this ->getAttributesNS () as $ attr ) {
0 commit comments