The ASN.1 to Java Compiler can automatically translate ASN.1 specifications into Java classes that can be easily integrated into your applications.
The compiler has two components: the ASN.1 Java Code Generator and the ASN.1 Java Runtime Library.
The ASN.1 Java Code Generator takes a set of ASN.1 modules as input and automatically generates Java classes corresponding to ASN.1 types. The Code Generator generates system-independent Java code.
The mapping between ASN.1 types and Java classes is quite straightforward and intuitive. The ASN.1 Java Code Generator always generates type as primitive as possible, the following table lists the mapping from ASN.1 types to Java types:
ASN.1 Type | Mapping to Java Type |
BOOLEAN | Boolean |
NULL | Object |
INTEGER | Integer/Long |
ENUMERATED | enum/singleton class1 |
REAL | Float/Double |
BIT STRING | Generated Class |
OCTET STRING | byte[] |
OBJECT IDENTIFIER | ObjectIdentifier2 |
RELATIVE-OID | ObjectIdentifier |
Character Strings | String |
GeneralizedTime | Date |
UTCTime | Date |
CHOICE | Generated Class |
SEQUENCE/SET | Generated Class |
SEQUENCE OF/SET OF | Vector3 |
The ASN.1 Java runtime library facilitate encode, decode and various other operations on application messages. All routines are written completely in Java and can be run on any JVM, including resource limited environments like mobile phone, PDA, etc.
Feature | ASN.1 to Java Compiler |
BER (Basic Encoding Rules) | YES |
CER (a canonical BER subset) | YES |
DER (another canonical BER subset) | YES |
PER (Packed Encoding Rules) | YES, align and unaligned PER |
XER (XML Encoding Rules) | NO |
Subtype constraints | YES |
Information Object Classes | YES |
Target language | Java |
Execution envionment | Java SE/Java ME |
The tag number can't exceed 221-1 but for reasonable ASN.1 specifications this should not be a problem.
The length of enumerated items, bit string, octet string, components or alternatives can't exceed 231-1.
The value of INTEGER should be in range -263~263-1 (i.e. BigInteger not support) .
The value of REAL is allways encoded/decoded in binary form, the precision should never exceed double type in Java (i.e. BigDecimal not support).
SET OF value dynamic sort is not supported, it's recommended to use SEQUENCE OF type instead of SET OF type.
1) singleton class is for J2SE 1.4 or under where enum type is not support.
2) wrap type over an id array, i.e. int[].
3) if type parameter is support, the Vector is parametered with component type.