Package org.mozilla.jss.asn1
Class ASN1Header
java.lang.Object
org.mozilla.jss.asn1.ASN1Header
The portion of a BER encoding that precedes the contents octets. Consists
of the tag, form, and length octets.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionASN1Header
(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
Modifier and TypeMethodDescriptionbyte[]
encode()
void
encode
(OutputStream ostream) long
Returns -1 for indefinite length encoding.getForm()
Returns the Form, PRIMITIVE or CONSTRUCTED.getTag()
long
Returns the length of the header plus the length of the contents; the total length of the DER encoding of an ASN1 value.boolean
isEOC()
static ASN1Header
lookAhead
(InputStream derStream) Returns information about the next item in the stream, but does not consume any octets.static byte[]
Converts an unsigned BigInteger to a minimal-length byte array.void
Verifies that this head has the given tag.void
Verifies that this header has the given tag and form.
-
Field Details
-
cachedEncoding
private byte[] cachedEncoding -
tag
-
contentLength
private long contentLength -
PRIMITIVE
-
CONSTRUCTED
-
form
-
MAX_LOOK_AHEAD
private static final int MAX_LOOK_AHEAD- See Also:
-
-
Constructor Details
-
ASN1Header
Gets info about the next item in the DER stream, consuming the identifier and length octets.- Parameters:
istream
- Input stream.- Throws:
InvalidBERException
- If there is an invalid BER encoding.IOException
- If other error occurred.
-
ASN1Header
This constructor is to be called when we are constructing an ASN1Value rather than decoding it.- Parameters:
tag
- Tag.form
- Form.contentLength
- Must be ≥0. Although indefinite length decoding is supported, indefinite length encoding is not.
-
-
Method Details
-
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.- Returns:
- Total length.
-
getTag
-
getContentLength
public long getContentLength()Returns -1 for indefinite length encoding.- Returns:
- Content length.
-
getForm
Returns the Form, PRIMITIVE or CONSTRUCTED.- Returns:
- The form.
-
lookAhead
Returns information about the next item in the stream, but does not consume any octets.- Parameters:
derStream
- DER stream.- Returns:
- ASN.1 header.
- Throws:
InvalidBERException
- If there is an invalid BER encoding.IOException
- If the input stream does not support look ahead.
-
encode
- Throws:
IOException
-
encode
public byte[] encode() -
unsignedBigIntToByteArray
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.- Parameters:
bi
- Input BigInteger.- Returns:
- Byte array.
-
validate
Verifies that this header has the given tag and form.- Parameters:
expectedTag
- Expected tag.expectedForm
- Expected form.- Throws:
InvalidBERException
- If the header's tag or form differ from those passed in.
-
validate
Verifies that this head has the given tag.- Parameters:
expectedTag
- Expected tag.- Throws:
InvalidBERException
- If the header's tag differs from that passed in.
-
isEOC
public boolean isEOC()- Returns:
true
if this is a BER end-of-contents marker.
-