Skip to content

Commit 06c2e7b

Browse files
committed
Fix comments
1 parent a7b967c commit 06c2e7b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/System Application/Test/Cryptography Management/src/RSATest.Codeunit.al

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,15 @@ codeunit 132617 "RSA Test"
242242

243243
// [WHEN] Decrypt encrypted text stream using OAEP Padding
244244
DecryptingTempBlob.CreateOutStream(DecryptedOutStream);
245-
DecryptionFailed := not TryDecrypt(RSA, PrivateKeyXmlStringSecret, EncryptedInStream, true, DecryptedOutStream);
245+
DecryptionFailed := not TryDecryptWithOaepPadding(RSA, PrivateKeyXmlStringSecret, EncryptedInStream, DecryptedOutStream);
246246

247247
// [THEN] Either decryption fails with an exception, or the decrypted text is garbage (not equal to plaintext)
248248
if not DecryptionFailed then begin
249249
DecryptingTempBlob.CreateInStream(DecryptedInStream);
250250
DecryptedText := Base64Convert.FromBase64(Base64Convert.ToBase64(DecryptedInStream));
251-
LibraryAssert.AreNotEqual(PlainText, DecryptedText, 'Decryption with wrong padding should fail or return garbage data.');
252-
end;
251+
LibraryAssert.AreNotEqual(PlainText, DecryptedText, 'Decryption failed with garbage data.');
252+
end else
253+
LibraryAssert.IsTrue(DecryptionFailed, 'Decryption failed with wrong padding.');
253254
end;
254255

255256
[Test]
@@ -283,20 +284,27 @@ codeunit 132617 "RSA Test"
283284

284285
// [WHEN] Decrypt encrypted text stream using PKCS#1 padding.
285286
DecryptingTempBlob.CreateOutStream(DecryptedOutStream);
286-
DecryptionFailed := not TryDecrypt(RSA, PrivateKeyXmlStringSecret, EncryptedInStream, false, DecryptedOutStream);
287+
DecryptionFailed := not TryDecrypt(RSA, PrivateKeyXmlStringSecret, EncryptedInStream, DecryptedOutStream);
287288

288289
// [THEN] Either decryption fails with an exception, or the decrypted text is garbage (not equal to plaintext)
289290
if not DecryptionFailed then begin
290291
DecryptingTempBlob.CreateInStream(DecryptedInStream);
291292
DecryptedText := Base64Convert.FromBase64(Base64Convert.ToBase64(DecryptedInStream));
292-
LibraryAssert.AreNotEqual(PlainText, DecryptedText, 'Decryption with wrong padding should fail or return garbage data.');
293-
end;
293+
LibraryAssert.AreNotEqual(PlainText, DecryptedText, 'Decryption failed with garbage data.');
294+
end else
295+
LibraryAssert.IsTrue(DecryptionFailed, 'Decryption failed with wrong padding.');
294296
end;
295297

296298
[TryFunction]
297-
local procedure TryDecrypt(RSA: Codeunit RSA; XmlString: SecretText; EncryptedInStream: InStream; OaepPadding: Boolean; DecryptedOutStream: OutStream)
299+
local procedure TryDecryptWithOaepPadding(RSA: Codeunit RSA; XmlString: SecretText; EncryptedInStream: InStream; DecryptedOutStream: OutStream)
298300
begin
299-
RSA.Decrypt(XmlString, EncryptedInStream, OaepPadding, DecryptedOutStream);
301+
RSA.Decrypt(XmlString, EncryptedInStream, true, DecryptedOutStream);
302+
end;
303+
304+
[TryFunction]
305+
local procedure TryDecrypt(RSA: Codeunit RSA; XmlString: SecretText; EncryptedInStream: InStream; DecryptedOutStream: OutStream)
306+
begin
307+
RSA.Decrypt(XmlString, EncryptedInStream, false, DecryptedOutStream);
300308
end;
301309

302310
local procedure SaveRandomTextToOutStream(OutStream: OutStream) PlainText: Text

0 commit comments

Comments
 (0)