diff --git a/composer.json b/composer.json index b22d3c10..b271ce32 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "ext-spl": "*", "simplesamlphp/assert": "~1.8.0", - "simplesamlphp/xml-common": "~1.24.0" + "simplesamlphp/xml-common": "dev-feature/xsd-types" }, "require-dev": { "simplesamlphp/simplesamlphp-test-framework": "~1.8.0" diff --git a/src/Assert/Assert.php b/src/Assert/Assert.php index 0d8f6b94..a728a6fc 100644 --- a/src/Assert/Assert.php +++ b/src/Assert/Assert.php @@ -10,7 +10,28 @@ * SimpleSAML\XMLSecurity\Assert\Assert wrapper class * * @package simplesamlphp/xml-security + * + * @method static void validCryptoBinary(mixed $value, string $message = '', string $exception = '') + * @method static void validDigestValue(mixed $value, string $message = '', string $exception = '') + * @method static void validECPoint(mixed $value, string $message = '', string $exception = '') + * @method static void validHMACOutputLength(mixed $value, string $message = '', string $exception = '') + * @method static void validKeySize(mixed $value, string $message = '', string $exception = '') + * @method static void nullOrValidCryptoBinary(mixed $value, string $message = '', string $exception = '') + * @method static void nullOrValidDigestValue(mixed $value, string $message = '', string $exception = '') + * @method static void nullOrValidECPoint(mixed $value, string $message = '', string $exception = '') + * @method static void nullOrValidHMACOutputLength(mixed $value, string $message = '', string $exception = '') + * @method static void nullOrValidKeySize(mixed $value, string $message = '', string $exception = '') + * @method static void allValidCryptoBinary(mixed $value, string $message = '', string $exception = '') + * @method static void allValidDigestValue(mixed $value, string $message = '', string $exception = '') + * @method static void allValidECPoint(mixed $value, string $message = '', string $exception = '') + * @method static void allValidHMACOutputLength(mixed $value, string $message = '', string $exception = '') + * @method static void allValidKeyValue(mixed $value, string $message = '', string $exception = '') */ class Assert extends BaseAssert { + use CryptoBinaryTrait; + use DigestValueTrait; + use ECPointTrait; + use HMACOutputLengthTrait; + use KeySizeTrait; } diff --git a/src/Assert/CryptoBinaryTrait.php b/src/Assert/CryptoBinaryTrait.php new file mode 100644 index 00000000..0c0dbe0a --- /dev/null +++ b/src/Assert/CryptoBinaryTrait.php @@ -0,0 +1,26 @@ +getMessage()); + } + + try { + parent::true( + intval($value) % 8 === 0, + '%s is not devisible by 8 and therefore not a valid ds:HMACOutputLengthType', + ); + } catch (AssertionFailedException $e) { + throw new ProtocolViolationException($e->getMessage()); + } + } +} diff --git a/src/Assert/KeySizeTrait.php b/src/Assert/KeySizeTrait.php new file mode 100644 index 00000000..32640e9b --- /dev/null +++ b/src/Assert/KeySizeTrait.php @@ -0,0 +1,36 @@ + 'ripemd160', ]; + /** * Padding schemas */ public const PADDING_PKCS1 = "PKCS1"; public const PADDING_PKCS1_OAEP = "OAEP"; + /** * Block encryption algorithms */ @@ -81,6 +128,7 @@ class Constants extends \SimpleSAML\XML\Constants self::BLOCK_ENC_AES256_GCM => 32, ]; + /** * Key transport algorithms */ @@ -95,6 +143,7 @@ class Constants extends \SimpleSAML\XML\Constants self::KEY_TRANSPORT_OAEP_MGF1P, ]; + /** * Canonicalization algorithms */ @@ -102,6 +151,19 @@ class Constants extends \SimpleSAML\XML\Constants public const C14N_INCLUSIVE_WITHOUT_COMMENTS = 'http://www.w3.org/TR/2001/REC-xml-c14n-20010315'; public const C14N_EXCLUSIVE_WITH_COMMENTS = 'http://www.w3.org/2001/10/xml-exc-c14n#WithComments'; public const C14N_EXCLUSIVE_WITHOUT_COMMENTS = 'http://www.w3.org/2001/10/xml-exc-c14n#'; + public const C14N11_INCLUSIVE_WITH_COMMENTS = 'http://www.w3.org/2006/12/xml-c14n11'; + public const C14N11_INCLUSIVE_WITHOUT_COMMENTS = 'http://www.w3.org/2006/12/xml-c14n11#WithComments'; + + /** @var string[] */ + public static array $CANONICALIZATION_ALGORITHMS = [ + self::C14N_INCLUSIVE_WITH_COMMENTS, + self::C14N_INCLUSIVE_WITHOUT_COMMENTS, + self::C14N_EXCLUSIVE_WITH_COMMENTS, + self::C14N_EXCLUSIVE_WITHOUT_COMMENTS, +// self::C14N11_INCLUSIVE_WITH_COMMENTS, +// self::C14N11_INCLUSIVE_WITHOUT_COMMENTS, + ]; + /** * Signature algorithms @@ -139,6 +201,19 @@ class Constants extends \SimpleSAML\XML\Constants self::SIG_HMAC_RIPEMD160 => self::DIGEST_RIPEMD160, ]; + + /** + * Encoding algorithms + */ + public const ENCODING_BASE64 = 'http://www.w3.org/2000/09/xmldsig#base64'; + + + /** + * Transforms algorithms + */ + public const TRANSFORMS_BASE64 = 'http://www.w3.org/2000/09/xmldsig#base64'; + + /** * XML & XPath namespaces and identifiers */ @@ -153,7 +228,4 @@ class Constants extends \SimpleSAML\XML\Constants public const XMLENC_ELEMENT = 'http://www.w3.org/2001/04/xmlenc#Element'; public const XMLENC_ENCRYPTEDKEY = 'http://www.w3.org/2001/04/xmlenc#EncryptedKey'; public const XMLENC_EXI = 'http://www.w3.org/2009/xmlenc11#EXI'; - - // The namespace for the Elliptic Curve Diffie-Hellman Ephemeral Static (ECDH-ES) algorithm - public const XMLENC11_ECDH_ES = 'http://www.w3.org/2009/xmlenc11#ECDH-ES'; } diff --git a/src/Exception/ProtocolViolationException.php b/src/Exception/ProtocolViolationException.php new file mode 100644 index 00000000..b1574626 --- /dev/null +++ b/src/Exception/ProtocolViolationException.php @@ -0,0 +1,29 @@ +documentElement); @@ -99,7 +108,7 @@ public function testSignatures(): void // verify signature $verifier = (new SignatureAlgorithmFactory([]))->getAlgorithm( - $signed->getSignature()->getSignedInfo()->getSignatureMethod()->getAlgorithm(), + $signed->getSignature()->getSignedInfo()->getSignatureMethod()->getAlgorithm()->getValue(), PEMCertificatesMock::getPublicKey(PEMCertificatesMock::PUBLIC_KEY), ); diff --git a/src/Type/CryptoBinaryValue.php b/src/Type/CryptoBinaryValue.php new file mode 100644 index 00000000..160500f0 --- /dev/null +++ b/src/Type/CryptoBinaryValue.php @@ -0,0 +1,28 @@ +sanitizeValue($value), SchemaViolationException::class); + } +} diff --git a/src/Type/DigestValue.php b/src/Type/DigestValue.php new file mode 100644 index 00000000..ef20c9bb --- /dev/null +++ b/src/Type/DigestValue.php @@ -0,0 +1,28 @@ +sanitizeValue($value), SchemaViolationException::class); + } +} diff --git a/src/Type/ECPointValue.php b/src/Type/ECPointValue.php new file mode 100644 index 00000000..a135cd81 --- /dev/null +++ b/src/Type/ECPointValue.php @@ -0,0 +1,28 @@ +sanitizeValue($value), SchemaViolationException::class); + } +} diff --git a/src/Type/HMACOutputLengthValue.php b/src/Type/HMACOutputLengthValue.php new file mode 100644 index 00000000..f93b4bd8 --- /dev/null +++ b/src/Type/HMACOutputLengthValue.php @@ -0,0 +1,29 @@ +sanitizeValue($value), SchemaViolationException::class); + } +} diff --git a/src/Type/KeySizeValue.php b/src/Type/KeySizeValue.php new file mode 100644 index 00000000..8ec3ef25 --- /dev/null +++ b/src/Type/KeySizeValue.php @@ -0,0 +1,28 @@ +sanitizeValue($value), SchemaViolationException::class); + } +} diff --git a/src/Utils/XML.php b/src/Utils/XML.php index 0e08bfd6..2bc127dc 100644 --- a/src/Utils/XML.php +++ b/src/Utils/XML.php @@ -8,7 +8,7 @@ use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\XML\ds\Transforms; -use function count; +use function array_map; use function is_null; /** @@ -89,15 +89,15 @@ public static function processTransforms( $arXPath = null; $prefixList = null; foreach ($transforms->getTransform() as $transform) { - $canonicalMethod = $transform->getAlgorithm(); + $canonicalMethod = $transform->getAlgorithm()->getValue(); switch ($canonicalMethod) { case C::C14N_EXCLUSIVE_WITHOUT_COMMENTS: case C::C14N_EXCLUSIVE_WITH_COMMENTS: $inclusiveNamespaces = $transform->getInclusiveNamespaces(); if ($inclusiveNamespaces !== null) { $prefixes = $inclusiveNamespaces->getPrefixes(); - if (count($prefixes) > 0) { - $prefixList = $prefixes; + if ($prefixes !== null) { + $prefixList = array_map('strval', $prefixes->toArray()); } } break; diff --git a/src/XML/EncryptableElementTrait.php b/src/XML/EncryptableElementTrait.php index fdae4cd2..f248f1e9 100644 --- a/src/XML/EncryptableElementTrait.php +++ b/src/XML/EncryptableElementTrait.php @@ -4,17 +4,14 @@ namespace SimpleSAML\XMLSecurity\XML; -use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory; -use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue}; +use SimpleSAML\XMLSecurity\Alg\Encryption\{EncryptionAlgorithmFactory, EncryptionAlgorithmInterface}; use SimpleSAML\XMLSecurity\Backend\EncryptionBackend; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Key\SymmetricKey; use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\xenc\CipherData; -use SimpleSAML\XMLSecurity\XML\xenc\CipherValue; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedData; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod; +use SimpleSAML\XMLSecurity\XML\xenc\{CipherData, CipherValue}; +use SimpleSAML\XMLSecurity\XML\xenc\{EncryptedData, EncryptedKey, EncryptionMethod}; /** * Trait aggregating functionality for elements that can be encrypted. @@ -61,7 +58,9 @@ public function encrypt(EncryptionAlgorithmInterface $encryptor): EncryptedData $encryptedKey = EncryptedKey::fromKey( $sessionKey, $encryptor, - new EncryptionMethod($encryptor->getAlgorithmId()), + new EncryptionMethod( + AnyURIValue::fromString($encryptor->getAlgorithmId()), + ), ); $keyInfo = new KeyInfo([$encryptedKey]); @@ -78,14 +77,20 @@ public function encrypt(EncryptionAlgorithmInterface $encryptor): EncryptedData return new EncryptedData( new CipherData( new CipherValue( - base64_encode($encryptor->encrypt($xmlRepresentation->ownerDocument->saveXML($xmlRepresentation))), + Base64BinaryValue::fromString( + base64_encode($encryptor->encrypt( + $xmlRepresentation->ownerDocument->saveXML($xmlRepresentation), + )), + ), ), ), null, - C::XMLENC_ELEMENT, + AnyURIValue::fromString(C::XMLENC_ELEMENT), null, null, - new EncryptionMethod($encryptor->getAlgorithmId()), + new EncryptionMethod( + AnyURIValue::fromString($encryptor->getAlgorithmId()), + ), $keyInfo, ); } diff --git a/src/XML/EncryptedElementInterface.php b/src/XML/EncryptedElementInterface.php index 9924765e..724b1acf 100644 --- a/src/XML/EncryptedElementInterface.php +++ b/src/XML/EncryptedElementInterface.php @@ -6,8 +6,7 @@ use SimpleSAML\XML\ElementInterface; use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedData; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey; +use SimpleSAML\XMLSecurity\XML\xenc\{EncryptedData, EncryptedKey}; /** * Interface for encrypted elements. diff --git a/src/XML/EncryptedElementTrait.php b/src/XML/EncryptedElementTrait.php index 48b381f8..dce41a02 100644 --- a/src/XML/EncryptedElementTrait.php +++ b/src/XML/EncryptedElementTrait.php @@ -7,18 +7,15 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\AbstractElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory; -use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, TooManyElementsException}; +use SimpleSAML\XMLSecurity\Alg\Encryption\{EncryptionAlgorithmFactory, EncryptionAlgorithmInterface}; use SimpleSAML\XMLSecurity\Backend\EncryptionBackend; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; -use SimpleSAML\XMLSecurity\Exception\NoEncryptedDataException; -use SimpleSAML\XMLSecurity\Exception\RuntimeException; +use SimpleSAML\XMLSecurity\Exception\{InvalidArgumentException, NoEncryptedDataException, RuntimeException}; use SimpleSAML\XMLSecurity\Key\SymmetricKey; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedData; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey; +use SimpleSAML\XMLSecurity\XML\xenc\{EncryptedData, EncryptedKey}; + +use function strval; /** * Trait aggregating functionality for encrypted elements. @@ -134,15 +131,20 @@ protected function decryptData(EncryptionAlgorithmInterface $decryptor): string $factory = new EncryptionAlgorithmFactory( $this->getBlacklistedAlgorithms() ?? EncryptionAlgorithmFactory::DEFAULT_BLACKLIST, ); - $decryptor = $factory->getAlgorithm($encMethod->getAlgorithm(), new SymmetricKey($decryptionKey)); + $decryptor = $factory->getAlgorithm( + $encMethod->getAlgorithm()->getValue(), + new SymmetricKey($decryptionKey), + ); $decryptor->setBackend($this->getEncryptionBackend()); } - if ($algId !== $decryptor->getAlgorithmId()) { + if ($algId->getValue() !== $decryptor->getAlgorithmId()) { throw new InvalidArgumentException('Decryption algorithm does not match EncryptionMethod.'); } - return $decryptor->decrypt(base64_decode($encData->getCipherData()->getCipherValue()->getContent(), true)); + return $decryptor->decrypt( + base64_decode(strval($encData->getCipherData()->getCipherValue()->getContent()), true), + ); } diff --git a/src/XML/SignableElementInterface.php b/src/XML/SignableElementInterface.php index 50a00ecd..ef0704b7 100644 --- a/src/XML/SignableElementInterface.php +++ b/src/XML/SignableElementInterface.php @@ -4,6 +4,7 @@ namespace SimpleSAML\XMLSecurity\XML; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmInterface; use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; @@ -19,9 +20,9 @@ interface SignableElementInterface extends CanonicalizableElementInterface * * When this method returns null, the signature created for this object will reference the entire document. * - * @return string|null The ID of this element, or null if we don't have one. + * @return \SimpleSAML\XML\Type\IDValue|null The ID of this element, or null if we don't have one. */ - public function getId(): ?string; + public function getId(): ?IDValue; /** diff --git a/src/XML/SignableElementTrait.php b/src/XML/SignableElementTrait.php index 4509ea9a..2e03a267 100644 --- a/src/XML/SignableElementTrait.php +++ b/src/XML/SignableElementTrait.php @@ -7,22 +7,25 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IDValue}; use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmInterface; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Exception\RuntimeException; -use SimpleSAML\XMLSecurity\Exception\UnsupportedAlgorithmException; +use SimpleSAML\XMLSecurity\Exception\{RuntimeException, UnsupportedAlgorithmException}; +use SimpleSAML\XMLSecurity\Type\DigestValue as DigestValueType; use SimpleSAML\XMLSecurity\Utils\XML; -use SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod; -use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; -use SimpleSAML\XMLSecurity\XML\ds\DigestValue; -use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\ds\Reference; -use SimpleSAML\XMLSecurity\XML\ds\Signature; -use SimpleSAML\XMLSecurity\XML\ds\SignatureMethod; -use SimpleSAML\XMLSecurity\XML\ds\SignatureValue; -use SimpleSAML\XMLSecurity\XML\ds\SignedInfo; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; +use SimpleSAML\XMLSecurity\XML\ds\{ + CanonicalizationMethod, + DigestMethod, + DigestValue, + KeyInfo, + Reference, + Signature, + SignatureMethod, + SignatureValue, + SignedInfo, + Transform, + Transforms, +}; use function base64_encode; use function hash; @@ -55,9 +58,9 @@ trait SignableElementTrait * * When this method returns null, the signature created for this object will reference the entire document. * - * @return string|null The ID of this element, or null if we don't have one. + * @return \SimpleSAML\XML\Type\IDValue|null The ID of this element, or null if we don't have one. */ - abstract public function getId(): ?string; + abstract public function getId(): ?IDValue; /** @@ -129,12 +132,18 @@ private function getReference( } return new Reference( - new DigestMethod($digestAlg), - new DigestValue(base64_encode(hash(C::$DIGEST_ALGORITHMS[$digestAlg], $canonicalDocument, true))), + new DigestMethod( + AnyURIValue::fromString($digestAlg), + ), + new DigestValue( + DigestValueType::fromString( + base64_encode(hash(C::$DIGEST_ALGORITHMS[$digestAlg], $canonicalDocument, true)), + ), + ), $transforms, null, null, - $uri, + ($uri !== null) ? AnyURIValue::fromString($uri) : null, ); } @@ -167,22 +176,38 @@ protected function doSign(DOMElement $xml): DOMElement $digest = $this->signer->getDigest(); $transforms = new Transforms([ - new Transform(C::XMLDSIG_ENVELOPED), - new Transform($this->c14nAlg), + new Transform( + AnyURIValue::fromString(C::XMLDSIG_ENVELOPED), + ), + new Transform( + AnyURIValue::fromString($this->c14nAlg), + ), ]); $canonicalDocument = XML::processTransforms($transforms, $xml); $signedInfo = new SignedInfo( - new CanonicalizationMethod($this->c14nAlg), - new SignatureMethod($algorithm), + new CanonicalizationMethod( + AnyURIValue::fromString($this->c14nAlg), + ), + new SignatureMethod( + AnyURIValue::fromString($algorithm), + ), [$this->getReference($digest, $transforms, $xml, $canonicalDocument)], ); $signingData = $signedInfo->canonicalize($this->c14nAlg); $signedData = base64_encode($this->signer->sign($signingData)); - $this->setSignature(new Signature($signedInfo, new SignatureValue($signedData), $this->keyInfo)); + $this->setSignature( + new Signature( + $signedInfo, + new SignatureValue( + Base64BinaryValue::fromString($signedData), + ), + $this->keyInfo, + ), + ); return DOMDocumentFactory::fromString($canonicalDocument)->documentElement; } diff --git a/src/XML/SignedElementInterface.php b/src/XML/SignedElementInterface.php index d48ef0c3..566cc91b 100644 --- a/src/XML/SignedElementInterface.php +++ b/src/XML/SignedElementInterface.php @@ -4,6 +4,7 @@ namespace SimpleSAML\XMLSecurity\XML; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmInterface; use SimpleSAML\XMLSecurity\Key\KeyInterface; use SimpleSAML\XMLSecurity\XML\ds\Signature; @@ -20,9 +21,9 @@ interface SignedElementInterface extends CanonicalizableElementInterface * * When this method returns null, the signature created for this object will reference the entire document. * - * @return string|null The ID of this element, or null if we don't have one. + * @return \SimpleSAML\XML\Type\IDValue|null The ID of this element, or null if we don't have one. */ - public function getId(): ?string; + public function getId(): ?IDValue; /** diff --git a/src/XML/SignedElementTrait.php b/src/XML/SignedElementTrait.php index 8fa73658..c89e05e1 100644 --- a/src/XML/SignedElementTrait.php +++ b/src/XML/SignedElementTrait.php @@ -7,30 +7,34 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory; -use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmInterface; +use SimpleSAML\XMLSecurity\Alg\Signature\{SignatureAlgorithmFactory, SignatureAlgorithmInterface}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\CryptoEncoding\PEM; -use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; -use SimpleSAML\XMLSecurity\Exception\NoSignatureFoundException; -use SimpleSAML\XMLSecurity\Exception\ReferenceValidationFailedException; -use SimpleSAML\XMLSecurity\Exception\RuntimeException; -use SimpleSAML\XMLSecurity\Exception\SignatureVerificationFailedException; +use SimpleSAML\XMLSecurity\Exception\{ + InvalidArgumentException, + NoSignatureFoundException, + ReferenceValidationFailedException, + RuntimeException, + SignatureVerificationFailedException, +}; use SimpleSAML\XMLSecurity\Key; use SimpleSAML\XMLSecurity\Key\KeyInterface; -use SimpleSAML\XMLSecurity\Utils\XML; -use SimpleSAML\XMLSecurity\Utils\XPath; -use SimpleSAML\XMLSecurity\XML\ds\Reference; -use SimpleSAML\XMLSecurity\XML\ds\Signature; -use SimpleSAML\XMLSecurity\XML\ds\SignedInfo; -use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; +use SimpleSAML\XMLSecurity\Utils\{XML, XPath}; +use SimpleSAML\XMLSecurity\XML\ds\{ + Reference, + Signature, + SignedInfo, + X509Certificate, + X509Data, +}; use function base64_decode; use function hash; use function hash_equals; use function in_array; +use function strval; /** * Helper trait for processing signed elements. @@ -104,7 +108,7 @@ private function validateReferenceUri(Reference $reference, DOMElement $xml): vo $id = $this->getId(); $uri = $reference->getURI(); - if (empty($uri) || $uri === '#xpointer(/)') { // same-document reference + if (empty($uri) || $uri->getValue() === '#xpointer(/)') { // same-document reference Assert::true( $xml->isSameNode($xml->ownerDocument->documentElement), 'Cannot use document reference when element is not the root of the document.', @@ -117,10 +121,10 @@ private function validateReferenceUri(Reference $reference, DOMElement $xml): vo ReferenceValidationFailedException::class, ); Assert::oneOf( - $uri, + $uri->getValue(), [ - '#' . $id, - '#xpointer(id(' . $id . '))', + '#' . $id->getValue(), + '#xpointer(id(' . $id->getValue() . '))', ], 'Reference does not point to given element.', ReferenceValidationFailedException::class, @@ -153,7 +157,7 @@ private function validateReference(SignedInfo $signedInfo): SignedElementInterfa $doc->documentElement->removeChild($sigNode[0]); $data = XML::processTransforms($reference->getTransforms(), $doc->documentElement); - $algo = $reference->getDigestMethod()->getAlgorithm(); + $algo = $reference->getDigestMethod()->getAlgorithm()->getValue(); Assert::keyExists( C::$DIGEST_ALGORITHMS, $algo, @@ -162,7 +166,12 @@ private function validateReference(SignedInfo $signedInfo): SignedElementInterfa ); $digest = hash(C::$DIGEST_ALGORITHMS[$algo], $data, true); - if (hash_equals($digest, base64_decode($reference->getDigestValue()->getRawContent(), true)) !== true) { + if ( + hash_equals( + $digest, + base64_decode($reference->getDigestValue()->getContent()->getValue(), true), + ) !== true + ) { throw new SignatureVerificationFailedException('Failed to verify signature.'); } @@ -190,7 +199,7 @@ private function verifyInternal(SignatureAlgorithmInterface $verifier): SignedEl $c14nAlg = $signedInfo->getCanonicalizationMethod()->getAlgorithm(); // the canonicalized ds:SignedInfo element (plaintext) - $c14nSignedInfo = $signedInfo->canonicalize($c14nAlg); + $c14nSignedInfo = $signedInfo->canonicalize($c14nAlg->getValue()); $ref = $this->validateReference( SignedInfo::fromXML(DOMDocumentFactory::fromString($c14nSignedInfo)->documentElement), ); @@ -199,7 +208,7 @@ private function verifyInternal(SignatureAlgorithmInterface $verifier): SignedEl $verifier?->verify( $c14nSignedInfo, // the canonicalized ds:SignedInfo element (plaintext) // the actual signature - base64_decode($this->getSignature()->getSignatureValue()->getRawContent(), true), + base64_decode(strval($this->getSignature()->getSignatureValue()->getValue()), true), ) ) { /* @@ -290,11 +299,11 @@ public function verify(?SignatureAlgorithmInterface $verifier = null): SignedEle // build a valid PEM for the certificate $cert = sprintf( "-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----", - $data->getRawContent(), + strval($data->getContent()), ); $cert = new Key\X509Certificate(PEM::fromString($cert)); - $verifier = $factory->getAlgorithm($algId, $cert->getPublicKey()); + $verifier = $factory->getAlgorithm($algId->getValue(), $cert->getPublicKey()); try { return $this->verifyInternal($verifier); @@ -308,9 +317,9 @@ public function verify(?SignatureAlgorithmInterface $verifier = null): SignedEle /** - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - abstract public function getId(): ?string; + abstract public function getId(): ?IDValue; /** diff --git a/src/XML/ds/AbstractDSAKeyValueType.php b/src/XML/ds/AbstractDSAKeyValueType.php index d63ba38b..8c058ac0 100644 --- a/src/XML/ds/AbstractDSAKeyValueType.php +++ b/src/XML/ds/AbstractDSAKeyValueType.php @@ -6,11 +6,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use function array_pop; diff --git a/src/XML/ds/AbstractKeyInfoType.php b/src/XML/ds/AbstractKeyInfoType.php index dadff6fc..9d8a28fc 100644 --- a/src/XML/ds/AbstractKeyInfoType.php +++ b/src/XML/ds/AbstractKeyInfoType.php @@ -8,12 +8,15 @@ use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\ExtendableElementTrait; use SimpleSAML\XML\SerializableElementInterface; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\Assert\Assert; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; +use function strval; + /** * Abstract class representing the KeyInfoType. * @@ -40,11 +43,11 @@ abstract class AbstractKeyInfoType extends AbstractDsElement * \SimpleSAML\XMLSecurity\XML\ds\MgmtData| * \SimpleSAML\XML\SerializableElementInterface * )[] $info - * @param string|null $Id + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ final public function __construct( protected array $info, - protected ?string $Id = null, + protected ?IDValue $Id = null, ) { Assert::notEmpty( $info, @@ -61,7 +64,6 @@ final public function __construct( SerializableElementInterface::class, InvalidArgumentException::class, ); - Assert::nullOrValidNCName($Id); foreach ($info as $item) { if ($item instanceof AbstractDsElement) { @@ -86,9 +88,9 @@ final public function __construct( /** * Collect the value of the Id-property * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -116,7 +118,7 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } foreach ($this->getInfo() as $elt) { diff --git a/src/XML/ds/AbstractPGPDataType.php b/src/XML/ds/AbstractPGPDataType.php index 644c0fc9..82332b20 100644 --- a/src/XML/ds/AbstractPGPDataType.php +++ b/src/XML/ds/AbstractPGPDataType.php @@ -6,12 +6,9 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; diff --git a/src/XML/ds/AbstractSPKIDataType.php b/src/XML/ds/AbstractSPKIDataType.php index 89621d9f..5b1c6f12 100644 --- a/src/XML/ds/AbstractSPKIDataType.php +++ b/src/XML/ds/AbstractSPKIDataType.php @@ -7,12 +7,9 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; use SimpleSAML\XML\Registry\ElementRegistry; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; -use SimpleSAML\XML\SerializableElementInterface; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait, SerializableElementInterface}; use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; /** diff --git a/src/XML/ds/CanonicalizationMethod.php b/src/XML/ds/CanonicalizationMethod.php index bf5c66a8..0af576f0 100644 --- a/src/XML/ds/CanonicalizationMethod.php +++ b/src/XML/ds/CanonicalizationMethod.php @@ -6,13 +6,14 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; +use function strval; + /** * Class representing a ds:CanonicalizationMethod element. * @@ -25,14 +26,13 @@ final class CanonicalizationMethod extends AbstractDsElement implements SchemaVa /** * Initialize a CanonicalizationMethod element. * - * @param string $Algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm */ public function __construct( - protected string $Algorithm, + protected AnyURIValue $Algorithm, ) { - Assert::validURI($Algorithm, SchemaViolationException::class); Assert::oneOf( - $Algorithm, + $Algorithm->getValue(), [ C::C14N_EXCLUSIVE_WITH_COMMENTS, C::C14N_EXCLUSIVE_WITHOUT_COMMENTS, @@ -48,9 +48,9 @@ public function __construct( /** * Collect the value of the Algorithm-property * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->Algorithm; } @@ -70,7 +70,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'CanonicalizationMethod', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, CanonicalizationMethod::NS, InvalidDOMElementException::class); - $Algorithm = CanonicalizationMethod::getAttribute($xml, 'Algorithm'); + $Algorithm = self::getAttribute($xml, 'Algorithm', AnyURIValue::class); return new static($Algorithm); } @@ -85,7 +85,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); return $e; } diff --git a/src/XML/ds/DigestMethod.php b/src/XML/ds/DigestMethod.php index 0dc2f333..4ee9aed1 100644 --- a/src/XML/ds/DigestMethod.php +++ b/src/XML/ds/DigestMethod.php @@ -6,15 +6,16 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; +use function strval; + /** * Class representing a ds:DigestMethod element. * @@ -25,21 +26,21 @@ final class DigestMethod extends AbstractDsElement implements SchemaValidatableE use ExtendableElementTrait; use SchemaValidatableElementTrait; + /** The namespace-attribute for the xs:any element */ public const XS_ANY_ELT_NAMESPACE = NS::OTHER; /** * Initialize a DigestMethod element. * - * @param string $Algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm * @param list<\SimpleSAML\XML\SerializableElementInterface> $elements */ public function __construct( - protected string $Algorithm, + protected AnyURIValue $Algorithm, array $elements = [], ) { - Assert::validURI($Algorithm, SchemaViolationException::class); Assert::oneOf( - $Algorithm, + $Algorithm->getValue(), array_keys(C::$DIGEST_ALGORITHMS), 'Invalid digest method: %s', InvalidArgumentException::class, @@ -52,9 +53,9 @@ public function __construct( /** * Collect the value of the Algorithm-property * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->Algorithm; } @@ -74,7 +75,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'DigestMethod', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, DigestMethod::NS, InvalidDOMElementException::class); - $Algorithm = DigestMethod::getAttribute($xml, 'Algorithm'); + $Algorithm = self::getAttribute($xml, 'Algorithm', AnyURIValue::class); $elements = self::getChildElementsFromXML($xml); return new static($Algorithm, $elements); @@ -90,7 +91,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); foreach ($this->elements as $elt) { if (!$elt->isEmptyElement()) { diff --git a/src/XML/ds/DigestValue.php b/src/XML/ds/DigestValue.php index 9747af30..458d26f2 100644 --- a/src/XML/ds/DigestValue.php +++ b/src/XML/ds/DigestValue.php @@ -4,9 +4,9 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XMLSecurity\Type\DigestValue as DigestValueType; /** * Class representing a ds:DigestValue element. @@ -15,15 +15,9 @@ */ final class DigestValue extends AbstractDsElement implements SchemaValidatableElementInterface { - use Base64ElementTrait; use SchemaValidatableElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = DigestValueType::class; } diff --git a/src/XML/ds/DsObject.php b/src/XML/ds/DsObject.php index 592c11ec..091422f4 100644 --- a/src/XML/ds/DsObject.php +++ b/src/XML/ds/DsObject.php @@ -7,11 +7,13 @@ use DOMElement; use SimpleSAML\XML\Exception\InvalidDOMElementException; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\Assert\Assert; +use function strval; + /** * Class representing a ds:Object element. * @@ -32,20 +34,17 @@ final class DsObject extends AbstractDsElement implements SchemaValidatableEleme /** * Initialize a ds:Object element. * - * @param string|null $Id - * @param string|null $MimeType - * @param string|null $Encoding + * @param \SimpleSAML\XML\Type\IDValue|null $Id + * @param \SimpleSAML\XML\Type\StringValue|null $MimeType + * @param \SimpleSAML\XML\Type\AnyURIValue|null $Encoding * @param \SimpleSAML\XML\SerializableElementInterface[] $elements */ public function __construct( - protected ?string $Id = null, - protected ?string $MimeType = null, - protected ?string $Encoding = null, + protected ?IDValue $Id = null, + protected ?StringValue $MimeType = null, + protected ?AnyURIValue $Encoding = null, array $elements = [], ) { - Assert::nullOrValidNCName($Id); - Assert::nullOrValidURI($Encoding); - $this->setElements($elements); } @@ -53,9 +52,9 @@ public function __construct( /** * Collect the value of the Id-property * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -64,9 +63,9 @@ public function getId(): ?string /** * Collect the value of the MimeType-property * - * @return string|null + * @return \SimpleSAML\XML\Type\StringValue|null */ - public function getMimeType(): ?string + public function getMimeType(): ?StringValue { return $this->MimeType; } @@ -75,9 +74,9 @@ public function getMimeType(): ?string /** * Collect the value of the Encoding-property * - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getEncoding(): ?string + public function getEncoding(): ?AnyURIValue { return $this->Encoding; } @@ -90,10 +89,10 @@ public function getEncoding(): ?string */ public function isEmptyElement(): bool { - return empty($this->elements) - && empty($this->Id) - && empty($this->MimeType) - && empty($this->Encoding); + return empty($this->getElements()) + && empty($this->getId()) + && empty($this->getMimeType()) + && empty($this->getEncoding()); } @@ -111,9 +110,9 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'Object', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, DsObject::NS, InvalidDOMElementException::class); - $Id = DsObject::getOptionalAttribute($xml, 'Id', null); - $MimeType = DsObject::getOptionalAttribute($xml, 'MimeType', null); - $Encoding = DsObject::getOptionalAttribute($xml, 'Encoding', null); + $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null); + $MimeType = self::getOptionalAttribute($xml, 'MimeType', StringValue::class, null); + $Encoding = self::getOptionalAttribute($xml, 'Encoding', AnyURIValue::class, null); $elements = self::getChildElementsFromXML($xml); return new static($Id, $MimeType, $Encoding, $elements); @@ -131,15 +130,15 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } if ($this->getMimeType() !== null) { - $e->setAttribute('MimeType', $this->getMimeType()); + $e->setAttribute('MimeType', strval($this->getMimeType())); } if ($this->getEncoding() !== null) { - $e->setAttribute('Encoding', $this->getEncoding()); + $e->setAttribute('Encoding', strval($this->getEncoding())); } foreach ($this->getElements() as $elt) { diff --git a/src/XML/ds/Exponent.php b/src/XML/ds/Exponent.php index 325f82fa..8e8fb924 100644 --- a/src/XML/ds/Exponent.php +++ b/src/XML/ds/Exponent.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:Exponent element. @@ -13,14 +14,8 @@ */ final class Exponent extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/G.php b/src/XML/ds/G.php index 0e879816..21c55975 100644 --- a/src/XML/ds/G.php +++ b/src/XML/ds/G.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:G element. @@ -13,14 +14,8 @@ */ final class G extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/HMACOutputLength.php b/src/XML/ds/HMACOutputLength.php index e8a6228c..258d7b9d 100644 --- a/src/XML/ds/HMACOutputLength.php +++ b/src/XML/ds/HMACOutputLength.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\IntegerElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\HMACOutputLengthValue; /** * Class representing a ds:HMACOutputLength element. @@ -13,14 +14,8 @@ */ final class HMACOutputLength extends AbstractDsElement { - use IntegerElementTrait; + use TypedTextContentTrait; - - /** - * @param string $length - */ - public function __construct(string $length) - { - $this->setContent($length); - } + /** @var string */ + public const TEXTCONTENT_TYPE = HMACOutputLengthValue::class; } diff --git a/src/XML/ds/J.php b/src/XML/ds/J.php index 22e724c3..49e7309a 100644 --- a/src/XML/ds/J.php +++ b/src/XML/ds/J.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:J element. @@ -13,14 +14,8 @@ */ final class J extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/KeyInfo.php b/src/XML/ds/KeyInfo.php index 01cb7c13..bc97e06b 100644 --- a/src/XML/ds/KeyInfo.php +++ b/src/XML/ds/KeyInfo.php @@ -7,8 +7,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\IDValue; use function array_merge; @@ -35,7 +35,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'KeyInfo', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, KeyInfo::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); + $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null); $keyName = KeyName::getChildrenOfClass($xml); $keyValue = KeyValue::getChildrenOfClass($xml); diff --git a/src/XML/ds/KeyName.php b/src/XML/ds/KeyName.php index b16bd14c..00527acf 100644 --- a/src/XML/ds/KeyName.php +++ b/src/XML/ds/KeyName.php @@ -4,9 +4,9 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:KeyName element. @@ -16,14 +16,8 @@ final class KeyName extends AbstractDsElement implements SchemaValidatableElementInterface { use SchemaValidatableElementTrait; - use StringElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = StringValue::class; } diff --git a/src/XML/ds/KeyValue.php b/src/XML/ds/KeyValue.php index 7fba8cc6..beb86b35 100644 --- a/src/XML/ds/KeyValue.php +++ b/src/XML/ds/KeyValue.php @@ -7,12 +7,9 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\ElementInterface; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use SimpleSAML\XML\XsNamespace as NS; /** diff --git a/src/XML/ds/Manifest.php b/src/XML/ds/Manifest.php index 1c7adac0..3e48b497 100644 --- a/src/XML/ds/Manifest.php +++ b/src/XML/ds/Manifest.php @@ -6,12 +6,13 @@ use DOMElement; use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Assert\Assert; +use function strval; + /** * Class representing a ds:Manifest element. * @@ -25,15 +26,14 @@ final class Manifest extends AbstractDsElement implements SchemaValidatableEleme * Initialize a ds:Manifest * * @param \SimpleSAML\XMLSecurity\XML\ds\Reference[] $references - * @param string|null $Id + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ public function __construct( protected array $references, - protected ?string $Id = null, + protected ?IDValue $Id = null, ) { Assert::maxCount($references, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOf($references, Reference::class); - Assert::nullOrValidNCName($Id); } @@ -47,9 +47,9 @@ public function getReferences(): array /** - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -69,7 +69,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'Manifest', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, Manifest::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); + $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null); $references = Reference::getChildrenOfClass($xml); Assert::minCount( @@ -97,7 +97,7 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } foreach ($this->getReferences() as $reference) { diff --git a/src/XML/ds/MgmtData.php b/src/XML/ds/MgmtData.php index b51eb4cc..97fe2853 100644 --- a/src/XML/ds/MgmtData.php +++ b/src/XML/ds/MgmtData.php @@ -4,9 +4,9 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:MgmtData element. @@ -16,14 +16,8 @@ final class MgmtData extends AbstractDsElement implements SchemaValidatableElementInterface { use SchemaValidatableElementTrait; - use StringElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = StringValue::class; } diff --git a/src/XML/ds/Modulus.php b/src/XML/ds/Modulus.php index ba48cac2..7dcb2552 100644 --- a/src/XML/ds/Modulus.php +++ b/src/XML/ds/Modulus.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:Modulus element. @@ -13,14 +14,8 @@ */ final class Modulus extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/P.php b/src/XML/ds/P.php index a5173b4c..0f0fde58 100644 --- a/src/XML/ds/P.php +++ b/src/XML/ds/P.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:P element. @@ -13,14 +14,8 @@ */ final class P extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/PGPKeyID.php b/src/XML/ds/PGPKeyID.php index dea62bc9..aae5f449 100644 --- a/src/XML/ds/PGPKeyID.php +++ b/src/XML/ds/PGPKeyID.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:PGPKeyID element. @@ -13,14 +14,8 @@ */ final class PGPKeyID extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/ds/PGPKeyPacket.php b/src/XML/ds/PGPKeyPacket.php index 614bf86d..c78324aa 100644 --- a/src/XML/ds/PGPKeyPacket.php +++ b/src/XML/ds/PGPKeyPacket.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:PGPKeyPacket element. @@ -13,14 +14,8 @@ */ final class PGPKeyPacket extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/ds/PgenCounter.php b/src/XML/ds/PgenCounter.php index 9210d1b8..b058746a 100644 --- a/src/XML/ds/PgenCounter.php +++ b/src/XML/ds/PgenCounter.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:PgenCounter element. @@ -13,14 +14,8 @@ */ final class PgenCounter extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/Q.php b/src/XML/ds/Q.php index 3089f707..ee38c076 100644 --- a/src/XML/ds/Q.php +++ b/src/XML/ds/Q.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:Q element. @@ -13,14 +14,8 @@ */ final class Q extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/RSAKeyValue.php b/src/XML/ds/RSAKeyValue.php index 4bfef458..65da8cad 100644 --- a/src/XML/ds/RSAKeyValue.php +++ b/src/XML/ds/RSAKeyValue.php @@ -6,11 +6,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; /** * Class representing a ds:RSAKeyValue element. diff --git a/src/XML/ds/Reference.php b/src/XML/ds/Reference.php index 91db0085..f6cf8da3 100644 --- a/src/XML/ds/Reference.php +++ b/src/XML/ds/Reference.php @@ -5,14 +5,13 @@ namespace SimpleSAML\XMLSecurity\XML\ds; use DOMElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; use SimpleSAML\XMLSecurity\Assert\Assert; use function array_pop; +use function strval; /** * Class representing a ds:Reference element. @@ -29,21 +28,18 @@ final class Reference extends AbstractDsElement implements SchemaValidatableElem * @param \SimpleSAML\XMLSecurity\XML\ds\DigestMethod $digestMethod * @param \SimpleSAML\XMLSecurity\XML\ds\DigestValue $digestValue * @param \SimpleSAML\XMLSecurity\XML\ds\Transforms|null $transforms - * @param string|null $Id - * @param string|null $Type - * @param string|null $URI + * @param \SimpleSAML\XML\Type\IDValue|null $Id + * @param \SimpleSAML\XML\Type\AnyURIValue|null $Type + * @param \SimpleSAML\XML\Type\AnyURIValue|null $URI */ public function __construct( protected DigestMethod $digestMethod, protected DigestValue $digestValue, protected ?Transforms $transforms = null, - protected ?string $Id = null, - protected ?string $Type = null, - protected ?string $URI = null, + protected ?IDValue $Id = null, + protected ?AnyURIValue $Type = null, + protected ?AnyURIValue $URI = null, ) { - Assert::nullOrValidNCName($Id); - Assert::nullOrValidURI($Type); - Assert::nullOrValidURI($URI); } @@ -75,27 +71,27 @@ public function getDigestValue(): DigestValue /** - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } /** - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getType(): ?string + public function getType(): ?AnyURIValue { return $this->Type; } /** - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getURI(): ?string + public function getURI(): ?AnyURIValue { return $this->URI; } @@ -108,7 +104,7 @@ public function getURI(): ?string */ public function isXPointer(): bool { - return !empty($this->URI) && str_starts_with($this->URI, '#xpointer'); + return !is_null($this->getURI()) && str_starts_with(strval($this->getURI()), '#xpointer'); } @@ -126,9 +122,9 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'Reference', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, Reference::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); - $Type = self::getOptionalAttribute($xml, 'Type', null); - $URI = self::getOptionalAttribute($xml, 'URI', null); + $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null); + $Type = self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null); + $URI = self::getOptionalAttribute($xml, 'URI', AnyURIValue::class, null); $transforms = Transforms::getChildrenOfClass($xml); Assert::maxCount( @@ -175,13 +171,13 @@ public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } if ($this->getType() !== null) { - $e->setAttribute('Type', $this->getType()); + $e->setAttribute('Type', strval($this->getType())); } if ($this->getURI() !== null) { - $e->setAttribute('URI', $this->getURI()); + $e->setAttribute('URI', strval($this->getURI())); } $this->getTransforms()?->toXML($e); diff --git a/src/XML/ds/RetrievalMethod.php b/src/XML/ds/RetrievalMethod.php index 01419508..bbf7eeba 100644 --- a/src/XML/ds/RetrievalMethod.php +++ b/src/XML/ds/RetrievalMethod.php @@ -6,11 +6,11 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; + +use function strval; /** * Class representing a ds:RetrievalMethod element. @@ -25,16 +25,14 @@ final class RetrievalMethod extends AbstractDsElement implements SchemaValidatab * Initialize a ds:RetrievalMethod * * @param \SimpleSAML\XMLSecurity\XML\ds\Transforms|null $transforms - * @param string $URI - * @param string|null $Type + * @param \SimpleSAML\XML\Type\AnyURIValue $URI + * @param \SimpleSAML\XML\Type\AnyURIValue|null $Type */ final public function __construct( protected ?Transforms $transforms, - protected string $URI, - protected ?string $Type = null, + protected AnyURIValue $URI, + protected ?AnyURIValue $Type = null, ) { - Assert::validURI($URI, SchemaViolationException::class); // Covers the empty string - Assert::nullOrValidURI($Type, SchemaViolationException::class); // Covers the empty string } @@ -48,18 +46,18 @@ public function getTransforms(): ?Transforms /** - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getURI(): string + public function getURI(): AnyURIValue { return $this->URI; } /** - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getType(): ?string + public function getType(): ?AnyURIValue { return $this->Type; } @@ -79,8 +77,8 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'RetrievalMethod', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, RetrievalMethod::NS, InvalidDOMElementException::class); - $URI = self::getAttribute($xml, 'URI'); - $Type = self::getOptionalAttribute($xml, 'Type', null); + $URI = self::getAttribute($xml, 'URI', AnyURIValue::class); + $Type = self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null); $transforms = Transforms::getChildrenOfClass($xml); Assert::maxCount( @@ -107,10 +105,10 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('URI', $this->getURI()); + $e->setAttribute('URI', strval($this->getURI())); if ($this->getType() !== null) { - $e->setAttribute('Type', $this->getType()); + $e->setAttribute('Type', strval($this->getType())); } $this->getTransforms()?->toXML($e); diff --git a/src/XML/ds/SPKISexp.php b/src/XML/ds/SPKISexp.php index 1ca50c4a..45ed2957 100644 --- a/src/XML/ds/SPKISexp.php +++ b/src/XML/ds/SPKISexp.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:SPKISexp element. @@ -13,14 +14,8 @@ */ final class SPKISexp extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/ds/Seed.php b/src/XML/ds/Seed.php index cf0713c9..b9951e47 100644 --- a/src/XML/ds/Seed.php +++ b/src/XML/ds/Seed.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:seed element. @@ -13,14 +14,8 @@ */ final class Seed extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/ds/Signature.php b/src/XML/ds/Signature.php index e5da1f3d..648ae9dd 100644 --- a/src/XML/ds/Signature.php +++ b/src/XML/ds/Signature.php @@ -5,15 +5,14 @@ namespace SimpleSAML\XMLSecurity\XML\ds; use DOMElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Assert\Assert; use SimpleSAML\XMLSecurity\Constants as C; use function array_pop; +use function strval; /** * Class representing a ds:Signature element. @@ -31,27 +30,26 @@ final class Signature extends AbstractDsElement implements SchemaValidatableElem * @param \SimpleSAML\XMLSecurity\XML\ds\SignatureValue $signatureValue * @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null $keyInfo * @param \SimpleSAML\XMLSecurity\XML\ds\DsObject[] $objects - * @param string|null $Id + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ public function __construct( protected SignedInfo $signedInfo, protected SignatureValue $signatureValue, - protected ?KeyInfo $keyInfo, + protected ?KeyInfo $keyInfo = null, protected array $objects = [], - protected ?string $Id = null, + protected ?IDValue $Id = null, ) { Assert::maxCount($objects, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOf($objects, DsObject::class); - Assert::nullOrValidNCName($Id); } /** * Get the Id used for this signature. * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -109,8 +107,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'Signature', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, Signature::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); - $signedInfo = SignedInfo::getChildrenOfClass($xml); Assert::minCount( $signedInfo, @@ -154,7 +150,7 @@ public static function fromXML(DOMElement $xml): static array_pop($signatureValue), empty($keyInfo) ? null : array_pop($keyInfo), $objects, - $Id, + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), ); } @@ -170,7 +166,7 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } $this->getSignedInfo()->toXML($e); diff --git a/src/XML/ds/SignatureMethod.php b/src/XML/ds/SignatureMethod.php index eeb04d8a..0c17cfab 100644 --- a/src/XML/ds/SignatureMethod.php +++ b/src/XML/ds/SignatureMethod.php @@ -6,12 +6,10 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; @@ -19,6 +17,7 @@ use function array_keys; use function array_merge; use function array_pop; +use function strval; /** * Class representing a ds:SignatureMethod element. @@ -37,18 +36,17 @@ final class SignatureMethod extends AbstractDsElement implements SchemaValidatab /** * Initialize a SignatureMethod element. * - * @param string $Algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm * @param \SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength|null $hmacOutputLength * @param array<\SimpleSAML\XML\SerializableElementInterface> $children */ public function __construct( - protected string $Algorithm, + protected AnyURIValue $Algorithm, protected ?HMACOutputLength $hmacOutputLength = null, array $children = [], ) { - Assert::validURI($Algorithm, SchemaViolationException::class); Assert::oneOf( - $Algorithm, + $Algorithm->getValue(), array_merge( array_keys(C::$RSA_DIGESTS), array_keys(C::$HMAC_DIGESTS), @@ -64,9 +62,9 @@ public function __construct( /** * Collect the value of the Algorithm-property * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->Algorithm; } @@ -97,7 +95,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'SignatureMethod', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, SignatureMethod::NS, InvalidDOMElementException::class); - $Algorithm = SignatureMethod::getAttribute($xml, 'Algorithm'); + $Algorithm = self::getAttribute($xml, 'Algorithm', AnyURIValue::class); $hmacOutputLength = HMACOutputLength::getChildrenOfClass($xml); Assert::maxCount($hmacOutputLength, 1, TooManyElementsException::class); @@ -115,7 +113,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); $this->getHMACOutputLength()?->toXML($e); diff --git a/src/XML/ds/SignatureProperties.php b/src/XML/ds/SignatureProperties.php index c0aeb7c8..4d90f006 100644 --- a/src/XML/ds/SignatureProperties.php +++ b/src/XML/ds/SignatureProperties.php @@ -6,13 +6,13 @@ use DOMElement; use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, SchemaViolationException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Assert\Assert; +use function strval; + /** * Class representing a ds:SignatureProperties element. * @@ -26,15 +26,14 @@ final class SignatureProperties extends AbstractDsElement implements SchemaValid * Initialize a ds:SignatureProperties * * @param \SimpleSAML\XMLSecurity\XML\ds\SignatureProperty[] $signatureProperty - * @param string|null $Id + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ public function __construct( protected array $signatureProperty, - protected ?string $Id = null, + protected ?IDValue $Id = null, ) { Assert::maxCount($signatureProperty, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOf($signatureProperty, SignatureProperty::class, SchemaViolationException::class); - Assert::nullOrValidNCName($Id); } @@ -48,9 +47,9 @@ public function getSignatureProperty(): array /** - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -71,8 +70,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->namespaceURI, SignatureProperties::NS, InvalidDOMElementException::class); $signatureProperty = SignatureProperty::getChildrenOfClass($xml); - $Id = self::getOptionalAttribute($xml, 'Id', null); - Assert::minCount( $signatureProperty, 1, @@ -82,7 +79,7 @@ public static function fromXML(DOMElement $xml): static return new static( $signatureProperty, - $Id, + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), ); } @@ -98,7 +95,7 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } foreach ($this->getSignatureProperty() as $signatureProperty) { diff --git a/src/XML/ds/SignatureProperty.php b/src/XML/ds/SignatureProperty.php index 3f07cedd..257faee0 100644 --- a/src/XML/ds/SignatureProperty.php +++ b/src/XML/ds/SignatureProperty.php @@ -5,15 +5,15 @@ namespace SimpleSAML\XMLSecurity\XML\ds; use DOMElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, SchemaViolationException}; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\Assert\Assert; +use function strval; + /** * Class representing a ds:SignatureProperty element. * @@ -32,34 +32,31 @@ final class SignatureProperty extends AbstractDsElement implements SchemaValidat * Initialize a ds:SignatureProperty * * @param \SimpleSAML\XML\SerializableElementInterface[] $elements - * @param string $Target - * @param string|null $Id + * @param \SimpleSAML\XML\Type\AnyURIValue $Target + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ public function __construct( array $elements, - protected string $Target, - protected ?string $Id = null, + protected AnyURIValue $Target, + protected ?IDValue $Id = null, ) { - Assert::validURI($Target, SchemaViolationException::class); // Covers the empty string - Assert::nullOrValidNCName($Id); - $this->setElements($elements); } /** - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getTarget(): string + public function getTarget(): AnyURIValue { return $this->Target; } /** - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -79,9 +76,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'SignatureProperty', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, SignatureProperty::NS, InvalidDOMElementException::class); - $Target = self::getAttribute($xml, 'Target'); - $Id = self::getOptionalAttribute($xml, 'Id', null); - $children = self::getChildElementsFromXML($xml); Assert::minCount( $children, @@ -92,8 +86,8 @@ public static function fromXML(DOMElement $xml): static return new static( $children, - $Target, - $Id, + self::getAttribute($xml, 'Target', AnyURIValue::class), + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), ); } @@ -107,10 +101,10 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Target', $this->getTarget()); + $e->setAttribute('Target', strval($this->getTarget())); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } foreach ($this->getElements() as $element) { diff --git a/src/XML/ds/SignatureValue.php b/src/XML/ds/SignatureValue.php index cb51b850..0bd1480c 100644 --- a/src/XML/ds/SignatureValue.php +++ b/src/XML/ds/SignatureValue.php @@ -5,12 +5,13 @@ namespace SimpleSAML\XMLSecurity\XML\ds; use DOMElement; -use SimpleSAML\XML\Base64ElementTrait; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{Base64BinaryValue, IDValue}; use SimpleSAML\XMLSecurity\Assert\Assert; +use function strval; + /** * Class representing a ds:SignatureValue element. * @@ -18,35 +19,42 @@ */ final class SignatureValue extends AbstractDsElement implements SchemaValidatableElementInterface { - use Base64ElementTrait; use SchemaValidatableElementTrait; /** - * @param string $content - * @param string|null $Id + * @param \SimpleSAML\XML\Type\Base64BinaryValue $value + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ public function __construct( - string $content, - protected ?string $Id = null, + protected Base64BinaryValue $value, + protected ?IDValue $Id = null, ) { - Assert::nullOrValidNCName($Id); - - $this->setContent($content); } /** * Get the Id used for this signature value. * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } + /** + * Get the content for this signature value. + * + * @return \SimpleSAML\XML\Type\Base64BinaryValue + */ + public function getValue(): ?Base64BinaryValue + { + return $this->value; + } + + /** * Convert XML into a SignatureValue element * @@ -61,9 +69,9 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'SignatureValue', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, SignatureValue::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); + $Id = self::getOptionalAttribute($xml, 'Id', IDValue::class, null); - return new static($xml->textContent, $Id); + return new static(Base64BinaryValue::fromString($xml->textContent), $Id); } @@ -76,10 +84,10 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->textContent = $this->getContent(); + $e->textContent = strval($this->getValue()); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } return $e; diff --git a/src/XML/ds/SignedInfo.php b/src/XML/ds/SignedInfo.php index 7fb621ae..a9ef2cba 100644 --- a/src/XML/ds/SignedInfo.php +++ b/src/XML/ds/SignedInfo.php @@ -6,17 +6,15 @@ use DOMElement; use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Assert\Assert; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; -use SimpleSAML\XMLSecurity\XML\CanonicalizableElementInterface; -use SimpleSAML\XMLSecurity\XML\CanonicalizableElementTrait; +use SimpleSAML\XMLSecurity\XML\{CanonicalizableElementInterface, CanonicalizableElementTrait}; use function array_pop; +use function strval; /** * Class representing a ds:SignedInfo element. @@ -42,17 +40,16 @@ final class SignedInfo extends AbstractDsElement implements * @param \SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod $canonicalizationMethod * @param \SimpleSAML\XMLSecurity\XML\ds\SignatureMethod $signatureMethod * @param \SimpleSAML\XMLSecurity\XML\ds\Reference[] $references - * @param string|null $Id + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ public function __construct( protected CanonicalizationMethod $canonicalizationMethod, protected SignatureMethod $signatureMethod, protected array $references, - protected ?string $Id = null, + protected ?IDValue $Id = null, ) { Assert::maxCount($references, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOf($references, Reference::class, InvalidArgumentException::class); - Assert::nullOrValidNCName($Id); } @@ -92,9 +89,9 @@ public function getReferences(): array /** * Collect the value of the Id-property * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -127,8 +124,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'SignedInfo', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, SignedInfo::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); - $canonicalizationMethod = CanonicalizationMethod::getChildrenOfClass($xml); Assert::minCount( $canonicalizationMethod, @@ -165,7 +160,13 @@ public static function fromXML(DOMElement $xml): static MissingElementException::class, ); - $signedInfo = new static(array_pop($canonicalizationMethod), array_pop($signatureMethod), $references, $Id); + $signedInfo = new static( + array_pop($canonicalizationMethod), + array_pop($signatureMethod), + $references, + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), + ); + $signedInfo->xml = $xml; return $signedInfo; } @@ -182,7 +183,7 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } $this->getCanonicalizationMethod()->toXML($e); diff --git a/src/XML/ds/Transform.php b/src/XML/ds/Transform.php index 1f4f7133..4607abd7 100644 --- a/src/XML/ds/Transform.php +++ b/src/XML/ds/Transform.php @@ -6,15 +6,14 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces; use function array_pop; +use function strval; /** * Class representing transforms. @@ -28,20 +27,18 @@ class Transform extends AbstractDsElement implements SchemaValidatableElementInt /** * Initialize the Transform element. * - * @param string $algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $algorithm * @param \SimpleSAML\XMLSecurity\XML\ds\XPath|null $xpath * @param \SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces|null $inclusiveNamespaces */ final public function __construct( - protected string $algorithm, + protected AnyURIValue $algorithm, protected ?XPath $xpath = null, protected ?InclusiveNamespaces $inclusiveNamespaces = null, ) { - Assert::validURI($algorithm, SchemaViolationException::class); - if ($xpath !== null) { Assert::nullOrEq( - $this->algorithm, + $algorithm->getValue(), C::XPATH10_URI, sprintf('Transform algorithm "%s" required if XPath provided.', C::XPATH10_URI), ); @@ -49,7 +46,7 @@ final public function __construct( if ($inclusiveNamespaces !== null) { Assert::oneOf( - $this->algorithm, + $algorithm->getValue(), [ C::C14N_INCLUSIVE_WITH_COMMENTS, C::C14N_EXCLUSIVE_WITHOUT_COMMENTS, @@ -67,9 +64,9 @@ final public function __construct( /** * Get the algorithm associated with this transform. * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->algorithm; } @@ -108,8 +105,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'Transform', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, Transform::NS, InvalidDOMElementException::class); - $alg = self::getAttribute($xml, 'Algorithm'); - $xpath = XPath::getChildrenOfClass($xml); Assert::maxCount($xpath, 1, 'Only one XPath element supported per Transform.', TooManyElementsException::class); @@ -121,7 +116,11 @@ public static function fromXML(DOMElement $xml): static TooManyElementsException::class, ); - return new static($alg, array_pop($xpath), array_pop($prefixes)); + return new static( + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), + array_pop($xpath), + array_pop($prefixes), + ); } @@ -134,7 +133,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); switch ($this->getAlgorithm()) { case C::XPATH10_URI: @@ -146,9 +145,6 @@ public function toXML(?DOMElement $parent = null): DOMElement break; } -//$doc = \SimpleSAML\XML\DOMDocumentFactory::create(); -//$doc->append($doc->importNode($e, true)); -//return $doc->documentElement; return $e; } } diff --git a/src/XML/ds/Transforms.php b/src/XML/ds/Transforms.php index ad068a8d..14b95448 100644 --- a/src/XML/ds/Transforms.php +++ b/src/XML/ds/Transforms.php @@ -8,8 +8,7 @@ use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Constants as C; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; /** diff --git a/src/XML/ds/X509CRL.php b/src/XML/ds/X509CRL.php index e40c3c77..61ded867 100644 --- a/src/XML/ds/X509CRL.php +++ b/src/XML/ds/X509CRL.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:X509CRL element. @@ -13,14 +14,8 @@ */ final class X509CRL extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/ds/X509Certificate.php b/src/XML/ds/X509Certificate.php index 9454dfb4..7d06f8d3 100644 --- a/src/XML/ds/X509Certificate.php +++ b/src/XML/ds/X509Certificate.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:X509Certificate element. @@ -13,14 +14,8 @@ */ final class X509Certificate extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/ds/X509Data.php b/src/XML/ds/X509Data.php index ae2a4845..e63dd909 100644 --- a/src/XML/ds/X509Data.php +++ b/src/XML/ds/X509Data.php @@ -6,12 +6,12 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Chunk; +use SimpleSAML\XML\ExtendableElementTrait; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait, SerializableElementInterface}; +use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; +use SimpleSAML\XMLSecurity\Exception\{InvalidArgumentException, ProtocolViolationException}; use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest; /** @@ -21,36 +21,64 @@ */ final class X509Data extends AbstractDsElement implements SchemaValidatableElementInterface { + use ExtendableElementTrait; use SchemaValidatableElementTrait; + /** The namespace-attribute for the xs:any element */ + public const XS_ANY_ELT_NAMESPACE = NS::OTHER; + + /** The exclusions for the xs:any element */ + public const XS_ANY_ELT_EXCLUSIONS = [ + [X509Digest::NS, 'X509Digest'], + ]; + + /** * Initialize a X509Data. * - * @param (\SimpleSAML\XML\Chunk| - * \SimpleSAML\XMLSecurity\XML\ds\X509Certificate| + * @param (\SimpleSAML\XMLSecurity\XML\ds\X509Certificate| * \SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial| * \SimpleSAML\XMLSecurity\XML\ds\X509SubjectName| + * \SimpleSAML\XMLSecurity\XML\ds\X509SKI| + * \SimpleSAML\XMLSecurity\XML\ds\X509CRL| * \SimpleSAML\XMLSecurity\XML\dsig11\X509Digest)[] $data + * @param \SimpleSAML\XML\SerializableElementInterface[] $children */ public function __construct( protected array $data, + protected array $children = [], ) { + /** + * At least one element from the dsig namespaces should be present and + * additional elements from an external namespace to accompany/complement them. + */ + Assert::minCount($data, 1, ProtocolViolationException::class); Assert::maxCount($data, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOfAny( $data, - [Chunk::class, X509Certificate::class, X509IssuerSerial::class, X509SubjectName::class, X509Digest::class], + [ + X509Certificate::class, + X509IssuerSerial::class, + X509SubjectName::class, + X509Digest::class, + X509SKI::class, + X509CRL::class, + ], InvalidArgumentException::class, ); + + $this->setElements($children); } /** * Collect the value of the data-property * - * @return (\SimpleSAML\XML\Chunk| - * \SimpleSAML\XMLSecurity\XML\ds\X509Certificate| + * @return (\SimpleSAML\XMLSecurity\XML\ds\X509Certificate| * \SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial| * \SimpleSAML\XMLSecurity\XML\ds\X509SubjectName| + * \SimpleSAML\XMLSecurity\XML\ds\X509SKI| + * \SimpleSAML\XMLSecurity\XML\ds\X509CRL| * \SimpleSAML\XMLSecurity\XML\dsig11\X509Digest)[] */ public function getData(): array @@ -73,30 +101,17 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'X509Data', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, X509Data::NS, InvalidDOMElementException::class); - $data = []; - - for ($n = $xml->firstChild; $n !== null; $n = $n->nextSibling) { - if (!($n instanceof DOMElement)) { - continue; - } elseif ($n->namespaceURI === self::NS) { - $data[] = match ($n->localName) { - 'X509Certificate' => X509Certificate::fromXML($n), - 'X509IssuerSerial' => X509IssuerSerial::fromXML($n), - 'X509SubjectName' => X509SubjectName::fromXML($n), - default => new Chunk($n), - }; - } elseif ($n->namespaceURI === C::NS_XDSIG11) { - $data[] = match ($n->localName) { - 'X509Digest' => X509Digest::fromXML($n), - default => new Chunk($n), - }; - } else { - $data[] = new Chunk($n); - continue; - } - } + $x509Certificate = X509Certificate::getChildrenOfClass($xml); + $x509IssuerSerial = X509IssuerSerial::getChildrenOfClass($xml); + $x509SubjectName = X509SubjectName::getChildrenOfClass($xml); + $x509SKI = X509SKI::getChildrenOfClass($xml); + $x509CRL = X509CRL::getChildrenOfClass($xml); + $x509Digest = X509Digest::getChildrenOfClass($xml); + + $data = array_merge($x509Certificate, $x509IssuerSerial, $x509SubjectName, $x509SKI, $x509CRL, $x509Digest); + $children = self::getChildElementsFromXML($xml); - return new static($data); + return new static($data, $children); } @@ -110,8 +125,12 @@ public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - foreach ($this->getData() as $n) { - $n->toXML($e); + foreach ($this->getData() as $d) { + $d->toXML($e); + } + + foreach ($this->getElements() as $c) { + $c->toXML($e); } return $e; diff --git a/src/XML/ds/X509IssuerName.php b/src/XML/ds/X509IssuerName.php index 3ddf66b0..9a240f13 100644 --- a/src/XML/ds/X509IssuerName.php +++ b/src/XML/ds/X509IssuerName.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:X509IssuerName element. @@ -13,14 +14,8 @@ */ final class X509IssuerName extends AbstractDsElement { - use StringElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = StringValue::class; } diff --git a/src/XML/ds/X509IssuerSerial.php b/src/XML/ds/X509IssuerSerial.php index dc0a70da..88b286b2 100644 --- a/src/XML/ds/X509IssuerSerial.php +++ b/src/XML/ds/X509IssuerSerial.php @@ -6,9 +6,7 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; use function array_pop; diff --git a/src/XML/ds/X509SKI.php b/src/XML/ds/X509SKI.php index 0bb61594..04fda0de 100644 --- a/src/XML/ds/X509SKI.php +++ b/src/XML/ds/X509SKI.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:X509SKI element. @@ -13,14 +14,8 @@ */ final class X509SKI extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/ds/X509SerialNumber.php b/src/XML/ds/X509SerialNumber.php index 19ad7d08..144659ab 100644 --- a/src/XML/ds/X509SerialNumber.php +++ b/src/XML/ds/X509SerialNumber.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\IntegerElementTrait; +use SimpleSAML\XML\Type\IntegerValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:X509SerialNumber element. @@ -13,14 +14,8 @@ */ final class X509SerialNumber extends AbstractDsElement { - use IntegerElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = IntegerValue::class; } diff --git a/src/XML/ds/X509SubjectName.php b/src/XML/ds/X509SubjectName.php index 026be96a..018f3aed 100644 --- a/src/XML/ds/X509SubjectName.php +++ b/src/XML/ds/X509SubjectName.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a ds:X509SubjectName element. @@ -13,14 +14,8 @@ */ final class X509SubjectName extends AbstractDsElement { - use StringElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = StringValue::class; } diff --git a/src/XML/ds/XPath.php b/src/XML/ds/XPath.php index 54c35180..a78a4ee7 100644 --- a/src/XML/ds/XPath.php +++ b/src/XML/ds/XPath.php @@ -7,6 +7,9 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Type\StringValue; + +use function strval; /** * Class implementing the XPath element. @@ -18,10 +21,10 @@ class XPath extends AbstractDsElement /** * Construct an XPath element. * - * @param string $expression The XPath expression itself. + * @param \SimpleSAML\XML\Type\StringValue $expression The XPath expression itself. */ final public function __construct( - protected string $expression, + protected StringValue $expression, ) { } @@ -29,9 +32,9 @@ final public function __construct( /** * Get the actual XPath expression. * - * @return string + * @return \SimpleSAML\XML\Type\StringValue */ - public function getExpression(): string + public function getExpression(): StringValue { return $this->expression; } @@ -51,7 +54,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'XPath', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, self::NS, InvalidDOMElementException::class); - return new static($xml->textContent); + return new static(StringValue::fromString($xml->textContent)); } @@ -62,7 +65,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->textContent = $this->getExpression(); + $e->textContent = strval($this->getExpression()); return $e; } diff --git a/src/XML/ds/Y.php b/src/XML/ds/Y.php index 2d8b7daf..d3342110 100644 --- a/src/XML/ds/Y.php +++ b/src/XML/ds/Y.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\ds; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a ds:Y element. @@ -13,14 +14,8 @@ */ final class Y extends AbstractDsElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/dsig11/KeyInfoReference.php b/src/XML/dsig11/KeyInfoReference.php index 18382dd3..af738046 100644 --- a/src/XML/dsig11/KeyInfoReference.php +++ b/src/XML/dsig11/KeyInfoReference.php @@ -5,10 +5,9 @@ namespace SimpleSAML\XMLSecurity\XML\dsig11; use DOMElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; use SimpleSAML\XMLSecurity\Assert\Assert; /** @@ -23,24 +22,22 @@ final class KeyInfoReference extends AbstractDsig11Element implements SchemaVali /** * Initialize a KeyInfoReference element. * - * @param string $URI - * @param string|null $Id + * @param \SimpleSAML\XML\Type\AnyURIValue $URI + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ public function __construct( - protected string $URI, - protected ?string $Id = null, + protected AnyURIValue $URI, + protected ?IDValue $Id = null, ) { - Assert::validURI($URI, SchemaViolationException::class); - Assert::nullOrValidNCName($Id); } /** * Collect the value of the URI-property * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getURI(): string + public function getURI(): AnyURIValue { return $this->URI; } @@ -49,9 +46,9 @@ public function getURI(): string /** * Collect the value of the Id-property * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -71,10 +68,10 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'KeyInfoReference', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, KeyInfoReference::NS, InvalidDOMElementException::class); - $URI = KeyInfoReference::getAttribute($xml, 'URI'); - $Id = KeyInfoReference::getOptionalAttribute($xml, 'Id', null); - - return new static($URI, $Id); + return new static( + KeyInfoReference::getAttribute($xml, 'URI', AnyURIValue::class), + KeyInfoReference::getOptionalAttribute($xml, 'Id', IDValue::class, null), + ); } @@ -87,10 +84,10 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('URI', $this->getURI()); + $e->setAttribute('URI', strval($this->getURI())); if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } return $e; diff --git a/src/XML/dsig11/X509Digest.php b/src/XML/dsig11/X509Digest.php index 607084dc..b9150f22 100644 --- a/src/XML/dsig11/X509Digest.php +++ b/src/XML/dsig11/X509Digest.php @@ -6,14 +6,14 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Base64ElementTrait; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; +use function strval; + /** * Class representing a dsig11:X509Digest element. * @@ -21,38 +21,45 @@ */ final class X509Digest extends AbstractDsig11Element implements SchemaValidatableElementInterface { - use Base64ElementTrait; use SchemaValidatableElementTrait; /** * Initialize a X509Digest element. * - * @param string $digest - * @param string $algorithm + * @param \SimpleSAML\XML\Type\Base64BinaryValue $digest + * @param \SimpleSAML\XML\Type\AnyURIValue $algorithm */ public function __construct( - string $digest, - protected string $algorithm, + protected Base64BinaryValue $digest, + protected AnyURIValue $algorithm, ) { - Assert::validURI($algorithm, SchemaViolationException::class); Assert::oneOf( - $algorithm, + strval($algorithm), array_keys(C::$DIGEST_ALGORITHMS), 'Invalid digest method: %s', InvalidArgumentException::class, ); + } + - $this->setContent($digest); + /** + * Collect the value of the digest-property + * + * @return \SimpleSAML\XML\Type\Base64BinaryValue + */ + public function getDigest(): Base64BinaryValue + { + return $this->digest; } /** * Collect the value of the algorithm-property * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->algorithm; } @@ -72,9 +79,10 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'X509Digest', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, X509Digest::NS, InvalidDOMElementException::class); - $algorithm = self::getAttribute($xml, 'Algorithm'); - - return new static($xml->textContent, $algorithm); + return new static( + Base64BinaryValue::fromString($xml->textContent), + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), + ); } @@ -87,8 +95,8 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->textContent = $this->getContent(); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->textContent = strval($this->getDigest()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); return $e; } diff --git a/src/XML/ec/InclusiveNamespaces.php b/src/XML/ec/InclusiveNamespaces.php index 49d4c173..ae4e31b3 100644 --- a/src/XML/ec/InclusiveNamespaces.php +++ b/src/XML/ec/InclusiveNamespaces.php @@ -5,15 +5,10 @@ namespace SimpleSAML\XMLSecurity\XML\ec; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; -use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\NMTokensValue; -use function explode; -use function join; +use function strval; /** * Class implementing InclusiveNamespaces @@ -27,27 +22,20 @@ class InclusiveNamespaces extends AbstractEcElement implements SchemaValidatable /** * Initialize the InclusiveNamespaces element. * - * @param string[] $prefixes + * @param \SimpleSAML\XML\Type\NMTokensValue|null $prefixes */ final public function __construct( - protected array $prefixes, + protected ?NMTokensValue $prefixes, ) { - Assert::maxCount($prefixes, C::UNBOUNDED_LIMIT); - Assert::allString( - $prefixes, - 'Can only add string InclusiveNamespaces prefixes.', - InvalidArgumentException::class, - ); - Assert::allRegex($prefixes, '/^[a-z0-9._\\-:]*$/i', SchemaViolationException::class); // xsd:NMTOKEN } /** * Get the prefixes specified by this element. * - * @return string[] + * @return \SimpleSAML\XML\Type\NMTokensValue|null */ - public function getPrefixes(): array + public function getPrefixes(): ?NMTokensValue { return $this->prefixes; } @@ -61,9 +49,9 @@ public function getPrefixes(): array */ public static function fromXML(DOMElement $xml): static { - $prefixes = self::getOptionalAttribute($xml, 'PrefixList', ''); - - return new static(array_filter(explode(' ', $prefixes))); + return new static( + self::getOptionalAttribute($xml, 'PrefixList', NMTokensValue::class, null), + ); } /** @@ -76,8 +64,8 @@ public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - if (!empty($this->getPrefixes())) { - $e->setAttribute('PrefixList', join(' ', $this->getPrefixes())); + if ($this->getPrefixes() !== null) { + $e->setAttribute('PrefixList', strval($this->getPrefixes())); } return $e; diff --git a/src/XML/xenc/AbstractAgreementMethodType.php b/src/XML/xenc/AbstractAgreementMethodType.php index 979eeb51..6295e7cd 100644 --- a/src/XML/xenc/AbstractAgreementMethodType.php +++ b/src/XML/xenc/AbstractAgreementMethodType.php @@ -6,15 +6,14 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XML\XsNamespace as NS; use function array_pop; +use function strval; /** * A class implementing the xenc:AbstractAgreementMethodType element. @@ -33,21 +32,19 @@ abstract class AbstractAgreementMethodType extends AbstractXencElement implement /** * AgreementMethodType constructor. * - * @param string $algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $algorithm * @param \SimpleSAML\XMLSecurity\XML\xenc\KANonce|null $kaNonce * @param \SimpleSAML\XMLSecurity\XML\xenc\OriginatorKeyInfo|null $originatorKeyInfo * @param \SimpleSAML\XMLSecurity\XML\xenc\RecipientKeyInfo|null $recipientKeyInfo * @param list<\SimpleSAML\XML\SerializableElementInterface> $children */ final public function __construct( - protected string $algorithm, + protected AnyURIValue $algorithm, protected ?KANonce $kaNonce = null, protected ?OriginatorKeyInfo $originatorKeyInfo = null, protected ?RecipientKeyInfo $recipientKeyInfo = null, protected array $children = [], ) { - Assert::validURI($algorithm, SchemaViolationException::class); // Covers the empty string - $this->setElements($children); } @@ -55,9 +52,9 @@ final public function __construct( /** * Get the URI identifying the algorithm used by this agreement method. * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->algorithm; } @@ -114,8 +111,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'AgreementMethod', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $algorithm = self::getAttribute($xml, 'Algorithm'); - $kaNonce = KANonce::getChildrenOfClass($xml); Assert::maxCount($kaNonce, 1, TooManyElementsException::class); @@ -128,7 +123,7 @@ public static function fromXML(DOMElement $xml): static $children = self::getChildElementsFromXML($xml); return new static( - $algorithm, + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), array_pop($kaNonce), array_pop($originatorKeyInfo), array_pop($recipientKeyInfo), @@ -146,7 +141,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); $this->getKANonce()?->toXML($e); diff --git a/src/XML/xenc/AbstractDHKeyValueType.php b/src/XML/xenc/AbstractDHKeyValueType.php index 2ba0144b..52517f03 100644 --- a/src/XML/xenc/AbstractDHKeyValueType.php +++ b/src/XML/xenc/AbstractDHKeyValueType.php @@ -6,12 +6,13 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{ + InvalidDOMElementException, + MissingElementException, + SchemaViolationException, + TooManyElementsException, +}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use function array_pop; diff --git a/src/XML/xenc/AbstractEncryptedType.php b/src/XML/xenc/AbstractEncryptedType.php index da8b702d..ea63c407 100644 --- a/src/XML/xenc/AbstractEncryptedType.php +++ b/src/XML/xenc/AbstractEncryptedType.php @@ -5,10 +5,11 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; use DOMElement; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XMLSecurity\Assert\Assert; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; +use function strval; + /** * Abstract class representing encrypted data. * @@ -22,26 +23,23 @@ abstract class AbstractEncryptedType extends AbstractXencElement * EncryptedData constructor. * * @param \SimpleSAML\XMLSecurity\XML\xenc\CipherData $cipherData The CipherData object of this EncryptedData. - * @param string|null $id The Id attribute of this object. Optional. - * @param string|null $type The Type attribute of this object. Optional. - * @param string|null $mimeType The MimeType attribute of this object. Optional. - * @param string|null $encoding The Encoding attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\IDValue|null $id The Id attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\AnyURIValue|null $type The Type attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\StringValue|null $mimeType The MimeType attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\AnyURIValue|null $encoding The Encoding attribute of this object. Optional. * @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod|null $encryptionMethod * The EncryptionMethod object of this EncryptedData. Optional. * @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null $keyInfo The KeyInfo object of this EncryptedData. Optional. */ public function __construct( protected CipherData $cipherData, - protected ?string $id = null, - protected ?string $type = null, - protected ?string $mimeType = null, - protected ?string $encoding = null, + protected ?IDValue $id = null, + protected ?AnyURIValue $type = null, + protected ?StringValue $mimeType = null, + protected ?AnyURIValue $encoding = null, protected ?EncryptionMethod $encryptionMethod = null, protected ?KeyInfo $keyInfo = null, ) { - Assert::nullOrValidNCName($id, SchemaViolationException::class); // Covers the empty string - Assert::nullOrValidURI($type, SchemaViolationException::class); // Covers the empty string - Assert::nullOrValidURI($encoding, SchemaViolationException::class); // Covers the empty string } @@ -59,9 +57,9 @@ public function getCipherData(): CipherData /** * Get the value of the Encoding attribute. * - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getEncoding(): ?string + public function getEncoding(): ?AnyURIValue { return $this->encoding; } @@ -81,9 +79,9 @@ public function getEncryptionMethod(): ?EncryptionMethod /** * Get the value of the Id attribute. * - * @return string + * @return \SimpleSAML\XML\Type\IDValue */ - public function getID(): ?string + public function getID(): ?IDValue { return $this->id; } @@ -103,9 +101,9 @@ public function getKeyInfo(): ?KeyInfo /** * Get the value of the MimeType attribute. * - * @return string + * @return \SimpleSAML\XML\Type\StringValue */ - public function getMimeType(): ?string + public function getMimeType(): ?StringValue { return $this->mimeType; } @@ -114,9 +112,9 @@ public function getMimeType(): ?string /** * Get the value of the Type attribute. * - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getType(): ?string + public function getType(): ?AnyURIValue { return $this->type; } @@ -131,22 +129,22 @@ public function toXML(?DOMElement $parent = null): DOMElement $id = $this->getId(); if ($id !== null) { - $e->setAttribute('Id', $id); + $e->setAttribute('Id', strval($id)); } $type = $this->getType(); if ($type !== null) { - $e->setAttribute('Type', $type); + $e->setAttribute('Type', strval($type)); } $mimeType = $this->getMimeType(); if ($mimeType !== null) { - $e->setAttribute('MimeType', $mimeType); + $e->setAttribute('MimeType', strval($mimeType)); } $encoding = $this->getEncoding(); if ($encoding !== null) { - $e->setAttribute('Encoding', $encoding); + $e->setAttribute('Encoding', strval($encoding)); } $this->getEncryptionMethod()?->toXML($e); diff --git a/src/XML/xenc/AbstractEncryptionMethod.php b/src/XML/xenc/AbstractEncryptionMethod.php index 0b386162..6550a00c 100644 --- a/src/XML/xenc/AbstractEncryptionMethod.php +++ b/src/XML/xenc/AbstractEncryptionMethod.php @@ -6,13 +6,13 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; use SimpleSAML\XML\ExtendableElementTrait; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XML\XsNamespace as NS; use function array_pop; +use function strval; /** * A class implementing the xenc:AbstractEncryptionMethod element. @@ -30,19 +30,17 @@ abstract class AbstractEncryptionMethod extends AbstractXencElement /** * EncryptionMethod constructor. * - * @param string $algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $algorithm * @param \SimpleSAML\XMLSecurity\XML\xenc\KeySize|null $keySize * @param \SimpleSAML\XMLSecurity\XML\xenc\OAEPparams|null $oaepParams * @param list<\SimpleSAML\XML\SerializableElementInterface> $children */ final public function __construct( - protected string $algorithm, + protected AnyURIValue $algorithm, protected ?KeySize $keySize = null, protected ?OAEPparams $oaepParams = null, protected array $children = [], ) { - Assert::validURI($algorithm, SchemaViolationException::class); // Covers the empty string - $this->setElements($children); } @@ -50,9 +48,9 @@ final public function __construct( /** * Get the URI identifying the algorithm used by this encryption method. * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->algorithm; } @@ -98,17 +96,18 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'EncryptionMethod', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $algorithm = self::getAttribute($xml, 'Algorithm'); - $keySize = KeySize::getChildrenOfClass($xml); Assert::maxCount($keySize, 1, TooManyElementsException::class); $oaepParams = OAEPparams::getChildrenOfClass($xml); Assert::maxCount($oaepParams, 1, TooManyElementsException::class); - $children = self::getChildElementsFromXML($xml); - - return new static($algorithm, array_pop($keySize), array_pop($oaepParams), $children); + return new static( + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), + array_pop($keySize), + array_pop($oaepParams), + self::getChildElementsFromXML($xml), + ); } @@ -121,7 +120,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); $this->getKeySize()?->toXML($e); $this->getOAEPparams()?->toXML($e); diff --git a/src/XML/xenc/AbstractEncryptionPropertiesType.php b/src/XML/xenc/AbstractEncryptionPropertiesType.php index 0c33620e..931382c3 100644 --- a/src/XML/xenc/AbstractEncryptionPropertiesType.php +++ b/src/XML/xenc/AbstractEncryptionPropertiesType.php @@ -5,13 +5,13 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; use DOMElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, SchemaViolationException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Assert\Assert; +use function strval; + /** * Class representing . * @@ -26,14 +26,13 @@ abstract class AbstractEncryptionPropertiesType extends AbstractXencElement impl * EncryptionProperty constructor. * * @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty[] $encryptionProperty - * @param string|null $Id + * @param \SimpleSAML\XML\Type\IDValue|null $Id */ final public function __construct( protected array $encryptionProperty, - protected ?string $Id = null, + protected ?IDValue $Id = null, ) { Assert::minCount($encryptionProperty, 1, MissingElementException::class); - Assert::nullOrValidNCName($Id, SchemaViolationException::class); } @@ -51,9 +50,9 @@ public function getEncryptionProperty(): array /** * Get the value of the $Id property. * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -72,7 +71,7 @@ public static function fromXML(DOMElement $xml): static return new static( EncryptionProperty::getChildrenOfClass($xml), - self::getOptionalAttribute($xml, 'Id', null), + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), ); } @@ -89,7 +88,7 @@ public function toXML(?DOMElement $parent = null): DOMElement } if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } return $e; diff --git a/src/XML/xenc/AbstractEncryptionPropertyType.php b/src/XML/xenc/AbstractEncryptionPropertyType.php index f482617c..fcbdfb8d 100644 --- a/src/XML/xenc/AbstractEncryptionPropertyType.php +++ b/src/XML/xenc/AbstractEncryptionPropertyType.php @@ -6,16 +6,15 @@ use DOMElement; use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\ExtendableAttributesTrait; -use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, SchemaViolationException}; +use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; use SimpleSAML\XML\XsNamespace as NS; use SimpleSAML\XMLSecurity\Assert\Assert; +use function strval; + /** * Class representing . * @@ -39,19 +38,17 @@ abstract class AbstractEncryptionPropertyType extends AbstractXencElement implem * EncryptionProperty constructor. * * @param \SimpleSAML\XML\SerializableElementInterface[] $children - * @param string|null $Target - * @param string|null $Id + * @param \SimpleSAML\XML\Type\AnyURIValue|null $Target + * @param \SimpleSAML\XML\Type\IDValue|null $Id * @param \SimpleSAML\XML\Attribute[] $namespacedAttributes */ final public function __construct( array $children, - protected ?string $Target = null, - protected ?string $Id = null, + protected ?AnyURIValue $Target = null, + protected ?IDValue $Id = null, array $namespacedAttributes = [], ) { Assert::minCount($children, 1, MissingElementException::class); - Assert::nullOrValidURI($Target, SchemaViolationException::class); - Assert::nullOrValidNCName($Id, SchemaViolationException::class); $this->setElements($children); $this->setAttributesNS($namespacedAttributes); @@ -61,9 +58,9 @@ final public function __construct( /** * Get the value of the $Target property. * - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getTarget(): ?string + public function getTarget(): ?AnyURIValue { return $this->Target; } @@ -72,9 +69,9 @@ public function getTarget(): ?string /** * Get the value of the $Id property. * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->Id; } @@ -93,8 +90,8 @@ public static function fromXML(DOMElement $xml): static return new static( self::getChildElementsFromXML($xml), - self::getOptionalAttribute($xml, 'Target', null), - self::getOptionalAttribute($xml, 'Id', null), + self::getOptionalAttribute($xml, 'Target', AnyURIValue::class, null), + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), self::getAttributesNSFromXML($xml), ); } @@ -108,11 +105,11 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getTarget() !== null) { - $e->setAttribute('Target', $this->getTarget()); + $e->setAttribute('Target', strval($this->getTarget())); } if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } foreach ($this->getAttributesNS() as $attr) { diff --git a/src/XML/xenc/AbstractReference.php b/src/XML/xenc/AbstractReference.php index 225fdbf1..b129b4b2 100644 --- a/src/XML/xenc/AbstractReference.php +++ b/src/XML/xenc/AbstractReference.php @@ -6,11 +6,13 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; use SimpleSAML\XML\ExtendableElementTrait; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XML\XsNamespace as NS; +use function strval; + /** * Abstract class representing references. No custom elements are allowed. * @@ -27,15 +29,13 @@ abstract class AbstractReference extends AbstractXencElement /** * AbstractReference constructor. * - * @param string $uri + * @param \SimpleSAML\XML\Type\AnyURIValue $uri * @param \SimpleSAML\XML\SerializableElementInterface[] $elements */ final public function __construct( - protected string $uri, + protected AnyURIValue $uri, array $elements = [], ) { - Assert::validURI($uri, SchemaViolationException::class); // Covers the empty string - $this->setElements($elements); } @@ -43,9 +43,9 @@ final public function __construct( /** * Get the value of the URI attribute of this reference. * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getURI(): string + public function getURI(): AnyURIValue { return $this->uri; } @@ -64,10 +64,10 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, static::getClassName(static::class), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $URI = self::getAttribute($xml, 'URI'); - $elements = self::getChildElementsFromXML($xml); - - return new static($URI, $elements); + return new static( + self::getAttribute($xml, 'URI', AnyURIValue::class), + self::getChildElementsFromXML($xml), + ); } @@ -77,7 +77,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('URI', $this->getUri()); + $e->setAttribute('URI', strval($this->getUri())); foreach ($this->getElements() as $elt) { $elt->toXML($e); diff --git a/src/XML/xenc/CarriedKeyName.php b/src/XML/xenc/CarriedKeyName.php index 438f1289..3e601443 100644 --- a/src/XML/xenc/CarriedKeyName.php +++ b/src/XML/xenc/CarriedKeyName.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a xenc:CarriedKeyName element. @@ -13,14 +14,8 @@ */ final class CarriedKeyName extends AbstractXencElement { - use StringElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = StringValue::class; } diff --git a/src/XML/xenc/CipherData.php b/src/XML/xenc/CipherData.php index 01067fdb..aec58726 100644 --- a/src/XML/xenc/CipherData.php +++ b/src/XML/xenc/CipherData.php @@ -6,10 +6,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use function array_pop; diff --git a/src/XML/xenc/CipherReference.php b/src/XML/xenc/CipherReference.php index 2b83c989..f7737603 100644 --- a/src/XML/xenc/CipherReference.php +++ b/src/XML/xenc/CipherReference.php @@ -7,12 +7,13 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XMLSecurity\XML\xenc\Transforms; +use function strval; + /** * Class representing a CipherReference. * @@ -25,14 +26,13 @@ final class CipherReference extends AbstractXencElement implements SchemaValidat /** * AbstractReference constructor. * - * @param string $uri + * @param \SimpleSAML\XML\Type\AnyURIValue $uri * @param \SimpleSAML\XMLSecurity\XML\xenc\Transforms[] $transforms */ final public function __construct( - protected string $uri, + protected AnyURIValue $uri, protected array $transforms = [], ) { - Assert::validURI($uri, SchemaViolationException::class); // Covers the empty string Assert::maxCount($transforms, C::UNBOUNDED_LIMIT); Assert::allIsInstanceOf($transforms, Transforms::class, SchemaViolationException::class); } @@ -41,9 +41,9 @@ final public function __construct( /** * Get the value of the URI attribute of this reference. * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getURI(): string + public function getURI(): AnyURIValue { return $this->uri; } @@ -62,10 +62,10 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, static::getClassName(static::class), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $URI = self::getAttribute($xml, 'URI'); - $transforms = Transforms::getChildrenOfClass($xml); - - return new static($URI, $transforms); + return new static( + self::getAttribute($xml, 'URI', AnyURIValue::class), + Transforms::getChildrenOfClass($xml), + ); } @@ -75,7 +75,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('URI', $this->getUri()); + $e->setAttribute('URI', strval($this->getUri())); foreach ($this->transforms as $transforms) { $transforms->toXML($e); diff --git a/src/XML/xenc/CipherValue.php b/src/XML/xenc/CipherValue.php index 491a6cec..2a5a848e 100644 --- a/src/XML/xenc/CipherValue.php +++ b/src/XML/xenc/CipherValue.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a xenc:CipherValue element. @@ -13,14 +14,8 @@ */ final class CipherValue extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/xenc/EncryptedData.php b/src/XML/xenc/EncryptedData.php index 317e573a..168ab69e 100644 --- a/src/XML/xenc/EncryptedData.php +++ b/src/XML/xenc/EncryptedData.php @@ -6,14 +6,10 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\xenc\CipherData; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod; use function array_pop; @@ -75,10 +71,10 @@ final public static function fromXML(DOMElement $xml): static return new static( $cipherData[0], - self::getOptionalAttribute($xml, 'Id', null), - self::getOptionalAttribute($xml, 'Type', null), - self::getOptionalAttribute($xml, 'MimeType', null), - self::getOptionalAttribute($xml, 'Encoding', null), + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), + self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null), + self::getOptionalAttribute($xml, 'MimeType', StringValue::class, null), + self::getOptionalAttribute($xml, 'Encoding', AnyURIValue::class, null), array_pop($encryptionMethod), array_pop($keyInfo), ); diff --git a/src/XML/xenc/EncryptedKey.php b/src/XML/xenc/EncryptedKey.php index 7acd86d1..11840fe6 100644 --- a/src/XML/xenc/EncryptedKey.php +++ b/src/XML/xenc/EncryptedKey.php @@ -6,15 +6,16 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; use SimpleSAML\XMLSecurity\Key\KeyInterface; use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; +use function strval; + /** * Class representing an encrypted key. * @@ -28,11 +29,11 @@ final class EncryptedKey extends AbstractEncryptedType implements SchemaValidata * EncryptedKey constructor. * * @param \SimpleSAML\XMLSecurity\XML\xenc\CipherData $cipherData The CipherData object of this EncryptedData. - * @param string|null $id The Id attribute of this object. Optional. - * @param string|null $type The Type attribute of this object. Optional. - * @param string|null $mimeType The MimeType attribute of this object. Optional. - * @param string|null $encoding The Encoding attribute of this object. Optional. - * @param string|null $recipient The Recipient attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\IDValue|null $id The Id attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\AnyURIValue|null $type The Type attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\StringValue|null $mimeType The MimeType attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\AnyURIValue|null $encoding The Encoding attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\StringValue|null $recipient The Recipient attribute of this object. Optional. * @param \SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName|null $carriedKeyName * The value of the CarriedKeyName element of this EncryptedData. * @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod|null $encryptionMethod @@ -43,11 +44,11 @@ final class EncryptedKey extends AbstractEncryptedType implements SchemaValidata */ final public function __construct( CipherData $cipherData, - ?string $id = null, - ?string $type = null, - ?string $mimeType = null, - ?string $encoding = null, - protected ?string $recipient = null, + ?IDValue $id = null, + ?AnyURIValue $type = null, + ?StringValue $mimeType = null, + ?AnyURIValue $encoding = null, + protected ?StringValue $recipient = null, protected ?CarriedKeyName $carriedKeyName = null, ?EncryptionMethod $encryptionMethod = null, ?KeyInfo $keyInfo = null, @@ -71,9 +72,9 @@ public function getCarriedKeyName(): ?CarriedKeyName /** * Get the value of the Recipient attribute. * - * @return string|null + * @return \SimpleSAML\XML\Type\StringValue|null */ - public function getRecipient(): ?string + public function getRecipient(): ?StringValue { return $this->recipient; } @@ -112,7 +113,7 @@ public function decrypt(EncryptionAlgorithmInterface $decryptor): string InvalidArgumentException::class, ); - return $decryptor->decrypt(base64_decode($cipherValue->getContent(), true)); + return $decryptor->decrypt(base64_decode($cipherValue->getContent()->getValue(), true)); } @@ -123,11 +124,11 @@ public function decrypt(EncryptionAlgorithmInterface $decryptor): string * @param \SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface $encryptor The encryptor to use. * @param \SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod $encryptionMethod * The EncryptionMethod object of this EncryptedData. Optional. - * @param string|null $id The Id attribute of this object. Optional. - * @param string|null $type The Type attribute of this object. Optional. - * @param string|null $mimeType The MimeType attribute of this object. Optional. - * @param string|null $encoding The Encoding attribute of this object. Optional. - * @param string|null $recipient The Recipient attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\IDValue|null $id The Id attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\AnyURIValue|null $type The Type attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\StringValue|null $mimeType The MimeType attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\AnyURIValue|null $encoding The Encoding attribute of this object. Optional. + * @param \SimpleSAML\XML\Type\StringValue|null $recipient The Recipient attribute of this object. Optional. * @param \SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName|null $carriedKeyName * The value of the CarriedKeyName element of this EncryptedData. * @param \SimpleSAML\XMLSecurity\XML\ds\KeyInfo|null $keyInfo The KeyInfo object of this EncryptedData. Optional. @@ -140,18 +141,18 @@ public static function fromKey( KeyInterface $keyToEncrypt, EncryptionAlgorithmInterface $encryptor, EncryptionMethod $encryptionMethod, - ?string $id = null, - ?string $type = null, - ?string $mimeType = null, - ?string $encoding = null, - ?string $recipient = null, + ?IDValue $id = null, + ?AnyURIValue $type = null, + ?StringValue $mimeType = null, + ?AnyURIValue $encoding = null, + ?StringValue $recipient = null, ?CarriedKeyName $carriedKeyName = null, ?KeyInfo $keyInfo = null, ?ReferenceList $referenceList = null, ): EncryptedKey { Assert::eq( $encryptor->getAlgorithmId(), - $encryptionMethod->getAlgorithm(), + $encryptionMethod->getAlgorithm()->getValue(), 'Encryptor algorithm and encryption method do not match.', InvalidArgumentException::class, ); @@ -159,9 +160,9 @@ public static function fromKey( return new self( new CipherData( new CipherValue( - base64_encode( + Base64BinaryValue::fromString(base64_encode( $encryptor->encrypt($keyToEncrypt->getMaterial()), - ), + )), ), ), $id, @@ -230,11 +231,11 @@ public static function fromXML(DOMElement $xml): static return new static( $cipherData[0], - self::getOptionalAttribute($xml, 'Id', null), - self::getOptionalAttribute($xml, 'Type', null), - self::getOptionalAttribute($xml, 'MimeType', null), - self::getOptionalAttribute($xml, 'Encoding', null), - self::getOptionalAttribute($xml, 'Recipient', null), + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), + self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null), + self::getOptionalAttribute($xml, 'MimeType', StringValue::class, null), + self::getOptionalAttribute($xml, 'Encoding', AnyURIValue::class, null), + self::getOptionalAttribute($xml, 'Recipient', StringValue::class, null), array_pop($carriedKeyNames), array_pop($encryptionMethod), array_pop($keyInfo), @@ -251,7 +252,7 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = parent::toXML($parent); if ($this->getRecipient() !== null) { - $e->setAttribute('Recipient', $this->getRecipient()); + $e->setAttribute('Recipient', strval($this->getRecipient())); } $this->getReferenceList()?->toXML($e); diff --git a/src/XML/xenc/Generator.php b/src/XML/xenc/Generator.php index 7adba9d2..3f07a5a5 100644 --- a/src/XML/xenc/Generator.php +++ b/src/XML/xenc/Generator.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a xenc:Generator element. @@ -13,14 +14,8 @@ */ final class Generator extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/xenc/KANonce.php b/src/XML/xenc/KANonce.php index 44e72e2a..086b313f 100644 --- a/src/XML/xenc/KANonce.php +++ b/src/XML/xenc/KANonce.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a xenc:KA-Nonce element. @@ -13,17 +14,11 @@ */ final class KANonce extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; /** @var string */ - public const LOCALNAME = 'KA-Nonce'; - + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const LOCALNAME = 'KA-Nonce'; } diff --git a/src/XML/xenc/KeySize.php b/src/XML/xenc/KeySize.php index c0864922..ac9f9000 100644 --- a/src/XML/xenc/KeySize.php +++ b/src/XML/xenc/KeySize.php @@ -4,10 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\KeySizeValue; /** * Class representing a xenc:KeySize element. @@ -16,55 +14,8 @@ */ final class KeySize extends AbstractXencElement { - /** - * @param int $keySize - */ - public function __construct( - protected int $keySize, - ) { - Assert::positiveInteger($keySize, SchemaViolationException::class); - } + use TypedTextContentTrait; - - /** - * @return int - */ - public function getKeySize(): int - { - return $this->keySize; - } - - - /** - * Convert XML into a class instance - * - * @param \DOMElement $xml The XML element we should load - * @return static - * - * @throws \SimpleSAML\XML\Exception\InvalidDOMElementException - * If the qualified name of the supplied element is wrong - */ - public static function fromXML(DOMElement $xml): static - { - Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); - Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - Assert::numeric($xml->textContent); - - return new static(intval($xml->textContent)); - } - - - /** - * Convert this element to XML. - * - * @param \DOMElement|null $parent The element we should append this element to. - * @return \DOMElement - */ - public function toXML(?DOMElement $parent = null): DOMElement - { - $e = $this->instantiateParentElement($parent); - $e->textContent = strval($this->getKeySize()); - - return $e; - } + /** @var string */ + public const TEXTCONTENT_TYPE = KeySizeValue::class; } diff --git a/src/XML/xenc/OAEPparams.php b/src/XML/xenc/OAEPparams.php index d3808656..109c9068 100644 --- a/src/XML/xenc/OAEPparams.php +++ b/src/XML/xenc/OAEPparams.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a xenc:OAEPparams element. @@ -13,14 +14,8 @@ */ final class OAEPparams extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/src/XML/xenc/OriginatorKeyInfo.php b/src/XML/xenc/OriginatorKeyInfo.php index 0baca4ab..2b478451 100644 --- a/src/XML/xenc/OriginatorKeyInfo.php +++ b/src/XML/xenc/OriginatorKeyInfo.php @@ -7,15 +7,18 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType; -use SimpleSAML\XMLSecurity\XML\ds\KeyName; -use SimpleSAML\XMLSecurity\XML\ds\KeyValue; -use SimpleSAML\XMLSecurity\XML\ds\MgmtData; -use SimpleSAML\XMLSecurity\XML\ds\PGPData; -use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod; -use SimpleSAML\XMLSecurity\XML\ds\SPKIData; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; +use SimpleSAML\XMLSecurity\XML\ds\{ + AbstractKeyInfoType, + KeyName, + KeyValue, + MgmtData, + PGPData, + RetrievalMethod, + SPKIData, + X509Data, +}; use function array_merge; @@ -47,8 +50,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'OriginatorKeyInfo', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, OriginatorKeyInfo::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); - $keyName = KeyName::getChildrenOfClass($xml); $keyValue = KeyValue::getChildrenOfClass($xml); $retrievalMethod = RetrievalMethod::getChildrenOfClass($xml); @@ -69,6 +70,9 @@ public static function fromXML(DOMElement $xml): static $other, ); - return new static($info, $Id); + return new static( + $info, + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), + ); } } diff --git a/src/XML/xenc/P.php b/src/XML/xenc/P.php index a9f4a530..ca057bb3 100644 --- a/src/XML/xenc/P.php +++ b/src/XML/xenc/P.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a xenc:P element. @@ -13,14 +14,8 @@ */ final class P extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/xenc/PgenCounter.php b/src/XML/xenc/PgenCounter.php index 5350a3c4..91c8664e 100644 --- a/src/XML/xenc/PgenCounter.php +++ b/src/XML/xenc/PgenCounter.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a xenc:pgenCounter element. @@ -13,17 +14,11 @@ */ final class PgenCounter extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; /** @var string */ - public const LOCALNAME = 'pgenCounter'; - + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const LOCALNAME = 'pgenCounter'; } diff --git a/src/XML/xenc/Q.php b/src/XML/xenc/Q.php index 379ecb54..c1e04c91 100644 --- a/src/XML/xenc/Q.php +++ b/src/XML/xenc/Q.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a xenc:Q element. @@ -13,14 +14,8 @@ */ final class Q extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; } diff --git a/src/XML/xenc/RecipientKeyInfo.php b/src/XML/xenc/RecipientKeyInfo.php index d3a9f9b8..d93c4c80 100644 --- a/src/XML/xenc/RecipientKeyInfo.php +++ b/src/XML/xenc/RecipientKeyInfo.php @@ -7,15 +7,18 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType; -use SimpleSAML\XMLSecurity\XML\ds\KeyName; -use SimpleSAML\XMLSecurity\XML\ds\KeyValue; -use SimpleSAML\XMLSecurity\XML\ds\MgmtData; -use SimpleSAML\XMLSecurity\XML\ds\PGPData; -use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod; -use SimpleSAML\XMLSecurity\XML\ds\SPKIData; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; +use SimpleSAML\XMLSecurity\XML\ds\{ + AbstractKeyInfoType, + KeyName, + KeyValue, + MgmtData, + PGPData, + RetrievalMethod, + SPKIData, + X509Data, +}; use function array_merge; @@ -47,8 +50,6 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'RecipientKeyInfo', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, RecipientKeyInfo::NS, InvalidDOMElementException::class); - $Id = self::getOptionalAttribute($xml, 'Id', null); - $keyName = KeyName::getChildrenOfClass($xml); $keyValue = KeyValue::getChildrenOfClass($xml); $retrievalMethod = RetrievalMethod::getChildrenOfClass($xml); @@ -69,6 +70,9 @@ public static function fromXML(DOMElement $xml): static $other, ); - return new static($info, $Id); + return new static( + $info, + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), + ); } } diff --git a/src/XML/xenc/ReferenceList.php b/src/XML/xenc/ReferenceList.php index 152e008e..f4142dc2 100644 --- a/src/XML/xenc/ReferenceList.php +++ b/src/XML/xenc/ReferenceList.php @@ -7,10 +7,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; use function array_merge; diff --git a/src/XML/xenc/Seed.php b/src/XML/xenc/Seed.php index 7eb7823a..652c1cf1 100644 --- a/src/XML/xenc/Seed.php +++ b/src/XML/xenc/Seed.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a xenc:seed element. @@ -13,17 +14,11 @@ */ final class Seed extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; /** @var string */ - public const LOCALNAME = 'seed'; - + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const LOCALNAME = 'seed'; } diff --git a/src/XML/xenc/XencPublic.php b/src/XML/xenc/XencPublic.php index d8169c0e..678d7a6d 100644 --- a/src/XML/xenc/XencPublic.php +++ b/src/XML/xenc/XencPublic.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\TypedTextContentTrait; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; /** * Class representing a xenc:Public element. @@ -13,17 +14,11 @@ */ final class XencPublic extends AbstractXencElement { - use Base64ElementTrait; + use TypedTextContentTrait; /** @var string */ - public const LOCALNAME = 'Public'; - + public const TEXTCONTENT_TYPE = CryptoBinaryValue::class; - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const LOCALNAME = 'Public'; } diff --git a/src/XML/xenc11/AbstractAlgorithmIdentifierType.php b/src/XML/xenc11/AbstractAlgorithmIdentifierType.php index 64cda62c..ed149dfc 100644 --- a/src/XML/xenc11/AbstractAlgorithmIdentifierType.php +++ b/src/XML/xenc11/AbstractAlgorithmIdentifierType.php @@ -5,8 +5,9 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; use DOMElement; -use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Type\AnyURIValue; + +use function strval; /** * Class representing . @@ -18,23 +19,22 @@ abstract class AbstractAlgorithmIdentifierType extends AbstractXenc11Element /** * AlgorithmIdentifierType constructor. * - * @param string $Algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm * @param \SimpleSAML\XMLSecurity\XML\xenc11\Parameters|null $parameters */ public function __construct( - protected string $Algorithm, + protected AnyURIValue $Algorithm, protected ?Parameters $parameters = null, ) { - Assert::validURI($Algorithm, SchemaViolationException::class); } /** * Get the value of the $Algorithm property. * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->Algorithm; } @@ -57,7 +57,7 @@ public function getParameters(): ?Parameters public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); if ($this->getParameters() !== null) { if (!$this->getParameters()->isEmptyElement()) { diff --git a/src/XML/xenc11/AbstractConcatKDFParamsType.php b/src/XML/xenc11/AbstractConcatKDFParamsType.php index 441f9957..e0829124 100644 --- a/src/XML/xenc11/AbstractConcatKDFParamsType.php +++ b/src/XML/xenc11/AbstractConcatKDFParamsType.php @@ -5,16 +5,19 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; use DOMElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{ + InvalidDOMElementException, + MissingElementException, + SchemaViolationException, + TooManyElementsException, +}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\HexBinaryValue; use SimpleSAML\XMLSecurity\Assert\Assert; use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; use function array_pop; +use function strval; /** * Class representing . @@ -30,25 +33,20 @@ abstract class AbstractConcatKDFParamsType extends AbstractXenc11Element impleme * ConcatKDFParams constructor. * * @param \SimpleSAML\XMLSecurity\XML\ds\DigestMethod $digestMethod - * @param string|null $AlgorithmID - * @param string|null $PartyUInfo - * @param string|null $PartyVInfo - * @param string|null $SuppPubInfo - * @param string|null $SuppPrivInfo + * @param \SimpleSAML\XML\Type\HexBinaryValue|null $AlgorithmID + * @param \SimpleSAML\XML\Type\HexBinaryValue|null $PartyUInfo + * @param \SimpleSAML\XML\Type\HexBinaryValue|null $PartyVInfo + * @param \SimpleSAML\XML\Type\HexBinaryValue|null $SuppPubInfo + * @param \SimpleSAML\XML\Type\HexBinaryValue|null $SuppPrivInfo */ final public function __construct( protected DigestMethod $digestMethod, - protected ?string $AlgorithmID = null, - protected ?string $PartyUInfo = null, - protected ?string $PartyVInfo = null, - protected ?string $SuppPubInfo = null, - protected ?string $SuppPrivInfo = null, + protected ?HexBinaryValue $AlgorithmID = null, + protected ?HexBinaryValue $PartyUInfo = null, + protected ?HexBinaryValue $PartyVInfo = null, + protected ?HexBinaryValue $SuppPubInfo = null, + protected ?HexBinaryValue $SuppPrivInfo = null, ) { - Assert::validHexBinary($AlgorithmID, SchemaViolationException::class); - Assert::validHexBinary($PartyUInfo, SchemaViolationException::class); - Assert::validHexBinary($PartyVInfo, SchemaViolationException::class); - Assert::validHexBinary($SuppPubInfo, SchemaViolationException::class); - Assert::validHexBinary($SuppPrivInfo, SchemaViolationException::class); } @@ -66,9 +64,9 @@ public function getDigestMethod(): DigestMethod /** * Get the value of the $AlgorithmID property. * - * @return string|null + * @return \SimpleSAML\XML\Type\HexBinaryValue|null */ - public function getAlgorithmID(): ?string + public function getAlgorithmID(): ?HexBinaryValue { return $this->AlgorithmID; } @@ -77,9 +75,9 @@ public function getAlgorithmID(): ?string /** * Get the value of the $PartyUInfo property. * - * @return string|null + * @return \SimpleSAML\XML\Type\HexBinaryValue|null */ - public function getPartyUInfo(): ?string + public function getPartyUInfo(): ?HexBinaryValue { return $this->PartyUInfo; } @@ -88,9 +86,9 @@ public function getPartyUInfo(): ?string /** * Get the value of the $PartyVInfo property. * - * @return string|null + * @return \SimpleSAML\XML\Type\HexBinaryValue|null */ - public function getPartyVInfo(): ?string + public function getPartyVInfo(): ?HexBinaryValue { return $this->PartyVInfo; } @@ -99,9 +97,9 @@ public function getPartyVInfo(): ?string /** * Get the value of the $SuppPubInfo property. * - * @return string|null + * @return \SimpleSAML\XML\Type\HexBinaryValue|null */ - public function getSuppPubInfo(): ?string + public function getSuppPubInfo(): ?HexBinaryValue { return $this->SuppPubInfo; } @@ -110,9 +108,9 @@ public function getSuppPubInfo(): ?string /** * Get the value of the $SuppPrivInfo property. * - * @return string|null + * @return \SimpleSAML\XML\Type\HexBinaryValue|null */ - public function getSuppPrivInfo(): ?string + public function getSuppPrivInfo(): ?HexBinaryValue { return $this->SuppPrivInfo; } @@ -135,11 +133,11 @@ public static function fromXML(DOMElement $xml): static return new static( array_pop($digestMethod), - self::getOptionalAttribute($xml, 'AlgorithmID', null), - self::getOptionalAttribute($xml, 'PartyUInfo', null), - self::getOptionalAttribute($xml, 'PartyVInfo', null), - self::getOptionalAttribute($xml, 'SuppPubInfo', null), - self::getOptionalAttribute($xml, 'SuppPrivInfo', null), + self::getOptionalAttribute($xml, 'AlgorithmID', HexBinaryValue::class, null), + self::getOptionalAttribute($xml, 'PartyUInfo', HexBinaryValue::class, null), + self::getOptionalAttribute($xml, 'PartyVInfo', HexBinaryValue::class, null), + self::getOptionalAttribute($xml, 'SuppPubInfo', HexBinaryValue::class, null), + self::getOptionalAttribute($xml, 'SuppPrivInfo', HexBinaryValue::class, null), ); } @@ -152,23 +150,23 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getAlgorithmID() !== null) { - $e->setAttribute('AlgorithmID', $this->getAlgorithmID()); + $e->setAttribute('AlgorithmID', strval($this->getAlgorithmID())); } if ($this->getPartyUInfo() !== null) { - $e->setAttribute('PartyUInfo', $this->getPartyUInfo()); + $e->setAttribute('PartyUInfo', strval($this->getPartyUInfo())); } if ($this->getPartyVInfo() !== null) { - $e->setAttribute('PartyVInfo', $this->getPartyVInfo()); + $e->setAttribute('PartyVInfo', strval($this->getPartyVInfo())); } if ($this->getSuppPubInfo() !== null) { - $e->setAttribute('SuppPubInfo', $this->getSuppPubInfo()); + $e->setAttribute('SuppPubInfo', strval($this->getSuppPubInfo())); } if ($this->getSuppPrivInfo() !== null) { - $e->setAttribute('SuppPrivInfo', $this->getSuppPrivInfo()); + $e->setAttribute('SuppPrivInfo', strval($this->getSuppPrivInfo())); } $this->getDigestMethod()->toXML($e); diff --git a/src/XML/xenc11/AbstractDerivedKeyType.php b/src/XML/xenc11/AbstractDerivedKeyType.php index 3db1febf..e69d9733 100644 --- a/src/XML/xenc11/AbstractDerivedKeyType.php +++ b/src/XML/xenc11/AbstractDerivedKeyType.php @@ -5,15 +5,14 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; use DOMElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Assert\Assert; use SimpleSAML\XMLSecurity\XML\xenc\ReferenceList; use function array_pop; +use function strval; /** * Class representing . @@ -28,34 +27,32 @@ abstract class AbstractDerivedKeyType extends AbstractXenc11Element implements /** * DerivedKey constructor. * - * @param string|null $recipient - * @param string|null $id - * @param string|null $type + * @param \SimpleSAML\XML\Type\StringValue|null $recipient + * @param \SimpleSAML\XML\Type\IDValue|null $id + * @param \SimpleSAML\XML\Type\AnyURIValue|null $type * @param \SimpleSAML\XMLSecurity\XML\xenc11\KeyDerivationMethod|null $keyDerivationMethod * @param \SimpleSAML\XMLSecurity\XML\xenc\ReferenceList|null $referenceList * @param \SimpleSAML\XMLSecurity\XML\xenc11\DerivedKeyName|null $derivedKeyName * @param \SimpleSAML\XMLSecurity\XML\xenc11\MasterKeyName|null $masterKeyName */ final public function __construct( - protected ?string $recipient = null, - protected ?string $id = null, - protected ?string $type = null, + protected ?StringValue $recipient = null, + protected ?IDValue $id = null, + protected ?AnyURIValue $type = null, protected ?KeyDerivationMethod $keyDerivationMethod = null, protected ?ReferenceList $referenceList = null, protected ?DerivedKeyName $derivedKeyName = null, protected ?MasterKeyName $masterKeyName = null, ) { - Assert::nullOrValidNCName($id, SchemaViolationException::class); - Assert::nullOrValidURI($type, SchemaViolationException::class); } /** * Get the value of the $recipient property. * - * @return string|null + * @return \SimpleSAML\XML\Type\StringValue|null */ - public function getRecipient(): ?string + public function getRecipient(): ?StringValue { return $this->recipient; } @@ -64,9 +61,9 @@ public function getRecipient(): ?string /** * Get the value of the $id property. * - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->id; } @@ -75,9 +72,9 @@ public function getId(): ?string /** * Get the value of the $type property. * - * @return string|null + * @return \SimpleSAML\XML\Type\AnyURIValue|null */ - public function getType(): ?string + public function getType(): ?AnyURIValue { return $this->type; } @@ -168,9 +165,9 @@ public static function fromXML(DOMElement $xml): static Assert::maxCount($masterKeyName, 1, TooManyElementsException::class); return new static( - self::getOptionalAttribute($xml, 'Recipient', null), - self::getOptionalAttribute($xml, 'Id', null), - self::getOptionalAttribute($xml, 'Type', null), + self::getOptionalAttribute($xml, 'Recipient', StringValue::class, null), + self::getOptionalAttribute($xml, 'Id', IDValue::class, null), + self::getOptionalAttribute($xml, 'Type', AnyURIValue::class, null), array_pop($keyDerivationMethod), array_pop($referenceList), array_pop($derivedKeyName), @@ -187,15 +184,15 @@ public function toXML(?DOMElement $parent = null): DOMElement $e = $this->instantiateParentElement($parent); if ($this->getRecipient() !== null) { - $e->setAttribute('Recipient', $this->getRecipient()); + $e->setAttribute('Recipient', strval($this->getRecipient())); } if ($this->getId() !== null) { - $e->setAttribute('Id', $this->getId()); + $e->setAttribute('Id', strval($this->getId())); } if ($this->getType() !== null) { - $e->setAttribute('Type', $this->getType()); + $e->setAttribute('Type', strval($this->getType())); } $this->getKeyDerivationMethod()?->toXML($e); diff --git a/src/XML/xenc11/AbstractKeyDerivationMethodType.php b/src/XML/xenc11/AbstractKeyDerivationMethodType.php index ce9d3aee..00c54b60 100644 --- a/src/XML/xenc11/AbstractKeyDerivationMethodType.php +++ b/src/XML/xenc11/AbstractKeyDerivationMethodType.php @@ -6,13 +6,14 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; use SimpleSAML\XML\ExtendableElementTrait; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XML\XsNamespace as NS; +use function strval; + /** * Class representing . * @@ -31,15 +32,13 @@ abstract class AbstractKeyDerivationMethodType extends AbstractXenc11Element imp /** * KeyDerivationMethod constructor. * - * @param string $Algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm * @param \SimpleSAML\XML\SerializableElementInterface[] $children */ final public function __construct( - protected string $Algorithm, + protected AnyURIValue $Algorithm, array $children, ) { - Assert::validURI($Algorithm, SchemaViolationException::class); - $this->setElements($children); } @@ -47,9 +46,9 @@ final public function __construct( /** * Get the value of the $Algorithm property. * - * @return string + * @return \SimpleSAML\XML\Type\AnyURIValue */ - public function getAlgorithm(): string + public function getAlgorithm(): AnyURIValue { return $this->Algorithm; } @@ -67,7 +66,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); return new static( - self::getOptionalAttribute($xml, 'Algorithm', null), + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), self::getChildElementsFromXML($xml), ); } @@ -79,7 +78,7 @@ public static function fromXML(DOMElement $xml): static public function toXML(?DOMElement $parent = null): DOMElement { $e = $this->instantiateParentElement($parent); - $e->setAttribute('Algorithm', $this->getAlgorithm()); + $e->setAttribute('Algorithm', strval($this->getAlgorithm())); foreach ($this->getElements() as $child) { if (!$child->isEmptyElement()) { diff --git a/src/XML/xenc11/AbstractMGFType.php b/src/XML/xenc11/AbstractMGFType.php index fea748bf..09d85e99 100644 --- a/src/XML/xenc11/AbstractMGFType.php +++ b/src/XML/xenc11/AbstractMGFType.php @@ -4,8 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; +use SimpleSAML\XML\Type\AnyURIValue; /** * Class representing . @@ -20,10 +20,10 @@ abstract class AbstractMGFType extends AbstractAlgorithmIdentifierType implement /** * MGFType constructor. * - * @param string $Algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm */ public function __construct( - string $Algorithm, + AnyURIValue $Algorithm, ) { parent::__construct($Algorithm, null); } diff --git a/src/XML/xenc11/AbstractPBKDF2ParameterType.php b/src/XML/xenc11/AbstractPBKDF2ParameterType.php index 51848bf9..1f511591 100644 --- a/src/XML/xenc11/AbstractPBKDF2ParameterType.php +++ b/src/XML/xenc11/AbstractPBKDF2ParameterType.php @@ -6,11 +6,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; -use SimpleSAML\XML\SchemaValidatableElementInterface; -use SimpleSAML\XML\SchemaValidatableElementTrait; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; +use SimpleSAML\XML\{SchemaValidatableElementInterface, SchemaValidatableElementTrait}; use function array_pop; diff --git a/src/XML/xenc11/AbstractPRFAlgorithmIdentifierType.php b/src/XML/xenc11/AbstractPRFAlgorithmIdentifierType.php index a3f73576..0ce7eac0 100644 --- a/src/XML/xenc11/AbstractPRFAlgorithmIdentifierType.php +++ b/src/XML/xenc11/AbstractPRFAlgorithmIdentifierType.php @@ -4,6 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; +use SimpleSAML\XML\Type\AnyURIValue; + /** * Class representing . * @@ -14,10 +16,10 @@ abstract class AbstractPRFAlgorithmIdentifierType extends AbstractAlgorithmIdent /** * AlgorithmPRFIdentifierType constructor. * - * @param string $Algorithm + * @param \SimpleSAML\XML\Type\AnyURIValue $Algorithm */ public function __construct( - string $Algorithm, + AnyURIValue $Algorithm, ) { parent::__construct($Algorithm, null); } diff --git a/src/XML/xenc11/DerivedKeyName.php b/src/XML/xenc11/DerivedKeyName.php index c51908b3..6c7ea8b5 100644 --- a/src/XML/xenc11/DerivedKeyName.php +++ b/src/XML/xenc11/DerivedKeyName.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a xenc11:DerivedKeyName element. @@ -13,14 +14,8 @@ */ final class DerivedKeyName extends AbstractXenc11Element { - use StringElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = StringValue::class; } diff --git a/src/XML/xenc11/IterationCount.php b/src/XML/xenc11/IterationCount.php index f57fa2a3..ae219cd5 100644 --- a/src/XML/xenc11/IterationCount.php +++ b/src/XML/xenc11/IterationCount.php @@ -6,10 +6,9 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; +use SimpleSAML\XML\Type\PositiveIntegerValue; -use function intval; use function strval; /** @@ -20,19 +19,18 @@ final class IterationCount extends AbstractXenc11Element { /** - * @param int $iterationCount + * @param \SimpleSAML\XML\Type\PositiveIntegerValue $iterationCount */ public function __construct( - protected int $iterationCount, + protected PositiveIntegerValue $iterationCount, ) { - Assert::positiveInteger($iterationCount, SchemaViolationException::class); } /** - * @return int + * @return \SimpleSAML\XML\Type\PositiveIntegerValue */ - public function getIterationCount(): int + public function getIterationCount(): PositiveIntegerValue { return $this->iterationCount; } @@ -51,9 +49,10 @@ public static function fromXML(DOMElement $xml): static { Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - Assert::numeric($xml->textContent); - return new static(intval($xml->textContent)); + return new static( + PositiveIntegerValue::fromString($xml->textContent), + ); } diff --git a/src/XML/xenc11/KeyLength.php b/src/XML/xenc11/KeyLength.php index 66a42d3c..91337ffb 100644 --- a/src/XML/xenc11/KeyLength.php +++ b/src/XML/xenc11/KeyLength.php @@ -6,10 +6,9 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\SchemaViolationException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, SchemaViolationException}; +use SimpleSAML\XML\Type\PositiveIntegerValue; -use function intval; use function strval; /** @@ -20,19 +19,18 @@ final class KeyLength extends AbstractXenc11Element { /** - * @param int $keyLength + * @param \SimpleSAML\XML\Type\PositiveIntegerValue $keyLength */ public function __construct( - protected int $keyLength, + protected PositiveIntegerValue $keyLength, ) { - Assert::positiveInteger($keyLength, SchemaViolationException::class); } /** - * @return int + * @return \SimpleSAML\XML\Type\PositiveIntegerValue */ - public function getKeyLength(): int + public function getKeyLength(): PositiveIntegerValue { return $this->keyLength; } @@ -51,9 +49,10 @@ public static function fromXML(DOMElement $xml): static { Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - Assert::numeric($xml->textContent); - return new static(intval($xml->textContent)); + return new static( + PositiveIntegerValue::fromString($xml->textContent), + ); } diff --git a/src/XML/xenc11/MGF.php b/src/XML/xenc11/MGF.php index 5b34c964..3873f3a3 100644 --- a/src/XML/xenc11/MGF.php +++ b/src/XML/xenc11/MGF.php @@ -7,6 +7,7 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Type\AnyURIValue; /** * A class implementing the xenc11:MGF element. @@ -27,7 +28,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); return new static( - self::getOptionalAttribute($xml, 'Algorithm', null), + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), ); } } diff --git a/src/XML/xenc11/MasterKeyName.php b/src/XML/xenc11/MasterKeyName.php index 6f079faf..dc2c6e21 100644 --- a/src/XML/xenc11/MasterKeyName.php +++ b/src/XML/xenc11/MasterKeyName.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; -use SimpleSAML\XML\StringElementTrait; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a xenc11:MasterKeyName element. @@ -13,14 +14,8 @@ */ final class MasterKeyName extends AbstractXenc11Element { - use StringElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = StringValue::class; } diff --git a/src/XML/xenc11/OtherSource.php b/src/XML/xenc11/OtherSource.php index f3527eda..915d47ed 100644 --- a/src/XML/xenc11/OtherSource.php +++ b/src/XML/xenc11/OtherSource.php @@ -6,8 +6,8 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, TooManyElementsException}; +use SimpleSAML\XML\Type\AnyURIValue; use function array_pop; @@ -33,7 +33,7 @@ public static function fromXML(DOMElement $xml): static Assert::maxCount($parameter, 1, TooManyElementsException::class); return new static( - self::getOptionalAttribute($xml, 'Algorithm', null), + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), array_pop($parameter), ); } diff --git a/src/XML/xenc11/PRF.php b/src/XML/xenc11/PRF.php index 2705a491..6684cc28 100644 --- a/src/XML/xenc11/PRF.php +++ b/src/XML/xenc11/PRF.php @@ -7,6 +7,7 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; +use SimpleSAML\XML\Type\AnyURIValue; /** * A class implementing the xenc11:PRF element. @@ -27,7 +28,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->namespaceURI, static::getNamespaceURI(), InvalidDOMElementException::class); return new static( - self::getOptionalAttribute($xml, 'Algorithm', null), + self::getAttribute($xml, 'Algorithm', AnyURIValue::class), ); } } diff --git a/src/XML/xenc11/Parameters.php b/src/XML/xenc11/Parameters.php index 13e5da69..191df592 100644 --- a/src/XML/xenc11/Parameters.php +++ b/src/XML/xenc11/Parameters.php @@ -7,8 +7,7 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\ExtendableAttributesTrait; -use SimpleSAML\XML\ExtendableElementTrait; +use SimpleSAML\XML\{ExtendableAttributesTrait, ExtendableElementTrait}; use SimpleSAML\XML\XsNamespace as NS; /** diff --git a/src/XML/xenc11/Salt.php b/src/XML/xenc11/Salt.php index 444d75a9..e9971be3 100644 --- a/src/XML/xenc11/Salt.php +++ b/src/XML/xenc11/Salt.php @@ -6,9 +6,7 @@ use DOMElement; use SimpleSAML\Assert\Assert; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\MissingElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, MissingElementException, TooManyElementsException}; use function array_merge; use function array_pop; diff --git a/src/XML/xenc11/Specified.php b/src/XML/xenc11/Specified.php index 14ff6437..f45818a6 100644 --- a/src/XML/xenc11/Specified.php +++ b/src/XML/xenc11/Specified.php @@ -4,7 +4,8 @@ namespace SimpleSAML\XMLSecurity\XML\xenc11; -use SimpleSAML\XML\Base64ElementTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XML\TypedTextContentTrait; /** * Class representing a xenc11:Specified element. @@ -13,14 +14,8 @@ */ final class Specified extends AbstractXenc11Element { - use Base64ElementTrait; + use TypedTextContentTrait; - - /** - * @param string $content - */ - public function __construct(string $content) - { - $this->setContent($content); - } + /** @var string */ + public const TEXTCONTENT_TYPE = Base64BinaryValue::class; } diff --git a/tests/Assert/CryptoBinaryTest.php b/tests/Assert/CryptoBinaryTest.php new file mode 100644 index 00000000..ce61739f --- /dev/null +++ b/tests/Assert/CryptoBinaryTest.php @@ -0,0 +1,48 @@ +assertTrue($shouldPass); + } catch (AssertionFailedException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideCryptoBinary(): array + { + return [ + 'empty' => [false, ''], + 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], + 'illegal characters' => [false, '&*$(#&^@!(^%$'], + 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], + ]; + } +} diff --git a/tests/Assert/DigestValueTest.php b/tests/Assert/DigestValueTest.php new file mode 100644 index 00000000..9f08553e --- /dev/null +++ b/tests/Assert/DigestValueTest.php @@ -0,0 +1,48 @@ +assertTrue($shouldPass); + } catch (AssertionFailedException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideDigestValue(): array + { + return [ + 'empty' => [false, ''], + 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], + 'illegal characters' => [false, '&*$(#&^@!(^%$'], + 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], + ]; + } +} diff --git a/tests/Assert/ECPointTest.php b/tests/Assert/ECPointTest.php new file mode 100644 index 00000000..c74da26d --- /dev/null +++ b/tests/Assert/ECPointTest.php @@ -0,0 +1,48 @@ +assertTrue($shouldPass); + } catch (AssertionFailedException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideECPoint(): array + { + return [ + 'empty' => [false, ''], + 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], + 'illegal characters' => [false, '&*$(#&^@!(^%$'], + 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], + ]; + } +} diff --git a/tests/Assert/HMACOutputLengthTest.php b/tests/Assert/HMACOutputLengthTest.php new file mode 100644 index 00000000..ffe6af74 --- /dev/null +++ b/tests/Assert/HMACOutputLengthTest.php @@ -0,0 +1,54 @@ +assertTrue($shouldPass); + } catch (SchemaViolationException | ProtocolViolationException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideHMACOutputLength(): array + { + return [ + 'empty' => [false, ''], + 'valid positive integer' => [true, '128'], + 'invalid indivisible by 8' => [false, '4'], + 'invalid signed positive integer' => [false, '+128'], + 'invalid zero' => [false, '0'], + 'invalid leading zeros' => [false, '0000000000000000000128'], + 'invalid with fractional' => [false, '1.'], + 'invalid negative' => [false, '-128'], + 'invalid with thousands-delimiter' => [false, '1,28'], + ]; + } +} diff --git a/tests/Assert/KeySizeTest.php b/tests/Assert/KeySizeTest.php new file mode 100644 index 00000000..b6590d02 --- /dev/null +++ b/tests/Assert/KeySizeTest.php @@ -0,0 +1,52 @@ +assertTrue($shouldPass); + } catch (AssertionFailedException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideKeySize(): array + { + return [ + 'empty' => [false, ''], + 'valid positive integer' => [true, '123456'], + 'invalid signed positive integer' => [false, '+123456'], + 'invalid zero' => [false, '0'], + 'invalid leading zeros' => [false, '0000000000000000000005'], + 'invalid with fractional' => [false, '1.'], + 'invalid negative' => [false, '-1234'], + 'invalid with thousands-delimiter' => [false, '1,234'], + ]; + } +} diff --git a/tests/Type/CryptoBinaryValueTest.php b/tests/Type/CryptoBinaryValueTest.php new file mode 100644 index 00000000..4cc9db28 --- /dev/null +++ b/tests/Type/CryptoBinaryValueTest.php @@ -0,0 +1,49 @@ +assertTrue($shouldPass); + } catch (SchemaViolationException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideCryptoBinary(): array + { + return [ + 'empty' => [false, ''], + 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], + 'illegal characters' => [false, '&*$(#&^@!(^%$'], + 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], + ]; + } +} diff --git a/tests/Type/DigestValueTest.php b/tests/Type/DigestValueTest.php new file mode 100644 index 00000000..6ce40b23 --- /dev/null +++ b/tests/Type/DigestValueTest.php @@ -0,0 +1,49 @@ +assertTrue($shouldPass); + } catch (SchemaViolationException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideDigestValue(): array + { + return [ + 'empty' => [false, ''], + 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], + 'illegal characters' => [false, '&*$(#&^@!(^%$'], + 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], + ]; + } +} diff --git a/tests/Type/ECPointValueTest.php b/tests/Type/ECPointValueTest.php new file mode 100644 index 00000000..a865e1e3 --- /dev/null +++ b/tests/Type/ECPointValueTest.php @@ -0,0 +1,49 @@ +assertTrue($shouldPass); + } catch (SchemaViolationException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideECPointValue(): array + { + return [ + 'empty' => [false, ''], + 'valid' => [true, 'U2ltcGxlU0FNTHBocA=='], + 'illegal characters' => [false, '&*$(#&^@!(^%$'], + 'length not dividable by 4' => [false, 'U2ltcGxlU0FTHBocA=='], + ]; + } +} diff --git a/tests/Type/HMACOutputLength.php b/tests/Type/HMACOutputLength.php new file mode 100644 index 00000000..a022aa04 --- /dev/null +++ b/tests/Type/HMACOutputLength.php @@ -0,0 +1,55 @@ +assertTrue($shouldPass); + } catch (SchemaViolationException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideHMACOutputLength(): array + { + return [ + 'empty' => [false, ''], + 'valid positive integer' => [true, '128'], + 'invalid indivisible by 8' => [false, '4'], + 'invalid signed positive integer' => [false, '+128'], + 'invalid zero' => [false, '0'], + 'invalid leading zeros' => [false, '0000000000000000000128'], + 'invalid with fractional' => [false, '1.'], + 'invalid negative' => [false, '-128'], + 'invalid with thousands-delimiter' => [false, '1,28'], + 'valid with whitespace collapse' => [true, " 1 28\n"], + ]; + } +} diff --git a/tests/Type/KeySizeValueTest.php b/tests/Type/KeySizeValueTest.php new file mode 100644 index 00000000..91369050 --- /dev/null +++ b/tests/Type/KeySizeValueTest.php @@ -0,0 +1,54 @@ +assertTrue($shouldPass); + } catch (SchemaViolationException $e) { + $this->assertFalse($shouldPass); + } + } + + + /** + * @return array + */ + public static function provideKeySize(): array + { + return [ + 'empty' => [false, ''], + 'valid positive integer' => [true, '123456'], + 'invalid signed positive integer' => [false, '+123456'], + 'invalid zero' => [false, '0'], + 'invalid leading zeros' => [false, '0000000000000000000005'], + 'invalid with fractional' => [false, '1.'], + 'invalid negative' => [false, '-1234'], + 'invalid with thousands-delimiter' => [false, '1,234'], + 'valid with whitespace collapse' => [true, " 1234 \n"], + ]; + } +} diff --git a/tests/XML/CustomSignable.php b/tests/XML/CustomSignable.php index 39632086..2ba71aa8 100644 --- a/tests/XML/CustomSignable.php +++ b/tests/XML/CustomSignable.php @@ -7,16 +7,13 @@ use DOMElement; use SimpleSAML\Assert\Assert; use SimpleSAML\XML\AbstractElement; -use SimpleSAML\XML\Exception\InvalidDOMElementException; -use SimpleSAML\XML\Exception\TooManyElementsException; +use SimpleSAML\XML\Exception\{InvalidDOMElementException, TooManyElementsException}; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Backend\EncryptionBackend; use SimpleSAML\XMLSecurity\XML\ds\Signature; -use SimpleSAML\XMLSecurity\XML\EncryptableElementInterface; -use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait; -use SimpleSAML\XMLSecurity\XML\SignableElementInterface; -use SimpleSAML\XMLSecurity\XML\SignableElementTrait; -use SimpleSAML\XMLSecurity\XML\SignedElementInterface; -use SimpleSAML\XMLSecurity\XML\SignedElementTrait; +use SimpleSAML\XMLSecurity\XML\{EncryptableElementInterface, EncryptableElementTrait}; +use SimpleSAML\XMLSecurity\XML\{SignableElementInterface, SignableElementTrait}; +use SimpleSAML\XMLSecurity\XML\{SignedElementInterface, SignedElementTrait}; /** * This is an example class demonstrating an object that can be signed and encrypted. @@ -51,10 +48,11 @@ class CustomSignable extends AbstractElement implements * Constructor * * @param \DOMElement $xml + * @param \SimpleSAML\XML\Type\IDValue $id */ final public function __construct( protected DOMElement $xml, - protected ?string $id, + protected ?IDValue $id, ) { } @@ -93,9 +91,9 @@ public function getXML(): DOMElement /** - * @return string|null + * @return \SimpleSAML\XML\Type\IDValue|null */ - public function getId(): ?string + public function getId(): ?IDValue { return $this->id; } @@ -163,7 +161,7 @@ public static function fromXML(DOMElement $xml): static Assert::same($xml->localName, 'CustomSignable', InvalidDOMElementException::class); Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); - $id = self::getOptionalAttribute($xml, 'id', null); + $id = self::getOptionalAttribute($xml, 'id', IDValue::class, null); $signature = Signature::getChildrenOfClass($xml); Assert::maxCount($signature, 1, TooManyElementsException::class); diff --git a/tests/XML/EncryptedCustom.php b/tests/XML/EncryptedCustom.php index 2615894d..e39c51e5 100644 --- a/tests/XML/EncryptedCustom.php +++ b/tests/XML/EncryptedCustom.php @@ -6,15 +6,12 @@ use SimpleSAML\XML\AbstractElement; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory; -use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface; -use SimpleSAML\XMLSecurity\Backend\EncryptionBackend; -use SimpleSAML\XMLSecurity\Backend\OpenSSL; +use SimpleSAML\XMLSecurity\Alg\Encryption\{EncryptionAlgorithmFactory, EncryptionAlgorithmInterface}; +use SimpleSAML\XMLSecurity\Backend\{EncryptionBackend, OpenSSL}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\RuntimeException; use SimpleSAML\XMLSecurity\Key\SymmetricKey; -use SimpleSAML\XMLSecurity\XML\EncryptedElementInterface; -use SimpleSAML\XMLSecurity\XML\EncryptedElementTrait; +use SimpleSAML\XMLSecurity\XML\{EncryptedElementInterface, EncryptedElementTrait}; use SimpleSAML\XMLSecurity\XML\xenc\EncryptedData; /** @@ -151,7 +148,7 @@ public function decryptWithSessionKey(EncryptionAlgorithmInterface $decryptor): * since this object can only be encrypted with them (which is the common scenario). Always remember to check * the supported algorithms. */ - $algId = $this->getEncryptedData()->getEncryptionMethod()->getAlgorithm(); + $algId = $this->getEncryptedData()->getEncryptionMethod()->getAlgorithm()->getValue(); if (!isset(C::$BLOCK_CIPHER_ALGORITHMS[$algId])) { throw new RuntimeException('Unknown or unsupported encryption algorithm.'); } @@ -170,7 +167,7 @@ public function decryptWithSessionKey(EncryptionAlgorithmInterface $decryptor): // finally, decrypt the element, create an XML document from it and then use that to create an object $xml = DOMDocumentFactory::fromString( - $alg->decrypt($this->getEncryptedData()->getCipherData()->getCipherValue()->getContent()), + $alg->decrypt($this->getEncryptedData()->getCipherData()->getCipherValue()->getContent()->getValue()), ); return CustomSignable::fromXML($xml->documentElement); } diff --git a/tests/XML/EncryptedCustomTest.php b/tests/XML/EncryptedCustomTest.php index f0f68a0e..88582d4b 100644 --- a/tests/XML/EncryptedCustomTest.php +++ b/tests/XML/EncryptedCustomTest.php @@ -12,13 +12,10 @@ use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory; use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Key\PrivateKey; -use SimpleSAML\XMLSecurity\Key\PublicKey; -use SimpleSAML\XMLSecurity\Key\SymmetricKey; +use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey}; use SimpleSAML\XMLSecurity\Test\XML\EncryptedCustom; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\EncryptableElementTrait; -use SimpleSAML\XMLSecurity\XML\EncryptedElementTrait; +use SimpleSAML\XMLSecurity\XML\{EncryptableElementTrait, EncryptedElementTrait}; use function dirname; @@ -126,7 +123,7 @@ public function testSignatureVerifiesAfterEncryptionAndDecryption(): void // verify signature $publicKey = PEMCertificatesMock::getPublicKey(PEMCertificatesMock::SELFSIGNED_PUBLIC_KEY); $verifier = (new SignatureAlgorithmFactory())->getAlgorithm( - $decryptedCustom->getSignature()->getSignedInfo()->getSignatureMethod()->getAlgorithm(), + $decryptedCustom->getSignature()->getSignedInfo()->getSignatureMethod()->getAlgorithm()->getValue(), $publicKey, ); diff --git a/tests/XML/SignableElementTest.php b/tests/XML/SignableElementTest.php index b1cc38ff..ef3abaa9 100644 --- a/tests/XML/SignableElementTest.php +++ b/tests/XML/SignableElementTest.php @@ -9,15 +9,14 @@ use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Exception\RuntimeException; use SimpleSAML\XMLSecurity\Key\PrivateKey; use SimpleSAML\XMLSecurity\Test\XML\CustomSignable; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; +use SimpleSAML\XMLSecurity\XML\ds\{KeyInfo, X509Certificate, X509Data}; use function array_pop; use function array_shift; @@ -86,7 +85,9 @@ public function testMarshalling(): void $keyInfo = new KeyInfo([ new X509Data([ - new X509Certificate(self::$certificate), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), ]), ]); @@ -118,7 +119,9 @@ public function testSigningElement(): void $keyInfo = new KeyInfo([ new X509Data([ - new X509Certificate(self::$certificate), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), ]), ]); @@ -154,7 +157,9 @@ public function testSigningDocumentWithComments(): void $keyInfo = new KeyInfo([ new X509Data([ - new X509Certificate(self::$certificate), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), ]), ]); @@ -190,7 +195,9 @@ public function testSigningElementWithIdAndComments(): void $keyInfo = new KeyInfo([ new X509Data([ - new X509Certificate(self::$certificate), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), ]), ]); diff --git a/tests/XML/SignedElementTest.php b/tests/XML/SignedElementTest.php index 8c1456d5..36234da6 100644 --- a/tests/XML/SignedElementTest.php +++ b/tests/XML/SignedElementTest.php @@ -11,10 +11,8 @@ use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\CryptoEncoding\PEM; -use SimpleSAML\XMLSecurity\Exception\RuntimeException; -use SimpleSAML\XMLSecurity\Exception\SignatureVerificationFailedException; -use SimpleSAML\XMLSecurity\Key\PublicKey; -use SimpleSAML\XMLSecurity\Key\X509Certificate; +use SimpleSAML\XMLSecurity\Exception\{RuntimeException, SignatureVerificationFailedException}; +use SimpleSAML\XMLSecurity\Key\{PublicKey, X509Certificate}; use SimpleSAML\XMLSecurity\Test\XML\CustomSignable; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; use SimpleSAML\XMLSecurity\XML\ds\Signature; @@ -102,7 +100,7 @@ public function testSuccessfulVerifyingWithGivenKey(): void $this->assertEquals(C::SIG_RSA_SHA256, $sigAlg); $factory = new SignatureAlgorithmFactory(); $certificate = new X509Certificate($this->certificate); - $verifier = $factory->getAlgorithm($sigAlg, $certificate->getPublicKey()); + $verifier = $factory->getAlgorithm($sigAlg->getValue(), $certificate->getPublicKey()); $verified = $customSigned->verify($verifier); $this->assertInstanceOf(CustomSignable::class, $verified); @@ -134,7 +132,7 @@ public function testSuccessfulVerifyingWithWrongKeyFirstRightOneSecond(): void foreach ([$this->wrong_certificate, $this->certificate] as $i => $key) { $factory = new SignatureAlgorithmFactory(); $certificate = new X509Certificate($key); - $verifier = $factory->getAlgorithm($sigAlg, $certificate->getPublicKey()); + $verifier = $factory->getAlgorithm($sigAlg->getValue(), $certificate->getPublicKey()); try { $verified = $customSigned->verify($verifier); @@ -194,7 +192,7 @@ public function testVerifyingTamperedSignatureWithoutKeyFails(): void $signature = $customSigned->getSignature(); $this->assertInstanceOf(Signature::class, $signature); $sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm(); - $this->assertEquals(C::SIG_RSA_SHA256, $sigAlg); + $this->assertEquals(C::SIG_RSA_SHA256, $sigAlg->getValue()); $this->expectException(RuntimeException::class); $this->expectExceptionMessage('Failed to verify signature.'); @@ -212,7 +210,7 @@ public function testVerifyingTamperedSignatureWithKeyFails(): void $this->assertTrue($customSigned->isSigned()); $signature = $customSigned->getSignature(); $this->assertInstanceOf(Signature::class, $signature); - $sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm(); + $sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm()->getValue(); $this->assertEquals(C::SIG_RSA_SHA256, $sigAlg); $factory = new SignatureAlgorithmFactory(); $certificate = new X509Certificate($this->certificate); @@ -238,7 +236,7 @@ public function testSuccessfulVerifyingDocumentWithComments(): void $this->assertTrue($customSigned->isSigned()); $signature = $customSigned->getSignature(); $this->assertInstanceOf(Signature::class, $signature); - $sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm(); + $sigAlg = $signature->getSignedInfo()->getSignatureMethod()->getAlgorithm()->getValue(); $this->assertEquals(C::SIG_RSA_SHA256, $sigAlg); $factory = new SignatureAlgorithmFactory(); $certificate = new X509Certificate($this->certificate); diff --git a/tests/XML/ds/CanonicalizationMethodTest.php b/tests/XML/ds/CanonicalizationMethodTest.php index b5856a75..aa7fdd4d 100644 --- a/tests/XML/ds/CanonicalizationMethodTest.php +++ b/tests/XML/ds/CanonicalizationMethodTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, CanonicalizationMethod}; use function dirname; @@ -20,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(CanonicalizationMethod::class)] final class CanonicalizationMethodTest extends TestCase @@ -43,7 +43,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $canonicalizationMethod = new CanonicalizationMethod(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS); + $canonicalizationMethod = new CanonicalizationMethod( + AnyURIValue::fromString(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/DSAKeyValueTest.php b/tests/XML/ds/DSAKeyValueTest.php index 19c7c902..1d2777d1 100644 --- a/tests/XML/ds/DSAKeyValueTest.php +++ b/tests/XML/ds/DSAKeyValueTest.php @@ -4,21 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDSAKeyValueType; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\DSAKeyValue; -use SimpleSAML\XMLSecurity\XML\ds\G; -use SimpleSAML\XMLSecurity\XML\ds\J; -use SimpleSAML\XMLSecurity\XML\ds\P; -use SimpleSAML\XMLSecurity\XML\ds\PgenCounter; -use SimpleSAML\XMLSecurity\XML\ds\Q; -use SimpleSAML\XMLSecurity\XML\ds\Seed; -use SimpleSAML\XMLSecurity\XML\ds\Y; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDSAKeyValueType, AbstractDsElement, DSAKeyValue}; +use SimpleSAML\XMLSecurity\XML\ds\{G, J, P, PgenCounter, Q, Seed, Y}; use function dirname; use function strval; @@ -28,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(AbstractDSAKeyValueType::class)] #[CoversClass(DSAKeyValue::class)] @@ -52,13 +45,27 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $p = new P('GpM1'); - $q = new Q('GpM2'); - $g = new G('GpM3'); - $y = new Y('GpM4'); - $j = new J('GpM5'); - $seed = new Seed('GpM6'); - $pgenCounter = new PgenCounter('GpM7'); + $p = new P( + CryptoBinaryValue::fromString('GpM1'), + ); + $q = new Q( + CryptoBinaryValue::fromString('GpM2'), + ); + $g = new G( + CryptoBinaryValue::fromString('GpM3'), + ); + $y = new Y( + CryptoBinaryValue::fromString('GpM4'), + ); + $j = new J( + CryptoBinaryValue::fromString('GpM5'), + ); + $seed = new Seed( + CryptoBinaryValue::fromString('GpM6'), + ); + $pgenCounter = new PgenCounter( + CryptoBinaryValue::fromString('GpM7'), + ); $dsaKeyValue = new DSAKeyValue($y, $g, $j, $p, $q, $seed, $pgenCounter); @@ -73,13 +80,27 @@ public function testMarshalling(): void */ public function testMarshallingElementOrder(): void { - $p = new P('GpM1'); - $q = new Q('GpM2'); - $g = new G('GpM3'); - $y = new Y('GpM4'); - $j = new J('GpM5'); - $seed = new Seed('GpM6'); - $pgenCounter = new PgenCounter('GpM7'); + $p = new P( + CryptoBinaryValue::fromString('GpM1'), + ); + $q = new Q( + CryptoBinaryValue::fromString('GpM2'), + ); + $g = new G( + CryptoBinaryValue::fromString('GpM3'), + ); + $y = new Y( + CryptoBinaryValue::fromString('GpM4'), + ); + $j = new J( + CryptoBinaryValue::fromString('GpM5'), + ); + $seed = new Seed( + CryptoBinaryValue::fromString('GpM6'), + ); + $pgenCounter = new PgenCounter( + CryptoBinaryValue::fromString('GpM7'), + ); $dsaKeyValue = new DSAKeyValue($y, $g, $j, $p, $q, $seed, $pgenCounter); diff --git a/tests/XML/ds/DigestMethodTest.php b/tests/XML/ds/DigestMethodTest.php index 2fd94b2e..ebcdad5d 100644 --- a/tests/XML/ds/DigestMethodTest.php +++ b/tests/XML/ds/DigestMethodTest.php @@ -4,15 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, DigestMethod}; use function dirname; use function strval; @@ -22,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(DigestMethod::class)] final class DigestMethodTest extends TestCase @@ -46,7 +45,7 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $digestMethod = new DigestMethod( - C::DIGEST_SHA256, + AnyURIValue::fromString(C::DIGEST_SHA256), [ new Chunk(DOMDocumentFactory::fromString( 'Random', diff --git a/tests/XML/ds/DigestValueTest.php b/tests/XML/ds/DigestValueTest.php index d9fcacae..74783dfb 100644 --- a/tests/XML/ds/DigestValueTest.php +++ b/tests/XML/ds/DigestValueTest.php @@ -4,15 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\DigestValue; +use SimpleSAML\XMLSecurity\Type\DigestValue as DigestValueType; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, DigestValue}; use function dirname; use function strval; @@ -22,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(DigestValue::class)] final class DigestValueTest extends TestCase @@ -45,20 +44,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $digestValue = new DigestValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $digestValue = new DigestValue( + DigestValueType::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($digestValue), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new DigestValue('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/ds/ExponentTest.php b/tests/XML/ds/ExponentTest.php index bf094a0a..6d7522dc 100644 --- a/tests/XML/ds/ExponentTest.php +++ b/tests/XML/ds/ExponentTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Exponent; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Exponent}; use function dirname; use function strval; @@ -21,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Exponent::class)] final class ExponentTest extends TestCase @@ -43,20 +43,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $exponent = new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='); + $exponent = new Exponent( + CryptoBinaryValue::fromString('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($exponent), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(SchemaViolationException::class); - new Exponent('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/ds/GTest.php b/tests/XML/ds/GTest.php index 3c82fce4..9b6694fb 100644 --- a/tests/XML/ds/GTest.php +++ b/tests/XML/ds/GTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\G; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, G}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(G::class)] final class GTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $g = new G('GpM6'); + $g = new G( + CryptoBinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/HMACOutputLengthTest.php b/tests/XML/ds/HMACOutputLengthTest.php index 6d3d2eba..b70870f9 100644 --- a/tests/XML/ds/HMACOutputLengthTest.php +++ b/tests/XML/ds/HMACOutputLengthTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength; +use SimpleSAML\XMLSecurity\Type\HMACOutputLengthValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, HMACOutputLength}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(HMACOutputLength::class)] final class HMACOutputLengthTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $hmacOutputLength = new HMACOutputLength('1234'); + $hmacOutputLength = new HMACOutputLength( + HMACOutputLengthValue::fromString('128'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/JTest.php b/tests/XML/ds/JTest.php index 0dfe7076..92719fac 100644 --- a/tests/XML/ds/JTest.php +++ b/tests/XML/ds/JTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\J; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, J}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(J::class)] final class JTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $j = new J('GpM6'); + $j = new J( + CryptoBinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/KeyInfoTest.php b/tests/XML/ds/KeyInfoTest.php index 2026673c..a151024d 100644 --- a/tests/XML/ds/KeyInfoTest.php +++ b/tests/XML/ds/KeyInfoTest.php @@ -4,30 +4,19 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{Base64BinaryValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType; -use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\ds\KeyName; -use SimpleSAML\XMLSecurity\XML\ds\MgmtData; -use SimpleSAML\XMLSecurity\XML\ds\PGPData; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyID; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyPacket; -use SimpleSAML\XMLSecurity\XML\ds\SPKIData; -use SimpleSAML\XMLSecurity\XML\ds\SPKISexp; -use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; -use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName; -use SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName; -use SimpleSAML\XMLSecurity\XML\xenc\P; -use SimpleSAML\XMLSecurity\XML\xenc\Seed; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, AbstractKeyInfoType, KeyInfo, KeyName, MgmtData}; +use SimpleSAML\XMLSecurity\XML\ds\{PGPData, PGPKeyID, PGPKeyPacket}; +use SimpleSAML\XMLSecurity\XML\ds\{SPKIData, SPKISexp}; +use SimpleSAML\XMLSecurity\XML\ds\{X509Certificate, X509Data, X509SubjectName}; +use SimpleSAML\XMLSecurity\XML\xenc\{CarriedKeyName, P, Seed}; use function dirname; use function openssl_x509_parse; @@ -39,6 +28,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(AbstractKeyInfoType::class)] #[CoversClass(KeyInfo::class)] @@ -94,37 +84,63 @@ public function setUp(): void */ public function testMarshalling(): void { - $SPKISexp1 = new SPKISexp('GpM6'); - $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $SPKISexp2 = new SPKISexp('GpM7'); - $SPKISexp3 = new SPKISexp('GpM8'); - $carriedKeyName = new CarriedKeyName('Some label'); + $SPKISexp1 = new SPKISexp( + Base64BinaryValue::fromString('GpM6'), + ); + $seed = new Seed( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); + $SPKISexp2 = new SPKISexp( + Base64BinaryValue::fromString('GpM7'), + ); + $SPKISexp3 = new SPKISexp( + Base64BinaryValue::fromString('GpM8'), + ); + $carriedKeyName = new CarriedKeyName( + StringValue::fromString('Some label'), + ); $keyInfo = new KeyInfo( [ - new KeyName('testkey'), + new KeyName( + StringValue::fromString('testkey'), + ), new X509Data( [ - new X509Certificate(self::$certificate), - new X509SubjectName(self::$certData['name']), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), ], ), new PGPData( - new PGPKeyID('GpM7'), - new PGPKeyPacket('GpM8'), - [new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')], + new PGPKeyID( + Base64BinaryValue::fromString('GpM7'), + ), + new PGPKeyPacket( + Base64BinaryValue::fromString('GpM8'), + ), + [ + new P( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ], ), new SPKIData([ [$SPKISexp1, $seed], [$SPKISexp2, null], [$SPKISexp3, $carriedKeyName], ]), - new MgmtData('ManagementData'), + new MgmtData( + StringValue::fromString('ManagementData'), + ), new Chunk(DOMDocumentFactory::fromString( 'some', )->documentElement), ], - 'fed654', + IDValue::fromString('fed654'), ); $this->assertEquals( diff --git a/tests/XML/ds/KeyNameTest.php b/tests/XML/ds/KeyNameTest.php index 7e1b23eb..917006e1 100644 --- a/tests/XML/ds/KeyNameTest.php +++ b/tests/XML/ds/KeyNameTest.php @@ -4,13 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\KeyName; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, KeyName}; use function dirname; use function strval; @@ -20,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(KeyName::class)] final class KeyNameTest extends TestCase @@ -43,7 +43,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $keyName = new KeyName('testkey'); + $keyName = new KeyName( + StringValue::fromString('testkey'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/KeyValueTest.php b/tests/XML/ds/KeyValueTest.php index da3f9695..2bfe27d1 100644 --- a/tests/XML/ds/KeyValueTest.php +++ b/tests/XML/ds/KeyValueTest.php @@ -5,15 +5,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; use DOMDocument; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\KeyValue; -use SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, KeyValue, RSAKeyValue}; use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty; use function dirname; @@ -24,6 +21,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(KeyValue::class)] final class KeyValueTest extends TestCase diff --git a/tests/XML/ds/ManifestTest.php b/tests/XML/ds/ManifestTest.php index bd908222..2ee31779 100644 --- a/tests/XML/ds/ManifestTest.php +++ b/tests/XML/ds/ManifestTest.php @@ -4,19 +4,15 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IDValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; -use SimpleSAML\XMLSecurity\XML\ds\DigestValue; -use SimpleSAML\XMLSecurity\XML\ds\Manifest; -use SimpleSAML\XMLSecurity\XML\ds\Reference; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; +use SimpleSAML\XMLSecurity\Type\DigestValue as DigestValueType; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, DigestMethod, DigestValue}; +use SimpleSAML\XMLSecurity\XML\ds\{Manifest, Reference, Transform, Transforms}; use function dirname; use function strval; @@ -26,6 +22,7 @@ * * @package simplesamlphp/saml2 */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Manifest::class)] final class ManifestTest extends TestCase @@ -51,19 +48,31 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $reference = new Reference( - new DigestMethod(C::DIGEST_SHA256), - new DigestValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + new DigestMethod( + AnyURIValue::fromString(C::DIGEST_SHA256), + ), + new DigestValue( + DigestValueType::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), new Transforms( [ - new Transform(C::XMLDSIG_ENVELOPED), - new Transform(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + new Transform( + AnyURIValue::fromString(C::XMLDSIG_ENVELOPED), + ), + new Transform( + AnyURIValue::fromString(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + ), ], ), - 'abc123', - C::XMLDSIG_MANIFEST, - '#_1e280ee704fb1d8d9dec4bd6c1889ec96942921153', + IDValue::fromString('abc123'), + AnyURIValue::fromString(C::XMLDSIG_MANIFEST), + AnyURIValue::fromString('#_1e280ee704fb1d8d9dec4bd6c1889ec96942921153'), + ); + + $manifest = new Manifest( + [$reference], + IDValue::FromString('def456'), ); - $manifest = new Manifest([$reference], 'def456'); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/MgmtDataTest.php b/tests/XML/ds/MgmtDataTest.php index e6d82212..02f130cc 100644 --- a/tests/XML/ds/MgmtDataTest.php +++ b/tests/XML/ds/MgmtDataTest.php @@ -4,13 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\MgmtData; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, MgmtData}; use function dirname; use function strval; @@ -20,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(MgmtData::class)] final class MgmtDataTest extends TestCase @@ -43,7 +43,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $mgmtData = new MgmtData('ManagementData'); + $mgmtData = new MgmtData( + StringValue::fromString('ManagementData'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/ModulusTest.php b/tests/XML/ds/ModulusTest.php index 1d0d5bb5..3858ef19 100644 --- a/tests/XML/ds/ModulusTest.php +++ b/tests/XML/ds/ModulusTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Modulus; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Modulus}; use function dirname; use function strval; @@ -21,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Modulus::class)] final class ModulusTest extends TestCase @@ -43,20 +43,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $modulus = new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='); + $modulus = new Modulus( + CryptoBinaryValue::fromString('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($modulus), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(SchemaViolationException::class); - new Modulus('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/ds/ObjectTest.php b/tests/XML/ds/ObjectTest.php index a055b5fc..bd7eba1a 100644 --- a/tests/XML/ds/ObjectTest.php +++ b/tests/XML/ds/ObjectTest.php @@ -4,20 +4,19 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\DsObject; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, DsObject}; /** * Class \SimpleSAML\XMLSecurity\XML\Test\ds\ObjectTest * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(DsObject::class)] final class ObjectTest extends TestCase @@ -44,9 +43,9 @@ public function testMarshalling(): void { $img = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII='; $obj = new DsObject( - 'abc123', - 'image/png', - 'http://www.w3.org/2000/09/xmldsig#base64', + IDValue::fromString('abc123'), + StringValue::fromString('image/png'), + AnyURIValue::fromString('http://www.w3.org/2000/09/xmldsig#base64'), [ new Chunk( DOMDocumentFactory::fromString(sprintf( diff --git a/tests/XML/ds/PGPDataTest.php b/tests/XML/ds/PGPDataTest.php index fce46e76..d8543487 100644 --- a/tests/XML/ds/PGPDataTest.php +++ b/tests/XML/ds/PGPDataTest.php @@ -4,17 +4,15 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\Exception\SchemaViolationException; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\AbstractPGPDataType; -use SimpleSAML\XMLSecurity\XML\ds\PGPData; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyID; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyPacket; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, AbstractPGPDataType}; +use SimpleSAML\XMLSecurity\XML\ds\{PGPData, PGPKeyID, PGPKeyPacket}; use SimpleSAML\XMLSecurity\XML\xenc\P; use function dirname; @@ -25,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(AbstractPGPDataType::class)] #[CoversClass(PGPData::class)] @@ -33,6 +32,10 @@ final class PGPDataTest extends TestCase use SchemaValidationTestTrait; use SerializableElementTestTrait; + private static PGPKeyID $pgpKeyId; + private static PGPKeyPacket $pgpKeyPacket; + private static P $p; + /** */ public static function setUpBeforeClass(): void @@ -42,6 +45,18 @@ public static function setUpBeforeClass(): void self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 3) . '/resources/xml/ds_PGPData.xml', ); + + self::$pgpKeyId = new PGPKeyID( + Base64BinaryValue::fromString('GpM7'), + ); + + self::$pgpKeyPacket = new PGPKeyPacket( + Base64BinaryValue::fromString('GpM8'), + ); + + self::$p = new P( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); } @@ -49,11 +64,7 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $pgpKeyId = new PGPKeyID('GpM7'); - $pgpKeyPacket = new PGPKeyPacket('GpM8'); - $p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - - $pgpData = new PGPData($pgpKeyId, $pgpKeyPacket, [$p]); + $pgpData = new PGPData(self::$pgpKeyId, self::$pgpKeyPacket, [self::$p]); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), @@ -76,11 +87,7 @@ public function testMarshallingBothIdAndPacketNullThrowsException(): void */ public function testMarshallingReferenceElementOrdering(): void { - $pgpKeyId = new PGPKeyID('GpM7'); - $pgpKeyPacket = new PGPKeyPacket('GpM8'); - $p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - - $pgpData = new PGPData($pgpKeyId, $pgpKeyPacket, [$p]); + $pgpData = new PGPData(self::$pgpKeyId, self::$pgpKeyPacket, [self::$p]); $pgpDataElement = $pgpData->toXML(); /** @var \DOMElement[] $children */ diff --git a/tests/XML/ds/PGPKeyIDTest.php b/tests/XML/ds/PGPKeyIDTest.php index 915dc6ee..20c27f5d 100644 --- a/tests/XML/ds/PGPKeyIDTest.php +++ b/tests/XML/ds/PGPKeyIDTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyID; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, PGPKeyID}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(PGPKeyID::class)] final class PGPKeyIDTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $pgpKeyId = new PGPKeyID('GpM7'); + $pgpKeyId = new PGPKeyID( + Base64BinaryValue::fromString('GpM7'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/PGPKeyPacketTest.php b/tests/XML/ds/PGPKeyPacketTest.php index b1d6c942..a371c40f 100644 --- a/tests/XML/ds/PGPKeyPacketTest.php +++ b/tests/XML/ds/PGPKeyPacketTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyPacket; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, PGPKeyPacket}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(PGPKeyPacket::class)] final class PGPKeyPacketTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $pgpKeyPacket = new PGPKeyPacket('GpM7'); + $pgpKeyPacket = new PGPKeyPacket( + Base64BinaryValue::fromString('GpM7'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/PTest.php b/tests/XML/ds/PTest.php index ecb1091c..16cbc331 100644 --- a/tests/XML/ds/PTest.php +++ b/tests/XML/ds/PTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\P; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, P}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(P::class)] final class PTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $p = new P('GpM6'); + $p = new P( + CryptoBinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/PgenCounterTest.php b/tests/XML/ds/PgenCounterTest.php index 09178b72..f98a0f21 100644 --- a/tests/XML/ds/PgenCounterTest.php +++ b/tests/XML/ds/PgenCounterTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\PgenCounter; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, PgenCounter}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(PgenCounter::class)] final class PgenCounterTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $pgenCounter = new PgenCounter('GpM6'); + $pgenCounter = new PgenCounter( + CryptoBinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/QTest.php b/tests/XML/ds/QTest.php index aace3a99..a81f54a2 100644 --- a/tests/XML/ds/QTest.php +++ b/tests/XML/ds/QTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Q; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Q}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Q::class)] final class QTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $q = new Q('GpM6'); + $q = new Q( + CryptoBinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/RSAKeyValueTest.php b/tests/XML/ds/RSAKeyValueTest.php index 0384e486..ea7e811a 100644 --- a/tests/XML/ds/RSAKeyValueTest.php +++ b/tests/XML/ds/RSAKeyValueTest.php @@ -4,16 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; use SimpleSAML\XML\Utils\XPath; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Exponent; -use SimpleSAML\XMLSecurity\XML\ds\Modulus; -use SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Exponent, Modulus, RSAKeyValue}; use function dirname; use function strval; @@ -23,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(RSAKeyValue::class)] final class RSAKeyValueTest extends TestCase @@ -30,6 +28,8 @@ final class RSAKeyValueTest extends TestCase use SchemaValidationTestTrait; use SerializableElementTestTrait; + private static RSAKeyValue $rsaKeyValue; + /** */ public static function setUpBeforeClass(): void @@ -39,6 +39,15 @@ public static function setUpBeforeClass(): void self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 3) . '/resources/xml/ds_RSAKeyValue.xml', ); + + self::$rsaKeyValue = new RSAKeyValue( + new Modulus( + CryptoBinaryValue::fromString('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), + ), + new Exponent( + CryptoBinaryValue::fromString('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), + ), + ); } @@ -46,14 +55,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $RSAKeyValue = new RSAKeyValue( - new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), - new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), - ); - $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($RSAKeyValue), + strval(self::$rsaKeyValue), ); } @@ -62,12 +66,7 @@ public function testMarshalling(): void */ public function testMarshallingElementOrder(): void { - $RSAKeyValue = new RSAKeyValue( - new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), - new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), - ); - - $RSAKeyValueElement = $RSAKeyValue->toXML(); + $RSAKeyValueElement = self::$rsaKeyValue->toXML(); $xpCache = XPath::getXPath($RSAKeyValueElement); $modulus = XPath::xpQuery($RSAKeyValueElement, './ds:Modulus', $xpCache); diff --git a/tests/XML/ds/ReferenceTest.php b/tests/XML/ds/ReferenceTest.php index 97a67c2b..7eae753c 100644 --- a/tests/XML/ds/ReferenceTest.php +++ b/tests/XML/ds/ReferenceTest.php @@ -4,18 +4,15 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IDValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; -use SimpleSAML\XMLSecurity\XML\ds\DigestValue; -use SimpleSAML\XMLSecurity\XML\ds\Reference; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; +use SimpleSAML\XMLSecurity\Type\DigestValue as DigestValueType; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, DigestMethod, DigestValue}; +use SimpleSAML\XMLSecurity\XML\ds\{Reference, Transform, Transforms}; use function dirname; use function strval; @@ -25,6 +22,7 @@ * * @package simplesamlphp/saml2 */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Reference::class)] final class ReferenceTest extends TestCase @@ -49,17 +47,25 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $reference = new Reference( - new DigestMethod(C::DIGEST_SHA256), - new DigestValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + new DigestMethod( + AnyURIValue::fromString(C::DIGEST_SHA256), + ), + new DigestValue( + DigestValueType::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), new Transforms( [ - new Transform(C::XMLDSIG_ENVELOPED), - new Transform(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + new Transform( + AnyURIValue::fromString(C::XMLDSIG_ENVELOPED), + ), + new Transform( + AnyURIValue::fromString(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + ), ], ), - 'ghi789', - 'urn:some:type', - '#_1e280ee704fb1d8d9dec4bd6c1889ec96942921153', + IDValue::fromString('ghi789'), + AnyURIValue::fromString('urn:some:type'), + AnyURIValue::fromString('#_1e280ee704fb1d8d9dec4bd6c1889ec96942921153'), ); $this->assertFalse($reference->isXPointer()); @@ -75,17 +81,25 @@ public function testMarshalling(): void public function testMarshallingReferenceElementOrdering(): void { $reference = new Reference( - new DigestMethod(C::DIGEST_SHA256), - new DigestValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + new DigestMethod( + AnyURIValue::fromString(C::DIGEST_SHA256), + ), + new DigestValue( + DigestValueType::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), new Transforms( [ - new Transform(C::XMLDSIG_ENVELOPED), - new Transform(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + new Transform( + AnyURIValue::fromString(C::XMLDSIG_ENVELOPED), + ), + new Transform( + AnyURIValue::fromString(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + ), ], ), - 'ghi789', - 'urn:some:type', - '#_1e280ee704fb1d8d9dec4bd6c1889ec96942921153', + IDValue::fromString('ghi789'), + AnyURIValue::fromString('urn:some:type'), + AnyURIValue::fromString('#_1e280ee704fb1d8d9dec4bd6c1889ec96942921153'), ); $referenceElement = $reference->toXML(); diff --git a/tests/XML/ds/RetrievalMethodTest.php b/tests/XML/ds/RetrievalMethodTest.php index d1d531d5..85a5f140 100644 --- a/tests/XML/ds/RetrievalMethodTest.php +++ b/tests/XML/ds/RetrievalMethodTest.php @@ -4,17 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\RetrievalMethod; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; -use SimpleSAML\XMLSecurity\XML\ds\XPath; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, RetrievalMethod}; +use SimpleSAML\XMLSecurity\XML\ds\{Transform, Transforms, XPath}; use function dirname; use function strval; @@ -24,6 +21,7 @@ * * @package simplesamlphp/saml2 */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(RetrievalMethod::class)] final class RetrievalMethodTest extends TestCase @@ -50,12 +48,18 @@ public function testMarshalling(): void { $transforms = new Transforms([ new Transform( - C::XPATH10_URI, - new XPath('self::xenc:CipherValue[@Id="example1"]'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('self::xenc:CipherValue[@Id="example1"]'), + ), ), ]); - $retrievalMethod = new RetrievalMethod($transforms, '#Encrypted_KEY_ID', C:: XMLENC_ENCRYPTEDKEY); + $retrievalMethod = new RetrievalMethod( + $transforms, + AnyURIValue::fromString('#Encrypted_KEY_ID'), + AnyURIValue::fromString(C::XMLENC_ENCRYPTEDKEY), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/SPKIDataTest.php b/tests/XML/ds/SPKIDataTest.php index 3efce155..299c46c3 100644 --- a/tests/XML/ds/SPKIDataTest.php +++ b/tests/XML/ds/SPKIDataTest.php @@ -4,17 +4,15 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\AbstractSPKIDataType; -use SimpleSAML\XMLSecurity\XML\ds\SPKIData; -use SimpleSAML\XMLSecurity\XML\ds\SPKISexp; -use SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName; -use SimpleSAML\XMLSecurity\XML\xenc\Seed; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{Base64BinaryValue, StringValue}; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, AbstractSPKIDataType}; +use SimpleSAML\XMLSecurity\XML\ds\{SPKIData, SPKISexp}; +use SimpleSAML\XMLSecurity\XML\xenc\{CarriedKeyName, Seed}; use function dirname; use function strval; @@ -24,6 +22,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(AbstractSPKIDataType::class)] #[CoversClass(SPKIData::class)] @@ -48,12 +47,24 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $SPKISexp1 = new SPKISexp('GpM6'); - $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $SPKISexp2 = new SPKISexp('GpM7'); - $SPKISexp3 = new SPKISexp('GpM8'); - $carriedKeyName = new CarriedKeyName('Some label'); - $SPKISexp4 = new SPKISexp('GpM9'); + $SPKISexp1 = new SPKISexp( + Base64BinaryValue::fromString('GpM6'), + ); + $seed = new Seed( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); + $SPKISexp2 = new SPKISexp( + Base64BinaryValue::fromString('GpM7'), + ); + $SPKISexp3 = new SPKISexp( + Base64BinaryValue::fromString('GpM8'), + ); + $carriedKeyName = new CarriedKeyName( + StringValue::fromString('Some label'), + ); + $SPKISexp4 = new SPKISexp( + Base64BinaryValue::fromString('GpM9'), + ); $SPKIData = new SPKIData([ [$SPKISexp1, $seed], diff --git a/tests/XML/ds/SPKISexpTest.php b/tests/XML/ds/SPKISexpTest.php index a3b32b6c..7bcbcdb9 100644 --- a/tests/XML/ds/SPKISexpTest.php +++ b/tests/XML/ds/SPKISexpTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\SPKISexp; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, SPKISexp}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(SPKISexp::class)] final class SPKISexpTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $SPKISexp = new SPKISexp('GpM6'); + $SPKISexp = new SPKISexp( + Base64BinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/SeedTest.php b/tests/XML/ds/SeedTest.php index f6ded14b..532a9f85 100644 --- a/tests/XML/ds/SeedTest.php +++ b/tests/XML/ds/SeedTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Seed; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Seed}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Seed::class)] final class SeedTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $seed = new Seed('GpM6'); + $seed = new Seed( + CryptoBinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/SignatureMethodTest.php b/tests/XML/ds/SignatureMethodTest.php index d1046a81..c0eee9fc 100644 --- a/tests/XML/ds/SignatureMethodTest.php +++ b/tests/XML/ds/SignatureMethodTest.php @@ -4,17 +4,15 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\AnyURIValue; use SimpleSAML\XMLSecurity\Constants as C; +use SimpleSAML\XMLSecurity\Type\HMACOutputLengthValue; use SimpleSAML\XMLSecurity\Utils\XPath; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\HMACOutputLength; -use SimpleSAML\XMLSecurity\XML\ds\SignatureMethod; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, HMACOutputLength, SignatureMethod}; use function dirname; use function strval; @@ -24,6 +22,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(SignatureMethod::class)] final class SignatureMethodTest extends TestCase @@ -49,13 +48,19 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $hmacOutputLength = new HMACOutputLength('1234'); + $hmacOutputLength = new HMACOutputLength( + HMACOutputLengthValue::fromString('128'), + ); $chunk = new Chunk(DOMDocumentFactory::fromString( 'Some', )->documentElement); - $signatureMethod = new SignatureMethod(C::SIG_RSA_SHA256, $hmacOutputLength, [$chunk]); + $signatureMethod = new SignatureMethod( + AnyURIValue::fromString(C::SIG_RSA_SHA256), + $hmacOutputLength, + [$chunk], + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), @@ -68,13 +73,19 @@ public function testMarshalling(): void */ public function testMarshallingElementOrder(): void { - $hmacOutputLength = new HMACOutputLength('1234'); + $hmacOutputLength = new HMACOutputLength( + HMACOutputLengthValue::fromString('128'), + ); $chunk = new Chunk(DOMDocumentFactory::fromString( 'Some', )->documentElement); - $signatureMethod = new SignatureMethod(C::SIG_RSA_SHA256, $hmacOutputLength, [$chunk]); + $signatureMethod = new SignatureMethod( + AnyURIValue::fromString(C::SIG_RSA_SHA256), + $hmacOutputLength, + [$chunk], + ); $signatureMethodElement = $signatureMethod->toXML(); diff --git a/tests/XML/ds/SignaturePropertiesTest.php b/tests/XML/ds/SignaturePropertiesTest.php index a1d5b901..83488670 100644 --- a/tests/XML/ds/SignaturePropertiesTest.php +++ b/tests/XML/ds/SignaturePropertiesTest.php @@ -4,15 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\SignatureProperties; -use SimpleSAML\XMLSecurity\XML\ds\SignatureProperty; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, SignatureProperties, SignatureProperty}; use function dirname; use function strval; @@ -22,6 +19,7 @@ * * @package simplesamlphp/saml2 */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(SignatureProperties::class)] final class SignaturePropertiesTest extends TestCase @@ -52,10 +50,14 @@ public function testMarshalling(): void $signatureProperty = new SignatureProperty( [new Chunk($document->documentElement)], - 'https://simplesamlphp.org/some/target', - 'abc123', + AnyURIValue::fromString('https://simplesamlphp.org/some/target'), + IDValue::fromString('abc123'), + ); + + $signatureProperties = new SignatureProperties( + [$signatureProperty], + IDValue::fromString('def456'), ); - $signatureProperties = new SignatureProperties([$signatureProperty], 'def456'); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/SignaturePropertyTest.php b/tests/XML/ds/SignaturePropertyTest.php index 9d14ca8f..cc8591e9 100644 --- a/tests/XML/ds/SignaturePropertyTest.php +++ b/tests/XML/ds/SignaturePropertyTest.php @@ -4,14 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\SignatureProperty; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, SignatureProperty}; use function dirname; use function strval; @@ -21,6 +19,7 @@ * * @package simplesamlphp/saml2 */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(SignatureProperty::class)] final class SignaturePropertyTest extends TestCase @@ -51,8 +50,8 @@ public function testMarshalling(): void $signatureProperty = new SignatureProperty( [new Chunk($document->documentElement)], - 'https://simplesamlphp.org/some/target', - 'abc123', + AnyURIValue::fromString('https://simplesamlphp.org/some/target'), + IDValue::fromString('abc123'), ); $this->assertEquals( diff --git a/tests/XML/ds/SignatureTest.php b/tests/XML/ds/SignatureTest.php index 2c2e8498..b1423962 100644 --- a/tests/XML/ds/SignatureTest.php +++ b/tests/XML/ds/SignatureTest.php @@ -4,19 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\IDValue; use SimpleSAML\XMLSecurity\Utils\XPath; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\DsObject; -use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\ds\Signature; -use SimpleSAML\XMLSecurity\XML\ds\SignatureValue; -use SimpleSAML\XMLSecurity\XML\ds\SignedInfo; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, DsObject, KeyInfo}; +use SimpleSAML\XMLSecurity\XML\ds\{Signature, SignatureValue, SignedInfo}; use function dirname; use function strval; @@ -26,6 +21,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Signature::class)] final class SignatureTest extends TestCase @@ -81,7 +77,7 @@ public function testMarshalling(): void ], ), ], - 'def456', + IDValue::fromString('def456'), ); $this->assertEquals( @@ -125,7 +121,7 @@ public function testMarshallingElementOrdering(): void ], ), ], - 'def456', + IDValue::fromString('def456'), ); $signatureElement = $signature->toXML(); diff --git a/tests/XML/ds/SignatureValueTest.php b/tests/XML/ds/SignatureValueTest.php index aea9f1d6..1b19b541 100644 --- a/tests/XML/ds/SignatureValueTest.php +++ b/tests/XML/ds/SignatureValueTest.php @@ -4,14 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\SignatureValue; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{Base64BinaryValue, IDValue}; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, SignatureValue}; use function dirname; use function strval; @@ -21,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(SignatureValue::class)] final class SignatureValueTest extends TestCase @@ -46,30 +45,19 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $this->assertEquals( - self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval(new SignatureValue( + $signatureValue = new SignatureValue( + Base64BinaryValue::fromString( 'j14G9v6AnsOiEJYgkTg864DG3e/KLqoGpuybPGSGblVTn7ST6M/BsvP7YiVZjLqJEuEvWmf2mW4DPb+pbArzzDcsLWEtNveMrw+F' . 'kWehDUQV9oe20iepo+W46wmj7zB/eWL+Z8MrGvlycoTndJU6CVwHTLsB+dq2FDa7JV4pAPjMY32JZTbiwKhzqw3nEi/eVrujJE4Y' . 'RrlW28D+rXhITfoUAGGvsqPzcwGzp02lnMe2SmXADY1u9lbVjOhUrJpgvWfn9YuiCR+wjvaGMwIwzfJxChLJZOBV+1ad1CyNTiu6' . 'qAblxZ4F8cWlMWJ7f0KkWvtw66HOf2VNR6Qan2Ra7Q==', - 'abc123', - )), + ), + IDValue::fromString('abc123'), ); - } - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - $digestValue = new SignatureValue( - 'j14G9v6AnsOiEJYgkTg864DG3e/KLqoGpuybPGSGblVTn7ST6M/BsvP7YiVZjLqJEuEvWmf2mW4DPb+pbArzzDcsLWEtNveMrw+F' . - 'kWehDUQV9oe20iepo+W46wmj7zB/eWL+Z8MrGvlycoTndJU6CVwHTLsB+dq2FDa7JV4pAPjMY32JZTbiwKhzqw3nEi/eVrujJE4Y' . - 'RrlW28D+rXhITfoUAGGvsqPzcwGzp02lnMe2SmXADY1u9lbVjOhUrJpgvWfn9YuiCR+wjvaGMwIwzfJxChLJZOBV+1ad1CyNTiu6' . - 'qblxZ4F8cWlMWJ7f0KkWvtw66HOf2VNR6Qan2Ra7Q==', - 'abc123', + $this->assertEquals( + self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), + strval($signatureValue), ); } } diff --git a/tests/XML/ds/SignedInfoTest.php b/tests/XML/ds/SignedInfoTest.php index 7e83e291..60646c4c 100644 --- a/tests/XML/ds/SignedInfoTest.php +++ b/tests/XML/ds/SignedInfoTest.php @@ -5,17 +5,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; use DOMElement; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\CanonicalizationMethod; -use SimpleSAML\XMLSecurity\XML\ds\Reference; -use SimpleSAML\XMLSecurity\XML\ds\SignatureMethod; -use SimpleSAML\XMLSecurity\XML\ds\SignedInfo; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, CanonicalizationMethod, Reference, SignatureMethod, SignedInfo}; use function dirname; use function strval; @@ -25,6 +21,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(SignedInfo::class)] final class SignedInfoTest extends TestCase @@ -49,8 +46,12 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $signedInfo = new SignedInfo( - new CanonicalizationMethod(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), - new SignatureMethod(C::SIG_RSA_SHA256), + new CanonicalizationMethod( + AnyURIValue::fromString(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), + ), + new SignatureMethod( + AnyURIValue::fromString(C::SIG_RSA_SHA256), + ), [ Reference::fromXML( DOMDocumentFactory::fromFile( @@ -58,7 +59,7 @@ public function testMarshalling(): void )->documentElement, ), ], - 'cba321', + IDValue::fromString('cba321'), ); $this->assertEquals( diff --git a/tests/XML/ds/TransformTest.php b/tests/XML/ds/TransformTest.php index ff47bc41..aaab6291 100644 --- a/tests/XML/ds/TransformTest.php +++ b/tests/XML/ds/TransformTest.php @@ -4,15 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, NMTokensValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\XPath; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Transform, XPath}; use SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces; use function dirname; @@ -23,6 +21,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Transform::class)] final class TransformTest extends TestCase @@ -48,8 +47,10 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $transform = new Transform( - C::XPATH10_URI, - new XPath('count(//. | //@* | //namespace::*)'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('count(//. | //@* | //namespace::*)'), + ), ); $this->assertEquals( @@ -58,9 +59,11 @@ public function testMarshalling(): void ); $transform = new Transform( - C::C14N_EXCLUSIVE_WITHOUT_COMMENTS, + AnyURIValue::fromString(C::C14N_EXCLUSIVE_WITHOUT_COMMENTS), null, - new InclusiveNamespaces(["dsig", "soap"]), + new InclusiveNamespaces( + NMTokensValue::fromString("dsig soap"), + ), ); diff --git a/tests/XML/ds/TransformsTest.php b/tests/XML/ds/TransformsTest.php index 36710ece..ae58fb39 100644 --- a/tests/XML/ds/TransformsTest.php +++ b/tests/XML/ds/TransformsTest.php @@ -4,16 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; -use SimpleSAML\XMLSecurity\XML\ds\XPath; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Transform, Transforms, XPath}; use function dirname; use function strval; @@ -23,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Transforms::class)] final class TransformsTest extends TestCase @@ -49,9 +47,9 @@ public function testMarshalling(): void $transforms = new Transforms( [ new Transform( - C::XPATH10_URI, + AnyURIValue::fromString(C::XPATH10_URI), new XPath( - 'count(//. | //@* | //namespace::*)', + StringValue::fromString('count(//. | //@* | //namespace::*)'), ), ), ], diff --git a/tests/XML/ds/X509CRLTest.php b/tests/XML/ds/X509CRLTest.php index c59beb9e..cbd7c0f3 100644 --- a/tests/XML/ds/X509CRLTest.php +++ b/tests/XML/ds/X509CRLTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509CRL; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509CRL}; use function dirname; use function strval; @@ -21,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509CRL::class)] final class X509CRLTest extends TestCase @@ -43,20 +43,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $X509CRL = new X509CRL('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $X509CRL = new X509CRL( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($X509CRL), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new X509CRL('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/ds/X509CertificateTest.php b/tests/XML/ds/X509CertificateTest.php index ccb5d73a..f4640d05 100644 --- a/tests/XML/ds/X509CertificateTest.php +++ b/tests/XML/ds/X509CertificateTest.php @@ -4,26 +4,25 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509Certificate}; use function dirname; use function str_replace; use function strval; -use function substr; /** * Class \SimpleSAML\XMLSecurity\Test\XML\ds\X509CertificateTest * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509Certificate::class)] final class X509CertificateTest extends TestCase @@ -70,21 +69,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $x509cert = new X509Certificate(self::$certificate); + $x509cert = new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($x509cert), ); } - - - /** - */ - public function testMarshallingInvalidBase64(): void - { - $certificate = str_replace(substr(self::$certificate, 1), '', self::$certificate); - $this->expectException(AssertionFailedException::class); - new X509Certificate($certificate); - } } diff --git a/tests/XML/ds/X509DataTest.php b/tests/XML/ds/X509DataTest.php index a2ff2e3e..5a35b92c 100644 --- a/tests/XML/ds/X509DataTest.php +++ b/tests/XML/ds/X509DataTest.php @@ -4,23 +4,17 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IntegerValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\CryptoEncoding\PEM; use SimpleSAML\XMLSecurity\Key; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; -use SimpleSAML\XMLSecurity\XML\ds\X509IssuerName; -use SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial; -use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber; -use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509Certificate, X509Data}; +use SimpleSAML\XMLSecurity\XML\ds\{X509IssuerName, X509IssuerSerial, X509SerialNumber, X509SubjectName}; use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest; use function base64_encode; @@ -35,6 +29,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509Data::class)] final class X509DataTest extends TestCase @@ -97,22 +92,40 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $x509data = new X509Data( + [ + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509IssuerSerial( + new X509IssuerName( + StringValue::fromString(sprintf( + 'C=%s,ST=%s,L=%s,O=%s,CN=%s,emailAddress=%s', + 'US', + 'Hawaii', + 'Honolulu', + 'SimpleSAMLphp HQ', + 'SimpleSAMLphp Testing CA', + 'noreply@simplesamlphp.org', + )), + ), + new X509SerialNumber( + IntegerValue::fromString('2'), + ), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), + new X509Digest( + Base64BinaryValue::fromString(self::$digest), + AnyURIValue::fromString(C::DIGEST_SHA256), + ), + ], [ new Chunk( DOMDocumentFactory::fromString( 'some', )->documentElement, ), - new X509Certificate(self::$certificate), - new X509IssuerSerial( - new X509IssuerName(sprintf( - 'C=US,ST=Hawaii,L=Honolulu,O=SimpleSAMLphp HQ,CN=SimpleSAMLphp Testing CA,emailAddress=%s', - 'noreply@simplesamlphp.org', - )), - new X509SerialNumber('2'), - ), - new X509SubjectName(self::$certData['name']), - new X509Digest(self::$digest, C::DIGEST_SHA256), new Chunk(DOMDocumentFactory::fromString( 'other', )->documentElement), diff --git a/tests/XML/ds/X509IssuerNameTest.php b/tests/XML/ds/X509IssuerNameTest.php index 91f65ad3..5e7962b7 100644 --- a/tests/XML/ds/X509IssuerNameTest.php +++ b/tests/XML/ds/X509IssuerNameTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509IssuerName; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509IssuerName}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509IssuerName::class)] final class X509IssuerNameTest extends TestCase @@ -42,7 +43,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $issuerName = new X509IssuerName('some name'); + $issuerName = new X509IssuerName( + StringValue::fromString('some name'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/X509IssuerSerialTest.php b/tests/XML/ds/X509IssuerSerialTest.php index b8658966..3f1f187b 100644 --- a/tests/XML/ds/X509IssuerSerialTest.php +++ b/tests/XML/ds/X509IssuerSerialTest.php @@ -4,19 +4,16 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\{IntegerValue, StringValue}; use SimpleSAML\XMLSecurity\CryptoEncoding\PEM; use SimpleSAML\XMLSecurity\Key; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\Utils\Certificate as CertificateUtils; -use SimpleSAML\XMLSecurity\Utils\XPath; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509IssuerName; -use SimpleSAML\XMLSecurity\XML\ds\X509IssuerSerial; -use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber; +use SimpleSAML\XMLSecurity\Utils\{Certificate as CertificateUtils, XPath}; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509IssuerName, X509IssuerSerial, X509SerialNumber}; use function dirname; use function strval; @@ -26,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509IssuerSerial::class)] final class X509IssuerSerialTest extends TestCase @@ -56,8 +54,12 @@ public function setUp(): void /** @var string[] $details */ $details = self::$key->getCertificateDetails(); - self::$issuer = new X509IssuerName(CertificateUtils::parseIssuer($details['issuer'])); - self::$serial = new X509SerialNumber($details['serialNumber']); + self::$issuer = new X509IssuerName( + StringValue::fromString(CertificateUtils::parseIssuer($details['issuer'])), + ); + self::$serial = new X509SerialNumber( + IntegerValue::fromString($details['serialNumber']), + ); } diff --git a/tests/XML/ds/X509SKITest.php b/tests/XML/ds/X509SKITest.php index a3eb849d..4eb97327 100644 --- a/tests/XML/ds/X509SKITest.php +++ b/tests/XML/ds/X509SKITest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509SKI; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509SKI}; use function dirname; use function strval; @@ -21,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509SKI::class)] final class X509SKITest extends TestCase @@ -43,20 +43,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $X509SKI = new X509SKI('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $X509SKI = new X509SKI( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($X509SKI), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new X509SKI('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/ds/X509SerialNumberTest.php b/tests/XML/ds/X509SerialNumberTest.php index ee0f8077..a098ec83 100644 --- a/tests/XML/ds/X509SerialNumberTest.php +++ b/tests/XML/ds/X509SerialNumberTest.php @@ -4,13 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\Exception\SchemaViolationException; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509SerialNumber; +use SimpleSAML\XML\Type\IntegerValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509SerialNumber}; use function dirname; use function strval; @@ -20,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509SerialNumber::class)] final class X509SerialNumberTest extends TestCase @@ -43,7 +44,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $serialNumber = new X509SerialNumber('123456'); + $serialNumber = new X509SerialNumber( + IntegerValue::fromString('123456'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/X509SubjectNameTest.php b/tests/XML/ds/X509SubjectNameTest.php index cec3e0b8..4140319a 100644 --- a/tests/XML/ds/X509SubjectNameTest.php +++ b/tests/XML/ds/X509SubjectNameTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, X509SubjectName}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(X509SubjectName::class)] final class X509SubjectNameTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $subjectName = new X509SubjectName('some name'); + $subjectName = new X509SubjectName( + StringValue::fromString('some name'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/ds/XPathTest.php b/tests/XML/ds/XPathTest.php index 227b07ea..31b4f88e 100644 --- a/tests/XML/ds/XPathTest.php +++ b/tests/XML/ds/XPathTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\XPath; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, XPath}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(XPath::class)] class XPathTest extends TestCase @@ -40,7 +41,9 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { - $xpath = new XPath('self::xenc:CipherValue[@Id="example1"]'); + $xpath = new XPath( + StringValue::fromString('self::xenc:CipherValue[@Id="example1"]'), + ); $this->assertEquals('self::xenc:CipherValue[@Id="example1"]', $xpath->getExpression()); $this->assertEquals( diff --git a/tests/XML/ds/YTest.php b/tests/XML/ds/YTest.php index a1417763..7cc82466 100644 --- a/tests/XML/ds/YTest.php +++ b/tests/XML/ds/YTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ds; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\Y; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{AbstractDsElement, Y}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ds')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(Y::class)] final class YTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $y = new Y('GpM6'); + $y = new Y( + CryptoBinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/dsig11/KeyInfoReferenceTest.php b/tests/XML/dsig11/KeyInfoReferenceTest.php index 96005875..c89ecc28 100644 --- a/tests/XML/dsig11/KeyInfoReferenceTest.php +++ b/tests/XML/dsig11/KeyInfoReferenceTest.php @@ -4,13 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\dsig11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element; -use SimpleSAML\XMLSecurity\XML\dsig11\KeyInfoReference; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue}; +use SimpleSAML\XMLSecurity\XML\dsig11\{AbstractDsig11Element, KeyInfoReference}; use function dirname; use function strval; @@ -20,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('dsig11')] #[CoversClass(AbstractDsig11Element::class)] #[CoversClass(KeyInfoReference::class)] final class KeyInfoReferenceTest extends TestCase @@ -43,7 +43,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $KeyInfoReference = new KeyInfoReference('#_e395489e5f8444f1aabb4b2ca98a23b793d211ddf0', 'abc123'); + $KeyInfoReference = new KeyInfoReference( + AnyURIValue::fromString('#_e395489e5f8444f1aabb4b2ca98a23b793d211ddf0'), + IDValue::fromString('abc123'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/dsig11/X509DigestTest.php b/tests/XML/dsig11/X509DigestTest.php index 0f50561c..cff9e35a 100644 --- a/tests/XML/dsig11/X509DigestTest.php +++ b/tests/XML/dsig11/X509DigestTest.php @@ -4,18 +4,17 @@ namespace SimpleSAML\XMLSecurity\Test\XML\dsig11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\CryptoEncoding\PEM; use SimpleSAML\XMLSecurity\Key; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\dsig11\AbstractDsig11Element; -use SimpleSAML\XMLSecurity\XML\dsig11\X509Digest; +use SimpleSAML\XMLSecurity\XML\dsig11\{AbstractDsig11Element, X509Digest}; use function base64_encode; use function dirname; @@ -27,6 +26,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('dsig11')] #[CoversClass(AbstractDsig11Element::class)] #[CoversClass(X509Digest::class)] final class X509DigestTest extends TestCase @@ -59,7 +59,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $x509digest = new X509Digest(self::$digest, C::DIGEST_SHA256); + $x509digest = new X509Digest( + Base64BinaryValue::fromString(self::$digest), + AnyURIValue::fromString(C::DIGEST_SHA256), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), diff --git a/tests/XML/ec/InclusiveNamespacesTest.php b/tests/XML/ec/InclusiveNamespacesTest.php index 9989d685..c97cf624 100644 --- a/tests/XML/ec/InclusiveNamespacesTest.php +++ b/tests/XML/ec/InclusiveNamespacesTest.php @@ -4,13 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\ec; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\ec\AbstractEcElement; -use SimpleSAML\XMLSecurity\XML\ec\InclusiveNamespaces; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\NMTokensValue; +use SimpleSAML\XMLSecurity\XML\ec\{AbstractEcElement, InclusiveNamespaces}; use function dirname; use function strval; @@ -20,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('ec')] #[CoversClass(AbstractEcElement::class)] #[CoversClass(InclusiveNamespaces::class)] class InclusiveNamespacesTest extends TestCase @@ -41,11 +41,11 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { - $inclusiveNamespaces = new InclusiveNamespaces(["dsig", "soap"]); + $inclusiveNamespaces = new InclusiveNamespaces( + NMTokensValue::fromString("dsig soap"), + ); - $this->assertCount(2, $inclusiveNamespaces->getPrefixes()); - $this->assertEquals("dsig", $inclusiveNamespaces->getPrefixes()[0]); - $this->assertEquals("soap", $inclusiveNamespaces->getPrefixes()[1]); + $this->assertEquals("dsig soap", strval($inclusiveNamespaces->getPrefixes())); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc/AgreementMethodTest.php b/tests/XML/xenc/AgreementMethodTest.php index e8dfe992..212f7c1a 100644 --- a/tests/XML/xenc/AgreementMethodTest.php +++ b/tests/XML/xenc/AgreementMethodTest.php @@ -4,11 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Chunk; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\{SerializableElementTestTrait, SchemaValidationTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; use SimpleSAML\XMLSecurity\Utils\XPath; @@ -26,6 +27,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractAgreementMethodType::class)] #[CoversClass(AgreementMethod::class)] @@ -81,10 +83,12 @@ public function setUp(): void */ public function testMarshalling(): void { - $kaNonce = new KANonce('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $kaNonce = new KANonce( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $digestMethod = new DigestMethod( - C::DIGEST_SHA256, + AnyURIValue::fromString(C::DIGEST_SHA256), [ new Chunk(DOMDocumentFactory::fromString( 'some', @@ -94,38 +98,50 @@ public function testMarshalling(): void $originatorKeyInfo = new OriginatorKeyInfo( [ - new KeyName('testkey'), + new KeyName( + StringValue::fromString('testkey'), + ), new X509Data( [ - new X509Certificate(self::$certificate), - new X509SubjectName(self::$certData['name']), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), ], ), new Chunk(DOMDocumentFactory::fromString( 'originator', )->documentElement), ], - 'fed123', + IDValue::fromString('fed123'), ); $recipientKeyInfo = new RecipientKeyInfo( [ - new KeyName('testkey'), + new KeyName( + StringValue::fromString('testkey'), + ), new X509Data( [ - new X509Certificate(self::$certificate), - new X509SubjectName(self::$certData['name']), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), ], ), new Chunk(DOMDocumentFactory::fromString( 'recipient', )->documentElement), ], - 'fed654', + IDValue::fromString('fed654'), ); $agreementMethod = new AgreementMethod( - C::XMLENC11_ECDH_ES, + AnyURIValue::fromString(C::KEY_AGREEMENT_ECDH_ES), $kaNonce, $originatorKeyInfo, $recipientKeyInfo, @@ -141,10 +157,12 @@ public function testMarshalling(): void public function testMarshallingElementOrdering(): void { - $kaNonce = new KANonce('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $kaNonce = new KANonce( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $digestMethod = new DigestMethod( - C::DIGEST_SHA256, + AnyURIValue::fromString(C::DIGEST_SHA256), [ new Chunk(DOMDocumentFactory::fromString( 'some', @@ -154,38 +172,50 @@ public function testMarshallingElementOrdering(): void $originatorKeyInfo = new OriginatorKeyInfo( [ - new KeyName('testkey'), + new KeyName( + StringValue::fromString('testkey'), + ), new X509Data( [ - new X509Certificate(self::$certificate), - new X509SubjectName(self::$certData['name']), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), ], ), new Chunk(DOMDocumentFactory::fromString( 'originator', )->documentElement), ], - 'fed321', + IDValue::fromString('fed321'), ); $recipientKeyInfo = new RecipientKeyInfo( [ - new KeyName('testkey'), + new KeyName( + StringValue::fromString('testkey'), + ), new X509Data( [ - new X509Certificate(self::$certificate), - new X509SubjectName(self::$certData['name']), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), ], ), new Chunk(DOMDocumentFactory::fromString( 'recipient', )->documentElement), ], - 'fed654', + IDValue::fromString('fed654'), ); $agreementMethod = new AgreementMethod( - C::XMLENC11_ECDH_ES, + AnyURIValue::fromString(C::KEY_AGREEMENT_ECDH_ES), $kaNonce, $originatorKeyInfo, $recipientKeyInfo, diff --git a/tests/XML/xenc/CarriedKeyNameTest.php b/tests/XML/xenc/CarriedKeyNameTest.php index b5758c00..419f05fc 100644 --- a/tests/XML/xenc/CarriedKeyNameTest.php +++ b/tests/XML/xenc/CarriedKeyNameTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, CarriedKeyName}; use function dirname; use function strval; @@ -22,6 +22,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(CarriedKeyName::class)] final class CarriedKeyNameTest extends TestCase @@ -44,7 +45,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $keyName = new CarriedKeyName('Some label'); + $keyName = new CarriedKeyName( + StringValue::fromString('Some label'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc/CipherDataTest.php b/tests/XML/xenc/CipherDataTest.php index dad95705..6665c40f 100644 --- a/tests/XML/xenc/CipherDataTest.php +++ b/tests/XML/xenc/CipherDataTest.php @@ -4,14 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\CipherData; -use SimpleSAML\XMLSecurity\XML\xenc\CipherValue; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, CipherData, CipherValue}; use function dirname; use function strval; @@ -24,6 +22,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(CipherData::class)] final class CipherDataTest extends TestCase @@ -50,7 +49,11 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $cipherData = new CipherData(new CipherValue('c29tZSB0ZXh0')); + $cipherData = new CipherData( + new CipherValue( + Base64BinaryValue::fromString('c29tZSB0ZXh0'), + ), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc/CipherReferenceTest.php b/tests/XML/xenc/CipherReferenceTest.php index 320ae411..63a8d1fb 100644 --- a/tests/XML/xenc/CipherReferenceTest.php +++ b/tests/XML/xenc/CipherReferenceTest.php @@ -4,18 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractReference; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\CipherReference; -use SimpleSAML\XMLSecurity\XML\xenc\Transforms; +use SimpleSAML\XMLSecurity\XML\ds\{Transform, XPath}; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractReference, AbstractXencElement, CipherReference, Transforms}; use function dirname; use function strval; @@ -29,6 +25,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractReference::class)] #[CoversClass(CipherReference::class)] @@ -51,8 +48,12 @@ public static function setUpBeforeClass(): void dirname(__FILE__, 3) . '/resources/xml/xenc_CipherReference.xml', ); - $xpath = new XPath('count(//. | //@* | //namespace::*)'); - $transform = new Transform(C::XPATH10_URI, $xpath); + $transform = new Transform( + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('count(//. | //@* | //namespace::*)'), + ), + ); self::$transforms = new Transforms([$transform]); } @@ -64,7 +65,10 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $cipherReference = new CipherReference('#Cipher_VALUE_ID', [self::$transforms]); + $cipherReference = new CipherReference( + AnyURIValue::fromString('#Cipher_VALUE_ID'), + [self::$transforms], + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc/CipherValueTest.php b/tests/XML/xenc/CipherValueTest.php index 9b264fd8..78e8b252 100644 --- a/tests/XML/xenc/CipherValueTest.php +++ b/tests/XML/xenc/CipherValueTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\CipherValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, CipherValue}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(CipherValue::class)] final class CipherValueTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $cipherValue = new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $cipherValue = new CipherValue( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($cipherValue), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new CipherValue('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/DHKeyValueTest.php b/tests/XML/xenc/DHKeyValueTest.php index 32a834bb..64b26091 100644 --- a/tests/XML/xenc/DHKeyValueTest.php +++ b/tests/XML/xenc/DHKeyValueTest.php @@ -4,21 +4,23 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; use SimpleSAML\XMLSecurity\Utils\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractDHKeyValueType; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\DHKeyValue; -use SimpleSAML\XMLSecurity\XML\xenc\Generator; -use SimpleSAML\XMLSecurity\XML\xenc\P; -use SimpleSAML\XMLSecurity\XML\xenc\PgenCounter; -use SimpleSAML\XMLSecurity\XML\xenc\Q; -use SimpleSAML\XMLSecurity\XML\xenc\Seed; -use SimpleSAML\XMLSecurity\XML\xenc\XencPublic; +use SimpleSAML\XMLSecurity\XML\xenc\{ + AbstractDHKeyValueType, + AbstractXencElement, + DHKeyValue, + Generator, + P, + PgenCounter, + Q, + Seed, + XencPublic, +}; use function dirname; use function strval; @@ -32,6 +34,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractDHKeyValueType::class)] #[CoversClass(DHKeyValue::class)] @@ -40,6 +43,8 @@ final class DHKeyValueTest extends TestCase use SchemaValidationTestTrait; use SerializableElementTestTrait; + private static DHKeyValue $dhKeyValue; + /** */ public static function setUpBeforeClass(): void @@ -49,6 +54,27 @@ public static function setUpBeforeClass(): void self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 3) . '/resources/xml/xenc_DHKeyValue.xml', ); + + self::$dhKeyValue = new DHKeyValue( + new XencPublic( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + new P( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + new Q( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + new Generator( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + new Seed( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + new PgenCounter( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ); } @@ -56,35 +82,17 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $xencPublic = new XencPublic('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $q = new Q('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $generator = new Generator('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $pgenCounter = new PgenCounter('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - - $dhKeyValue = new DHKeyValue($xencPublic, $p, $q, $generator, $seed, $pgenCounter); - $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), - strval($dhKeyValue), + strval(self::$dhKeyValue), ); } /** */ public function testMarshallingElementOrder(): void { - $xencPublic = new XencPublic('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $q = new Q('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $generator = new Generator('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $pgenCounter = new PgenCounter('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - - $dhKeyValue = new DHKeyValue($xencPublic, $p, $q, $generator, $seed, $pgenCounter); - // Marshall it to a \DOMElement - $dhKeyValueElement = $dhKeyValue->toXML(); + $dhKeyValueElement = self::$dhKeyValue->toXML(); $xpCache = XPath::getXPath($dhKeyValueElement); diff --git a/tests/XML/xenc/DataReferenceTest.php b/tests/XML/xenc/DataReferenceTest.php index 48028e67..68853c9d 100644 --- a/tests/XML/xenc/DataReferenceTest.php +++ b/tests/XML/xenc/DataReferenceTest.php @@ -4,17 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; -use SimpleSAML\XMLSecurity\XML\ds\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractReference; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\DataReference; +use SimpleSAML\XMLSecurity\XML\ds\{Transform, Transforms, XPath}; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractReference, AbstractXencElement, DataReference}; use function dirname; use function strval; @@ -28,6 +25,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractReference::class)] #[CoversClass(DataReference::class)] @@ -55,13 +53,15 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $dataReference = new DataReference( - '#Encrypted_DATA_ID', + AnyURIValue::fromString('#Encrypted_DATA_ID'), [ new Transforms( [ new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedData[@Id="example1"]'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('self::xenc:EncryptedData[@Id="example1"]'), + ), ), ], ), diff --git a/tests/XML/xenc/EncryptedDataTest.php b/tests/XML/xenc/EncryptedDataTest.php index cba409aa..243ccdbc 100644 --- a/tests/XML/xenc/EncryptedDataTest.php +++ b/tests/XML/xenc/EncryptedDataTest.php @@ -4,20 +4,23 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IDValue, StringValue}; +use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Utils\XPath; use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptedType; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\CipherData; -use SimpleSAML\XMLSecurity\XML\xenc\CipherValue; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedData; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod; +use SimpleSAML\XMLSecurity\XML\xenc\{ + AbstractEncryptedType, + AbstractXencElement, + CipherData, + CipherValue, + EncryptedData, + EncryptedKey, + EncryptionMethod, +}; use function dirname; use function strval; @@ -31,6 +34,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractEncryptedType::class)] #[CoversClass(EncryptedData::class)] @@ -59,23 +63,35 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $encryptedData = new EncryptedData( - new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), - 'MyID', - 'http://www.w3.org/2001/04/xmlenc#Element', - 'text/plain', - 'urn:x-simplesamlphp:encoding', - new EncryptionMethod('http://www.w3.org/2001/04/xmlenc#aes128-cbc'), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ), + IDValue::fromString('MyID'), + AnyURIValue::fromString(C::XMLENC_ELEMENT), + StringValue::fromString('text/plain'), + AnyURIValue::fromString('urn:x-simplesamlphp:encoding'), + new EncryptionMethod( + AnyURIValue::fromString(C::BLOCK_ENC_AES128), + ), new KeyInfo( [ new EncryptedKey( - new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ), null, null, null, null, null, null, - new EncryptionMethod('http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'), + new EncryptionMethod( + AnyURIValue::fromString(C::SIG_RSA_SHA256), + ), ), ], ), @@ -93,23 +109,35 @@ public function testMarshalling(): void public function testMarshallingElementOrdering(): void { $encryptedData = new EncryptedData( - new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), - 'MyID', - 'http://www.w3.org/2001/04/xmlenc#Element', - 'text/plain', - 'urn:x-simplesamlphp:encoding', - new EncryptionMethod('http://www.w3.org/2001/04/xmlenc#aes128-cbc'), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ), + IDValue::fromString('MyID'), + AnyURIValue::fromString(C::XMLENC_ELEMENT), + StringValue::fromString('text/plain'), + AnyURIValue::fromString('urn:x-simplesamlphp:encoding'), + new EncryptionMethod( + AnyURIValue::fromString(C::BLOCK_ENC_AES128), + ), new KeyInfo( [ new EncryptedKey( - new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ), null, null, null, null, null, null, - new EncryptionMethod('http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'), + new EncryptionMethod( + AnyURIValue::fromString(C::SIG_RSA_SHA256), + ), ), ], ), diff --git a/tests/XML/xenc/EncryptedKeyTest.php b/tests/XML/xenc/EncryptedKeyTest.php index 3ced3a2a..1254047a 100644 --- a/tests/XML/xenc/EncryptedKeyTest.php +++ b/tests/XML/xenc/EncryptedKeyTest.php @@ -4,28 +4,28 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Key\PrivateKey; -use SimpleSAML\XMLSecurity\Key\PublicKey; -use SimpleSAML\XMLSecurity\Key\SymmetricKey; +use SimpleSAML\XMLSecurity\Key\{PrivateKey, PublicKey, SymmetricKey}; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; use SimpleSAML\XMLSecurity\Utils\XPath; use SimpleSAML\XMLSecurity\XML\ds\KeyInfo; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptedType; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName; -use SimpleSAML\XMLSecurity\XML\xenc\CipherData; -use SimpleSAML\XMLSecurity\XML\xenc\CipherValue; -use SimpleSAML\XMLSecurity\XML\xenc\DataReference; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptedKey; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod; -use SimpleSAML\XMLSecurity\XML\xenc\ReferenceList; +use SimpleSAML\XMLSecurity\XML\xenc\{ + AbstractEncryptedType, + AbstractXencElement, + CarriedKeyName, + CipherData, + CipherValue, + DataReference, + EncryptedKey, + EncryptionMethod, + ReferenceList, +}; use function bin2hex; use function dirname; @@ -40,6 +40,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractEncryptedType::class)] #[CoversClass(EncryptedKey::class)] @@ -77,32 +78,54 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $encryptedKey = new EncryptedKey( - new CipherData(new CipherValue('3W3C4UoWshi02yrqsLC2z8Qr1FjdTz7LV9CvpunilOX4teGKsjKqNbS92DKcXLwS8s' - . '4eHBdHejiL1bySDQT5diN/TVo8zz0AmPwX3/eHPQE91NWzceB+yaoEDauMPvi7twUdoipbLZa7cyT4QR+RO9w5P5wf4wDoTPUoQ' - . 'V6dF9YSJqehuRFCqVJprIDZNfrKnm7WfwMiaMLvaLVdLWgXjuVdiH0lT/F4KJrhJwAnjp57KGn9mhAcwkFe+qDIMSi8Ond6I0FO' - . 'V3SOx8NxpSTHYfZ4qE1Xn/dvUUXqgRnEFPHAw4JFmJPjgTSCPU6BdwBLzqVjh1pCLoCn66P/Zt7I9Q==')), - 'Encrypted_KEY_ID', - 'http://www.w3.org/2001/04/xmlenc#Element', - 'text/plain', - 'urn:x-simplesamlphp:encoding', - 'some_ENTITY_ID', - new CarriedKeyName('Name of the key'), - new EncryptionMethod('http://www.w3.org/2001/04/xmlenc#rsa-1_5'), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString( + '3W3C4UoWshi02yrqsLC2z8Qr1FjdTz7LV9CvpunilOX4teGKsjKqNbS92DKcXLwS8s' . + '4eHBdHejiL1bySDQT5diN/TVo8zz0AmPwX3/eHPQE91NWzceB+yaoEDauMPvi7twUd' . + 'oipbLZa7cyT4QR+RO9w5P5wf4wDoTPUoQV6dF9YSJqehuRFCqVJprIDZNfrKnm7Wfw' . + 'MiaMLvaLVdLWgXjuVdiH0lT/F4KJrhJwAnjp57KGn9mhAcwkFe+qDIMSi8Ond6I0FO' . + 'V3SOx8NxpSTHYfZ4qE1Xn/dvUUXqgRnEFPHAw4JFmJPjgTSCPU6BdwBLzqVjh1pCLo' . + 'Cn66P/Zt7I9Q==', + ), + ), + ), + IDValue::fromString('Encrypted_KEY_ID'), + AnyURIValue::fromString(C::XMLENC_ELEMENT), + StringValue::fromString('text/plain'), + AnyURIValue::fromString('urn:x-simplesamlphp:encoding'), + StringValue::fromString('some_ENTITY_ID'), + new CarriedKeyName( + StringValue::fromString('Name of the key'), + ), + new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_RSA_1_5), + ), new KeyInfo( [ new EncryptedKey( - new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ), null, null, null, null, null, null, - new EncryptionMethod('http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'), + new EncryptionMethod( + AnyURIValue::fromString(C::SIG_RSA_SHA256), + ), ), ], ), - new ReferenceList([new DataReference('#Encrypted_DATA_ID')]), + new ReferenceList([ + new DataReference( + AnyURIValue::fromString('#Encrypted_DATA_ID'), + ), + ]), ); $this->assertEquals( @@ -117,32 +140,54 @@ public function testMarshalling(): void public function testMarshallingElementOrdering(): void { $encryptedKey = new EncryptedKey( - new CipherData(new CipherValue('3W3C4UoWshi02yrqsLC2z8Qr1FjdTz7LV9CvpunilOX4teGKsjKqNbS92DKcXLwS8s' - . '4eHBdHejiL1bySDQT5diN/TVo8zz0AmPwX3/eHPQE91NWzceB+yaoEDauMPvi7twUdoipbLZa7cyT4QR+RO9w5P5wf4wDoTPUoQ' - . 'V6dF9YSJqehuRFCqVJprIDZNfrKnm7WfwMiaMLvaLVdLWgXjuVdiH0lT/F4KJrhJwAnjp57KGn9mhAcwkFe+qDIMSi8Ond6I0FO' - . 'V3SOx8NxpSTHYfZ4qE1Xn/dvUUXqgRnEFPHAw4JFmJPjgTSCPU6BdwBLzqVjh1pCLoCn66P/Zt7I9Q==')), - 'Encrypted_KEY_ID', - 'http://www.w3.org/2001/04/xmlenc#Element', - 'text/plain', - 'urn:x-simplesamlphp:encoding', - 'some_ENTITY_ID', - new CarriedKeyName('Name of the key'), - new EncryptionMethod('http://www.w3.org/2001/04/xmlenc#rsa-1_5'), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString( + '3W3C4UoWshi02yrqsLC2z8Qr1FjdTz7LV9CvpunilOX4teGKsjKqNbS92DKcXLwS8s' . + '4eHBdHejiL1bySDQT5diN/TVo8zz0AmPwX3/eHPQE91NWzceB+yaoEDauMPvi7twUd' . + 'oipbLZa7cyT4QR+RO9w5P5wf4wDoTPUoQV6dF9YSJqehuRFCqVJprIDZNfrKnm7Wfw' . + 'MiaMLvaLVdLWgXjuVdiH0lT/F4KJrhJwAnjp57KGn9mhAcwkFe+qDIMSi8Ond6I0FO' . + 'V3SOx8NxpSTHYfZ4qE1Xn/dvUUXqgRnEFPHAw4JFmJPjgTSCPU6BdwBLzqVjh1pCLo' . + 'Cn66P/Zt7I9Q==', + ), + ), + ), + IDValue::fromString('Encrypted_KEY_ID'), + AnyURIValue::fromString(C::XMLENC_ELEMENT), + StringValue::fromString('text/plain'), + AnyURIValue::fromString('urn:x-simplesamlphp:encoding'), + StringValue::fromString('some_ENTITY_ID'), + new CarriedKeyName( + StringValue::fromString('Name of the key'), + ), + new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_RSA_1_5), + ), new KeyInfo( [ new EncryptedKey( - new CipherData(new CipherValue('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')), + new CipherData( + new CipherValue( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ), null, null, null, null, null, null, - new EncryptionMethod('http://www.w3.org/2001/04/xmldsig-more#rsa-sha256'), + new EncryptionMethod( + AnyURIValue::fromString(C::SIG_RSA_SHA256), + ), ), ], ), - new ReferenceList([new DataReference('#Encrypted_DATA_ID')]), + new ReferenceList([ + new DataReference( + AnyURIValue::fromString('#Encrypted_DATA_ID'), + ), + ]), ); // Marshall it to a \DOMElement @@ -181,7 +226,9 @@ public function testPKCS1Encryption(): void $encryptedKey = EncryptedKey::fromKey( $symmetricKey, $encryptor, - new EncryptionMethod(C::KEY_TRANSPORT_RSA_1_5), + new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_RSA_1_5), + ), ); $decryptor = $factory->getAlgorithm(C::KEY_TRANSPORT_RSA_1_5, self::$privKey); @@ -202,7 +249,9 @@ public function testOAEPEncryption(): void $encryptedKey = EncryptedKey::fromKey( $symmetricKey, $encryptor, - new EncryptionMethod(C::KEY_TRANSPORT_OAEP), + new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_OAEP), + ), ); $decryptor = $factory->getAlgorithm(C::KEY_TRANSPORT_OAEP, self::$privKey); @@ -223,7 +272,9 @@ public function testOAEMGF1PPEncryption(): void $encryptedKey = EncryptedKey::fromKey( $symmetricKey, $encryptor, - new EncryptionMethod(C::KEY_TRANSPORT_OAEP_MGF1P), + new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_OAEP_MGF1P), + ), ); $decryptor = $factory->getAlgorithm(C::KEY_TRANSPORT_OAEP_MGF1P, self::$privKey); diff --git a/tests/XML/xenc/EncryptionMethodTest.php b/tests/XML/xenc/EncryptionMethodTest.php index cbda1709..66e2b6ac 100644 --- a/tests/XML/xenc/EncryptionMethodTest.php +++ b/tests/XML/xenc/EncryptionMethodTest.php @@ -4,19 +4,22 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; use SimpleSAML\XML\Exception\MissingAttributeException; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\{AnyURIValue, Base64BinaryValue}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\Utils\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptionMethod; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod; -use SimpleSAML\XMLSecurity\XML\xenc\KeySize; -use SimpleSAML\XMLSecurity\XML\xenc\OAEPparams; +use SimpleSAML\XMLSecurity\Type\KeySizeValue; +use SimpleSAML\XMLSecurity\XML\xenc\{ + AbstractEncryptionMethod, + AbstractXencElement, + EncryptionMethod, + KeySize, + OAEPparams, +}; use function dirname; use function strval; @@ -29,6 +32,7 @@ * @covers \SimpleSAML\XMLSecurity\XML\xenc\EncryptionMethod * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractEncryptionMethod::class)] #[CoversClass(EncryptionMethod::class)] @@ -56,13 +60,21 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $alg = 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'; $chunkXml = DOMDocumentFactory::fromString('Value'); /** @var \DOMElement $chunkElt */ $chunkElt = $chunkXml->documentElement; $chunk = Chunk::fromXML($chunkElt); - $em = new EncryptionMethod($alg, new KeySize(10), new OAEPparams('9lWu3Q=='), [$chunk]); + $em = new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_OAEP_MGF1P), + new KeySize( + KeySizeValue::fromString('10'), + ), + new OAEPparams( + Base64BinaryValue::fromString('9lWu3Q=='), + ), + [$chunk], + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), @@ -76,12 +88,14 @@ public function testMarshalling(): void */ public function testMarshallingWithoutOptionalParameters(): void { - $em = new EncryptionMethod('http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'); $document = DOMDocumentFactory::fromString( '', ); + $em = new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_OAEP_MGF1P), + ); $this->assertNull($em->getKeySize()); $this->assertNull($em->getOAEPParams()); $this->assertEmpty($em->getElements()); @@ -94,13 +108,21 @@ public function testMarshallingWithoutOptionalParameters(): void public function testMarshallingElementOrdering(): void { - $alg = 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p'; $chunkXml = DOMDocumentFactory::fromString('Value'); /** @var \DOMElement $chunkElt */ $chunkElt = $chunkXml->documentElement; $chunk = Chunk::fromXML($chunkElt); - $em = new EncryptionMethod($alg, new KeySize(10), new OAEPparams('9lWu3Q=='), [$chunk]); + $em = new EncryptionMethod( + AnyURIValue::fromString(C::KEY_TRANSPORT_OAEP_MGF1P), + new KeySize( + KeySizeValue::fromString('10'), + ), + new OAEPparams( + Base64BinaryValue::fromString('9lWu3Q=='), + ), + [$chunk], + ); // Marshall it to a \DOMElement $emElement = $em->toXML(); diff --git a/tests/XML/xenc/EncryptionPropertiesTest.php b/tests/XML/xenc/EncryptionPropertiesTest.php index 867e2059..722fce2c 100644 --- a/tests/XML/xenc/EncryptionPropertiesTest.php +++ b/tests/XML/xenc/EncryptionPropertiesTest.php @@ -4,18 +4,18 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Attribute as XMLAttribute; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptionPropertiesType; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperties; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty; +use SimpleSAML\XML\{Chunk, Constants as C, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; +use SimpleSAML\XMLSecurity\XML\xenc\{ + AbstractEncryptionPropertiesType, + AbstractXencElement, + EncryptionProperties, + EncryptionProperty, +}; use function dirname; use function strval; @@ -29,6 +29,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractEncryptionPropertiesType::class)] #[CoversClass(EncryptionProperties::class)] @@ -68,23 +69,36 @@ public function testMarshalling(): void /** @var \DOMElement $otherElt */ $otherElt = $otherDoc->documentElement; - $attr1 = new XMLAttribute(C::NS_XML, 'xml', 'lang', 'en'); - $attr2 = new XMLAttribute(C::NS_XML, 'xml', 'lang', 'nl'); + $attr1 = new XMLAttribute( + C::NS_XML, + 'xml', + 'lang', + StringValue::fromString('en'), + ); + $attr2 = new XMLAttribute( + C::NS_XML, + 'xml', + 'lang', + StringValue::fromString('nl'), + ); $encryptionProperty1 = new EncryptionProperty( [new Chunk($someElt)], - 'urn:x-simplesamlphp:phpunit', - 'inner-first', + AnyURIValue::fromString('urn:x-simplesamlphp:phpunit'), + IDValue::fromString('inner-first'), [$attr1], ); $encryptionProperty2 = new EncryptionProperty( [new Chunk($otherElt)], - 'urn:x-simplesamlphp:phpunit', - 'inner-second', + AnyURIValue::fromString('urn:x-simplesamlphp:phpunit'), + IDValue::fromString('inner-second'), [$attr2], ); - $encryptionProperties = new EncryptionProperties([$encryptionProperty1, $encryptionProperty2], 'outer'); + $encryptionProperties = new EncryptionProperties( + [$encryptionProperty1, $encryptionProperty2], + IDValue::fromString('outer'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc/EncryptionPropertyTest.php b/tests/XML/xenc/EncryptionPropertyTest.php index 7d24b14c..439f791e 100644 --- a/tests/XML/xenc/EncryptionPropertyTest.php +++ b/tests/XML/xenc/EncryptionPropertyTest.php @@ -4,17 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Attribute as XMLAttribute; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\Constants as C; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractEncryptionPropertyType; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\EncryptionProperty; +use SimpleSAML\XML\{Attribute as XMLAttribute, Chunk, Constants as C, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractEncryptionPropertyType, AbstractXencElement, EncryptionProperty}; use function dirname; use function strval; @@ -28,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractEncryptionPropertyType::class)] #[CoversClass(EncryptionProperty::class)] @@ -61,11 +57,17 @@ public function testMarshalling(): void /** @var \DOMElement $elt */ $elt = $doc->documentElement; - $attr = new XMLAttribute(C::NS_XML, 'xml', 'lang', 'en'); + $attr = new XMLAttribute( + C::NS_XML, + 'xml', + 'lang', + StringValue::fromString('en'), + ); + $encryptionProperty = new EncryptionProperty( [new Chunk($elt)], - 'urn:x-simplesamlphp:phpunit', - 'phpunit', + AnyURIValue::fromString('urn:x-simplesamlphp:phpunit'), + IDValue::fromString('phpunit'), [$attr], ); diff --git a/tests/XML/xenc/GeneratorTest.php b/tests/XML/xenc/GeneratorTest.php index eb7e6c0d..f35ca1d4 100644 --- a/tests/XML/xenc/GeneratorTest.php +++ b/tests/XML/xenc/GeneratorTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\Generator; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, Generator}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(Generator::class)] final class GeneratorTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $generator = new Generator('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $generator = new Generator( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($generator), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new Generator('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/KANonceTest.php b/tests/XML/xenc/KANonceTest.php index fb72c681..382e895f 100644 --- a/tests/XML/xenc/KANonceTest.php +++ b/tests/XML/xenc/KANonceTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\Base64BinaryValue; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\KANonce; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, KANonce}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(KANonce::class)] final class KANonceTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $kaNonce = new KANonce('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $kaNonce = new KANonce( + Base64BinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($kaNonce), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new KANonce('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/KeyReferenceTest.php b/tests/XML/xenc/KeyReferenceTest.php index 092b8800..712eea6a 100644 --- a/tests/XML/xenc/KeyReferenceTest.php +++ b/tests/XML/xenc/KeyReferenceTest.php @@ -4,17 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; -use SimpleSAML\XMLSecurity\XML\ds\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractReference; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\KeyReference; +use SimpleSAML\XMLSecurity\XML\ds\{Transform, Transforms, XPath}; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractReference, AbstractXencElement, KeyReference}; use function dirname; use function strval; @@ -28,6 +25,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(AbstractReference::class)] #[CoversClass(KeyReference::class)] @@ -55,13 +53,15 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $keyReference = new KeyReference( - '#Encrypted_KEY_ID', + AnyURIValue::fromString('#Encrypted_KEY_ID'), [ new Transforms( [ new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedKey[@Id="example1"]'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('self::xenc:EncryptedKey[@Id="example1"]'), + ), ), ], ), diff --git a/tests/XML/xenc/KeySizeTest.php b/tests/XML/xenc/KeySizeTest.php index b5502619..b3b9ba0c 100644 --- a/tests/XML/xenc/KeySizeTest.php +++ b/tests/XML/xenc/KeySizeTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\KeySize; +use SimpleSAML\XMLSecurity\Type\KeySizeValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, KeySize}; use function dirname; use function strval; @@ -22,6 +22,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(KeySize::class)] final class KeySizeTest extends TestCase @@ -44,7 +45,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $keySize = new KeySize(10); + $keySize = new KeySize( + KeySizeValue::fromString('10'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc/OAEPparamsTest.php b/tests/XML/xenc/OAEPparamsTest.php index 8132e424..376176bd 100644 --- a/tests/XML/xenc/OAEPparamsTest.php +++ b/tests/XML/xenc/OAEPparamsTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\OAEPparams; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, OAEPparams}; use function dirname; use function strval; @@ -22,6 +22,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(OAEPparams::class)] final class OAEPparamsTest extends TestCase @@ -44,7 +45,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $params = new OAEPparams('9lWu3Q=='); + $params = new OAEPparams( + Base64BinaryValue::fromString('9lWu3Q=='), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc/OriginatorKeyInfoTest.php b/tests/XML/xenc/OriginatorKeyInfoTest.php index 7a4a70db..30c94a0f 100644 --- a/tests/XML/xenc/OriginatorKeyInfoTest.php +++ b/tests/XML/xenc/OriginatorKeyInfoTest.php @@ -4,29 +4,30 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Chunk; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\{Base64BinaryValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType; -use SimpleSAML\XMLSecurity\XML\ds\KeyName; -use SimpleSAML\XMLSecurity\XML\ds\MgmtData; -use SimpleSAML\XMLSecurity\XML\ds\PGPData; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyID; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyPacket; -use SimpleSAML\XMLSecurity\XML\ds\SPKIData; -use SimpleSAML\XMLSecurity\XML\ds\SPKISexp; -use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; -use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName; -use SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName; -use SimpleSAML\XMLSecurity\XML\xenc\OriginatorKeyInfo; -use SimpleSAML\XMLSecurity\XML\xenc\P; -use SimpleSAML\XMLSecurity\XML\xenc\Seed; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{ + AbstractDsElement, + AbstractKeyInfoType, + KeyName, + MgmtData, + PGPData, + PGPKeyID, + PGPKeyPacket, + SPKIData, + SPKISexp, + X509Certificate, + X509Data, + X509SubjectName, +}; +use SimpleSAML\XMLSecurity\XML\xenc\{CarriedKeyName, OriginatorKeyInfo, P, Seed}; use function dirname; use function openssl_x509_parse; @@ -38,6 +39,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(AbstractKeyInfoType::class)] #[CoversClass(OriginatorKeyInfo::class)] @@ -92,37 +94,63 @@ public function setUp(): void */ public function testMarshalling(): void { - $SPKISexp1 = new SPKISexp('GpM6'); - $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $SPKISexp2 = new SPKISexp('GpM7'); - $SPKISexp3 = new SPKISexp('GpM8'); - $carriedKeyName = new CarriedKeyName('Some label'); + $SPKISexp1 = new SPKISexp( + Base64BinaryValue::fromString('GpM6'), + ); + $seed = new Seed( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); + $SPKISexp2 = new SPKISexp( + Base64BinaryValue::fromString('GpM7'), + ); + $SPKISexp3 = new SPKISexp( + Base64BinaryValue::fromString('GpM8'), + ); + $carriedKeyName = new CarriedKeyName( + StringValue::fromString('Some label'), + ); $originatorKeyInfo = new OriginatorKeyInfo( [ - new KeyName('testkey'), + new KeyName( + StringValue::fromString('testkey'), + ), new X509Data( [ - new X509Certificate(self::$certificate), - new X509SubjectName(self::$certData['name']), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), ], ), new PGPData( - new PGPKeyID('GpM7'), - new PGPKeyPacket('GpM8'), - [new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')], + new PGPKeyID( + Base64BinaryValue::fromString('GpM7'), + ), + new PGPKeyPacket( + Base64BinaryValue::fromString('GpM8'), + ), + [ + new P( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ], ), new SPKIData([ [$SPKISexp1, $seed], [$SPKISexp2, null], [$SPKISexp3, $carriedKeyName], ]), - new MgmtData('ManagementData'), + new MgmtData( + StringValue::fromString('ManagementData'), + ), new Chunk(DOMDocumentFactory::fromString( 'some', )->documentElement), ], - 'fed654', + IDValue::fromString('fed654'), ); $this->assertEquals( diff --git a/tests/XML/xenc/PTest.php b/tests/XML/xenc/PTest.php index 0e6c4cc8..5a30dabb 100644 --- a/tests/XML/xenc/PTest.php +++ b/tests/XML/xenc/PTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\P; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, P}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(P::class)] final class PTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $p = new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $p = new P( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($p), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new P('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/PgenCounterTest.php b/tests/XML/xenc/PgenCounterTest.php index bf5b9652..34dfe270 100644 --- a/tests/XML/xenc/PgenCounterTest.php +++ b/tests/XML/xenc/PgenCounterTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\PgenCounter; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, PgenCounter}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(PgenCounter::class)] final class PgenCounterTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $pgenCounter = new PgenCounter('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $pgenCounter = new PgenCounter( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($pgenCounter), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new PgenCounter('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/PublicTest.php b/tests/XML/xenc/PublicTest.php index 425979d3..2466bc45 100644 --- a/tests/XML/xenc/PublicTest.php +++ b/tests/XML/xenc/PublicTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\XencPublic; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, XencPublic}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(XencPublic::class)] final class PublicTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $public = new XencPublic('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $public = new XencPublic( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($public), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new XencPublic('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/QTest.php b/tests/XML/xenc/QTest.php index 46ddcb12..7d2240ed 100644 --- a/tests/XML/xenc/QTest.php +++ b/tests/XML/xenc/QTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\Q; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, Q}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(Q::class)] final class QTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $q = new Q('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $q = new Q( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($q), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new Q('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/RecipientKeyInfoTest.php b/tests/XML/xenc/RecipientKeyInfoTest.php index 55cf2ba3..09aec482 100644 --- a/tests/XML/xenc/RecipientKeyInfoTest.php +++ b/tests/XML/xenc/RecipientKeyInfoTest.php @@ -4,29 +4,29 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\{Base64BinaryValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Exception\InvalidArgumentException; use SimpleSAML\XMLSecurity\TestUtils\PEMCertificatesMock; -use SimpleSAML\XMLSecurity\XML\ds\AbstractDsElement; -use SimpleSAML\XMLSecurity\XML\ds\AbstractKeyInfoType; -use SimpleSAML\XMLSecurity\XML\ds\KeyName; -use SimpleSAML\XMLSecurity\XML\ds\MgmtData; -use SimpleSAML\XMLSecurity\XML\ds\PGPData; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyID; -use SimpleSAML\XMLSecurity\XML\ds\PGPKeyPacket; -use SimpleSAML\XMLSecurity\XML\ds\SPKIData; -use SimpleSAML\XMLSecurity\XML\ds\SPKISexp; -use SimpleSAML\XMLSecurity\XML\ds\X509Certificate; -use SimpleSAML\XMLSecurity\XML\ds\X509Data; -use SimpleSAML\XMLSecurity\XML\ds\X509SubjectName; -use SimpleSAML\XMLSecurity\XML\xenc\CarriedKeyName; -use SimpleSAML\XMLSecurity\XML\xenc\P; -use SimpleSAML\XMLSecurity\XML\xenc\RecipientKeyInfo; -use SimpleSAML\XMLSecurity\XML\xenc\Seed; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\ds\{ + AbstractDsElement, + AbstractKeyInfoType, + KeyName, + MgmtData, + PGPData, + PGPKeyID, + PGPKeyPacket, + SPKIData, + SPKISexp, + X509Certificate, + X509Data, + X509SubjectName, +}; +use SimpleSAML\XMLSecurity\XML\xenc\{CarriedKeyName, P, RecipientKeyInfo, Seed}; use function dirname; use function openssl_x509_parse; @@ -38,6 +38,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractDsElement::class)] #[CoversClass(AbstractKeyInfoType::class)] #[CoversClass(RecipientKeyInfo::class)] @@ -92,37 +93,63 @@ public function setUp(): void */ public function testMarshalling(): void { - $SPKISexp1 = new SPKISexp('GpM6'); - $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - $SPKISexp2 = new SPKISexp('GpM7'); - $SPKISexp3 = new SPKISexp('GpM8'); - $carriedKeyName = new CarriedKeyName('Some label'); + $SPKISexp1 = new SPKISexp( + Base64BinaryValue::fromString('GpM6'), + ); + $seed = new Seed( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); + $SPKISexp2 = new SPKISexp( + Base64BinaryValue::fromString('GpM7'), + ); + $SPKISexp3 = new SPKISexp( + Base64BinaryValue::fromString('GpM8'), + ); + $carriedKeyName = new CarriedKeyName( + StringValue::fromString('Some label'), + ); $recipientKeyInfo = new RecipientKeyInfo( [ - new KeyName('testkey'), + new KeyName( + StringValue::fromString('testkey'), + ), new X509Data( [ - new X509Certificate(self::$certificate), - new X509SubjectName(self::$certData['name']), + new X509Certificate( + Base64BinaryValue::fromString(self::$certificate), + ), + new X509SubjectName( + StringValue::fromString(self::$certData['name']), + ), ], ), new PGPData( - new PGPKeyID('GpM7'), - new PGPKeyPacket('GpM8'), - [new P('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI=')], + new PGPKeyID( + Base64BinaryValue::fromString('GpM7'), + ), + new PGPKeyPacket( + Base64BinaryValue::fromString('GpM8'), + ), + [ + new P( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ), + ], ), new SPKIData([ [$SPKISexp1, $seed], [$SPKISexp2, null], [$SPKISexp3, $carriedKeyName], ]), - new MgmtData('ManagementData'), + new MgmtData( + StringValue::fromString('ManagementData'), + ), new Chunk(DOMDocumentFactory::fromString( 'some', )->documentElement), ], - 'fed654', + IDValue::fromString('fed654'), ); $this->assertEquals( diff --git a/tests/XML/xenc/ReferenceListTest.php b/tests/XML/xenc/ReferenceListTest.php index 127c28fd..51d945e1 100644 --- a/tests/XML/xenc/ReferenceListTest.php +++ b/tests/XML/xenc/ReferenceListTest.php @@ -4,19 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; -use SimpleSAML\XMLSecurity\XML\ds\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\DataReference; -use SimpleSAML\XMLSecurity\XML\xenc\KeyReference; -use SimpleSAML\XMLSecurity\XML\xenc\ReferenceList; +use SimpleSAML\XMLSecurity\XML\ds\{Transform, Transforms, XPath}; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, DataReference, KeyReference, ReferenceList}; use function dirname; use function strval; @@ -29,6 +24,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(ReferenceList::class)] final class ReferenceListTest extends TestCase @@ -56,20 +52,30 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $transformData = new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedData[@Id="example1"]'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('self::xenc:EncryptedData[@Id="example1"]'), + ), ); $transformKey = new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedKey[@Id="example1"]'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('self::xenc:EncryptedKey[@Id="example1"]'), + ), ); $referenceList = new ReferenceList( [ - new DataReference('#Encrypted_DATA_ID', [new Transforms([$transformData])]), + new DataReference( + AnyURIValue::fromString('#Encrypted_DATA_ID'), + [new Transforms([$transformData])], + ), ], [ - new KeyReference('#Encrypted_KEY_ID', [new Transforms([$transformKey])]), + new KeyReference( + AnyURIValue::fromString('#Encrypted_KEY_ID'), + [new Transforms([$transformKey])], + ), ], ); diff --git a/tests/XML/xenc/SeedTest.php b/tests/XML/xenc/SeedTest.php index 03a581f1..af84a41d 100644 --- a/tests/XML/xenc/SeedTest.php +++ b/tests/XML/xenc/SeedTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\Assert\AssertionFailedException; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; use SimpleSAML\XMLSecurity\Test\XML\XMLDumper; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\Seed; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, Seed}; use function dirname; use function strval; @@ -24,6 +23,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(Seed::class)] final class SeedTest extends TestCase @@ -46,20 +46,13 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $seed = new Seed('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); + $seed = new Seed( + CryptoBinaryValue::fromString('/CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='), + ); $this->assertEquals( XMLDumper::dumpDOMDocumentXMLWithBase64Content(self::$xmlRepresentation), strval($seed), ); } - - - /** - */ - public function testMarshallingNotBase64(): void - { - $this->expectException(AssertionFailedException::class); - new Seed('/CTj3d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI='); - } } diff --git a/tests/XML/xenc/TransformsTest.php b/tests/XML/xenc/TransformsTest.php index 9aa0261d..bb0c47a6 100644 --- a/tests/XML/xenc/TransformsTest.php +++ b/tests/XML/xenc/TransformsTest.php @@ -4,15 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\AbstractXencElement; -use SimpleSAML\XMLSecurity\XML\xenc\Transforms; +use SimpleSAML\XMLSecurity\XML\ds\{Transform, XPath}; +use SimpleSAML\XMLSecurity\XML\xenc\{AbstractXencElement, Transforms}; use function dirname; use function strval; @@ -25,6 +24,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc')] #[CoversClass(AbstractXencElement::class)] #[CoversClass(Transforms::class)] final class TransformsTest extends TestCase @@ -51,9 +51,9 @@ public function testMarshalling(): void $transforms = new Transforms( [ new Transform( - C::XPATH10_URI, + AnyURIValue::fromString(C::XPATH10_URI), new XPath( - 'count(//. | //@* | //namespace::*)', + StringValue::fromString('count(//. | //@* | //namespace::*)'), ), ), ], diff --git a/tests/XML/xenc11/ConcatKDFParamsTest.php b/tests/XML/xenc11/ConcatKDFParamsTest.php index 4bffa81f..78095998 100644 --- a/tests/XML/xenc11/ConcatKDFParamsTest.php +++ b/tests/XML/xenc11/ConcatKDFParamsTest.php @@ -4,17 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, HexBinaryValue}; use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\XML\ds\DigestMethod; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractConcatKDFParamsType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\ConcatKDFParams; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractConcatKDFParamsType, AbstractXenc11Element, ConcatKDFParams}; use function dirname; use function strval; @@ -24,6 +21,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(AbstractConcatKDFParamsType::class)] #[CoversClass(ConcatKDFParams::class)] @@ -49,7 +47,7 @@ public static function setUpBeforeClass(): void public function testMarshalling(): void { $digestMethod = new DigestMethod( - C::DIGEST_SHA256, + AnyURIValue::fromString(C::DIGEST_SHA256), [ new Chunk(DOMDocumentFactory::fromString( 'Random', @@ -59,11 +57,11 @@ public function testMarshalling(): void $concatKdfParams = new ConcatKDFParams( $digestMethod, - 'a1b2', - 'b2c3', - 'c3d4', - 'd4e5', - 'e5f6', + HexBinaryValue::fromString('a1b2'), + HexBinaryValue::fromString('b2c3'), + HexBinaryValue::fromString('c3d4'), + HexBinaryValue::fromString('d4e5'), + HexBinaryValue::fromString('e5f6'), ); $this->assertEquals( diff --git a/tests/XML/xenc11/DerivedKeyNameTest.php b/tests/XML/xenc11/DerivedKeyNameTest.php index ccd95a8f..f9255f14 100644 --- a/tests/XML/xenc11/DerivedKeyNameTest.php +++ b/tests/XML/xenc11/DerivedKeyNameTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\DerivedKeyName; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractXenc11Element, DerivedKeyName}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(DerivedKeyName::class)] final class DerivedKeyNameTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $derivedKeyName = new DerivedKeyName('phpunit'); + $derivedKeyName = new DerivedKeyName( + StringValue::fromString('phpunit'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/DerivedKeyTest.php b/tests/XML/xenc11/DerivedKeyTest.php index b10e56f9..51fa613c 100644 --- a/tests/XML/xenc11/DerivedKeyTest.php +++ b/tests/XML/xenc11/DerivedKeyTest.php @@ -4,28 +4,24 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, IDValue, StringValue}; use SimpleSAML\XMLSecurity\Constants as C; +use SimpleSAML\XMLSecurity\Type\CryptoBinaryValue; use SimpleSAML\XMLSecurity\Utils\XPath as XPathUtils; -use SimpleSAML\XMLSecurity\XML\ds\Exponent; -use SimpleSAML\XMLSecurity\XML\ds\Modulus; -use SimpleSAML\XMLSecurity\XML\ds\RSAKeyValue; -use SimpleSAML\XMLSecurity\XML\ds\Transform; -use SimpleSAML\XMLSecurity\XML\ds\Transforms; -use SimpleSAML\XMLSecurity\XML\ds\XPath; -use SimpleSAML\XMLSecurity\XML\xenc\DataReference; -use SimpleSAML\XMLSecurity\XML\xenc\KeyReference; -use SimpleSAML\XMLSecurity\XML\xenc\ReferenceList; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractDerivedKeyType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\DerivedKey; -use SimpleSAML\XMLSecurity\XML\xenc11\DerivedKeyName; -use SimpleSAML\XMLSecurity\XML\xenc11\KeyDerivationMethod; -use SimpleSAML\XMLSecurity\XML\xenc11\MasterKeyName; +use SimpleSAML\XMLSecurity\XML\ds\{Exponent, Modulus, RSAKeyValue, Transform, Transforms, XPath}; +use SimpleSAML\XMLSecurity\XML\xenc\{DataReference, KeyReference, ReferenceList}; +use SimpleSAML\XMLSecurity\XML\xenc11\{ + AbstractDerivedKeyType, + AbstractXenc11Element, + DerivedKey, + DerivedKeyName, + MasterKeyName, + KeyDerivationMethod, +}; use function dirname; use function strval; @@ -39,6 +35,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(AbstractDerivedKeyType::class)] #[CoversClass(DerivedKey::class)] @@ -47,6 +44,9 @@ final class DerivedKeyTest extends TestCase use SchemaValidationTestTrait; use SerializableElementTestTrait; + private static KeyDerivationMethod $keyDerivationMethod; + private static ReferenceList $referenceList; + /** */ public static function setUpBeforeClass(): void @@ -56,51 +56,71 @@ public static function setUpBeforeClass(): void self::$xmlRepresentation = DOMDocumentFactory::fromFile( dirname(__FILE__, 3) . '/resources/xml/xenc11_DerivedKey.xml', ); - } - - - // marshalling - - /** - */ - public function testMarshalling(): void - { - $alg = 'http://www.w3.org/2009/xmlenc11#ConcatKDF'; - $RSAKeyValue = new RSAKeyValue( - new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), - new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), + self::$keyDerivationMethod = new KeyDerivationMethod( + AnyURIValue::fromString(C::KEY_DERIVATION_CONCATKDF), + [ + new RSAKeyValue( + new Modulus( + CryptoBinaryValue::fromString('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), + ), + new Exponent( + CryptoBinaryValue::fromString('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), + ), + ), + ], ); - $keyDerivationMethod = new KeyDerivationMethod($alg, [$RSAKeyValue]); - $transformData = new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedData[@Id="example1"]'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('self::xenc:EncryptedData[@Id="example1"]'), + ), ); $transformKey = new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedKey[@Id="example1"]'), + AnyURIValue::fromString(C::XPATH10_URI), + new XPath( + StringValue::fromString('self::xenc:EncryptedKey[@Id="example1"]'), + ), ); - $referenceList = new ReferenceList( + self::$referenceList = new ReferenceList( [ - new DataReference('#Encrypted_DATA_ID', [new Transforms([$transformData])]), + new DataReference( + AnyURIValue::fromString('#Encrypted_DATA_ID'), + [new Transforms([$transformData])], + ), ], [ - new KeyReference('#Encrypted_KEY_ID', [new Transforms([$transformKey])]), + new KeyReference( + AnyURIValue::fromString('#Encrypted_KEY_ID'), + [new Transforms([$transformKey])], + ), ], ); + } + + + // marshalling + - $derivedKeyName = new DerivedKeyName('phpunit'); - $masterKeyName = new MasterKeyName('phpunit'); + /** + */ + public function testMarshalling(): void + { + $derivedKeyName = new DerivedKeyName( + StringValue::fromString('phpunit'), + ); + $masterKeyName = new MasterKeyName( + StringValue::fromString('phpunit'), + ); $derivedKey = new DerivedKey( - 'phpunit', - 'phpunit', - 'urn:x-simplesamlphp:type', - $keyDerivationMethod, - $referenceList, + StringValue::fromString('phpunit'), + IDValue::fromString('phpunit'), + AnyURIValue::fromString('urn:x-simplesamlphp:type'), + self::$keyDerivationMethod, + self::$referenceList, $derivedKeyName, $masterKeyName, ); @@ -116,41 +136,19 @@ public function testMarshalling(): void */ public function testMarshallingElementOrder(): void { - $alg = 'http://www.w3.org/2009/xmlenc11#ConcatKDF'; - $RSAKeyValue = new RSAKeyValue( - new Modulus('dGhpcyBpcyBzb21lIHJhbmRvbSBtb2R1bHVzCg=='), - new Exponent('dGhpcyBpcyBzb21lIHJhbmRvbSBleHBvbmVudAo='), - ); - - $keyDerivationMethod = new KeyDerivationMethod($alg, [$RSAKeyValue]); - - $transformData = new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedData[@Id="example1"]'), + $derivedKeyName = new DerivedKeyName( + StringValue::fromString('phpunit'), ); - $transformKey = new Transform( - C::XPATH10_URI, - new XPath('self::xenc:EncryptedKey[@Id="example1"]'), + $masterKeyName = new MasterKeyName( + StringValue::fromString('phpunit'), ); - $referenceList = new ReferenceList( - [ - new DataReference('#Encrypted_DATA_ID', [new Transforms([$transformData])]), - ], - [ - new KeyReference('#Encrypted_KEY_ID', [new Transforms([$transformKey])]), - ], - ); - - $derivedKeyName = new DerivedKeyName('phpunit'); - $masterKeyName = new MasterKeyName('phpunit'); - $derivedKey = new DerivedKey( - 'phpunit', - 'phpunit', - 'urn:x-simplesamlphp:type', - $keyDerivationMethod, - $referenceList, + StringValue::fromString('phpunit'), + IDValue::fromString('phpunit'), + AnyURIValue::fromString('urn:x-simplesamlphp:type'), + self::$keyDerivationMethod, + self::$referenceList, $derivedKeyName, $masterKeyName, ); diff --git a/tests/XML/xenc11/IterationCountTest.php b/tests/XML/xenc11/IterationCountTest.php index 2138b88f..c6e1f5f4 100644 --- a/tests/XML/xenc11/IterationCountTest.php +++ b/tests/XML/xenc11/IterationCountTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\IterationCount; +use SimpleSAML\XML\Type\PositiveIntegerValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractXenc11Element, IterationCount}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(IterationCount::class)] final class IterationCountTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $iterationCount = new IterationCount(3); + $iterationCount = new IterationCount( + PositiveIntegerValue::fromString('3'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/KeyDerivationMethodTest.php b/tests/XML/xenc11/KeyDerivationMethodTest.php index 52fc69be..6f9782fd 100644 --- a/tests/XML/xenc11/KeyDerivationMethodTest.php +++ b/tests/XML/xenc11/KeyDerivationMethodTest.php @@ -4,15 +4,14 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; +use SimpleSAML\XMLSecurity\Constants as C; use SimpleSAML\XMLSecurity\XML\ds\KeyName; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractKeyDerivationMethodType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\KeyDerivationMethod; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractKeyDerivationMethodType, AbstractXenc11Element, KeyDerivationMethod}; use function dirname; use function strval; @@ -25,6 +24,7 @@ * @covers \SimpleSAML\XMLSecurity\XML\xenc11\KeyDerivationMethod * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(AbstractKeyDerivationMethodType::class)] #[CoversClass(KeyDerivationMethod::class)] @@ -53,10 +53,12 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $alg = 'http://www.w3.org/2009/xmlenc11#ConcatKDF'; - $keyName = new KeyName('testkey'); - - $kdm = new KeyDerivationMethod($alg, [$keyName]); + $kdm = new KeyDerivationMethod( + AnyURIValue::fromString(C::KEY_DERIVATION_CONCATKDF), + [ + new KeyName(StringValue::fromString('testkey')), + ], + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/KeyLengthTest.php b/tests/XML/xenc11/KeyLengthTest.php index 43950f2d..fd89b97b 100644 --- a/tests/XML/xenc11/KeyLengthTest.php +++ b/tests/XML/xenc11/KeyLengthTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\KeyLength; +use SimpleSAML\XML\Type\PositiveIntegerValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractXenc11Element, KeyLength}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(KeyLength::class)] final class KeyLengthTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $keyLength = new KeyLength(4096); + $keyLength = new KeyLength( + PositiveIntegerValue::fromString('4096'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/MGFTest.php b/tests/XML/xenc11/MGFTest.php index ab4792d2..248a05c5 100644 --- a/tests/XML/xenc11/MGFTest.php +++ b/tests/XML/xenc11/MGFTest.php @@ -4,15 +4,17 @@ namespace SimpleSAML\Test\SAML2\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractAlgorithmIdentifierType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractMGFType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\MGF; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\AnyURIValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{ + AbstractAlgorithmIdentifierType, + AbstractMGFType, + AbstractXenc11Element, + MGF, +}; use function dirname; use function strval; @@ -22,6 +24,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(MGF::class)] #[CoversClass(AbstractMGFType::class)] #[CoversClass(AbstractAlgorithmIdentifierType::class)] @@ -50,7 +53,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $mgf = new MGF('urn:x-simplesamlphp:algorithm'); + $mgf = new MGF( + AnyURIValue::fromString('urn:x-simplesamlphp:algorithm'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/MasterKeyNameTest.php b/tests/XML/xenc11/MasterKeyNameTest.php index c8d87668..df0f081c 100644 --- a/tests/XML/xenc11/MasterKeyNameTest.php +++ b/tests/XML/xenc11/MasterKeyNameTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\MasterKeyName; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractXenc11Element, MasterKeyName}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(MasterKeyName::class)] final class MasterKeyNameTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $masterKeyName = new MasterKeyName('phpunit'); + $masterKeyName = new MasterKeyName( + StringValue::fromString('phpunit'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/OtherSourceTest.php b/tests/XML/xenc11/OtherSourceTest.php index 15271539..68fc9c4f 100644 --- a/tests/XML/xenc11/OtherSourceTest.php +++ b/tests/XML/xenc11/OtherSourceTest.php @@ -4,16 +4,18 @@ namespace SimpleSAML\Test\SAML2\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Attribute as XMLAttribute; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractAlgorithmIdentifierType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\OtherSource; -use SimpleSAML\XMLSecurity\XML\xenc11\Parameters; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; +use SimpleSAML\XMLSecurity\XML\xenc11\{ + AbstractAlgorithmIdentifierType, + AbstractXenc11Element, + OtherSource, + Parameters, +}; use function dirname; use function strval; @@ -23,6 +25,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(OtherSource::class)] #[CoversClass(AbstractAlgorithmIdentifierType::class)] #[CoversClass(AbstractXenc11Element::class)] @@ -64,10 +67,13 @@ public function testMarshalling(): void $parameters = new Parameters( [$chunk], - [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1')], + [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', StringValue::fromString('testval1'))], ); - $otherSource = new OtherSource('urn:x-simplesamlphp:algorithm', $parameters); + $otherSource = new OtherSource( + AnyURIValue::fromString('urn:x-simplesamlphp:algorithm'), + $parameters, + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/PBKDF2paramsTest.php b/tests/XML/xenc11/PBKDF2paramsTest.php index 5ee13e81..204dc8c4 100644 --- a/tests/XML/xenc11/PBKDF2paramsTest.php +++ b/tests/XML/xenc11/PBKDF2paramsTest.php @@ -4,22 +4,23 @@ namespace SimpleSAML\Test\SAML2\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Attribute as XMLAttribute; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; -use SimpleSAML\XML\TestUtils\SchemaValidationTestTrait; -use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractPBKDF2ParameterType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\IterationCount; -use SimpleSAML\XMLSecurity\XML\xenc11\KeyLength; -use SimpleSAML\XMLSecurity\XML\xenc11\OtherSource; -use SimpleSAML\XMLSecurity\XML\xenc11\Parameters; -use SimpleSAML\XMLSecurity\XML\xenc11\PBKDF2params; -use SimpleSAML\XMLSecurity\XML\xenc11\PRF; -use SimpleSAML\XMLSecurity\XML\xenc11\Salt; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; +use SimpleSAML\XML\TestUtils\{SchemaValidationTestTrait, SerializableElementTestTrait}; +use SimpleSAML\XML\Type\{AnyURIValue, PositiveIntegerValue, StringValue}; +use SimpleSAML\XMLSecurity\XML\xenc11\{ + AbstractPBKDF2ParameterType, + AbstractXenc11Element, + IterationCount, + KeyLength, + OtherSource, + Parameters, + PBKDF2params, + PRF, + Salt, +}; use function dirname; use function strval; @@ -29,6 +30,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(PBKDF2params::class)] #[CoversClass(AbstractPBKDF2ParameterType::class)] #[CoversClass(AbstractXenc11Element::class)] @@ -62,15 +64,24 @@ public function testMarshalling(): void $parameters = new Parameters( [new Chunk($someDoc->documentElement)], - [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1')], + [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', StringValue::fromString('testval1'))], ); - $otherSource = new OtherSource('urn:x-simplesamlphp:algorithm', $parameters); + $otherSource = new OtherSource( + AnyURIValue::fromString('urn:x-simplesamlphp:algorithm'), + $parameters, + ); $salt = new Salt($otherSource); - $iterationCount = new IterationCount(3); - $keyLength = new KeyLength(4096); - $prf = new PRF('urn:x-simplesamlphp:algorithm'); + $iterationCount = new IterationCount( + PositiveIntegerValue::fromString('3'), + ); + $keyLength = new KeyLength( + PositiveIntegerValue::fromString('4096'), + ); + $prf = new PRF( + AnyURIValue::fromString('urn:x-simplesamlphp:algorithm'), + ); $PBKDF2params = new PBKDF2params($salt, $iterationCount, $keyLength, $prf); diff --git a/tests/XML/xenc11/PRFTest.php b/tests/XML/xenc11/PRFTest.php index b550794f..850381fd 100644 --- a/tests/XML/xenc11/PRFTest.php +++ b/tests/XML/xenc11/PRFTest.php @@ -4,14 +4,17 @@ namespace SimpleSAML\Test\SAML2\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractAlgorithmIdentifierType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractPRFAlgorithmIdentifierType; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\PRF; +use SimpleSAML\XML\Type\AnyURIValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{ + AbstractAlgorithmIdentifierType, + AbstractPRFAlgorithmIdentifierType, + AbstractXenc11Element, + PRF, +}; use function dirname; use function strval; @@ -21,6 +24,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(PRF::class)] #[CoversClass(AbstractPRFAlgorithmIdentifierType::class)] #[CoversClass(AbstractAlgorithmIdentifierType::class)] @@ -48,7 +52,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $prf = new PRF('urn:x-simplesamlphp:algorithm'); + $prf = new PRF( + AnyURIValue::fromString('urn:x-simplesamlphp:algorithm'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/XML/xenc11/ParametersTest.php b/tests/XML/xenc11/ParametersTest.php index f5717045..b5c0150d 100644 --- a/tests/XML/xenc11/ParametersTest.php +++ b/tests/XML/xenc11/ParametersTest.php @@ -4,14 +4,13 @@ namespace SimpleSAML\Test\SAML2\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Attribute as XMLAttribute; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\Parameters; +use SimpleSAML\XML\Type\StringValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractXenc11Element, Parameters}; use function dirname; use function strval; @@ -21,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(Parameters::class)] #[CoversClass(AbstractXenc11Element::class)] final class ParametersTest extends TestCase @@ -61,7 +61,7 @@ public function testMarshalling(): void $parameters = new Parameters( [$chunk], - [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1')], + [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', StringValue::fromString('testval1'))], ); $this->assertEquals( diff --git a/tests/XML/xenc11/SaltTest.php b/tests/XML/xenc11/SaltTest.php index dda8c842..40085d01 100644 --- a/tests/XML/xenc11/SaltTest.php +++ b/tests/XML/xenc11/SaltTest.php @@ -4,16 +4,13 @@ namespace SimpleSAML\Test\SAML2\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\Attribute as XMLAttribute; -use SimpleSAML\XML\Chunk; -use SimpleSAML\XML\DOMDocumentFactory; +use SimpleSAML\XML\{Chunk, DOMDocumentFactory}; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\OtherSource; -use SimpleSAML\XMLSecurity\XML\xenc11\Parameters; -use SimpleSAML\XMLSecurity\XML\xenc11\Salt; +use SimpleSAML\XML\Type\{AnyURIValue, StringValue}; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractXenc11Element, OtherSource, Parameters, Salt}; use function dirname; use function strval; @@ -23,6 +20,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(Salt::class)] #[CoversClass(AbstractXenc11Element::class)] final class SaltTest extends TestCase @@ -54,10 +52,13 @@ public function testMarshalling(): void $parameters = new Parameters( [new Chunk($someDoc->documentElement)], - [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', 'testval1')], + [new XMLAttribute('urn:x-simplesamlphp:namespace', 'ssp', 'attr1', StringValue::fromString('testval1'))], ); - $otherSource = new OtherSource('urn:x-simplesamlphp:algorithm', $parameters); + $otherSource = new OtherSource( + AnyURIValue::fromString('urn:x-simplesamlphp:algorithm'), + $parameters, + ); $salt = new Salt($otherSource); $this->assertEquals( diff --git a/tests/XML/xenc11/SpecifiedTest.php b/tests/XML/xenc11/SpecifiedTest.php index b6c58109..0a360210 100644 --- a/tests/XML/xenc11/SpecifiedTest.php +++ b/tests/XML/xenc11/SpecifiedTest.php @@ -4,12 +4,12 @@ namespace SimpleSAML\XMLSecurity\Test\XML\xenc11; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\{CoversClass, Group}; use PHPUnit\Framework\TestCase; use SimpleSAML\XML\DOMDocumentFactory; use SimpleSAML\XML\TestUtils\SerializableElementTestTrait; -use SimpleSAML\XMLSecurity\XML\xenc11\AbstractXenc11Element; -use SimpleSAML\XMLSecurity\XML\xenc11\Specified; +use SimpleSAML\XML\Type\Base64BinaryValue; +use SimpleSAML\XMLSecurity\XML\xenc11\{AbstractXenc11Element, Specified}; use function dirname; use function strval; @@ -19,6 +19,7 @@ * * @package simplesamlphp/xml-security */ +#[Group('xenc11')] #[CoversClass(AbstractXenc11Element::class)] #[CoversClass(Specified::class)] final class SpecifiedTest extends TestCase @@ -41,7 +42,9 @@ public static function setUpBeforeClass(): void */ public function testMarshalling(): void { - $specified = new Specified('GpM6'); + $specified = new Specified( + Base64BinaryValue::fromString('GpM6'), + ); $this->assertEquals( self::$xmlRepresentation->saveXML(self::$xmlRepresentation->documentElement), diff --git a/tests/resources/xml/ds_HMACOutputLength.xml b/tests/resources/xml/ds_HMACOutputLength.xml index cf8b9f3a..c8e9ac05 100644 --- a/tests/resources/xml/ds_HMACOutputLength.xml +++ b/tests/resources/xml/ds_HMACOutputLength.xml @@ -1 +1 @@ -1234 +128 diff --git a/tests/resources/xml/ds_KeyInfo.xml b/tests/resources/xml/ds_KeyInfo.xml index 1fa0b62b..660cf824 100644 --- a/tests/resources/xml/ds_KeyInfo.xml +++ b/tests/resources/xml/ds_KeyInfo.xml @@ -16,6 +16,6 @@ GpM8 Some label - ManagementData + ManagementData some diff --git a/tests/resources/xml/ds_SignatureMethod.xml b/tests/resources/xml/ds_SignatureMethod.xml index 0ddb104f..84cebcb4 100644 --- a/tests/resources/xml/ds_SignatureMethod.xml +++ b/tests/resources/xml/ds_SignatureMethod.xml @@ -1,4 +1,4 @@ - 1234 + 128 Some diff --git a/tests/resources/xml/ds_X509Data.xml b/tests/resources/xml/ds_X509Data.xml index f8711fe9..a590da2c 100644 --- a/tests/resources/xml/ds_X509Data.xml +++ b/tests/resources/xml/ds_X509Data.xml @@ -1,5 +1,4 @@ - some MIICxDCCAi2gAwIBAgIUZ9QDx+SBFHednUWDFGm9tyVKrgQwDQYJKoZIhvcNAQELBQAwczElMCMGA1UEAwwcc2VsZnNpZ25lZC5zaW1wbGVzYW1scGhwLm9yZzEZMBcGA1UECgwQU2ltcGxlU0FNTHBocCBIUTERMA8GA1UEBwwISG9ub2x1bHUxDzANBgNVBAgMBkhhd2FpaTELMAkGA1UEBhMCVVMwIBcNMjIxMjAzMTAzNTQwWhgPMjEyMjExMDkxMDM1NDBaMHMxJTAjBgNVBAMMHHNlbGZzaWduZWQuc2ltcGxlc2FtbHBocC5vcmcxGTAXBgNVBAoMEFNpbXBsZVNBTUxwaHAgSFExETAPBgNVBAcMCEhvbm9sdWx1MQ8wDQYDVQQIDAZIYXdhaWkxCzAJBgNVBAYTAlVTMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDessdFRVDTMQQW3Na81B1CjJV1tmY3nopoIhZrkbDxLa+pv7jGDRcYreyu1DoQxEs06V2nHLoyOPhqJXSFivqtUwVYhR6NYgbNI6RRSsIJCweH0YOdlHna7gULPcLX0Bfbi4odStaFwG9yzDySwSEPtsKxm5pENPjNVGh+jJ+H/QIDAQABo1MwUTAdBgNVHQ4EFgQUvV75t8EoQo2fVa0E9otdtIGK5X0wHwYDVR0jBBgwFoAUvV75t8EoQo2fVa0E9otdtIGK5X0wDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOBgQANQUeiwPJXkWMXuaDHToEBKcezYGqGEYnGUi9LMjeb+Kln7X8nn5iknlz4k77rWCbSwLPC/WDr0ySYQA+HagaeUaFpoiYFJKS6uFlK1HYWnM3W4PUiGHg1/xeZlMO44wTwybXVo0y9KMhchfB5XNbDdoJcqWYvi6xtmZZNRbxUyw== C=US,ST=Hawaii,L=Honolulu,O=SimpleSAMLphp HQ,CN=SimpleSAMLphp Testing CA,emailAddress=noreply@simplesamlphp.org @@ -7,5 +6,6 @@ /CN=selfsigned.simplesamlphp.org/O=SimpleSAMLphp HQ/L=Honolulu/ST=Hawaii/C=US 6tN39Q9d6IevlAWLeM7lQGazUnVlJOe1wCk3sro2rfE= + some other diff --git a/tests/resources/xml/xenc_OriginatorKeyInfo.xml b/tests/resources/xml/xenc_OriginatorKeyInfo.xml index 720eaa1b..dc6f7b20 100644 --- a/tests/resources/xml/xenc_OriginatorKeyInfo.xml +++ b/tests/resources/xml/xenc_OriginatorKeyInfo.xml @@ -7,14 +7,14 @@ GpM7 GpM8 - /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= + /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= GpM6 - /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= + /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= GpM7 GpM8 - Some label + Some label ManagementData some diff --git a/tests/resources/xml/xenc_RecipientKeyInfo.xml b/tests/resources/xml/xenc_RecipientKeyInfo.xml index 948b6fa4..6ef30bc8 100644 --- a/tests/resources/xml/xenc_RecipientKeyInfo.xml +++ b/tests/resources/xml/xenc_RecipientKeyInfo.xml @@ -7,14 +7,14 @@ GpM7 GpM8 - /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= + /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= GpM6 - /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= + /CTj03d1DB5e2t7CTo9BEzCf5S9NRzwnBgZRlm32REI= GpM7 GpM8 - Some label + Some label ManagementData some