X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fbouncycastle%2Fasn1%2FBERInputStream.java;h=fd960eca276c4a6fe94f625ada7d2daa8e692cb1;hb=d70f271afd972a3bdeba9ee54b1e9a3334e6fe4b;hp=824b439c5dffeec7bb47392d8c0c6b3ffbec19f1;hpb=3f13b8f2e9c92b428dc237327f3e86353902ac29;p=org.ibex.core.git diff --git a/src/org/bouncycastle/asn1/BERInputStream.java b/src/org/bouncycastle/asn1/BERInputStream.java index 824b439..fd960ec 100644 --- a/src/org/bouncycastle/asn1/BERInputStream.java +++ b/src/org/bouncycastle/asn1/BERInputStream.java @@ -47,19 +47,11 @@ public class BERInputStream return bOut.toByteArray(); } - private BERConstructedOctetString buildConstructedOctetString( - DEROctetString o1, - DEROctetString o2) + private BERConstructedOctetString buildConstructedOctetString() throws IOException { Vector octs = new Vector(); - if (o1 != null) - { - octs.addElement(o1); - octs.addElement(o2); - } - for (;;) { DERObject o = readObject(); @@ -88,8 +80,6 @@ public class BERInputStream if (length < 0) // indefinite length method { - byte[] bytes; - switch (tag) { case NULL: @@ -110,36 +100,82 @@ public class BERInputStream } return seq; case OCTET_STRING | CONSTRUCTED: - return buildConstructedOctetString(null, null); - default: - if ((tag & (TAGGED | CONSTRUCTED)) != 0) - { - // with tagged object tag number is bottom 4 bits - BERTaggedObject tagObj = new BERTaggedObject(tag & 0x0f, readObject()); - DERObject o = readObject(); + return buildConstructedOctetString(); + case SET | CONSTRUCTED: + DEREncodableVector v = new DEREncodableVector(); + + for (;;) + { + DERObject obj = readObject(); - if (o == END_OF_STREAM) - { - return tagObj; - } - else if (o instanceof DEROctetString - && tagObj.getObject() instanceof DEROctetString) + if (obj == END_OF_STREAM) { - // - // it's an implicit object - mark it as so... - // - tagObj = new BERTaggedObject(false, tag & 0x0f, - buildConstructedOctetString((DEROctetString)tagObj.getObject(), (DEROctetString)o)); - - return tagObj; + break; } - throw new IOException("truncated tagged object"); + v.add(obj); + } + return new BERSet(v); + default: + // + // with tagged object tag number is bottom 5 bits + // + if ((tag & TAGGED) != 0) + { + if ((tag & 0x1f) == 0x1f) + { + throw new IOException("unsupported high tag encountered"); + } + + // + // simple type - implicit... return an octet string + // + if ((tag & CONSTRUCTED) == 0) + { + byte[] bytes = readIndefiniteLengthFully(); + + return new BERTaggedObject(false, tag & 0x1f, new DEROctetString(bytes)); + } + + // + // either constructed or explicitly tagged + // + DERObject dObj = readObject(); + + if (dObj == END_OF_STREAM) // empty tag! + { + return new DERTaggedObject(tag & 0x1f); + } + + DERObject next = readObject(); + + // + // explicitly tagged (probably!) - if it isn't we'd have to + // tell from the context + // + if (next == END_OF_STREAM) + { + return new BERTaggedObject(tag & 0x1f, dObj); + } + + // + // another implicit object, we'll create a sequence... + // + seq = new BERConstructedSequence(); + + seq.addObject(dObj); + + do + { + seq.addObject(next); + next = readObject(); + } + while (next != END_OF_STREAM); + + return new BERTaggedObject(false, tag & 0x1f, seq); } - - bytes = readIndefiniteLengthFully(); - return buildObject(tag, bytes); + throw new IOException("unknown BER object encountered"); } } else