From acb5a70e445351f245ef3ffa19e69315f8548ec7 Mon Sep 17 00:00:00 2001 From: Vincent Breitmoser Date: Thu, 31 Jul 2014 19:27:01 +0200 Subject: fix fromStream method, properly recognize multiple concatenated streams --- .../keychain/pgp/UncachedKeyRing.java | 37 ++++++++++++---------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java') diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java index e7229ffbd..502e3a70c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -27,9 +27,11 @@ import java.io.ByteArrayOutputStream; 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.Iterator; +import java.util.List; import java.util.Set; import java.util.TreeSet; @@ -133,26 +135,27 @@ public class UncachedKeyRing { } try { - if (mObjectFactory == null) { - if (stream.available() == 0) { - // end of stream. that's fine - return; + while(stream.available() > 0) { + // if there are no objects left from the last factory, create a new one + if (mObjectFactory == null) { + mObjectFactory = new PGPObjectFactory(PGPUtil.getDecoderStream(stream)); } - mObjectFactory = new PGPObjectFactory(PGPUtil.getDecoderStream(stream)); - } - // go through all objects in this block - Object obj; - while ((obj = mObjectFactory.nextObject()) != null) { - Log.d(Constants.TAG, "Found class: " + obj.getClass()); - if (!(obj instanceof PGPKeyRing)) { - Log.i(Constants.TAG, - "Skipping object of bad type " + obj.getClass().getName() + " in stream"); - // skip object - continue; + // go through all objects in this block + Object obj; + while ((obj = mObjectFactory.nextObject()) != null) { + Log.d(Constants.TAG, "Found class: " + obj.getClass()); + if (!(obj instanceof PGPKeyRing)) { + Log.i(Constants.TAG, + "Skipping object of bad type " + obj.getClass().getName() + " in stream"); + // skip object + continue; + } + mNext = new UncachedKeyRing((PGPKeyRing) obj); + return; } - mNext = new UncachedKeyRing((PGPKeyRing) obj); - return; + // if we are past the while loop, that means the objectFactory had no next + mObjectFactory = null; } } catch (IOException e) { Log.e(Constants.TAG, "IOException while processing stream", e); -- cgit v1.2.3