diff options
Diffstat (limited to 'OpenPGP-Keychain/src/main/java')
-rw-r--r-- | OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java index 20d446824..c7dd7d647 100644 --- a/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java +++ b/OpenPGP-Keychain/src/main/java/org/sufficientlysecure/keychain/pgp/PgpConversionHelper.java @@ -59,13 +59,30 @@ public class PgpConversionHelper { * @return */ 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>(); - - @SuppressWarnings("unchecked") - Iterator<PGPSecretKey> itr = keyRing.getSecretKeys(); - while (itr.hasNext()) { - keys.add(itr.next()); + try { + while ((obj = factory.nextObject()) != null) { + PGPSecretKey secKey = null; + if(obj instanceof PGPSecretKey) { + 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; |