aboutsummaryrefslogtreecommitdiffstats
path: root/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedPublicKey.java
diff options
context:
space:
mode:
authorVincent Breitmoser <valodim@mugenguild.com>2014-05-21 21:07:32 +0200
committerVincent Breitmoser <valodim@mugenguild.com>2014-05-21 21:07:32 +0200
commit761d87b661ef14023870ad7be107d33d69ab03e7 (patch)
treef99d583784fde28d467dbeabd583c32755c3807c /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedPublicKey.java
parent2f95100d88954db389cba8e615390795d121c1c8 (diff)
downloadopen-keychain-761d87b661ef14023870ad7be107d33d69ab03e7.tar.gz
open-keychain-761d87b661ef14023870ad7be107d33d69ab03e7.tar.bz2
open-keychain-761d87b661ef14023870ad7be107d33d69ab03e7.zip
wrapped-key-ring: split up CachedKeyRing and WrappedKeyRing
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedPublicKey.java')
-rw-r--r--OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedPublicKey.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedPublicKey.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedPublicKey.java
new file mode 100644
index 000000000..72352a451
--- /dev/null
+++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/WrappedPublicKey.java
@@ -0,0 +1,62 @@
+package org.sufficientlysecure.keychain.pgp;
+
+import org.spongycastle.openpgp.PGPException;
+import org.spongycastle.openpgp.PGPOnePassSignature;
+import org.spongycastle.openpgp.PGPPublicKey;
+import org.spongycastle.openpgp.PGPSignature;
+import org.spongycastle.openpgp.operator.jcajce.JcaPGPContentVerifierBuilderProvider;
+import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
+import org.sufficientlysecure.keychain.Constants;
+import org.sufficientlysecure.keychain.util.IterableIterator;
+
+import java.security.SignatureException;
+
+public class WrappedPublicKey extends UncachedPublicKey {
+
+ // this is the parent key ring
+ final KeyRing mRing;
+
+ WrappedPublicKey(KeyRing ring, PGPPublicKey key) {
+ super(key);
+ mRing = ring;
+ }
+
+ public IterableIterator<String> getUserIds() {
+ return new IterableIterator<String>(mPublicKey.getUserIDs());
+ }
+
+ public KeyRing getKeyRing() {
+ return mRing;
+ }
+
+ JcePublicKeyKeyEncryptionMethodGenerator getPubKeyEncryptionGenerator() {
+ return new JcePublicKeyKeyEncryptionMethodGenerator(mPublicKey);
+ }
+
+ public void initSignature(PGPSignature sig) throws PGPException {
+ JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
+ new JcaPGPContentVerifierBuilderProvider()
+ .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
+ sig.init(contentVerifierBuilderProvider, mPublicKey);
+ }
+
+ public void initSignature(PGPOnePassSignature sig) throws PGPException {
+ JcaPGPContentVerifierBuilderProvider contentVerifierBuilderProvider =
+ new JcaPGPContentVerifierBuilderProvider()
+ .setProvider(Constants.BOUNCY_CASTLE_PROVIDER_NAME);
+ sig.init(contentVerifierBuilderProvider, mPublicKey);
+ }
+
+ /** Verify a signature for this pubkey, after it has been initialized by the signer using
+ * initSignature(). This method should probably move into a wrapped PGPSignature class
+ * at some point.
+ */
+ public boolean verifySignature(PGPSignature sig, String uid) throws PGPException {
+ try {
+ return sig.verifyCertification(uid, mPublicKey);
+ } catch (SignatureException e) {
+ throw new PGPException("Error!", e);
+ }
+ }
+
+}