cryptix.asn1.lang
Class Tag

java.lang.Object
  |
  +--cryptix.asn1.lang.Tag

public class Tag
extends java.lang.Object

A class to handle ASN.1 Tag elements.

Copyright ©1997, 1998, 1999 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.3 $

Author:
Raif S. Naffah, Eric Rescorla

Field Summary
static int APPLICATION
           
static int BIT_STRING
           
static int BOOLEAN
           
(package private)  int clazz
           
(package private)  boolean constructed
           
static int CONTEXT
           
(package private)  boolean explicit
           
static int IA5_STRING
           
static int INTEGER
           
static int NULL
           
static int OBJECT_IDENTIFIER
           
static int OCTET_STRING
           
static int PRINT_STRING
           
static int PRIVATE
           
static int SEQUENCE
           
static int SEQUENCE_OF
           
static int SET
           
static int SET_OF
           
static int T61_STRING
           
static int UNIVERSAL
           
static int UTC_TIME
           
(package private)  int value
           
 
Constructor Summary
(package private) Tag(int value, boolean explicit)
          Convenience constructor.
(package private) Tag(int clazz, int value, boolean explicit)
          Convenience constructor.
(package private) Tag(int clazz, int value, boolean explicit, boolean constructed)
          Constructs an ASN.1 Tag instance.
 
Method Summary
static Tag decode(java.io.InputStream in)
          Constructs a Tag instance from the designated input stream.
 int getClazz()
          Returns the tag's class.
static Tag getExpectedTag(int expectedValue, java.io.InputStream in)
          Convenience method similar to the method with same name and 3 arguments, except it assumes that the tag's class is UNIVERSAL.
static Tag getExpectedTag(int expectedClass, int expectedValue, java.io.InputStream in)
          Returns the tag element of an ASN.1 object if it is of the designated expected class and type, or null otherwise.
static Tag getExpectedTag(Tag tag, java.io.InputStream in)
          Convenience method similar to the method with same name and 3 arguments, except it uses the given tag's class and value.
static byte[] getTag(java.io.InputStream in)
          Get a tag off the wire as a byte[]
 int getValue()
          Returns the tag's class number.
 boolean isConstructed()
          Returns true if the tag is constructed false otherwise.
 boolean isExplicit()
          Returns true if the tag is explicit, false otherwise.
static Tag peek(java.io.InputStream in)
          Returns the Tag instance parsed from the given input stream, if one is there, without modifying the stram marker.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIVERSAL

public static final int UNIVERSAL
See Also:
Constant Field Values

APPLICATION

public static final int APPLICATION
See Also:
Constant Field Values

CONTEXT

public static final int CONTEXT
See Also:
Constant Field Values

PRIVATE

public static final int PRIVATE
See Also:
Constant Field Values

BOOLEAN

public static final int BOOLEAN
See Also:
Constant Field Values

INTEGER

public static final int INTEGER
See Also:
Constant Field Values

BIT_STRING

public static final int BIT_STRING
See Also:
Constant Field Values

OCTET_STRING

public static final int OCTET_STRING
See Also:
Constant Field Values

NULL

public static final int NULL
See Also:
Constant Field Values

OBJECT_IDENTIFIER

public static final int OBJECT_IDENTIFIER
See Also:
Constant Field Values

SEQUENCE

public static final int SEQUENCE
See Also:
Constant Field Values

SEQUENCE_OF

public static final int SEQUENCE_OF
See Also:
Constant Field Values

SET

public static final int SET
See Also:
Constant Field Values

SET_OF

public static final int SET_OF
See Also:
Constant Field Values

PRINT_STRING

public static final int PRINT_STRING
See Also:
Constant Field Values

T61_STRING

public static final int T61_STRING
See Also:
Constant Field Values

IA5_STRING

public static final int IA5_STRING
See Also:
Constant Field Values

UTC_TIME

public static final int UTC_TIME
See Also:
Constant Field Values

clazz

int clazz

value

int value

explicit

boolean explicit

constructed

boolean constructed
Constructor Detail

Tag

Tag(int clazz,
    int value,
    boolean explicit,
    boolean constructed)
Constructs an ASN.1 Tag instance.

Parameters:
clazz - The tag's class, default is UNIVERSAL.
value - The tag's value.
explicit - Whether this tag is explicit or implicit.
constructed - Whether this tag is constructed or not. Default is not constrcuted.

Tag

Tag(int clazz,
    int value,
    boolean explicit)
Convenience constructor. Constructs an ASN.1 Tag instance.

Parameters:
clazz - The tag's class, default is UNIVERSAL.
value - The tag's value.
explicit - Whether this tag is explicit or implicit.

Tag

Tag(int value,
    boolean explicit)
Convenience constructor. Constructs an ASN.1 Tag instance.

Parameters:
value - The tag's value.
explicit - Whether this tag is explicit or implicit.
Method Detail

getClazz

public int getClazz()
Returns the tag's class.


getValue

public int getValue()
Returns the tag's class number.


isExplicit

public boolean isExplicit()
Returns true if the tag is explicit, false otherwise.


isConstructed

public boolean isConstructed()
Returns true if the tag is constructed false otherwise.


getExpectedTag

public static Tag getExpectedTag(int expectedClass,
                                 int expectedValue,
                                 java.io.InputStream in)
                          throws java.io.IOException
Returns the tag element of an ASN.1 object if it is of the designated expected class and type, or null otherwise. If the stream does not contain the expected tag (of given type) this method ensures that the stream marker is not modified.

Parameters:
expectedClass - The tag's class expected to be found at the current marker location of the given input stream.
expectedValue - The tag's number expected to be found at the current marker location of the given input stream.
in - The input source stream.
Returns:
An instance of the Tag class containing the concrete Tag instance found in the input stream.
java.io.IOException

getExpectedTag

public static Tag getExpectedTag(int expectedValue,
                                 java.io.InputStream in)
                          throws java.io.IOException
Convenience method similar to the method with same name and 3 arguments, except it assumes that the tag's class is UNIVERSAL.

Parameters:
expectedValue - The tag's number expected to be found at the current marker location of the given input stream.
in - The input source stream.
Returns:
An instance of the Tag class containing the concrete Tag instance found in the input stream.
java.io.IOException

getExpectedTag

public static Tag getExpectedTag(Tag tag,
                                 java.io.InputStream in)
                          throws java.io.IOException
Convenience method similar to the method with same name and 3 arguments, except it uses the given tag's class and value.

Parameters:
tag - The tag's instance (class and value) expected to be found at the current marker location of the given input stream.
in - The input source stream.
Returns:
An instance of the Tag class containing the concrete Tag instance found in the input stream.
java.io.IOException

getTag

public static byte[] getTag(java.io.InputStream in)
                     throws java.io.IOException
Get a tag off the wire as a byte[]

Parameters:
in - The input stream
Returns:
a byte with the tag bytes
Throws:
java.io.IOException - --EKR

decode

public static Tag decode(java.io.InputStream in)
                  throws java.io.IOException
Constructs a Tag instance from the designated input stream.

Parameters:
in - The input stream.
Returns:
A Tag instance parsed from an input stream.
Throws:
java.io.IOException - If an error occurs while parsing the input stream.

peek

public static Tag peek(java.io.InputStream in)
                throws java.io.IOException
Returns the Tag instance parsed from the given input stream, if one is there, without modifying the stram marker.

Parameters:
in - The input stream.
Returns:
A Tag instance parsed from the designated input stream.
Throws:
java.io.IOException - If an error occurs while parsing the input stream.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object