diff options
author | Alex Klyubin <klyubin@google.com> | 2015-04-03 09:44:39 -0700 |
---|---|---|
committer | Alex Klyubin <klyubin@google.com> | 2015-04-03 12:09:56 -0700 |
commit | a0f656f9bd8db0c08540233846a000b2fe582814 (patch) | |
tree | 7f8963fc0f861a3b95756582126d1d8234c42878 /keystore | |
parent | 6aed9ec1b85ff1a8a39c4ec091a017f79413ead0 (diff) | |
download | frameworks_base-a0f656f9bd8db0c08540233846a000b2fe582814.zip frameworks_base-a0f656f9bd8db0c08540233846a000b2fe582814.tar.gz frameworks_base-a0f656f9bd8db0c08540233846a000b2fe582814.tar.bz2 |
Obtain SPI without using Reflection.
Bug: 18088752
Change-Id: I76d42e17f5f28af6fd9a96ee812d286f6c6a085b
Diffstat (limited to 'keystore')
-rw-r--r-- | keystore/java/android/security/AndroidKeyStoreProvider.java | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/keystore/java/android/security/AndroidKeyStoreProvider.java b/keystore/java/android/security/AndroidKeyStoreProvider.java index a7c2ddb..a26530c 100644 --- a/keystore/java/android/security/AndroidKeyStoreProvider.java +++ b/keystore/java/android/security/AndroidKeyStoreProvider.java @@ -16,7 +16,6 @@ package android.security; -import java.lang.reflect.Method; import java.security.Provider; import javax.crypto.Cipher; @@ -92,23 +91,17 @@ public class AndroidKeyStoreProvider extends Provider { if (cryptoPrimitive == null) { throw new NullPointerException(); } - if ((!(cryptoPrimitive instanceof Mac)) && (!(cryptoPrimitive instanceof Cipher))) { - throw new IllegalArgumentException("Unsupported crypto primitive: " + cryptoPrimitive); - } Object spi; - // TODO: Replace this Reflection based codewith direct invocations once the libcore changes - // are in. - try { - Method getSpiMethod = cryptoPrimitive.getClass().getDeclaredMethod("getSpi"); - getSpiMethod.setAccessible(true); - spi = getSpiMethod.invoke(cryptoPrimitive); - } catch (ReflectiveOperationException e) { - throw new IllegalArgumentException( - "Unsupported crypto primitive: " + cryptoPrimitive, e); + if (cryptoPrimitive instanceof Mac) { + spi = ((Mac) cryptoPrimitive).getSpi(); + } else if (cryptoPrimitive instanceof Cipher) { + spi = ((Cipher) cryptoPrimitive).getSpi(); + } else { + throw new IllegalArgumentException("Unsupported crypto primitive: " + cryptoPrimitive); } if (!(spi instanceof KeyStoreCryptoOperation)) { throw new IllegalArgumentException( - "Crypto primitive not backed by Android KeyStore: " + cryptoPrimitive + "Crypto primitive not backed by AndroidKeyStore: " + cryptoPrimitive + ", spi: " + spi); } return ((KeyStoreCryptoOperation) spi).getOperationHandle(); |