jASN1 User Guide
Download PDF Version
jASN1 can be used for ASN.1 BER/DER encoding/decoding using Java. It consists of two projects: jasn1-compiler and the jasn1 library (both licensed under the Mozilla Public License (MPL) v2.0). The jasn1-compiler is an application that creates Java classes from ASN.1 syntax. These generated classes can then be used together with the jasn1 library to efficiently encode and decode messages using the Basic Encoding Rules (BER). The encoded bytes also confirm to the Distinguished Encoding Rules (DER) which is a subset of BER.
The software has been tested under Linux, Android and Windows.
For the latest release of this software visit http://www.openmuc.org .
After extracting the distribution tar file the jASN1 libraries can be found in the directory build/libs-all. For license information check the license directory in the distribution. Run scripts to run the ASN.1 compiler are found in the folder run-scripts.
Besides the jASN1 libraries the folder build/libs-all/ contains the following external library:
ANTLR, License: The BSD License, http://www.antlr.org Copyright (c) 2012 Terence Parr and Sam Harwell All rights reserved.
The jasn1-compiler uses ANTLR to parse the ASN.1 definitions. The excellent grammar to generate the ANTLR parser was taken from the BinaryNotes ASN.1 Framework (http://bnotes.sourceforge.net/ licensed under the Apache 2.0 license). Copyright 2006-2011 Abdulla Abdurakhmanov
3. How to use jASN1
In a first step you have to compile the ASN.1 code of your choice to Java classes. To run the compiler you can use the run scripts for Linux and Windows found in the run-scripts folder. Executing the scripts without any parameters will print help information to the screen.
The generated classes can then be used to easily encode and decode BER encoded data. The encoded data will confirm to the DER syntax. For an example on how to use the generated classes see the folder projects/jasn1-compiler/src/sample/java/org/openmuc/jasn1/sample/.
3.1. ASN1 syntax:
In some cases it could be favorable not to decode elements of type ANY because it would involve big array copying. Therefor the compiler supports the alternative element type called ANY_NODECODE which can be used inside the ASN.1 file in order to generate Java code that will not decode nor encode elements of these types.
4. Modifying and Compiling jASN1
We use the Gradle build automation tool. The distribution contains a fully functional gradle build file (build.gradle). Thus if you changed code and want to rebuild a library you can do it easily with Gradle. Also if you want to import our software into Eclipse you can easily create Eclipse project files using Gradle. Just follow the instructions on our FAQ site.