com.objsys.asn1j.runtime
Class Asn1Type

java.lang.Object
  extended by com.objsys.asn1j.runtime.Asn1Type
All Implemented Interfaces:
Asn1TypeIF, java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
Asn1ArrayType, Asn1BigInteger, Asn1BitString, Asn1Boolean, Asn1CHARACTER_STRING, Asn1CHARACTER_STRING_identification_context_negotiation, Asn1CHARACTER_STRING_identification_syntaxes, Asn1CharString, Asn1Choice, Asn1EmbeddedPDV, Asn1EmbeddedPDV_identification_context_negotiation, Asn1EmbeddedPDV_identification_syntaxes, Asn1Enumerated, Asn1External, Asn1Integer, Asn1Null, Asn1ObjectIdentifier, Asn1OctetString, Asn1OpenExt, Asn1Real, Asn1UniversalString, Asn1X694OrderElement, Asn1XerCHARACTER_STRING, Asn1XerCHARACTER_STRING_identification_context_negotiation, Asn1XerCHARACTER_STRING_identification_syntaxes, Asn1XerEmbeddedPDV, Asn1XerEmbeddedPDV_identification_context_negotiation, Asn1XerEmbeddedPDV_identification_syntaxes, Asn1XerExternal, Asn1XmlCHARACTER_STRING, Asn1XmlCHARACTER_STRING_identification_context_negotiation, Asn1XmlCHARACTER_STRING_identification_syntaxes, Asn1XmlEmbeddedPDV, Asn1XmlEmbeddedPDV_identification_context_negotiation, Asn1XmlEmbeddedPDV_identification_syntaxes, Asn1XmlExternal

public abstract class Asn1Type
extends java.lang.Object
implements Asn1TypeIF, java.io.Serializable, java.lang.Cloneable

This is the base class for all ASN.1 built-in types.

See Also:
Serialized Form

Field Summary
static short BIT_STRING
          BIT_STRING type code = 3
static short BMPString
          BMPString type code = 30
static short BOOLEAN
          BOOLEAN type code = 1
static short DATE
          DATE type code = 31
static short DATE_TIME
          DATE-TIME type code = 33
static short DURATION
          DURATION type code = 34
static short ENUMERATED
          ENUMERATED type code = 10
static short EOC
          EOC type code = 0
static short EXTERNAL
          EXTERNAL type code = 8
static short GeneralString
          GeneralString type code = 27
static short GeneralTime
          GeneralTime type code = 24
static short GraphicString
          GraphicString type code = 25
static short IA5String
          IA5String type code = 22
static short INTEGER
          INTEGER type code = 2
protected  java.lang.String mAsn1TypeName
          This type's ASN.1 name.
static short NULL
          NULL type code = 5
static short NumericString
          NumericString type code = 18
static short OBJECT_IDENTIFIER
          OBJECT_IDENTIFIER type code = 6
static short ObjectDescriptor
          ObjectDescriptor type code = 7
static short OCTET_STRING
          OCTET_STRING type code = 4
static short OID_IRI
          OID-IRI type code = 35
static short OpenType
          OpenType type code = 99
static short PrintableString
          PrintableString type code = 19
static short REAL
          REAL type code = 9
static short RELATIVE_OID_IRI
          RELATIVE-OID-IRI type code = 35
static short RelativeOID
          RELATIVE_OID type code = 13
static short SEQUENCE
          SEQUENCE type code = 16
static short SET
          SET type code = 17
static short T61String
          T61String type code = TeletexString
static short TeletexString
          TeletexString type code = 20
static short TIME
          TIME type code = 14
static short TIME_OF_DAY
          TIME-OF-DAY type code = 32
static short UniversalString
          type code= 28
static short UTCTime
          UTCTime type code = 23
static short UTF8String
          UTF8String type code = 12
static short VideotexString
          VideotexString type code = 21
static short VisibleString
          VisibleString type code = 26
 
Constructor Summary
Asn1Type()
           
 
Method Summary
 java.lang.Object clone()
          Creates and returns a copy of this object.
 void decode(Asn1BerDecodeBuffer buffer)
          This method is used to decode a message that is encoded in BER or DER format.
 void decode(Asn1BerDecodeBuffer buffer, boolean explicit, int implicitLength)
          This method is used to decode a message that is encoded in BER or DER format.
static Asn1Type decode(Asn1BerDecodeBuffer buffer, java.lang.Object decoder, boolean explicit, int implicitLength)
          Decode a value from the given buffer, using the given decoder.
 void decode(Asn1PerDecodeBuffer buffer)
          This method is the base implementation of the standard Packed Encoding Rules (PER) decode method.
static Asn1Type decode(Asn1PerDecodeBuffer buffer, java.lang.Object decoder)
          Decode a value from the given buffer, using the given decoder.
 void decode(java.lang.Object reader, java.io.InputStream byteStream)
          This method declaration is the signature of the standard XML Encoding Rules (XER) decode method.
 void decode(java.lang.Object reader, java.lang.String xmlURI)
          This method declaration is the signature of the standard XML Encoding Rules (XER) decode method.
 void decodeXML(java.lang.String buffer, java.lang.String attrs)
          This method decodes the XML content of a simple type.
 int encode(Asn1BerEncodeBuffer buffer)
          This method is used to encode a message in BER or DER format.
 int encode(Asn1BerEncodeBuffer buffer, boolean explicit)
          This method is used to encode this data type in BER or DER format.
 void encode(Asn1BerOutputStream out, boolean explicit)
          This method writes to the stream an encoded ASN.1 type value including the UNIVERSAL tag value and length if explicit tagging is specified.
 void encode(Asn1PerEncodeBuffer buffer)
          This method is the base implementation of the standard Packed Encoding Rules (PER) encode method.
 void encode(Asn1PerOutputStream out)
          This method is the base implementation of the standard Packed Encoding Rules (PER) encode method using output stream.
 void encode(Asn1XerEncoder buffer)
          This method is the base implementation of the standard XML Encoding Rules (XER) encode method.
 void encode(Asn1XerEncoder buffer, java.lang.String elemName)
          This method is the base implementation of the standard XML Encoding Rules (XER) encode method.
 boolean equals(Asn1Type obj)
          Return true if the two objects are equal.
 java.lang.String getAsn1TypeName()
          Returns the ASN.1 specification type name for this type.
 int getLength()
          This method will return the length of types that can be bound by a size constraint (BIT STRING, OCTET STRING, character string, and SEQUENCE OF/SET OF).
static java.lang.String getTypeName(short typeCode)
          The static getTypeName method will convert a type code into a type name as defined in the X.680 standard..
 int hashCode()
          Returns the hash code of the object.
 void indent(java.io.PrintStream out, int level)
          This method will indent three spaces in the given print stream.
 boolean isOpenType()
          Returns open type mode for XML encoding/decoding.
protected static int matchTag(Asn1BerDecodeBuffer buffer, Asn1Tag tag)
          This method will compare the next parsed tag with the given tag value.
protected static int matchTag(Asn1BerDecodeBuffer buffer, short tagClass, short tagForm, int tagIDCode)
          This method will compare the next parsed tag with the given tag value.
 void pdiag(java.lang.String s)
          This is a diagnostics print method.
 void print(java.io.PrintStream out, java.lang.String varName, int level)
          This method will format and output a primitive value to the given print stream.
static void setKey(byte[] rtkey)
           
 void setOpenType()
          Sets open type mode for XML encoding/decoding.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EOC

public static final short EOC
EOC type code = 0

See Also:
Constant Field Values

BOOLEAN

public static final short BOOLEAN
BOOLEAN type code = 1

See Also:
Constant Field Values

INTEGER

public static final short INTEGER
INTEGER type code = 2

See Also:
Constant Field Values

BIT_STRING

public static final short BIT_STRING
BIT_STRING type code = 3

See Also:
Constant Field Values

OCTET_STRING

public static final short OCTET_STRING
OCTET_STRING type code = 4

See Also:
Constant Field Values

NULL

public static final short NULL
NULL type code = 5

See Also:
Constant Field Values

OBJECT_IDENTIFIER

public static final short OBJECT_IDENTIFIER
OBJECT_IDENTIFIER type code = 6

See Also:
Constant Field Values

ObjectDescriptor

public static final short ObjectDescriptor
ObjectDescriptor type code = 7

See Also:
Constant Field Values

EXTERNAL

public static final short EXTERNAL
EXTERNAL type code = 8

See Also:
Constant Field Values

REAL

public static final short REAL
REAL type code = 9

See Also:
Constant Field Values

ENUMERATED

public static final short ENUMERATED
ENUMERATED type code = 10

See Also:
Constant Field Values

UTF8String

public static final short UTF8String
UTF8String type code = 12

See Also:
Constant Field Values

RelativeOID

public static final short RelativeOID
RELATIVE_OID type code = 13

See Also:
Constant Field Values

TIME

public static final short TIME
TIME type code = 14

See Also:
Constant Field Values

SEQUENCE

public static final short SEQUENCE
SEQUENCE type code = 16

See Also:
Constant Field Values

SET

public static final short SET
SET type code = 17

See Also:
Constant Field Values

NumericString

public static final short NumericString
NumericString type code = 18

See Also:
Constant Field Values

PrintableString

public static final short PrintableString
PrintableString type code = 19

See Also:
Constant Field Values

TeletexString

public static final short TeletexString
TeletexString type code = 20

See Also:
Constant Field Values

T61String

public static final short T61String
T61String type code = TeletexString

See Also:
Constant Field Values

VideotexString

public static final short VideotexString
VideotexString type code = 21

See Also:
Constant Field Values

IA5String

public static final short IA5String
IA5String type code = 22

See Also:
Constant Field Values

UTCTime

public static final short UTCTime
UTCTime type code = 23

See Also:
Constant Field Values

GeneralTime

public static final short GeneralTime
GeneralTime type code = 24

See Also:
Constant Field Values

GraphicString

public static final short GraphicString
GraphicString type code = 25

See Also:
Constant Field Values

VisibleString

public static final short VisibleString
VisibleString type code = 26

See Also:
Constant Field Values

GeneralString

public static final short GeneralString
GeneralString type code = 27

See Also:
Constant Field Values

UniversalString

public static final short UniversalString
type code= 28

See Also:
Constant Field Values

BMPString

public static final short BMPString
BMPString type code = 30

See Also:
Constant Field Values

DATE

public static final short DATE
DATE type code = 31

See Also:
Constant Field Values

TIME_OF_DAY

public static final short TIME_OF_DAY
TIME-OF-DAY type code = 32

See Also:
Constant Field Values

DATE_TIME

public static final short DATE_TIME
DATE-TIME type code = 33

See Also:
Constant Field Values

DURATION

public static final short DURATION
DURATION type code = 34

See Also:
Constant Field Values

OID_IRI

public static final short OID_IRI
OID-IRI type code = 35

See Also:
Constant Field Values

RELATIVE_OID_IRI

public static final short RELATIVE_OID_IRI
RELATIVE-OID-IRI type code = 35

See Also:
Constant Field Values

OpenType

public static final short OpenType
OpenType type code = 99

See Also:
Constant Field Values

mAsn1TypeName

protected transient java.lang.String mAsn1TypeName
This type's ASN.1 name. The name is taken from the input specification.

Constructor Detail

Asn1Type

public Asn1Type()
Method Detail

decode

public void decode(Asn1BerDecodeBuffer buffer,
                   boolean explicit,
                   int implicitLength)
            throws Asn1Exception,
                   java.io.IOException
This method is used to decode a message that is encoded in BER or DER format.

Specified by:
decode in interface Asn1TypeIF
Parameters:
buffer - Decode message buffer object
explicit - Flag indicating explicit tag should be parsed from the encoded type.
implicitLength - Length of the contents field (only required if explicit is false).
Throws:
Asn1Exception
java.io.IOException

decode

public void decode(Asn1BerDecodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
This method is used to decode a message that is encoded in BER or DER format. This version of the method sets tagging to explicit (Asn1Tag.EXPL) and implicit length to zero.

Parameters:
buffer - Decode message buffer object
Throws:
Asn1Exception
java.io.IOException

decode

public static Asn1Type decode(Asn1BerDecodeBuffer buffer,
                              java.lang.Object decoder,
                              boolean explicit,
                              int implicitLength)
                       throws Asn1Exception,
                              java.io.IOException
Decode a value from the given buffer, using the given decoder.

Parameters:
buffer -
decoder - One of the following:
  • An Asn1BerDecoder. In this case, decoding will be performed using the Asn1Decoder interface.
  • The Class for a subclass of Asn1Type. In this case, the class will be instantiated and used to perform decoding. The instantiated object is returned.
explicit - if true, the value to be decoded is preceded by a tag and length, which must first be decoded. Otherwise, implicitLength provides the length of the value to be decoded.
implicitLength - The length of the value to be decoded if explicit was given as false.
Throws:
Asn1Exception
java.io.IOException

encode

public int encode(Asn1BerEncodeBuffer buffer,
                  boolean explicit)
           throws Asn1Exception
This method is used to encode this data type in BER or DER format.

Specified by:
encode in interface Asn1TypeIF
Parameters:
buffer - Encode message buffer object
explicit - Flag indicating explicit tag should be added to the encoded type.
Returns:
Decoded integer value
Throws:
Asn1Exception

encode

public int encode(Asn1BerEncodeBuffer buffer)
           throws Asn1Exception
This method is used to encode a message in BER or DER format. This version of the method sets tagging to explicit (Asn1Tag.EXPL).

Parameters:
buffer - Decode message buffer object
Returns:
Decoded integer value
Throws:
Asn1Exception

decode

public static Asn1Type decode(Asn1PerDecodeBuffer buffer,
                              java.lang.Object decoder)
                       throws Asn1Exception,
                              java.io.IOException
Decode a value from the given buffer, using the given decoder.

Parameters:
buffer -
decoder - One of the following:
  • An Asn1PerDecoder. In this case, decoding will be performed using the Asn1Decoder interface.
  • The Class for a subclass of Asn1Type. In this case, the class will be instantiated and used to perform decoding. The instantiated object is returned.
Throws:
Asn1Exception
java.io.IOException

decode

public void decode(Asn1PerDecodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
This method is the base implementation of the standard Packed Encoding Rules (PER) decode method. It throws an exception because it should never be invoked by compiler generated code.

Specified by:
decode in interface Asn1TypeIF
Parameters:
buffer - PER Encode message buffer object
Throws:
Asn1Exception
java.io.IOException

encode

public void encode(Asn1PerEncodeBuffer buffer)
            throws Asn1Exception,
                   java.io.IOException
This method is the base implementation of the standard Packed Encoding Rules (PER) encode method. It throws an exception because it should never be invoked by compiler generated code.

Specified by:
encode in interface Asn1TypeIF
Parameters:
buffer - PER Encode message buffer object
Throws:
Asn1Exception
java.io.IOException

encode

public void encode(Asn1XerEncoder buffer)
            throws Asn1Exception,
                   java.io.IOException
This method is the base implementation of the standard XML Encoding Rules (XER) encode method. This method invokes the generated method with element name set to null. This will cause the ASN.1 type name to be used as the top-level element name.

Specified by:
encode in interface Asn1TypeIF
Parameters:
buffer - XER Encode message buffer object
Throws:
java.io.IOException - Any exception thrown by the underlying stream.
Asn1Exception - Thrown, if operation is failed.

encode

public void encode(Asn1XerEncoder buffer,
                   java.lang.String elemName)
            throws Asn1Exception,
                   java.io.IOException
This method is the base implementation of the standard XML Encoding Rules (XER) encode method. It throws an exception because it should never be invoked by compiler generated code.

Specified by:
encode in interface Asn1TypeIF
Parameters:
buffer - XER Encode message buffer object
elemName - XML element name of item
Throws:
java.io.IOException - Any exception thrown by the underlying stream.
Asn1Exception - Thrown, if operation is failed.

decode

public void decode(java.lang.Object reader,
                   java.lang.String xmlURI)
            throws Asn1Exception,
                   java.io.IOException
This method declaration is the signature of the standard XML Encoding Rules (XER) decode method.

Specified by:
decode in interface Asn1TypeIF
Parameters:
reader - XML reader object
xmlURI - URI of a source
Throws:
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
Asn1Exception - Thrown, if operation is failed.

decode

public void decode(java.lang.Object reader,
                   java.io.InputStream byteStream)
            throws Asn1Exception,
                   java.io.IOException
This method declaration is the signature of the standard XML Encoding Rules (XER) decode method.

Specified by:
decode in interface Asn1TypeIF
Parameters:
reader - XML reader object
byteStream - Input byte stream object
Throws:
java.io.IOException - An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
Asn1Exception - Thrown, if operation is failed.

decodeXML

public void decodeXML(java.lang.String buffer,
                      java.lang.String attrs)
               throws Asn1Exception
This method decodes the XML content of a simple type.

Specified by:
decodeXML in interface Asn1TypeIF
Parameters:
buffer - String containing data to be decoded
attrs - Attributes string from element tag
Throws:
Asn1Exception

setOpenType

public void setOpenType()
Sets open type mode for XML encoding/decoding.

Specified by:
setOpenType in interface Asn1TypeIF

isOpenType

public boolean isOpenType()
Returns open type mode for XML encoding/decoding.

Specified by:
isOpenType in interface Asn1TypeIF
Returns:
true if open type mode is on.

getLength

public int getLength()
              throws Asn1InvalidLengthException
This method will return the length of types that can be bound by a size constraint (BIT STRING, OCTET STRING, character string, and SEQUENCE OF/SET OF). An attempt to invoke it on any other type will cause an exception to be thrown.

Returns:
Length of item in units (for example, bits for BIT STRING, octets for OCTET STRING, etc.)
Throws:
Asn1InvalidLengthException

setKey

public static void setKey(byte[] rtkey)

matchTag

protected static int matchTag(Asn1BerDecodeBuffer buffer,
                              short tagClass,
                              short tagForm,
                              int tagIDCode)
                       throws Asn1Exception,
                              java.io.IOException
This method will compare the next parsed tag with the given tag value. If they do not match, an exception will be thrown.

Parameters:
buffer - Decode message buffer object
tagClass - Tag class value (UNIV, APPL, CTXT, or PRIV)
tagForm - Tag form value (PRIM or CONS)
tagIDCode - Tag identifier code
Returns:
Decoded length value
Throws:
Asn1TagMatchFailedException - Tag is not equal to expected value
Asn1Exception
java.io.IOException

matchTag

protected static int matchTag(Asn1BerDecodeBuffer buffer,
                              Asn1Tag tag)
                       throws Asn1Exception,
                              java.io.IOException
This method will compare the next parsed tag with the given tag value. If they do not match, an exception will be thrown.

Parameters:
buffer - Decode message buffer object
tag - Tag value to compare
Returns:
Decoded length value
Throws:
Asn1TagMatchFailedException - Tag is not equal to expected value
Asn1Exception
java.io.IOException

indent

public void indent(java.io.PrintStream out,
                   int level)
This method will indent three spaces in the given print stream. It is used by the print methods to provide a ofmratted output of an encoded element value.

Parameters:
out - Print stream
level - Indentation level (# of spaces is 3 x this number)

pdiag

public void pdiag(java.lang.String s)
This is a diagnostics print method. It is a shorthand way to invoke the Diag object's println method.

Parameters:
s - diagnostics message to be printed.

print

public void print(java.io.PrintStream out,
                  java.lang.String varName,
                  int level)
This method will format and output a primitive value to the given print stream.

Specified by:
print in interface Asn1TypeIF
Parameters:
out - Print output stream
varName - Name of variable
level - Indentation level

getTypeName

public static java.lang.String getTypeName(short typeCode)
The static getTypeName method will convert a type code into a type name as defined in the X.680 standard..

Parameters:
typeCode - Type code to be converted

encode

public void encode(Asn1BerOutputStream out,
                   boolean explicit)
            throws Asn1Exception,
                   java.io.IOException
This method writes to the stream an encoded ASN.1 type value including the UNIVERSAL tag value and length if explicit tagging is specified. This overloaded version uses the Basic Encoding Rules (BER).

Specified by:
encode in interface Asn1TypeIF
Parameters:
out - BER Output Stream object
explicit - Flag indicating explicit tagging should be done
Throws:
java.io.IOException - Any exception thrown by the underlying OutputStream.
Asn1Exception - Thrown, if operation is failed.

encode

public void encode(Asn1PerOutputStream out)
            throws Asn1Exception,
                   java.io.IOException
This method is the base implementation of the standard Packed Encoding Rules (PER) encode method using output stream. It throws an exception because it should never be invoked by compiler generated code.

Specified by:
encode in interface Asn1TypeIF
Parameters:
out - PER Output Stream object
Throws:
java.io.IOException - Any exception thrown by the Asn1PerOutputStream.
Asn1Exception - Thrown, if operation is failed.

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Creates and returns a copy of this object.

Overrides:
clone in class java.lang.Object
Returns:
a clone of this instance.
Throws:
java.lang.CloneNotSupportedException - if the object's class does not support the Cloneable interface. Subclasses that override the clone method can also throw this exception to indicate that an instance cannot be cloned.
See Also:
Cloneable

equals

public boolean equals(Asn1Type obj)
Return true if the two objects are equal. Note: The default implementation here is to invoke equals(Object). This is acceptable for the runtime classes, which have overridden equals(Object).


hashCode

public int hashCode()
Returns the hash code of the object. Note: The default behavior of the hashcode is to return 1. This method is overridden in subclasses of Asn1Type to produce real hashcodes.

Overrides:
hashCode in class java.lang.Object

getAsn1TypeName

public java.lang.String getAsn1TypeName()
Returns the ASN.1 specification type name for this type.