allow lists to be subkeys or keyrings

This commit is contained in:
Ashley Hughes 2014-03-25 22:28:32 +00:00
parent e7b3dd64f4
commit 68f035ff88

View File

@ -59,13 +59,30 @@ public class PgpConversionHelper {
* @return * @return
*/ */
public static ArrayList<PGPSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) { public static ArrayList<PGPSecretKey> BytesToPGPSecretKeyList(byte[] keysBytes) {
PGPSecretKeyRing keyRing = (PGPSecretKeyRing) BytesToPGPKeyRing(keysBytes); PGPObjectFactory factory = new PGPObjectFactory(keysBytes);
Object obj = null;
ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>(); ArrayList<PGPSecretKey> keys = new ArrayList<PGPSecretKey>();
try {
@SuppressWarnings("unchecked") while ((obj = factory.nextObject()) != null) {
Iterator<PGPSecretKey> itr = keyRing.getSecretKeys(); PGPSecretKey secKey = null;
while (itr.hasNext()) { if(obj instanceof PGPSecretKey) {
keys.add(itr.next()); if ((secKey = (PGPSecretKey)obj ) == null) {
Log.e(Constants.TAG, "No keys given!");
}
keys.add(secKey);
} else if(obj instanceof PGPSecretKeyRing) { //master keys are sent as keyrings
PGPSecretKeyRing keyRing = null;
if ((keyRing = (PGPSecretKeyRing)obj) == null) {
Log.e(Constants.TAG, "No keys given!");
}
@SuppressWarnings("unchecked")
Iterator<PGPSecretKey> itr = keyRing.getSecretKeys();
while (itr.hasNext()) {
keys.add(itr.next());
}
}
}
} catch (IOException e) {
} }
return keys; return keys;