JMRTD 0.4.6

net.sourceforge.scuba.tlv
Class BERTLVObject

java.lang.Object
  extended by net.sourceforge.scuba.tlv.BERTLVObject

public class BERTLVObject
extends Object

Generic data structure for storing Tag Length Value (TLV) objects encoded according to the Basic Encoding Rules (BER). Written by Martijn Oostdijk (MO) and Cees-Bart Breunesse (CB) of the Security of Systems group (SoS) of the Institute of Computing and Information Sciences (ICIS) at Radboud University (RU). Based on ISO 7816-4 Annex D (which apparently is based on ISO 8825 and/or X.208, X.209, X.680, X.690). See ASN.1.

Version:
$Revision: 227 $
Author:
Martijn Oostdijk (martijno@cs.ru.nl), Cees-Bart Breunesse (ceesb@cs.ru.nl)

Field Summary
static int APPLICATION_CLASS
          Application tag class.
static int BIT_STRING_TYPE_TAG
          Universal tag type.
static int BMP_STRING_TYPE_TAG
          Universal tag type.
static int BOOLEAN_TYPE_TAG
          Universal tag type.
static int CONTEXT_SPECIFIC_CLASS
          Context specific tag class.
static int EMBEDDED_PDV_TYPE_TAG
          Universal tag type.
static int ENUMERATED_TYPE_TAG
          Universal tag type.
static int EXTERNAL_TYPE_TAG
          Universal tag type.
static int GENERAL_STRING_TYPE_TAG
          Universal tag type.
static int GENERALIZED_TIME_TYPE_TAG
          Universal tag type.
static int GRAPHIC_STRING_TYPE_TAG
          Universal tag type.
static int IA5_STRING_TYPE_TAG
          Universal tag type.
static int INTEGER_TYPE_TAG
          Universal tag type.
static int NULL_TYPE_TAG
          Universal tag type.
static int NUMERIC_STRING_TYPE_TAG
          Universal tag type.
static int OBJECT_DESCRIPTOR_TYPE_TAG
          Universal tag type.
static int OBJECT_IDENTIFIER_TYPE_TAG
          Universal tag type.
static int OCTET_STRING_TYPE_TAG
          Universal tag type.
static int PRINTABLE_STRING_TYPE_TAG
          Universal tag type.
static int PRIVATE_CLASS
          Private tag class.
static int REAL_TYPE_TAG
          Universal tag type.
static int SEQUENCE_TYPE_TAG
          Universal tag type.
static int SET_TYPE_TAG
          Universal tag type.
static int T61_STRING_TYPE_TAG
          Universal tag type.
static int UNIVERSAL_CLASS
          Universal tag class.
static int UNIVERSAL_STRING_TYPE_TAG
          Universal tag type.
static int UTC_TIME_TYPE_TAG
          Universal tag type.
static int UTF8_STRING_TYPE_TAG
          Universal tag type.
static int VISIBLE_STRING_TYPE_TAG
          Universal tag type.
 
Constructor Summary
BERTLVObject(int tag, Object value)
          Constructs a new TLV object with tag tag containing data value.
BERTLVObject(int tag, Object value, boolean interpretValue)
          Constructs a new TLV object with tag tag containing data value.
 
Method Summary
 void addSubObject(BERTLVObject object)
          Adds object as subobject of this TLV object when this is not a primitive object.
 BERTLVObject getChildByIndex(int index)
          Returns the indexed child (starting from 0) or null otherwise.
 byte[] getEncoded()
          This object, including tag and length, as byte array.
static BERTLVObject getInstance(InputStream in)
           
 int getLength()
           
static byte[] getLengthAsBytes(int length)
          The length bytes of this object.
static int getLengthLength(int length)
           
 BERTLVObject getSubObject(int tag)
          Gets the first sub-object (including this object) whose tag equals tag.
 BERTLVObject getSubObject(int[] tagPath, int offset, int length)
          Gets the first sub-object (including this object) following the tags in tagPath.
 int getTag()
           
static byte[] getTagAsBytes(int tag)
          The tag bytes of this object.
static int getTagLength(int tag)
           
 Object getValue()
          The encoded value.
 void reconstructLength()
          Reconstructs the length of the encoded value.
 String toString()
          A textual (nested tree-like) representation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIVERSAL_CLASS

public static final int UNIVERSAL_CLASS
Universal tag class.

See Also:
Constant Field Values

APPLICATION_CLASS

public static final int APPLICATION_CLASS
Application tag class.

See Also:
Constant Field Values

CONTEXT_SPECIFIC_CLASS

public static final int CONTEXT_SPECIFIC_CLASS
Context specific tag class.

See Also:
Constant Field Values

PRIVATE_CLASS

public static final int PRIVATE_CLASS
Private tag class.

See Also:
Constant Field Values

BOOLEAN_TYPE_TAG

public static final int BOOLEAN_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

INTEGER_TYPE_TAG

public static final int INTEGER_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

BIT_STRING_TYPE_TAG

public static final int BIT_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

OCTET_STRING_TYPE_TAG

public static final int OCTET_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

NULL_TYPE_TAG

public static final int NULL_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

OBJECT_IDENTIFIER_TYPE_TAG

public static final int OBJECT_IDENTIFIER_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

OBJECT_DESCRIPTOR_TYPE_TAG

public static final int OBJECT_DESCRIPTOR_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

EXTERNAL_TYPE_TAG

public static final int EXTERNAL_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

REAL_TYPE_TAG

public static final int REAL_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

ENUMERATED_TYPE_TAG

public static final int ENUMERATED_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

EMBEDDED_PDV_TYPE_TAG

public static final int EMBEDDED_PDV_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

UTF8_STRING_TYPE_TAG

public static final int UTF8_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

SEQUENCE_TYPE_TAG

public static final int SEQUENCE_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

SET_TYPE_TAG

public static final int SET_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

NUMERIC_STRING_TYPE_TAG

public static final int NUMERIC_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

PRINTABLE_STRING_TYPE_TAG

public static final int PRINTABLE_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

T61_STRING_TYPE_TAG

public static final int T61_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

IA5_STRING_TYPE_TAG

public static final int IA5_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

UTC_TIME_TYPE_TAG

public static final int UTC_TIME_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

GENERALIZED_TIME_TYPE_TAG

public static final int GENERALIZED_TIME_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

GRAPHIC_STRING_TYPE_TAG

public static final int GRAPHIC_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

VISIBLE_STRING_TYPE_TAG

public static final int VISIBLE_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

GENERAL_STRING_TYPE_TAG

public static final int GENERAL_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

UNIVERSAL_STRING_TYPE_TAG

public static final int UNIVERSAL_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values

BMP_STRING_TYPE_TAG

public static final int BMP_STRING_TYPE_TAG
Universal tag type.

See Also:
Constant Field Values
Constructor Detail

BERTLVObject

public BERTLVObject(int tag,
                    Object value)
Constructs a new TLV object with tag tag containing data value.

Parameters:
tag - tag of TLV object
value - data of TLV object
Throws:
IOException - if something goes wrong.

BERTLVObject

public BERTLVObject(int tag,
                    Object value,
                    boolean interpretValue)
Constructs a new TLV object with tag tag containing data value.

Parameters:
tag - tag of TLV object
value - data of TLV object
interpretValue - whether the embedded byte[] values should be interpreted/parsed. Some ASN1 streams don't like that :(
Throws:
IOException - if something goes wrong.
Method Detail

getInstance

public static BERTLVObject getInstance(InputStream in)
                                throws IOException
Throws:
IOException

addSubObject

public void addSubObject(BERTLVObject object)
Adds object as subobject of this TLV object when this is not a primitive object.

Parameters:
object - to add as a subobject.

getTag

public int getTag()

reconstructLength

public void reconstructLength()
Reconstructs the length of the encoded value.


getLength

public int getLength()

getValue

public Object getValue()
The encoded value.

Returns:
the encoded value

getEncoded

public byte[] getEncoded()
This object, including tag and length, as byte array.

Returns:
this object, including tag and length, as byte array

getSubObject

public BERTLVObject getSubObject(int tag)
Gets the first sub-object (including this object) whose tag equals tag.

Parameters:
tag - the tag to search for
Returns:
the first

getSubObject

public BERTLVObject getSubObject(int[] tagPath,
                                 int offset,
                                 int length)
Gets the first sub-object (including this object) following the tags in tagPath.

Parameters:
tagPath - the path to follow
offset - in the tagPath
length - of the tagPath
Returns:
the first

getChildByIndex

public BERTLVObject getChildByIndex(int index)
Returns the indexed child (starting from 0) or null otherwise.

Parameters:
index -
Returns:
the object pointed to by index.

toString

public String toString()
A textual (nested tree-like) representation of this object. Always ends in newline character, no need to add it yourself.

Overrides:
toString in class Object
Returns:
a textual representation of this object.
See Also:
Object.toString()

getTagLength

public static int getTagLength(int tag)

getLengthLength

public static int getLengthLength(int length)

getTagAsBytes

public static byte[] getTagAsBytes(int tag)
The tag bytes of this object.

Returns:
the tag bytes of this object.

getLengthAsBytes

public static byte[] getLengthAsBytes(int length)
The length bytes of this object.

Returns:
length of encoded value as bytes

JMRTD 0.4.6