aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-10-02 19:23:08 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-10-02 19:26:07 +0200
commit37cb5c4c78880b5b4737cffdaa4ead76506a3843 (patch)
tree244b981b9475cbbdb021a85a5f7eab35b120c994 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
parent9a296c012d8aaaf4273892ad06a4f66ea4edefac (diff)
downloadopen-keychain-37cb5c4c78880b5b4737cffdaa4ead76506a3843.tar.gz
open-keychain-37cb5c4c78880b5b4737cffdaa4ead76506a3843.tar.bz2
open-keychain-37cb5c4c78880b5b4737cffdaa4ead76506a3843.zip
make getSignId a secret key operation, and respect unavailable keys
This one should remedy #811, but waiting for a test
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java58
1 files changed, 13 insertions, 45 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 cfb4a915e..ad3ebae5f 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/provider/CachedPublicKeyRing.java
@@ -136,64 +136,32 @@ public class CachedPublicKeyRing extends KeyRing {
@Override
public long getEncryptId() throws PgpGeneralException {
try {
- Cursor subkeys = getSubkeys();
- if (subkeys != null) {
- try {
- while (subkeys.moveToNext()) {
- if (subkeys.getInt(subkeys.getColumnIndexOrThrow(KeychainContract.Keys.CAN_ENCRYPT)) != 0) {
- return subkeys.getLong(subkeys.getColumnIndexOrThrow(KeychainContract.Keys.KEY_ID));
- }
- }
- } finally {
- subkeys.close();
- }
- }
- } catch(Exception e) {
- throw new PgpGeneralException(e);
- }
- throw new PgpGeneralException("No encrypt key found");
- }
-
- @Override
- public boolean hasEncrypt() throws PgpGeneralException {
- try {
Object data = mProviderHelper.getGenericData(mUri,
- KeychainContract.KeyRings.HAS_ENCRYPT,
+ KeyRings.HAS_ENCRYPT,
ProviderHelper.FIELD_TYPE_INTEGER);
- return (Long) data > 0;
+ return (Long) data;
} catch(ProviderHelper.NotFoundException e) {
throw new PgpGeneralException(e);
}
}
@Override
- public long getSignId() throws PgpGeneralException {
- try {
- Cursor subkeys = getSubkeys();
- if (subkeys != null) {
- try {
- while (subkeys.moveToNext()) {
- if (subkeys.getInt(subkeys.getColumnIndexOrThrow(KeychainContract.Keys.CAN_SIGN)) != 0) {
- return subkeys.getLong(subkeys.getColumnIndexOrThrow(KeychainContract.Keys.KEY_ID));
- }
- }
- } finally {
- subkeys.close();
- }
- }
- } catch(Exception e) {
- throw new PgpGeneralException(e);
- }
- throw new PgpGeneralException("No sign key found");
+ public boolean hasEncrypt() throws PgpGeneralException {
+ return getEncryptId() != 0;
}
- @Override
- public boolean hasSign() throws PgpGeneralException {
+ /** Returns the key id which should be used for signing.
+ *
+ * This method returns keys which are actually available (ie. secret available, and not stripped,
+ * revoked, or expired), hence only works on keyrings where a secret key is available!
+ *
+ */
+ public long getSecretSignId() throws PgpGeneralException {
try {
Object data = mProviderHelper.getGenericData(mUri,
- KeychainContract.KeyRings.HAS_SIGN,
+ KeyRings.HAS_SIGN,
ProviderHelper.FIELD_TYPE_INTEGER);
- return (Long) data > 0;
+ return (Long) data;
} catch(ProviderHelper.NotFoundException e) {
throw new PgpGeneralException(e);
}