cryptix.asn1.lang

Class 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 $

Authors:
Raif S. Naffah
Eric Rescorla

Field Summary

static int
APPLICATION
static int
BIT_STRING
static int
BOOLEAN
static int
CONTEXT
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
clazz
(package private) boolean
constructed
(package private) boolean
explicit
(package private) int
value

Constructor Summary

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

Method Summary

static Tag
decode(InputStream in)
Constructs a Tag instance from the designated input stream.
int
getClazz()
Returns the tag's class.
static Tag
getExpectedTag(Tag tag, 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 Tag
getExpectedTag(int expectedValue, 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, 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 byte[]
getTag(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(InputStream in)
Returns the Tag instance parsed from the given input stream, if one is there, without modifying the stram marker.
String
toString()

Field Details

APPLICATION

public static final int APPLICATION

Field Value:
64


BIT_STRING

public static final int BIT_STRING

Field Value:
3


BOOLEAN

public static final int BOOLEAN

Field Value:
1


CONTEXT

public static final int CONTEXT

Field Value:
128


IA5_STRING

public static final int IA5_STRING

Field Value:
22


INTEGER

public static final int INTEGER

Field Value:
2


NULL

public static final int NULL

Field Value:
5


OBJECT_IDENTIFIER

public static final int OBJECT_IDENTIFIER

Field Value:
6


OCTET_STRING

public static final int OCTET_STRING

Field Value:
4


PRINT_STRING

public static final int PRINT_STRING

Field Value:
19


PRIVATE

public static final int PRIVATE

Field Value:
192


SEQUENCE

public static final int SEQUENCE

Field Value:
16


SEQUENCE_OF

public static final int SEQUENCE_OF

Field Value:
48


SET

public static final int SET

Field Value:
17


SET_OF

public static final int SET_OF

Field Value:
49


T61_STRING

public static final int T61_STRING

Field Value:
20


UNIVERSAL

public static final int UNIVERSAL

Field Value:
0


UTC_TIME

public static final int UTC_TIME

Field Value:
23


clazz

(package private)  int clazz


constructed

(package private)  boolean constructed


explicit

(package private)  boolean explicit


value

(package private)  int value

Constructor Details

Tag

(package private)  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.


Tag

(package private)  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

(package private)  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.

Method Details

decode

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

Parameters:
in - The input stream.

Returns:
A Tag instance parsed from an input stream.


getClazz

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


getExpectedTag

public static Tag getExpectedTag(Tag tag,
                                 InputStream in)
            throws 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.


getExpectedTag

public static Tag getExpectedTag(int expectedValue,
                                 InputStream in)
            throws 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.


getExpectedTag

public static Tag getExpectedTag(int expectedClass,
                                 int expectedValue,
                                 InputStream in)
            throws 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.


getTag

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

Parameters:
in - The input stream

Returns:
a byte with the tag bytes


getValue

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


isConstructed

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


isExplicit

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


peek

public static Tag peek(InputStream in)
            throws 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.


toString

public String toString()