generate public keyring from secret if not available

This commit is contained in:
Vincent Breitmoser
2014-06-18 20:55:44 +02:00
parent f8d895dea4
commit 3bffe4da55
5 changed files with 41 additions and 23 deletions

View File

@@ -27,6 +27,7 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
@@ -759,6 +760,21 @@ public class UncachedKeyRing {
}
public UncachedKeyRing extractPublicKeyRing() {
if(!isSecret()) {
throw new RuntimeException("Tried to extract public keyring from non-secret keyring. " +
"This is a programming error and should never happen!");
}
ArrayList<PGPPublicKey> keys = new ArrayList();
Iterator<PGPPublicKey> it = mRing.getPublicKeys();
while (it.hasNext()) {
keys.add(it.next());
}
return new UncachedKeyRing(new PGPPublicKeyRing(keys));
}
/** This method replaces a public key in a keyring.
*
* This method essentially wraps PGP*KeyRing.insertPublicKey, where the keyring may be of either