diff options
author | Kenny Root <kroot@google.com> | 2015-07-20 15:24:55 -0700 |
---|---|---|
committer | Kenny Root <kroot@google.com> | 2015-07-23 09:19:15 -0700 |
commit | 484509de8262bb0a56b303016e93f4be1cf0d795 (patch) | |
tree | 32ec5080fcb093612d0cf11a598bf60e5c10a193 /luni/src/test/java | |
parent | 45a9e938ee58e79b00ae37233678ef9ab54e0392 (diff) | |
download | libcore-484509de8262bb0a56b303016e93f4be1cf0d795.zip libcore-484509de8262bb0a56b303016e93f4be1cf0d795.tar.gz libcore-484509de8262bb0a56b303016e93f4be1cf0d795.tar.bz2 |
Late binding: add Cipher#init checks
Cipher should check that the chosen CipherSpi actually supports
initalization with the given parameters. If not, it should return the
first exception that it ran into so that the developer can have an idea
of why the initialization failed. This is most likely do to unsupported
key or algorithm parameters.
Collapse some functions into one so it's easier to keep track of the
exception that should be thrown should all else fail. Also since we try
to initialize during the CipherSpi selection, there is no need to
initialize the returned CipherSpi again.
Also remove an instanceof check to be in line with other implementations
that just throw a ClassCastException since we now will try other
providers before falling back to throwing the unchecked exception. This
might actually provide better debug messages for a developer working on
a CipherSpi provider.
(cherry picked from commit f591462f7901011b2bce61c3cbbdc54840e5b4bc)
Bug: 22573249
Change-Id: Ieec97a8f00e9c0c3889520a3ec9f8bc4e514b35a
Diffstat (limited to 'luni/src/test/java')
-rw-r--r-- | luni/src/test/java/libcore/javax/crypto/CipherTest.java | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java index 73c5f7d..dd7d6e7 100644 --- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java +++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java @@ -988,9 +988,10 @@ public final class CipherTest extends TestCase { Security.addProvider(mockProviderInvalid); try { - Cipher.getInstance("FOO"); - fail("Should not find any matching providers"); - } catch (NoSuchAlgorithmException expected) { + Cipher c = Cipher.getInstance("FOO"); + c.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(new byte[16], "FOO")); + fail("Should not find any matching providers; found: " + c); + } catch (ClassCastException expected) { } finally { Security.removeProvider(mockProviderInvalid.getName()); } |