work on passphrase caching, make use of cached SecretKeyType data (WIP!)

This commit is contained in:
Vincent Breitmoser
2014-09-03 02:42:05 +02:00
parent e9b14585f5
commit 7bc424a8cb
5 changed files with 70 additions and 86 deletions

View File

@@ -27,6 +27,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.provider.KeychainContract.Keys;
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
import org.sufficientlysecure.keychain.util.Log;
/** This implementation of KeyRing provides a cached view of PublicKeyRing
@@ -226,16 +227,12 @@ public class CachedPublicKeyRing extends KeyRing {
return mProviderHelper.getContentResolver().query(keysUri, null, null, null, null);
}
public SecretKeyType getSecretKeyType(long keyId) throws PgpGeneralException {
try {
Object data = mProviderHelper.getGenericData(Keys.buildKeysUri(mUri),
KeyRings.HAS_SECRET,
ProviderHelper.FIELD_TYPE_INTEGER,
KeyRings.KEY_ID + " = " + Long.toString(keyId));
return SecretKeyType.fromNum(((Long) data).intValue());
} catch(ProviderHelper.NotFoundException e) {
throw new PgpGeneralException(e);
}
public SecretKeyType getSecretKeyType(long keyId) throws NotFoundException {
Object data = mProviderHelper.getGenericData(Keys.buildKeysUri(mUri),
KeyRings.HAS_SECRET,
ProviderHelper.FIELD_TYPE_INTEGER,
KeyRings.KEY_ID + " = " + Long.toString(keyId));
return SecretKeyType.fromNum(((Long) data).intValue());
}
}

View File

@@ -141,7 +141,11 @@ public class ProviderHelper {
public static final int FIELD_TYPE_BLOB = 5;
public Object getGenericData(Uri uri, String column, int type) throws NotFoundException {
return getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column);
Object result = getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column);
if (result == null) {
throw new NotFoundException();
}
return result;
}
public Object getGenericData(Uri uri, String column, int type, String selection)
@@ -229,6 +233,11 @@ public class ProviderHelper {
}
public long getMasterKeyId(long subKeyId) throws NotFoundException {
return (Long) getGenericData(KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId),
KeyRings.MASTER_KEY_ID, FIELD_TYPE_INTEGER);
}
public CachedPublicKeyRing getCachedPublicKeyRing(Uri queryUri) {
return new CachedPublicKeyRing(this, queryUri);
}