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

## opencard.opt.util
Class TLV

    java.lang.Object
      opencard.opt.util.TLV

    public class TLV

extends java.lang.Object

This class represents a TLV (Tag Length Value) structure. There are methods for creating trees consisting of TLV objects from ASN.1 BER encoded byte sequences and for creating byte sequences from TLV object trees. All manipulations are done on the tree structure.

Version:
  $Id: TLV.java,v 1.2 2005/09/19 10:21:22 asc Exp $
Author:
  Thomas Schaeck
See Also:
  `Tag`

Constructor Summary
`TLV()` Create an empty TLV.
`TLV(byte[] binary)` Create a `TLV` object from an ASN.1 BER encoded byte array.
`TLV(byte[] binary, int[] offset)` Create a `TLV` object from an ASN.1 BER encoded byte array.
`TLV(Tag tag, byte[] value)` Create a TLV object from the given `Tag` object and data.
`TLV(Tag tag, int number)` Create a primitive TLV object from a given tag and positive integer.
`TLV(Tag tag, TLV tlv)` Create a constructed TLV object from the given `Tag` object and `TLV` object to be contained.

Method Summary
`TLV` | `add(TLV tlv)` Add the given `TLV` object to this `TLV` instance (only if constructed).
`TLV` | `findTag(Tag tag, TLV cursor)` Search for a given tag value and return the first TLV found.
`static void` | `fromBinary(byte[] binary, int[] offset, TLV tlv, TLV parent)` Read a `TLV` object from a binary representation.
`static int` | `lenBytes(int length)` Return the number of bytes required for coding the passed integer value as described in the ASN.1 Basic Encoding Rules.
`int` | `length()` Get the length of this TLV's value field in bytes.
`static byte[]` | `lengthToBinary(int length)` BER-code the length of this TLV.
`void` | `setValue(byte[] newValue)` Set the value field of this TLV from the byte array.
`Tag` | `tag()` Get the tag of this TLV.
`byte[]` | `toBinary()` BER-code this TLV.
`byte[]` | `toBinaryContent()` BER-code this TLV's value field.
`java.lang.String` | `toString()` Convert a TLV to a string.
`java.lang.String` | `toString(java.util.Hashtable ht, int level)` Convert a TLV to a string.
`byte[]` | `valueAsByteArray()` Get the value field of this TLV as a byte array.
`int` | `valueAsNumber()` Get the value of this TLV as a positive integer number.

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

Constructor Detail

### TLV

    public TLV()

  Create an empty TLV.

### TLV

    public TLV(byte[] binary)

  Create a `TLV` object from an ASN.1 BER encoded byte array.

  Parameters:
    `binary` - A byte array containing the binary representation of a TLV structure, encoded conforming to the ASN.1 Basic Encoding Rules defined in ISO 8825.

### TLV

    public TLV(byte[] binary,
               int[] offset)

  Create a `TLV` object from an ASN.1 BER encoded byte array.

  Parameters:
    `binary` - A byte array containing the binary representation of a TLV structure, encoded conforming to the ASN.1 Basic Encoding Rules defined in ISO 8825.

### TLV

    public TLV(Tag tag,
               byte[] value)

  Create a TLV object from the given `Tag` object and data.

  If the given `Tag` object has the constructed bit set, the result will be a TLV tree, otherwise it's just a primitive TLV that contains the data given in value field.

  Parameters:
    `tag` - An instance of class `Tag` representing the tag field of the TLV to be created.
    `value` - An array of bytes representing the Value field of the TLV to be created.

### TLV

    public TLV(Tag tag,
               int number)

  Create a primitive TLV object from a given tag and positive integer.

  Parameters:
    `tag` - An instance of class `Tag` representing the tag field of the TLV to be created.
    `number` - An integer representing the Value field of the TLV to be created.

### TLV

    public TLV(Tag tag,
               TLV tlv)

  Create a constructed TLV object from the given `Tag` object and `TLV` object to be contained.

  Parameters:
    `tag` - An instance of class `Tag` representing the tag field of the TLV to be created.
    `tlv` - An instance of class `TLV` representing the Value field of the TLV to be created.

Method Detail

### add

    public TLV add(TLV tlv)

  Add the given `TLV` object to this `TLV` instance (only if constructed).

  Parameters:
    `tlv` - The `TLV` object to be concatenated to this `TLV` instance.

### findTag

    public TLV findTag(Tag tag,
                       TLV cursor)

  Search for a given tag value and return the first TLV found.

  Parameters:
    `tag` - The `Tag` object representing the tag to be searched for, `null` for any tag.
    `cursor` - A reference to a `TLV` object where the search should start; if `null`, the search is started with the child of this `TLV` instance.
  Returns:
    The first `TLV` object found, which has the given tag value; `null` if no match is found.

### fromBinary

    public static void fromBinary(byte[] binary,
                                  int[] offset,
                                  TLV tlv,
                                  TLV parent)

  Read a `TLV` object from a binary representation.

  Parameters:
    `binary` - A byte array containing the binary representation of a TLV structure, encoded conforming to the ASN.1 Basic Encoding Rules defined in ISO 8825.
    `offset` - An integer value giving the offset, where the binary representation starts.
    `tlv` - The `TLV` object to be read from the binary representation.
    `parent` - The `TLV` object representing the parent of the object to be read.

### lenBytes

    public static int lenBytes(int length)

  Return the number of bytes required for coding the passed integer value as described in the ASN.1 Basic Encoding Rules.

  Parameters:
    `length` - An integer value.
  Returns:
    An integer value giving the number of bytes.

### length

    public int length()

  Get the length of this TLV's value field in bytes.

  Returns:
    An integer giving the length.

### lengthToBinary

    public static byte[] lengthToBinary(int length)

  BER-code the length of this TLV.

  Parameters:
    `length` - The length to be encoded
  Returns:
    The BER-coded length field

### setValue

    public void setValue(byte[] newValue)

  Set the value field of this TLV from the byte array.

  Parameters:
    `newValue` - The byte array for the value field.

### tag

    public Tag tag()

  Get the tag of this TLV.

  Returns:
    The `Tag` object of this `TLV` object.

### toBinary

    public byte[] toBinary()

  BER-code this TLV.

  Returns:
    A byte array containing the BER-coded representation of this `TLV` instance.

### toBinaryContent

    public byte[] toBinaryContent()

  BER-code this TLV's value field.

  Returns:
    A byte array containing the BER-coded binary representation of the value field of this `TLV` instance.

### toString

    public java.lang.String toString()

  Convert a TLV to a string.

  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    A `String` object representing this `TLV` object.

### toString

    public java.lang.String toString(java.util.Hashtable ht,
                                     int level)

  Convert a TLV to a string.

  Parameters:
    `ht` - A `Hashtable` object mapping `Tag` objects to objects.
    `level` - An integer value giving the indention leve to be used.
  Returns:
    A `String` object representing this `TLV` object.

### valueAsByteArray

    public byte[] valueAsByteArray()

  Get the value field of this TLV as a byte array.

  Returns:
    A byte array representing the value field of this `TLV` instance; `null` if the TLV is constructed.

### valueAsNumber

    public int valueAsNumber()

  Get the value of this TLV as a positive integer number.

  Returns:
    An integer representing the value (unsigned int) of this `TLV` instance's value field.

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