77use DOMElement ;
88use SimpleSAML \Assert \Assert ;
99use SimpleSAML \XML \Exception \InvalidDOMElementException ;
10+ use SimpleSAML \XML \XMLStringElementTrait ;
11+
1012
1113/**
1214 * Class representing a ds:X509Certificate element.
1517 */
1618final class X509Certificate extends AbstractDsElement
1719{
18- /**
19- * The base64-encoded certificate.
20- *
21- * @var string
22- */
23- protected string $ certificate ;
24-
25-
26- /**
27- * Initialize an X509Certificate element.
28- *
29- * @param string $certificate
30- */
31- public function __construct (string $ certificate )
32- {
33- $ this ->setCertificate ($ certificate );
34- }
20+ use XMLStringElementTrait;
3521
3622
3723 /**
38- * Collect the value of the certificate-property
24+ * Validate the content of the element.
3925 *
40- * @return string
26+ * @param string $content The value to go in the XML textContent
27+ * @throws \Exception on failure
28+ * @return void
4129 */
42- public function getCertificate ( ): string
30+ protected function validateContent ( string $ content ): void
4331 {
44- return $ this ->certificate ;
45- }
46-
47-
48- /**
49- * Set the value of the certificate-property
50- *
51- * @param string $certificate
52- */
53- private function setCertificate (string $ certificate ): void
54- {
55- Assert::notEmpty ($ certificate , 'ds:X509Certificate cannot be empty ' );
56- Assert::stringPlausibleBase64 ($ certificate , 'ds:X509Certificate is not a valid Base64 encoded string ' );
57-
58- $ this ->certificate = $ certificate ;
32+ Assert::notEmpty ($ content , 'ds:X509Certificate cannot be empty ' );
33+ Assert::stringPlausibleBase64 ($ content , 'ds:X509Certificate is not a valid Base64 encoded string ' );
5934 }
6035
6136
@@ -75,19 +50,4 @@ public static function fromXML(DOMElement $xml): object
7550
7651 return new self ($ xml ->textContent );
7752 }
78-
79-
80- /**
81- * Convert this X509Certificate element to XML.
82- *
83- * @param \DOMElement|null $parent The element we should append this X509Certificate element to.
84- * @return \DOMElement
85- */
86- public function toXML (DOMElement $ parent = null ): DOMElement
87- {
88- $ e = $ this ->instantiateParentElement ($ parent );
89- $ e ->textContent = $ this ->certificate ;
90-
91- return $ e ;
92- }
9353}
0 commit comments