aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java16
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java18
2 files changed, 32 insertions, 2 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
index 21f0dddf6..18b02156d 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
@@ -22,8 +22,11 @@ import android.database.Cursor;
import android.net.Uri;
import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
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.util.Log;
/** This implementation of KeyRing provides a cached view of PublicKeyRing
@@ -222,4 +225,17 @@ public class CachedPublicKeyRing extends KeyRing {
Uri keysUri = KeychainContract.Keys.buildKeysUri(extractOrGetMasterKeyId());
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);
+ }
+ }
+
}
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
index e1dae55ad..bfa95280e 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/ProviderHelper.java
@@ -141,12 +141,22 @@ 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}).get(column);
+ return getGenericData(uri, new String[]{column}, new int[]{type}, null).get(column);
+ }
+
+ public Object getGenericData(Uri uri, String column, int type, String selection)
+ throws NotFoundException {
+ return getGenericData(uri, new String[]{column}, new int[]{type}, selection).get(column);
}
public HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types)
+ throws NotFoundException {
+ return getGenericData(uri, proj, types, null);
+ }
+
+ public HashMap<String, Object> getGenericData(Uri uri, String[] proj, int[] types, String selection)
throws NotFoundException {
- Cursor cursor = mContentResolver.query(uri, proj, null, null, null);
+ Cursor cursor = mContentResolver.query(uri, proj, selection, null, null);
try {
HashMap<String, Object> result = new HashMap<String, Object>(proj.length);
@@ -223,6 +233,10 @@ public class ProviderHelper {
return new CachedPublicKeyRing(this, queryUri);
}
+ public CachedPublicKeyRing getCachedPublicKeyRing(long id) {
+ return new CachedPublicKeyRing(this, KeyRings.buildUnifiedKeyRingUri(id));
+ }
+
public CanonicalizedPublicKeyRing getCanonicalizedPublicKeyRing(long id) throws NotFoundException {
return (CanonicalizedPublicKeyRing) getCanonicalizedKeyRing(KeyRings.buildUnifiedKeyRingUri(id), false);
}