iaik.asn1
Class ASN

java.lang.Object
  |
  +--iaik.asn1.ASN
All Implemented Interfaces:
Cloneable

public class ASN
extends Object
implements Cloneable

The ASN class registers the several ASN.1 types. These types are represented at the Java level with ASN.XXX literals.

This class also acts as a factory for creating ASN.1 OBJECT subclasses for various kinds of Java objects.

This class consists of a static and a dynamic part. The static part may be used to statically register, create and/or parse ASN1 objects of already exising type. The dynamic part may be used for dynamically creating new ASN1 types to be registered within the IAIK-JCE ASN.1 architecture.

Each new created ASN.1 type has to be registered in the factory by specifying the class that implements the particular ASN.1 type. When dynamically creating a new ASN.1 type, the tag class, the tag number, and a name has to be specified for refering to the new type. Within the ASN.1 syntax, tags are used for unequivocally identifying some specific ASN.1 type. Each tag consists of a tag class and a tag number within this tag class. Four tag classes are defined:

As an example, the following code sequence creates a new class "MyPrivateType" that implements a private ASN.1 type "MyPrivateType" with tag number 1, and subsequently registers the new type within the ASN.1 factory:
 class MyPrivateType extends ASN1Object {

   private static ASN private_type = new ASN(0x01, "MyPrivateType", ASN.PRIVATE);

    static {
      // register this class as the implementation of the private tag 0x01
      ASN.register(private_type, MyPrivateType.class);
   }
   ...
 }
 
Once an ASN.1 type has been registered within the IAIK-JCE ASN.1 environment, one of the static create methods of this class may be used for creating an instance of this specific type. The following example creates an instance of the already registered universal ASN.1 type OCTET_STRING for the byte value 0x01 0xE3 0x54:
 ASN1Object obj = null;
 byte[] value = { (byte)0x01, (byte)0xE3, (byte)0x54 };
 obj = ASN.create(ASN.OCTET_STRING, value);
 
When a class implements the ASN1Type interface, the static createSequenceOf respectively createSetOf methods of this class may be used for constructing ASN.1 SEQUENCE OF respectively ASN.1 SET OF structures of the pearticular ASN.1 type in mind, e.g.:
 classThatImplementsASN1Type[] cASN1Type = ...;
 ASN1Object obj = ASN.createSequenceOf(cASN1Type);
 
The chain may be parsed back again by using the parseSequenceOf method, which may be utilized for both, SEQUENCE OF and SET OF structures:
 classThatImplementsASN1Type[] cASN1Type1 =
   (classThatImplementsASN1Type[])ASN.parseSequenceOf(obj, classThatImplementsASN1Type.class);
 

Version:
File Revision 31
See Also:
ASN1, ASN1Object, ASN1Type

Field Summary
static int APPLICATION
          Tag class: application
static ASN BIT_STRING
          Global ASN.1 type BIT_STRING
static ASN BMPString
          Global ASN.1 type BMPString
static ASN BOOLEAN
          Global ASN.1 type BOOLEAN
static ASN CON_SPEC
          Global ASN.1 type CON_SPEC (CONTEXTSPECIFIC)
static int CONTEXT_SPECIFIC
          Tag class: context-specific
static ASN ENUMERATED
          Global ASN.1 type ENUMERATED
static ASN EXTERNAL
          Global ASN.1 type EXTERNAL
static ASN GeneralizedTime
          Global ASN.1 type GeneralizedTime (any time precision according to the ISO 2014 norm)
static ASN GeneralString
          Global ASN.1 type GeneralString
static ASN IA5String
          Global ASN.1 type IA5String (String of ASCII characters)
static ASN INTEGER
          Global ASN.1 type INTEGER
protected  String name
          Dynamic part: the name of this ASN.1 type.
static ASN NULL
          Global ASN.1 type NULL
static ASN NumericString
          Global ASN.1 type NumericString
static ASN OBJECT_DESCRIPTOR
          Global ASN.1 type OBJECT_DESCRIPTOR
static ASN ObjectID
          Global ASN.1 type ObjectID
static ASN OCTET_STRING
          Global ASN.1 type OCTET_STRING
static ASN PrintableString
          Global ASN.1 type PrintableString
static int PRIVATE
          Tag class: private
static ASN SEQUENCE
          Global ASN.1 type SEQUENCE
static ASN SET
          Global ASN.1 type SET
static ASN T61String
          Global ASN.1 type T61String (TeletexString; eight-bit extension to the ASCII character set )
protected  int tag
          Dynamic part: the tag number of this specific ASN.1 type.
protected  int tag_class
          Dynamic part: tag class of this specific ASN.1 type.
static ASN UNIString
          Global ASN.1 type UniversalString
static int UNIVERSAL
          Tag class: universal
static ASN UNKNOWN
          Global ASN.1 type UNKNOWN
static ASN UTCTime
          Global ASN.1 type UTCTime (coordinated universal time) (maximum precision down to seconds)
static ASN UTF8String
          Global ASN.1 string type UTF8String
static ASN VisibleString
          Global ASN.1 type VisibleString (ISO 646 String)
 
Constructor Summary
ASN(int tag, String name)
          Creates a new ASN.1 type with given tag number and name.
ASN(int tag, String name, int tagClass)
          Creates a new ASN.1 type with given tag number, name and tag class.
 
Method Summary
 Object clone()
          Returns a clone ("field by field copy") of this ASN.1 type with same tag and name.
static ASN1Object create(ASN type)
          Craetes a new ASN.1 object for the given ASN.1 type.
static ASN1Object create(ASN type, Object value)
          Creates new ASN.1 object for the given ASN.1 type and Java value.
static ASN1Object createSequenceOf(ASN1Type[] array)
          Creates a SEQUENCE OF ASN.1 object from the given array of ASN.1 types.
static ASN1Object createSequenceOf(Vector asn1Type)
          Creates a SEQUENCE OF ASN.1 object from the given vector of ASN.1 types.
static ASN1Object createSetOf(ASN1Type[] array)
          Creates a SET OF ASN.1 object from the given array of ASN.1 types.
static ASN1Object createSetOf(ASN1Type[] array, boolean sorted)
          Creates a SET OF ASN.1 object from the given array of ASN.1 types.
static ASN1Object createSetOf(Vector asn1Type)
          Creates a SET OF ASN.1 object from the given vector of ASN.1 types.
 boolean equals(Object o)
          Compares two ASN.1 types by tag number and tag class.
 String getName()
          Returns the name of this ASN.1 type.
 int getTag()
          Returns the tag number of this ASN.1 type.
 int getTagClass()
          Returns the tag class.
 int hashCode()
          Returns a hashcode for this object.
static ASN1Type[] parseSequenceOf(ASN1Object obj, Class cls)
          Parses a SEQUENCE OF ASN.1 object and returns an array containing all the components of the given ASN.1 object.
static void register(ASN type, Class cls)
          Registers a new ASN.1 type.
 String toString()
          Returns a String describing this ASN.1 type.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

UNIVERSAL

public static final int UNIVERSAL
Tag class: universal

APPLICATION

public static final int APPLICATION
Tag class: application

CONTEXT_SPECIFIC

public static final int CONTEXT_SPECIFIC
Tag class: context-specific

PRIVATE

public static final int PRIVATE
Tag class: private

UNKNOWN

public static final ASN UNKNOWN
Global ASN.1 type UNKNOWN

BOOLEAN

public static final ASN BOOLEAN
Global ASN.1 type BOOLEAN

INTEGER

public static final ASN INTEGER
Global ASN.1 type INTEGER

BIT_STRING

public static final ASN BIT_STRING
Global ASN.1 type BIT_STRING

OCTET_STRING

public static final ASN OCTET_STRING
Global ASN.1 type OCTET_STRING

NULL

public static final ASN NULL
Global ASN.1 type NULL

ObjectID

public static final ASN ObjectID
Global ASN.1 type ObjectID

OBJECT_DESCRIPTOR

public static final ASN OBJECT_DESCRIPTOR
Global ASN.1 type OBJECT_DESCRIPTOR

EXTERNAL

public static final ASN EXTERNAL
Global ASN.1 type EXTERNAL

ENUMERATED

public static final ASN ENUMERATED
Global ASN.1 type ENUMERATED

UTF8String

public static final ASN UTF8String
Global ASN.1 string type UTF8String

SEQUENCE

public static final ASN SEQUENCE
Global ASN.1 type SEQUENCE

SET

public static final ASN SET
Global ASN.1 type SET

NumericString

public static final ASN NumericString
Global ASN.1 type NumericString

PrintableString

public static final ASN PrintableString
Global ASN.1 type PrintableString

T61String

public static final ASN T61String
Global ASN.1 type T61String (TeletexString; eight-bit extension to the ASCII character set )

IA5String

public static final ASN IA5String
Global ASN.1 type IA5String (String of ASCII characters)

UTCTime

public static final ASN UTCTime
Global ASN.1 type UTCTime (coordinated universal time) (maximum precision down to seconds)

GeneralizedTime

public static final ASN GeneralizedTime
Global ASN.1 type GeneralizedTime (any time precision according to the ISO 2014 norm)

VisibleString

public static final ASN VisibleString
Global ASN.1 type VisibleString (ISO 646 String)

GeneralString

public static final ASN GeneralString
Global ASN.1 type GeneralString

UNIString

public static final ASN UNIString
Global ASN.1 type UniversalString

BMPString

public static final ASN BMPString
Global ASN.1 type BMPString

CON_SPEC

public static final ASN CON_SPEC
Global ASN.1 type CON_SPEC (CONTEXTSPECIFIC)

tag

protected int tag
Dynamic part: the tag number of this specific ASN.1 type.

tag_class

protected int tag_class
Dynamic part: tag class of this specific ASN.1 type.

name

protected String name
Dynamic part: the name of this ASN.1 type.
Constructor Detail

ASN

public ASN(int tag,
           String name)
Creates a new ASN.1 type with given tag number and name. The tag class is set to UNIVERSAL.
Parameters:
tag - the tag number of the new ASN.1 type
name - the name of the new ASN.1 type

ASN

public ASN(int tag,
           String name,
           int tagClass)
Creates a new ASN.1 type with given tag number, name and tag class. Each new created ASN.1 type has to be registered in the factory by specifying the class that implements the particular ASN.1 type. As an example, the following code sequence creates a new class "MyPrivateType" that implements a private ASN.1 type "MyPrivateType" with tag number 1, and subsequently registers the new type within the ASN.1 factory:
 class MyPrivateType extends ASN1Object {

   private static ASN private_type = new ASN(0x01, "MyPrivateType", ASN.PRIVATE);

    static {
      // register this class as the implementation of the private tag 0x01
      ASN.register(private_type, MyPrivateType.class);
   }
   ...
 }
 
Parameters:
tag - the tag number of the new ASN.1 type
name - the name of the new ASN.1 type
tagClass - the tag class (UNIVERSAL, APPLICATION, CONTEXT_SPECIFIC, or PRIVATE)
Method Detail

create

public static ASN1Object create(ASN type)
                         throws InstantiationException
Craetes a new ASN.1 object for the given ASN.1 type. If null is supplied as type, an ASN.1 NULL object is returned.
Only ASN.1 objects of already registered type can be created by this method. The following example creates a new instance of an ASN.1 object of registered universal type OCTET_STRING:
 ASN1Object obj = null;
 obj = ASN.create(ASN.OCTET_STRING);
 
Parameters:
type - the ASN.1 type name of the new ASN.1 object to be created
Returns:
the new created ASN.1 object which is a ASN.1 NULL object if the given type is null
Throws:
InstantiationException - if the internal factory cannot create an instance of requested type
See Also:
ASN1Object

create

public static ASN1Object create(ASN type,
                                Object value)
                         throws InstantiationException
Creates new ASN.1 object for the given ASN.1 type and Java value. If, for instance, the new ASN.1 object is of ASN.1 type IA5String, the corresponding Java value will be a Java String object.
Only ASN.1 objects of already registered type can be created by this method. The following example creates an instance of the already registered universal ASN.1 type OCTET_STRING for the byte value 0x01 0xE3 0x54:
 ASN1Object obj = null;
 byte[] value = { (byte)0x01, (byte)0xE3, (byte)0x54 };
 obj = ASN.create(ASN.OCTET_STRING, value);
 
Parameters:
type - the ASN.1 type name of the new ASN.1 object to be created
value - the Java value to be set for this ASN.1 object
Returns:
the new created ASN.1 object which is a ASN.1 NULL object if the given type is null
Throws:
InstantiationException - if the internal factory cannot create an instance of requested type
See Also:
ASN1Object

register

public static void register(ASN type,
                            Class cls)
Registers a new ASN.1 type. Called by the OBJECT classes' static initializers to register those ASN.1 types that the OBJECT classes know of.

As an example, the following code sequence creates a new class "MyPrivateType" that implements a private ASN.1 type "MyPrivateType" with tag number 1, and subsequently registers the new type within the ASN.1 factory:

 class MyPrivateType extends ASN1Object {

   private static ASN private_type = new ASN(0x01, "MyPrivateType", ASN.PRIVATE);

    static {
      // register this class as the implementation of the private tag 0x01
      ASN.register(private_type, MyPrivateType.class);
   }
   ...
 }
 
Parameters:
type - the new ASN.1 type to be registered
cls - the class that implements the ASN.1 type to be registered

createSequenceOf

public static ASN1Object createSequenceOf(ASN1Type[] array)
                                   throws CodingException
Creates a SEQUENCE OF ASN.1 object from the given array of ASN.1 types. All components have to be of the same ASN.1 type. This method only can be utilized for instances of classes that implement the ASN1Type interface, e.g.:
 classThatImplementsASN1Type[] cASN1Type = ...;
 ASN1Object obj = ASN.createSequenceOf(cASN1Type);
 
The chain may be parsed back again by using the parseSequenceOf method.
Parameters:
array - the array of objects
Returns:
the created ASN1Object as SEQUENCE OF ASN1Type
Throws:
CodingException - if there occurs an error while constructing the ASN1Object
See Also:
ASN1Object, ASN1Type, SEQUENCE

createSequenceOf

public static ASN1Object createSequenceOf(Vector asn1Type)
                                   throws CodingException
Creates a SEQUENCE OF ASN.1 object from the given vector of ASN.1 types. All components have to be of the same ASN.1 type. This method only can be utilized for instances of classes that implement the ASN1Type interface, e.g.:
 Vector vectorOfASN1TypeImplementingClassInstances = ...;
 ...
 ASN1Object obj = ASN.createSequenceOf(vectorOfASN1TypeImplementingClassInstances);
 
The class instances may be parsed back again by using the parseSequenceOf method.
Parameters:
asn1Type - a Vector containing the ASN1Type objects
Returns:
the created ASN1Object as SEQUENCE OF ASN1Type
Throws:
CodingException - if there occurs an error while constructing the ASN1Object
See Also:
ASN1Object, ASN1Type, SEQUENCE

createSetOf

public static ASN1Object createSetOf(ASN1Type[] array)
                              throws CodingException
Creates a SET OF ASN.1 object from the given array of ASN.1 types. All components have to be of the same ASN.1 type. This method only can be utilized for instances of classes that implement the ASN1Type interface, e.g.:
 classThatImplementsASN1Type[] cASN1Type = ...;
 ASN1Object obj = ASN.createSetOf(cASN1Type);
 
The chain may be parsed back again by using the parseSequenceOf method.
Parameters:
array - the array of objects
Returns:
the created ASN1Object as SET OF ASN1Type
Throws:
CodingException - if there was an error while constructing the ASN1Object
See Also:
ASN1Object, ASN1Type, SET

createSetOf

public static ASN1Object createSetOf(ASN1Type[] array,
                                     boolean sorted)
                              throws CodingException
Creates a SET OF ASN.1 object from the given array of ASN.1 types. If the parameter sorted is set to true, the SET OF will be sorted by the component encodings to give a proper DER encoding. Otherwise the components appear unsorted to give a BER encoding.
Parameters:
array - the array of objects
sorted - whether to sort the components or not
Returns:
the created ASN1Object as SET OF ASN1Type
Throws:
CodingException - if there was an error while constructing the ASN1Object
See Also:
ASN1Object, ASN1Type, SET

createSetOf

public static ASN1Object createSetOf(Vector asn1Type)
                              throws CodingException
Creates a SET OF ASN.1 object from the given vector of ASN.1 types. All components have to be of the same ASN.1 type. This method only can be utilized for instances of classes that implement the ASN1Type interface, e.g.:
 Vector vectorOfASN1TypeImplementingClassInstances = ...;
 ...
 ASN1Object obj = ASN.createSetOf(vectorOfASN1TypeImplementingClassInstances);
 
The class instances may be parsed back again by using the parseSequenceOf method.
Parameters:
asn1Type - a Vector containing the ASN1Type objects
Returns:
the created ASN1Object as SET OF ASN1Type
Throws:
CodingException - if there occurs an error while constructing the ASN1Object
See Also:
ASN1Object, ASN1Type, SET

parseSequenceOf

public static ASN1Type[] parseSequenceOf(ASN1Object obj,
                                         Class cls)
                                  throws CodingException
Parses a SEQUENCE OF ASN.1 object and returns an array containing all the components of the given ASN.1 object. All components are of the same ASN.1 type specified by the given class implementing the ASN.1 type in mind. This class has to implement the ASN1Type interface. This method also may be used for parsing a SET OF ASN.1 objects that may have been created by means of the createSetOf method, e.g.:
 classThatImplementsASN1Type[] cASN1Type1 =
   (classThatImplementsASN1Type[])ASN.parseSequenceOf(obj, classThatImplementsASN1Type.class);
 
Parameters:
obj - the ASN1Object to be parsed
className - the name of the class that implements the components´ ASN.1 type
Returns:
an ASN1Type array containing the components of the parsed ASN.1 object
Throws:
CodingException - if the ASN1Object could not be parsed
See Also:
ASN1Type, ASN1Object

getName

public String getName()
Returns the name of this ASN.1 type.
Returns:
the name of this ASN.1 type

getTag

public int getTag()
Returns the tag number of this ASN.1 type. The tag number unequivocally identifies some specific ASN.1 type within its tag class.
Returns:
the tag number of this ASN.1 type

getTagClass

public int getTagClass()
Returns the tag class. The tag class may be:
Returns:
the tag class

equals

public boolean equals(Object o)
Compares two ASN.1 types by tag number and tag class. This method returns true, if the two ASN.1 types have the same tag class and the same tag number; otherwise it returns false.
Overrides:
equals in class Object
Parameters:
o - the ASN.1 type to be compared with the actual ASN.1 type
Returns:
true if the two ASN.1 types match, false otherwise

hashCode

public int hashCode()
Returns a hashcode for this object.
Overrides:
hashCode in class Object
Returns:
a hashcode

clone

public Object clone()
Returns a clone ("field by field copy") of this ASN.1 type with same tag and name.
Overrides:
clone in class Object
Returns:
a clone of this ASN.1 type

toString

public String toString()
Returns a String describing this ASN.1 type.
Overrides:
toString in class Object
Returns:
a string specifying tag and name of this ASN.1 type

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK