aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKey.java
diff options
context:
space:
mode:
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKey.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKey.java58
1 files changed, 54 insertions, 4 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKey.java
index 7a63a7a42..8fb3402b2 100644
--- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKey.java
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKey.java
@@ -18,6 +18,7 @@
package org.sufficientlysecure.keychain.pgp;
+import org.spongycastle.bcpg.sig.KeyFlags;
import org.spongycastle.openpgp.PGPPublicKey;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
import org.sufficientlysecure.keychain.util.IterableIterator;
@@ -46,12 +47,61 @@ public class CanonicalizedPublicKey extends UncachedPublicKey {
return new IterableIterator<String>(mPublicKey.getUserIDs());
}
- public KeyRing getKeyRing() {
- return mRing;
+ JcePublicKeyKeyEncryptionMethodGenerator getPubKeyEncryptionGenerator() {
+ return new JcePublicKeyKeyEncryptionMethodGenerator(mPublicKey);
}
- JcePublicKeyKeyEncryptionMethodGenerator getPubKeyEncryptionGenerator() {
- return new JcePublicKeyKeyEncryptionMethodGenerator(mPublicKey);
+ public boolean canSign() {
+ // if key flags subpacket is available, honor it!
+ if (getKeyUsage() != null) {
+ return (getKeyUsage() & KeyFlags.SIGN_DATA) != 0;
+ }
+
+ if (UncachedKeyRing.isSigningAlgo(mPublicKey.getAlgorithm())) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean canCertify() {
+ // if key flags subpacket is available, honor it!
+ if (getKeyUsage() != null) {
+ return (getKeyUsage() & KeyFlags.CERTIFY_OTHER) != 0;
+ }
+
+ if (UncachedKeyRing.isSigningAlgo(mPublicKey.getAlgorithm())) {
+ return true;
+ }
+
+ return false;
}
+ public boolean canEncrypt() {
+ // if key flags subpacket is available, honor it!
+ if (getKeyUsage() != null) {
+ return (getKeyUsage() & (KeyFlags.ENCRYPT_COMMS | KeyFlags.ENCRYPT_STORAGE)) != 0;
+ }
+
+ // RSA_GENERAL, RSA_ENCRYPT, ELGAMAL_ENCRYPT, ELGAMAL_GENERAL, ECDH
+ if (UncachedKeyRing.isEncryptionAlgo(mPublicKey.getAlgorithm())) {
+ return true;
+ }
+
+ return false;
+ }
+
+ public boolean canAuthenticate() {
+ // if key flags subpacket is available, honor it!
+ if (getKeyUsage() != null) {
+ return (getKeyUsage() & KeyFlags.AUTHENTICATION) != 0;
+ }
+
+ return false;
+ }
+
+ /** Same method as superclass, but we make it public. */
+ public Integer getKeyUsage() {
+ return super.getKeyUsage();
+ }
}