diff options
| author | Kenny Root <kroot@google.com> | 2012-08-17 21:13:48 -0700 |
|---|---|---|
| committer | Kenny Root <kroot@google.com> | 2012-08-20 09:48:41 -0700 |
| commit | 473c712b19bad992ab4eafcd43175fdce77b913d (patch) | |
| tree | 53695829e6276f1ab596ec873b63e3fa9ad2c491 /keystore/java/android/security/KeyStore.java | |
| parent | bc11e52cafa182996a338641c86bf3a07f571b1d (diff) | |
Add getmtime to Android KeyStore API
java.security.KeyStore requires that you be able to get the creation
date for any given entry. We'll approximate that through using the mtime
of the file in the keystore.
Change-Id: I16f74354a6c2e78a1a0b4dc2ae720c5391274e6f
Diffstat (limited to 'keystore/java/android/security/KeyStore.java')
| -rw-r--r-- | keystore/java/android/security/KeyStore.java | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/keystore/java/android/security/KeyStore.java b/keystore/java/android/security/KeyStore.java index f49c4294fb9e..4637991af134 100644 --- a/keystore/java/android/security/KeyStore.java +++ b/keystore/java/android/security/KeyStore.java @@ -26,6 +26,7 @@ import java.io.UTFDataFormatException; import java.nio.charset.Charsets; import java.nio.charset.ModifiedUtf8; import java.util.ArrayList; +import java.util.Date; /** * @hide This should not be made public in its present form because it @@ -228,6 +229,23 @@ public class KeyStore { return ungrant(getKeyBytes(key), getUidBytes(uid)); } + private long getmtime(byte[] key) { + final ArrayList<byte[]> values = execute('c', key); + if (values == null || values.isEmpty()) { + return -1L; + } + + return Long.parseLong(new String(values.get(0))) * 1000L; + } + + /** + * Returns the last modification time of the key in milliseconds since the + * epoch. Will return -1L if the key could not be found or other error. + */ + public long getmtime(String key) { + return getmtime(getKeyBytes(key)); + } + public int getLastError() { return mError; } |
