org.mozilla.jss.asn1

Class ASN1Header

public class ASN1Header extends Object

The portion of a BER encoding that precedes the contents octets. Consists of the tag, form, and length octets.
Field Summary
static FormCONSTRUCTED
static FormPRIMITIVE
Constructor Summary
ASN1Header(InputStream istream)
Gets info about the next item in the DER stream, consuming the identifier and length octets.
ASN1Header(Tag tag, Form form, long contentLength)
This constructor is to be called when we are constructing an ASN1Value rather than decoding it.
Method Summary
voidencode(OutputStream ostream)
byte[]encode()
longgetContentLength()
Returns -1 for indefinite length encoding.
FormgetForm()
Returns the Form, PRIMITIVE or CONSTRUCTED.
TaggetTag()
longgetTotalLength()
Returns the length of the header plus the length of the contents; the total length of the DER encoding of an ASN1 value.
booleanisEOC()
Returns true if this is a BER end-of-contents marker.
static ASN1HeaderlookAhead(InputStream derStream)
Returns information about the next item in the stream, but does not consume any octets.
static byte[]unsignedBigIntToByteArray(BigInteger bi)
Converts an unsigned BigInteger to a minimal-length byte array.
voidvalidate(Tag expectedTag, Form expectedForm)
Verifies that this header has the given tag and form.
voidvalidate(Tag expectedTag)
Verifies that this head has the given tag.

Field Detail

CONSTRUCTED

public static final Form CONSTRUCTED

PRIMITIVE

public static final Form PRIMITIVE

Constructor Detail

ASN1Header

public ASN1Header(InputStream istream)
Gets info about the next item in the DER stream, consuming the identifier and length octets.

ASN1Header

public ASN1Header(Tag tag, Form form, long contentLength)
This constructor is to be called when we are constructing an ASN1Value rather than decoding it.

Parameters: contentLength Must be >=0. Although indefinite length decoding is supported, indefinite length encoding is not.

Method Detail

encode

public void encode(OutputStream ostream)

encode

public byte[] encode()

getContentLength

public long getContentLength()
Returns -1 for indefinite length encoding.

getForm

public Form getForm()
Returns the Form, PRIMITIVE or CONSTRUCTED.

getTag

public Tag getTag()

getTotalLength

public long getTotalLength()
Returns the length of the header plus the length of the contents; the total length of the DER encoding of an ASN1 value. Returns -1 if indefinite length encoding was used.

isEOC

public boolean isEOC()
Returns true if this is a BER end-of-contents marker.

lookAhead

public static ASN1Header lookAhead(InputStream derStream)
Returns information about the next item in the stream, but does not consume any octets.

Throws: IOException If the input stream does not support look ahead.

unsignedBigIntToByteArray

public static byte[] unsignedBigIntToByteArray(BigInteger bi)
Converts an unsigned BigInteger to a minimal-length byte array. This is necessary because BigInteger.toByteArray() attaches an extra sign bit, which could cause the size of the byte representation to be bumped up by an extra byte.

validate

public void validate(Tag expectedTag, Form expectedForm)
Verifies that this header has the given tag and form.

Throws: InvalidBERException If the header's tag or form differ from those passed in.

validate

public void validate(Tag expectedTag)
Verifies that this head has the given tag.

Throws: InvalidBERException If the header's tag differs from that passed in.