Skip to content

Commit 0ff803d

Browse files
committed
Configurable encryption type
1 parent 220e1e5 commit 0ff803d

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/XML/EncryptableElementTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ trait EncryptableElementTrait
4848
* @param \SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmInterface $encryptor The encryptor to use,
4949
* either to encrypt the object itself, or to encrypt a session key (if the encryptor implements a key transport
5050
* algorithm).
51+
* @param \SimpleSAML\XMLSchema\Type\AnyURIValue|null $type
5152
*
5253
* @return \SimpleSAML\XMLSecurity\XML\xenc\EncryptedData
5354
*/
54-
public function encrypt(EncryptionAlgorithmInterface $encryptor): EncryptedData
55+
public function encrypt(EncryptionAlgorithmInterface $encryptor, ?AnyURIValue $type = null): EncryptedData
5556
{
5657
$keyInfo = null;
5758
if (in_array($encryptor->getAlgorithmId(), C::$KEY_TRANSPORT_ALGORITHMS)) {
@@ -88,7 +89,7 @@ public function encrypt(EncryptionAlgorithmInterface $encryptor): EncryptedData
8889
),
8990
),
9091
null,
91-
AnyURIValue::fromString(C::XMLENC_ELEMENT),
92+
$type,
9293
null,
9394
null,
9495
new EncryptionMethod(

tests/XML/EncryptedCustomTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use DOMElement;
88
use PHPUnit\Framework\TestCase;
99
use SimpleSAML\XML\DOMDocumentFactory;
10+
use SimpleSAML\XMLSchema\Type\AnyURIValue;
1011
use SimpleSAML\XMLSecurity\Alg\Encryption\EncryptionAlgorithmFactory;
1112
use SimpleSAML\XMLSecurity\Alg\KeyTransport\KeyTransportAlgorithmFactory;
1213
use SimpleSAML\XMLSecurity\Alg\Signature\SignatureAlgorithmFactory;
@@ -60,7 +61,9 @@ public function testEncryptAndDecryptSharedSecret(): void
6061
// encrypt
6162
$factory = new EncryptionAlgorithmFactory();
6263
$encryptor = $factory->getAlgorithm(C::BLOCK_ENC_AES128, $sharedKey);
63-
$encryptedCustom = new EncryptedCustom($customSigned->encrypt($encryptor));
64+
$encryptedCustom = new EncryptedCustom(
65+
$customSigned->encrypt($encryptor, AnyURIValue::fromString(C::XMLENC_ELEMENT)),
66+
);
6467

6568
// decrypt
6669
$decryptedCustom = $encryptedCustom->decrypt($encryptor);
@@ -80,7 +83,9 @@ public function testEncryptAndDecryptSessionKey(): void
8083
// encrypt
8184
$factory = new KeyTransportAlgorithmFactory();
8285
$encryptor = $factory->getAlgorithm(C::KEY_TRANSPORT_OAEP_MGF1P, $this->pubKey);
83-
$encryptedCustom = new EncryptedCustom($customSigned->encrypt($encryptor));
86+
$encryptedCustom = new EncryptedCustom(
87+
$customSigned->encrypt($encryptor, AnyURIValue::fromString(C::XMLENC_ELEMENT)),
88+
);
8489

8590
// decrypt
8691
$decryptor = $factory->getAlgorithm(C::KEY_TRANSPORT_OAEP_MGF1P, $this->privKey);
@@ -110,7 +115,9 @@ public function testSignatureVerifiesAfterEncryptionAndDecryption(): void
110115
// encrypt
111116
$factory = new KeyTransportAlgorithmFactory();
112117
$encryptor = $factory->getAlgorithm(C::KEY_TRANSPORT_OAEP_MGF1P, $this->pubKey);
113-
$encryptedCustom = new EncryptedCustom($customSigned->encrypt($encryptor));
118+
$encryptedCustom = new EncryptedCustom(
119+
$customSigned->encrypt($encryptor, AnyURIValue::fromString(C::XMLENC_ELEMENT)),
120+
);
114121

115122
// decrypt
116123
$decryptor = $factory->getAlgorithm(C::KEY_TRANSPORT_OAEP_MGF1P, $this->privKey);

0 commit comments

Comments
 (0)