diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-07-31 17:08:33 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-07-31 17:09:30 +0200 |
commit | b156a057e8c5b715f515725ab051087a86ecd547 (patch) | |
tree | 84f321e44796e684f8aede8653a131cc7cedf1b4 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java | |
parent | 9475285013accafd24d5bc14da9ba01ca218cbe8 (diff) | |
download | open-keychain-b156a057e8c5b715f515725ab051087a86ecd547.tar.gz open-keychain-b156a057e8c5b715f515725ab051087a86ecd547.tar.bz2 open-keychain-b156a057e8c5b715f515725ab051087a86ecd547.zip |
rename Wrapped*Key* to Canonicalized*Key*
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java new file mode 100644 index 000000000..70288dceb --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/CanonicalizedPublicKeyRing.java @@ -0,0 +1,84 @@ +package org.sufficientlysecure.keychain.pgp; + +import org.spongycastle.bcpg.ArmoredOutputStream; +import org.spongycastle.openpgp.PGPObjectFactory; +import org.spongycastle.openpgp.PGPPublicKey; +import org.spongycastle.openpgp.PGPPublicKeyRing; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; +import org.sufficientlysecure.keychain.util.IterableIterator; + +import java.io.IOException; +import java.util.Iterator; + +public class CanonicalizedPublicKeyRing extends CanonicalizedKeyRing { + + private PGPPublicKeyRing mRing; + + CanonicalizedPublicKeyRing(PGPPublicKeyRing ring, int verified) { + super(verified); + mRing = ring; + } + + public CanonicalizedPublicKeyRing(byte[] blob, int verified) { + super(verified); + if(mRing == null) { + // get first object in block + PGPObjectFactory factory = new PGPObjectFactory(blob); + try { + Object obj = factory.nextObject(); + if (! (obj instanceof PGPPublicKeyRing)) { + throw new RuntimeException("Error constructing CanonicalizedPublicKeyRing, should never happen!"); + } + mRing = (PGPPublicKeyRing) obj; + if (factory.nextObject() != null) { + throw new RuntimeException("Encountered trailing data after keyring, should never happen!"); + } + } catch (IOException e) { + throw new RuntimeException("IO Error constructing CanonicalizedPublicKeyRing, should never happen!"); + } + } + } + + PGPPublicKeyRing getRing() { + return mRing; + } + + public void encode(ArmoredOutputStream stream) throws IOException { + getRing().encode(stream); + } + + /** Getter that returns the subkey that should be used for signing. */ + CanonicalizedPublicKey getEncryptionSubKey() throws PgpGeneralException { + PGPPublicKey key = getRing().getPublicKey(getEncryptId()); + if(key != null) { + CanonicalizedPublicKey cKey = new CanonicalizedPublicKey(this, key); + if(!cKey.canEncrypt()) { + throw new PgpGeneralException("key error"); + } + return cKey; + } + throw new PgpGeneralException("no encryption key available"); + } + + public IterableIterator<CanonicalizedPublicKey> publicKeyIterator() { + @SuppressWarnings("unchecked") + final Iterator<PGPPublicKey> it = getRing().getPublicKeys(); + return new IterableIterator<CanonicalizedPublicKey>(new Iterator<CanonicalizedPublicKey>() { + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public CanonicalizedPublicKey next() { + return new CanonicalizedPublicKey(CanonicalizedPublicKeyRing.this, it.next()); + } + + @Override + public void remove() { + it.remove(); + } + }); + } + +}
\ No newline at end of file |