Use decryption keys on decryption tests in CipherTest
Previously the test was using the encryption key for a decryption test,
which is just incorrect, and will fail when we start disallowing decryption
with public keys in RSA with OAEP.
Also factor the decryption key out into a variable to match how the
encryption key is handled.
Test: cts -m CtsLibcoreTestCases -t libcore.javax.crypto.CipherTest
Change-Id: I852ac1b45e8ed891ff35e81902cec6284c037e2e
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
index 2b3347c..f995a7c 100644
--- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java
+++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
@@ -1495,9 +1495,11 @@
final AlgorithmParameterSpec decryptSpec = getDecryptAlgorithmParameterSpec(encryptSpec, c);
int decryptMode = getDecryptMode(algorithm);
- test_Cipher_init_Decrypt_NullParameters(c, decryptMode, encryptKey, decryptSpec != null);
+ Key decryptKey = getDecryptKey(algorithm);
- c.init(decryptMode, getDecryptKey(algorithm), decryptSpec);
+ test_Cipher_init_Decrypt_NullParameters(c, decryptMode, decryptKey, decryptSpec != null);
+
+ c.init(decryptMode, decryptKey, decryptSpec);
assertEquals(cipherID + " getBlockSize() decryptMode",
getExpectedBlockSize(algorithm, decryptMode, providerName), c.getBlockSize());
assertEquals(cipherID + " getOutputSize(0) decryptMode",
@@ -1547,7 +1549,7 @@
byte[] cipherText = c.wrap(sk);
// Unwrap it
- c.init(Cipher.UNWRAP_MODE, getDecryptKey(algorithm), decryptSpec);
+ c.init(Cipher.UNWRAP_MODE, decryptKey, decryptSpec);
Key decryptedKey = c.unwrap(cipherText, sk.getAlgorithm(), Cipher.SECRET_KEY);
assertEquals(cipherID
@@ -1568,7 +1570,7 @@
byte[] cipherText2 = c.doFinal(getActualPlainText(algorithm));
assertEquals(cipherID, Arrays.toString(cipherText), Arrays.toString(cipherText2));
}
- c.init(Cipher.DECRYPT_MODE, getDecryptKey(algorithm), decryptSpec);
+ c.init(Cipher.DECRYPT_MODE, decryptKey, decryptSpec);
if (isAEAD(algorithm)) {
c.updateAAD(new byte[24]);
}