Overview | Package | Class | Tree | Deprecated | Index | Help
| JSS 3.1.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.mozilla.jss.asn1
Class ASN1Header

    java.lang.Object
      |
      +--org.mozilla.jss.asn1.ASN1Header

public class ASN1Header
extends java.lang.Object

The portion of a BER encoding that precedes the contents octets. Consists of the tag, form, and length octets.

Field Summary
`private byte[]` | `cachedEncoding`
`static Form` | `CONSTRUCTED`
`private long` | `contentLength`
`private Form` | `form`
`private static int` | `MAX_LOOK_AHEAD`
`static Form` | `PRIMITIVE`
`private Tag` | `tag`

Constructor Summary
`ASN1Header(java.io.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
`byte[]` | `encode()`
`void` | `encode(java.io.OutputStream ostream)`
`long` | `getContentLength()` Returns -1 for indefinite length encoding.
`Form` | `getForm()` Returns the Form, PRIMITIVE or CONSTRUCTED.
`Tag` | `getTag()`
`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.
`boolean` | `isEOC()` Returns `true` if this is a BER end-of-contents marker.
`static ASN1Header` | `lookAhead(java.io.InputStream derStream)` Returns information about the next item in the stream, but does not consume any octets.
`static byte[]` | `unsignedBigIntToByteArray(java.math.BigInteger bi)` Converts an unsigned BigInteger to a minimal-length byte array.
`void` | `validate(Tag expectedTag)` Verifies that this head has the given tag.
`void` | `validate(Tag expectedTag, Form expectedForm)` Verifies that this header has the given tag and form.

Methods inherited from class java.lang.Object
`, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait`

Field Detail

### cachedEncoding

    private byte[] cachedEncoding

### tag

    private Tag tag

### contentLength

    private long contentLength

### PRIMITIVE

    public static final Form PRIMITIVE

### CONSTRUCTED

    public static final Form CONSTRUCTED

### form

    private Form form

### MAX_LOOK_AHEAD

    private static final int MAX_LOOK_AHEAD

Constructor Detail

### ASN1Header

    public ASN1Header(java.io.InputStream istream)
               throws InvalidBERException,
                      java.io.IOException

  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

### 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.

### getTag

    public Tag getTag()

### getContentLength

    public long getContentLength()

  Returns -1 for indefinite length encoding.

### getForm

    public Form getForm()

  Returns the Form, PRIMITIVE or CONSTRUCTED.

### lookAhead

    public static ASN1Header lookAhead(java.io.InputStream derStream)
                                throws java.io.IOException,
                                       InvalidBERException

  Returns information about the next item in the stream, but does not consume any octets.
  Throws:
    `java.io.IOException` - If the input stream does not support look ahead.

### encode

    public void encode(java.io.OutputStream ostream)
                throws java.io.IOException

### encode

    public byte[] encode()

### unsignedBigIntToByteArray

    public static byte[] unsignedBigIntToByteArray(java.math.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)
                  throws InvalidBERException

  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)
                  throws InvalidBERException

  Verifies that this head has the given 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.

Overview | Package | Class | Tree | Deprecated | Index | Help
| JSS 3.1.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD