am b292e49b: Merge "Obtain SPI without using Reflection."
* commit 'b292e49b32fa321e59bf88c68e4c4d8c139645dd': Obtain SPI without using Reflection.
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package android.security;
|
package android.security;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.security.Provider;
|
import java.security.Provider;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
@@ -92,19 +91,13 @@ public class AndroidKeyStoreProvider extends Provider {
|
|||||||
if (cryptoPrimitive == null) {
|
if (cryptoPrimitive == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
if ((!(cryptoPrimitive instanceof Mac)) && (!(cryptoPrimitive instanceof Cipher))) {
|
|
||||||
throw new IllegalArgumentException("Unsupported crypto primitive: " + cryptoPrimitive);
|
|
||||||
}
|
|
||||||
Object spi;
|
Object spi;
|
||||||
// TODO: Replace this Reflection based codewith direct invocations once the libcore changes
|
if (cryptoPrimitive instanceof Mac) {
|
||||||
// are in.
|
spi = ((Mac) cryptoPrimitive).getSpi();
|
||||||
try {
|
} else if (cryptoPrimitive instanceof Cipher) {
|
||||||
Method getSpiMethod = cryptoPrimitive.getClass().getDeclaredMethod("getSpi");
|
spi = ((Cipher) cryptoPrimitive).getSpi();
|
||||||
getSpiMethod.setAccessible(true);
|
} else {
|
||||||
spi = getSpiMethod.invoke(cryptoPrimitive);
|
throw new IllegalArgumentException("Unsupported crypto primitive: " + cryptoPrimitive);
|
||||||
} catch (ReflectiveOperationException e) {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Unsupported crypto primitive: " + cryptoPrimitive, e);
|
|
||||||
}
|
}
|
||||||
if (!(spi instanceof KeyStoreCryptoOperation)) {
|
if (!(spi instanceof KeyStoreCryptoOperation)) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
|
|||||||
Reference in New Issue
Block a user