|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.asn1.ASN
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:
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);
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 |
public static final int UNIVERSAL
public static final int APPLICATION
public static final int CONTEXT_SPECIFIC
public static final int PRIVATE
public static final ASN UNKNOWN
UNKNOWN
public static final ASN BOOLEAN
BOOLEAN
public static final ASN INTEGER
INTEGER
public static final ASN BIT_STRING
BIT_STRING
public static final ASN OCTET_STRING
OCTET_STRING
public static final ASN NULL
NULL
public static final ASN ObjectID
ObjectID
public static final ASN OBJECT_DESCRIPTOR
OBJECT_DESCRIPTOR
public static final ASN EXTERNAL
EXTERNAL
public static final ASN ENUMERATED
ENUMERATED
public static final ASN UTF8String
UTF8String
public static final ASN SEQUENCE
SEQUENCE
public static final ASN SET
SET
public static final ASN NumericString
NumericString
public static final ASN PrintableString
PrintableString
public static final ASN T61String
T61String
(TeletexString;
eight-bit extension to the ASCII character set )public static final ASN IA5String
IA5String
(String of ASCII characters)public static final ASN UTCTime
UTCTime
(coordinated universal time)
(maximum precision down to seconds)public static final ASN GeneralizedTime
GeneralizedTime
(any time precision according to the ISO 2014 norm)public static final ASN VisibleString
VisibleString
(ISO 646 String)public static final ASN GeneralString
GeneralString
public static final ASN UNIString
UniversalString
public static final ASN BMPString
BMPString
public static final ASN CON_SPEC
CON_SPEC
(CONTEXTSPECIFIC)protected int tag
protected int tag_class
protected String name
Constructor Detail |
public ASN(int tag, String name)
tag
- the tag number of the new ASN.1 typename
- the name of the new ASN.1 typepublic ASN(int tag, String name, int tagClass)
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); } ... }
tag
- the tag number of the new ASN.1 typename
- the name of the new ASN.1 typetagClass
- the tag class (UNIVERSAL,
APPLICATION, CONTEXT_SPECIFIC, or PRIVATE)Method Detail |
public static ASN1Object create(ASN type) throws InstantiationException
null
is supplied as type, an ASN.1 NULL object is returned.
ASN1Object obj = null; obj = ASN.create(ASN.OCTET_STRING);
type
- the ASN.1 type name of the new ASN.1 object to be creatednull
InstantiationException
- if the internal factory
cannot create an instance of requested typeASN1Object
public static ASN1Object create(ASN type, Object value) throws InstantiationException
IA5String
, the corresponding Java value will be a Java
String
object.
ASN1Object obj = null; byte[] value = { (byte)0x01, (byte)0xE3, (byte)0x54 }; obj = ASN.create(ASN.OCTET_STRING, value);
type
- the ASN.1 type name of the new ASN.1 object to be createdvalue
- the Java value to be set for this ASN.1 objectnull
InstantiationException
- if the internal factory
cannot create an instance of requested typeASN1Object
public static void register(ASN type, Class cls)
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); } ... }
type
- the new ASN.1 type to be registeredcls
- the class that implements the ASN.1 type to be registeredpublic static ASN1Object createSequenceOf(ASN1Type[] array) throws CodingException
ASN1Type
interface, e.g.:
classThatImplementsASN1Type[] cASN1Type = ...; ASN1Object obj = ASN.createSequenceOf(cASN1Type);The chain may be parsed back again by using the
parseSequenceOf
method.array
- the array of objectsCodingException
- if there occurs an error while constructing the ASN1ObjectASN1Object
,
ASN1Type
,
SEQUENCE
public static ASN1Object createSequenceOf(Vector asn1Type) throws CodingException
ASN1Type
interface, e.g.:
Vector vectorOfASN1TypeImplementingClassInstances = ...; ... ASN1Object obj = ASN.createSequenceOf(vectorOfASN1TypeImplementingClassInstances);The class instances may be parsed back again by using the
parseSequenceOf
method.asn1Type
- a Vector containing the ASN1Type objectsCodingException
- if there occurs an error while constructing the ASN1ObjectASN1Object
,
ASN1Type
,
SEQUENCE
public static ASN1Object createSetOf(ASN1Type[] array) throws CodingException
ASN1Type
interface, e.g.:
classThatImplementsASN1Type[] cASN1Type = ...; ASN1Object obj = ASN.createSetOf(cASN1Type);The chain may be parsed back again by using the
parseSequenceOf
method.array
- the array of objectsCodingException
- if there was an error while constructing the ASN1ObjectASN1Object
,
ASN1Type
,
SET
public static ASN1Object createSetOf(ASN1Type[] array, boolean sorted) throws CodingException
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.array
- the array of objectssorted
- whether to sort the components or notCodingException
- if there was an error while constructing the ASN1ObjectASN1Object
,
ASN1Type
,
SET
public static ASN1Object createSetOf(Vector asn1Type) throws CodingException
ASN1Type
interface, e.g.:
Vector vectorOfASN1TypeImplementingClassInstances = ...; ... ASN1Object obj = ASN.createSetOf(vectorOfASN1TypeImplementingClassInstances);The class instances may be parsed back again by using the
parseSequenceOf
method.asn1Type
- a Vector containing the ASN1Type objectsCodingException
- if there occurs an error while constructing the ASN1ObjectASN1Object
,
ASN1Type
,
SET
public static ASN1Type[] parseSequenceOf(ASN1Object obj, Class cls) throws CodingException
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);
obj
- the ASN1Object to be parsedclassName
- the name of the class that implements the components´ ASN.1 typeASN1Type
array containing the components of the parsed ASN.1 objectCodingException
- if the ASN1Object could not be parsedASN1Type
,
ASN1Object
public String getName()
public int getTag()
public int getTagClass()
public boolean equals(Object o)
true
, if the two ASN.1 types have
the same tag class and the same tag number; otherwise it
returns false
.equals
in class Object
o
- the ASN.1 type to be compared with the actual ASN.1 typetrue
if the two ASN.1 types match, false
otherwisepublic int hashCode()
hashCode
in class Object
public Object clone()
clone
in class Object
public String toString()
toString
in class Object
|
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). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |