summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Klyubin <klyubin@google.com>2015-05-07 14:03:03 -0700
committerAlex Klyubin <klyubin@google.com>2015-05-18 12:25:55 -0700
commit4ec153a9ae62f6f62694fd0a320db16c254174c9 (patch)
treede6090278675db09f7984378cffcf155961ebcd2
parent3f4bc323149f721cd91fc8b4c80e186a1dfe1ce7 (diff)
downloadlibcore-4ec153a9ae62f6f62694fd0a320db16c254174c9.zip
libcore-4ec153a9ae62f6f62694fd0a320db16c254174c9.tar.gz
libcore-4ec153a9ae62f6f62694fd0a320db16c254174c9.tar.bz2
Expose getCurrentSpi from crypto operations as hidden API.
050e672aaaaa8f8c57788e8d551f43c5fbffe339 exposed the existing getSpi method of Cipher, Signature, Mac, and KeyAgreement as hidden API. Unfortunately, the getSpi method creates an SPI instance if one is not yet set. This changes the state of the crypto operation and does does not lend itself well to being used for read-only querying of the SPI from a crypto operation. This CL addresses the issue by adding a getCurrentSpi hidden API to these crypto operations. getCurrentSpi simply returns the current SPI instance, if any, and does not modify the state of the crypto operation. A follow-up CL will revert 050e672aaaaa8f8c57788e8d551f43c5fbffe339 which will no longer be needed. This is not reverted here to avoid breaking the build. (cherry-picked from commit 5d15925a79b8beddfafa8de2ede7fff360a386cb) Bug: 18088752 Change-Id: I8de4c121c9a395b3687b173d0bba4e1931ebf958
-rw-r--r--luni/src/main/java/java/security/Signature.java17
-rw-r--r--luni/src/main/java/javax/crypto/Cipher.java16
-rw-r--r--luni/src/main/java/javax/crypto/KeyAgreement.java12
-rw-r--r--luni/src/main/java/javax/crypto/Mac.java12
4 files changed, 57 insertions, 0 deletions
diff --git a/luni/src/main/java/java/security/Signature.java b/luni/src/main/java/java/security/Signature.java
index 3151058..a45fa59 100644
--- a/luni/src/main/java/java/security/Signature.java
+++ b/luni/src/main/java/java/security/Signature.java
@@ -254,6 +254,16 @@ public abstract class Signature extends SignatureSpi {
}
/**
+ * Returns the {@code SignatureSpi} backing this {@code Signature} or {@code null} if no
+ * {@code SignatureSpi} is backing this {@code Signature}.
+ *
+ * @hide
+ */
+ public SignatureSpi getCurrentSpi() {
+ return null;
+ }
+
+ /**
* Returns the name of the algorithm of this {@code Signature}.
*
* @return the name of the algorithm of this {@code Signature}.
@@ -746,5 +756,12 @@ public abstract class Signature extends SignatureSpi {
public SignatureSpi getSpi() {
return getSpi(null);
}
+
+ @Override
+ public SignatureSpi getCurrentSpi() {
+ synchronized (initLock) {
+ return spiImpl;
+ }
+ }
}
}
diff --git a/luni/src/main/java/javax/crypto/Cipher.java b/luni/src/main/java/javax/crypto/Cipher.java
index 66d03ad..225822d 100644
--- a/luni/src/main/java/javax/crypto/Cipher.java
+++ b/luni/src/main/java/javax/crypto/Cipher.java
@@ -374,6 +374,22 @@ public class Cipher {
}
/**
+ * Returns the {@code CipherSpi} backing this {@code Cipher} or {@code null} if no
+ * {@code CipherSpi} is backing this {@code Cipher}.
+ *
+ * @hide
+ */
+ public CipherSpi getCurrentSpi() {
+ if (specifiedSpi != null) {
+ return specifiedSpi;
+ }
+
+ synchronized (initLock) {
+ return spiImpl;
+ }
+ }
+
+ /**
* Try all combinations of mode strings:
*
* <pre>
diff --git a/luni/src/main/java/javax/crypto/KeyAgreement.java b/luni/src/main/java/javax/crypto/KeyAgreement.java
index d27aa2e..c804273 100644
--- a/luni/src/main/java/javax/crypto/KeyAgreement.java
+++ b/luni/src/main/java/javax/crypto/KeyAgreement.java
@@ -260,6 +260,18 @@ public class KeyAgreement {
}
/**
+ * Returns the {@code KeyAgreementSpi} backing this {@code KeyAgreement} or {@code null} if no
+ * {@code KeyAgreementSpi} is backing this {@code KeyAgreement}.
+ *
+ * @hide
+ */
+ public KeyAgreementSpi getCurrentSpi() {
+ synchronized (initLock) {
+ return spiImpl;
+ }
+ }
+
+ /**
* Initializes this {@code KeyAgreement} with the specified key.
*
* @param key the key to initialize this key agreement.
diff --git a/luni/src/main/java/javax/crypto/Mac.java b/luni/src/main/java/javax/crypto/Mac.java
index 536f0c5..5774eb2 100644
--- a/luni/src/main/java/javax/crypto/Mac.java
+++ b/luni/src/main/java/javax/crypto/Mac.java
@@ -274,6 +274,18 @@ public class Mac implements Cloneable {
}
/**
+ * Returns the {@code MacSpi} backing this {@code Mac} or {@code null} if no {@code MacSpi} is
+ * backing this {@code Mac}.
+ *
+ * @hide
+ */
+ public MacSpi getCurrentSpi() {
+ synchronized (initLock) {
+ return spiImpl;
+ }
+ }
+
+ /**
* Returns the length of this MAC (in bytes).
*
* @return the length of this MAC (in bytes).