public class BERInputStream
extends DERInputStream
{
- private DERObject END_OF_STREAM = new DERObject() {
- void encode(
- DEROutputStream out)
- throws IOException
- {
- throw new IOException("Eeek!");
- }
-
- };
+ private DERObject END_OF_STREAM = new DERObject() {
+ void encode(
+ DEROutputStream out)
+ throws IOException
+ {
+ throw new IOException("Eeek!");
+ }
+
+ };
public BERInputStream(
InputStream is)
{
while ((b = read()) >= 0)
{
- if (b1 == 0 && b == 0)
- {
- break;
- }
+ if (b1 == 0 && b == 0)
+ {
+ break;
+ }
bOut.write(b1);
b1 = b;
return bOut.toByteArray();
}
- private BERConstructedOctetString buildConstructedOctetString()
- throws IOException
- {
+ private BERConstructedOctetString buildConstructedOctetString()
+ throws IOException
+ {
Vector octs = new Vector();
- for (;;)
- {
- DERObject o = readObject();
+ for (;;)
+ {
+ DERObject o = readObject();
- if (o == END_OF_STREAM)
- {
- break;
- }
+ if (o == END_OF_STREAM)
+ {
+ break;
+ }
octs.addElement(o);
- }
+ }
- return new BERConstructedOctetString(octs);
- }
+ return new BERConstructedOctetString(octs);
+ }
public DERObject readObject()
throws IOException
case SEQUENCE | CONSTRUCTED:
BERConstructedSequence seq = new BERConstructedSequence();
- for (;;)
- {
- DERObject obj = readObject();
-
- if (obj == END_OF_STREAM)
- {
- break;
- }
-
- seq.addObject(obj);
- }
- return seq;
+ for (;;)
+ {
+ DERObject obj = readObject();
+
+ if (obj == END_OF_STREAM)
+ {
+ break;
+ }
+
+ seq.addObject(obj);
+ }
+ return seq;
case OCTET_STRING | CONSTRUCTED:
- return buildConstructedOctetString();
+ return buildConstructedOctetString();
case SET | CONSTRUCTED:
DEREncodableVector v = new DEREncodableVector();
- for (;;)
- {
- DERObject obj = readObject();
-
- if (obj == END_OF_STREAM)
- {
- break;
- }
-
- v.add(obj);
- }
- return new BERSet(v);
+ for (;;)
+ {
+ DERObject obj = readObject();
+
+ if (obj == END_OF_STREAM)
+ {
+ break;
+ }
+
+ v.add(obj);
+ }
+ return new BERSet(v);
default:
//
// with tagged object tag number is bottom 5 bits
//
// either constructed or explicitly tagged
//
- DERObject dObj = readObject();
+ DERObject dObj = readObject();
- if (dObj == END_OF_STREAM) // empty tag!
+ if (dObj == END_OF_STREAM) // empty tag!
{
return new DERTaggedObject(tag & 0x1f);
}
readFully(bytes);
- return buildObject(tag, bytes);
+ return buildObject(tag, bytes);
}
}
}
}
}
- /**
- * 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;
return new DERUnknownTag(tag, bytes);
}
- }
+ }
public DERObject readObject()
throws IOException
readFully(bytes);
- return buildObject(tag, bytes);
- }
+ return buildObject(tag, bytes);
+ }
}
out.writeEncoded(tag, data);
}
- public boolean equals(
- Object o)
- {
+ public boolean equals(
+ Object o)
+ {
if ((o == null) || !(o instanceof DERUnknownTag))
{
return false;
if(tag != other.tag)
{
- return false;
- }
-
- if(data.length != other.data.length)
- {
- return false;
- }
-
- for(int i = 0; i < data.length; i++)
- {
- if(data[i] != other.data[i])
- {
- return false;
- }
- }
-
- return true;
- }
+ return false;
+ }
+
+ if(data.length != other.data.length)
+ {
+ return false;
+ }
+
+ for(int i = 0; i < data.length; i++)
+ {
+ if(data[i] != other.data[i])
+ {
+ return false;
+ }
+ }
+
+ return true;
+ }
}