1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
/* see bouncycastle_license.txt */
package com.lowagie.bc.asn1;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class DEROutputStream
extends FilterOutputStream implements DERTags
{
public DEROutputStream(
OutputStream os)
{
super(os);
}
private void writeLength(
int length)
throws IOException
{
if (length > 127)
{
int size = 1;
int val = length;
while ((val >>>= 8) != 0)
{
size++;
}
write((byte)(size | 0x80));
for (int i = (size - 1) * 8; i >= 0; i -= 8)
{
write((byte)(length >> i));
}
}
else
{
write((byte)length);
}
}
void writeEncoded(
int tag,
byte[] bytes)
throws IOException
{
write(tag);
writeLength(bytes.length);
write(bytes);
}
protected void writeNull()
throws IOException
{
write(NULL);
write(0x00);
}
public void writeObject(
Object obj)
throws IOException
{
if (obj == null)
{
writeNull();
}
else if (obj instanceof DERObject)
{
((DERObject)obj).encode(this);
}
else if (obj instanceof DEREncodable)
{
((DEREncodable)obj).getDERObject().encode(this);
}
else
{
throw new IOException("object not DEREncodable");
}
}
}
|