X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fbouncycastle%2Fasn1%2FDERInputStream.java;h=107cc13f2dabf661793da548707cbaf2cb672635;hb=ab6994d434e6aef3c2d5e65ab5e755d6447f875f;hp=61de7355b4dad2d93385be188bb274d2586b3767;hpb=e5e9355b4f4e0e2c8de9068a71c1e3cc26fa9905;p=org.ibex.core.git diff --git a/src/org/bouncycastle/asn1/DERInputStream.java b/src/org/bouncycastle/asn1/DERInputStream.java index 61de735..107cc13 100644 --- a/src/org/bouncycastle/asn1/DERInputStream.java +++ b/src/org/bouncycastle/asn1/DERInputStream.java @@ -1,7 +1,12 @@ package org.bouncycastle.asn1; -import java.math.BigInteger; -import java.io.*; +import java.io.FilterInputStream; + +import java.io.InputStream; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.EOFException; + public class DERInputStream extends FilterInputStream implements DERTags @@ -64,16 +69,16 @@ public class DERInputStream } } - /** - * build an object given its tag and a byte stream to construct it - * from. - */ + /** + * build an object given its tag and a byte stream to construct it + * from. + */ protected DERObject buildObject( - int tag, - byte[] bytes) - throws IOException - { - switch (tag) + int tag, + byte[] bytes) + throws IOException + { + switch (tag) { case NULL: return null; @@ -99,7 +104,7 @@ public class DERInputStream bIn = new ByteArrayInputStream(bytes); dIn = new BERInputStream(bIn); - DERSet set = new DERSet(dIn.readObject()); + DEREncodableVector v = new DEREncodableVector(); try { @@ -107,41 +112,21 @@ public class DERInputStream { DERObject obj = dIn.readObject(); - set.addObject(obj); + v.add(obj); } } catch (EOFException ex) { - return set; + return new DERConstructedSet(v); } case BOOLEAN: return new DERBoolean(bytes); case INTEGER: return new DERInteger(bytes); + case ENUMERATED: + return new DEREnumerated(bytes); case OBJECT_IDENTIFIER: - int head = bytes[0] & 0xff; - StringBuffer objId = new StringBuffer(); - - objId.append(Integer.toString(head / 40)); - objId.append('.'); - objId.append(Integer.toString(head % 40)); - - int value = 0; - - for (int i = 1; i != bytes.length; i++) - { - int b = bytes[i] & 0xff; - - value = value * 128 + (b & 0x7f); - if ((b & 128) == 0) // end of number reached - { - objId.append('.'); - objId.append(Integer.toString(value)); - value = 0; - } - } - - return new DERObjectIdentifier(objId.toString()); + return new DERObjectIdentifier(bytes); case BIT_STRING: int padBits = bytes[0]; byte[] data = new byte[bytes.length - 1]; @@ -149,6 +134,8 @@ public class DERInputStream System.arraycopy(bytes, 1, data, 0, bytes.length - 1); return new DERBitString(data, padBits); + case UTF8_STRING: + return new DERUTF8String(bytes); case PRINTABLE_STRING: return new DERPrintableString(bytes); case IA5_STRING: @@ -157,21 +144,30 @@ public class DERInputStream return new DERT61String(bytes); case VISIBLE_STRING: return new DERVisibleString(bytes); + case UNIVERSAL_STRING: + return new DERUniversalString(bytes); case BMP_STRING: return new DERBMPString(bytes); case OCTET_STRING: return new DEROctetString(bytes); case UTC_TIME: - return new DERUTCTime(new String(bytes)); + return new DERUTCTime(bytes); + case GENERALIZED_TIME: + return new DERGeneralizedTime(bytes); default: // - // with tagged object tag number is bottom 4 bits + // with tagged object tag number is bottom 5 bits // - if ((tag & (TAGGED | CONSTRUCTED)) != 0) + if ((tag & TAGGED) != 0) { + if ((tag & 0x1f) == 0x1f) + { + throw new IOException("unsupported high tag encountered"); + } + if (bytes.length == 0) // empty tag! { - return new DERTaggedObject(tag & 0x0f); + return new DERTaggedObject(false, tag & 0x1f, new DERConstructedSequence()); } // @@ -179,7 +175,7 @@ public class DERInputStream // if ((tag & CONSTRUCTED) == 0) { - return new DERTaggedObject(false, tag & 0x0f, new DEROctetString(bytes)); + return new DERTaggedObject(false, tag & 0x1f, new DEROctetString(bytes)); } bIn = new ByteArrayInputStream(bytes); @@ -193,7 +189,7 @@ public class DERInputStream // if (dIn.available() == 0) { - return new DERTaggedObject(tag & 0x0f, dObj); + return new DERTaggedObject(tag & 0x1f, dObj); } // @@ -217,12 +213,12 @@ public class DERInputStream // ignore -- } - return new DERTaggedObject(false, tag & 0x0f, seq); + return new DERTaggedObject(false, tag & 0x1f, seq); } return new DERUnknownTag(tag, bytes); } - } + } public DERObject readObject() throws IOException @@ -238,6 +234,6 @@ public class DERInputStream readFully(bytes); - return buildObject(tag, bytes); - } + return buildObject(tag, bytes); + } }