Package opencard.opt.util
Class Tag
- java.lang.Object
-
- opencard.opt.util.Tag
-
public class Tag extends java.lang.Object
This class represents Tags as defined in the Basic Encoding Rules for ASN.1 defined in ISO 8825. A tag consists of two class bits (0 - 4), a flag indicating wether the TLV is constructed or primitive.The encoding is like this (C = class bit, c = composed flag, X = data bit):
Range from 0x0 - 0x1E: C C c X X X X X
Range from 0x1F - 0x80: C C c 1 1 1 1 1 0 X X X X X X X
Range from 0x81 - 0x4000: C C c 1 X X X X 1 X X X X X X X 0 X X X X X X X
Range from 0x4001 - 0x200000: C C c 1 X X X X 1 X X X X X X X 1 X X X X X X X 0 X X X X X X X
Range from 0x200001 - 0x10000000: C C c 1 X X X X 1 X X X X X X X 1 X X X X X X X 0 X X X X X X X 0 X X X X X X X- Author:
- Thomas Schaeck
- See Also:
TLV
-
-
Constructor Summary
Constructors Constructor Description Tag()
Create a null tag.Tag(byte[] binary)
Tag(byte[] binary, int[] offset)
Create a tag from binary representation.Tag(int tag, byte tagClass, boolean constructed)
Creates a tag from a given tag value, class and constructed flag.Tag(Tag t)
Clone a tag.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
code()
Get the code of the tag.boolean
equals(java.lang.Object o)
Check for equality.void
fromBinary(byte[] binary, int[] offset)
Initialize the Tag object from a BER-coded binary representation.byte[]
getBytes()
Gets a byte array representing the tag.int
hashCode()
Compute a hash code for this tag.boolean
isConstructed()
Check whether this Tag is constructed.void
set(int tag, byte tagclass, boolean constructed)
Set the tag number, class and constructed flag of this Tag to the given values.void
setConstructed(boolean constructed)
Set the constructed flag of this Tag to the given value.int
size()
Return the number of bytes which are required to BER-code the tag value.void
toBinary(byte[] binary, int[] offset)
Convert the tag to binary representation.java.lang.String
toString()
Get a string representation for this tag.
-
-
-
Constructor Detail
-
Tag
public Tag()
Create a null tag.
-
Tag
public Tag(Tag t)
Clone a tag.- Parameters:
t
- The Tag object to be cloned.
-
Tag
public Tag(int tag, byte tagClass, boolean constructed)
Creates a tag from a given tag value, class and constructed flag.- Parameters:
tag
- An integer representing the value of the tag.tagClass
- A byte value representing the class of the tag.constructed
- A boolean value true signals that the tag is constructed, false signals that the tag is primitive.
-
Tag
public Tag(byte[] binary, int[] offset)
Create a tag from binary representation.- Parameters:
binary
- The byte array from which the tag shall be generated.offset
- An integer value giving the offset into the the byte array from where to start.
-
Tag
public Tag(byte[] binary)
-
-
Method Detail
-
size
public int size()
Return the number of bytes which are required to BER-code the tag value.- Returns:
- An integer giving the number of bytes.
-
fromBinary
public void fromBinary(byte[] binary, int[] offset)
Initialize the Tag object from a BER-coded binary representation.- Parameters:
binary
- A byte array containing the BER-coded tag.offset
- An integer giving an offset into the byte array from where to start.
-
getBytes
public byte[] getBytes()
Gets a byte array representing the tag.- Returns:
- the tag as a byte array
-
toBinary
public void toBinary(byte[] binary, int[] offset)
Convert the tag to binary representation.- Parameters:
binary
- A byte array to which the BER-coded binary representation of the tag shall be written.offset
- An integer value giving an offset into the byte array from where to start.
-
set
public void set(int tag, byte tagclass, boolean constructed)
Set the tag number, class and constructed flag of this Tag to the given values.- Parameters:
tag
- An integer value giving the tag value.tagclass
- A byte value giving the class.constructed
- A boolean representing the constructed flag.
-
setConstructed
public void setConstructed(boolean constructed)
Set the constructed flag of this Tag to the given value.- Parameters:
constructed
- A boolean representing the constructed flag.
-
code
public int code()
Get the code of the tag.- Returns:
- An integer value representing the tag's code.
-
isConstructed
public boolean isConstructed()
Check whether this Tag is constructed.- Returns:
- true if it is constructed, false otherwise.
-
hashCode
public int hashCode()
Compute a hash code for this tag.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- An integer value representing the hash code.
-
equals
public boolean equals(java.lang.Object o)
Check for equality.- Overrides:
equals
in classjava.lang.Object
- Returns:
- true, if this Tag instance equals the given tag, false otherwise.
-
toString
public java.lang.String toString()
Get a string representation for this tag.- Overrides:
toString
in classjava.lang.Object
- Returns:
- The string representation.
-
-