Asn1API

An Asn1API is a library containing all the material needed to encode and decode data according to an ASN.1 schema. It comprises an ASN.1 runtime library that is in charge of the methods for encoding and decoding the basic types.

They are available in Java and C#.

The developer integrates the generated code and the ASN.1 runtime into his application.

Free trialRequest for quotesCustomer cases

Content of an Asn1API library

The Java or C# classes derived from the ASN.1 schéma. They have been generated by  Asn1Compiler.

The ASN.1 encoding/decoding runtime.

The user guide describing the packages and namespaces, explains how to use the Java or C# classes as well as the encoding and decoding methods.

The documentation of generated classes in  javadoc format or HTML Help MSDN-style.

Some use case examples.

Available APIs

3GPP

CDR_3GPP, CDR_3GPP_32298, TAP3,

NBAP, HNBAP, RANAP, RUA, RNSAP, SABP, SBCAP, URRC, PCAP, MAP, RRLP, PMF_3GPP, LTE_RRC, LTE_S1AP, LTE_X2AP

ECMA

CSTAp1, CSTAp2, CSTAp3, CSTAp3XML

ETSI

ETSI_LI, ITS

ITU-T

H245, H323, T120, MEGACO, E115

ISO

MMS, Z39.50, FTAM, RFID

IETF

LDAPv3, SNMPv2, CMS, PKIX

OASIS

XCBF

Open Mobile Alliance

SUPL, USUPL

Example

Here is a Java and C# example showing the use of an API generated from the file sample.asn1:

SampleModule 
DEFINITIONS AUTOMATIC TAGS ::=
BEGIN
MainStruct ::= SEQUENCE {
name IA5String,
age INTEGER
}
END

The main generated files are:

  • Sample/src/java/Sample/SampleFactory.java
  • Sample/src/java/samplemodule/MainStruct.java

SampleFactory is a factory class to enable encoders and decoders creation. MainStruct is the class generated for the ASN.1 type MainStruct. It contains the set/get methods for accessing the values of the components "name" and "age". An example of use is:

import com.unigone.asn1RT.IDecoder;
import com.unigone.asn1RT.IEncoder;
import com.unigone.asn1RT.Asn1Exception;
import com.unigone.asn1RT.util.ByteArray;

import Sample.*;
import Sample.samplemodule.*;

...

/* encoder/decoder creation */
_encoder = SampleFactory.createEncoder();
_decoder = SampleFactory.createDecoder();

// fill a value
MainStruct mainStruct = new MainStruct();
mainStruct.setName("ABC");
mainStruct.setAge(7);

try
{
// ensure type is valid before encoding it
mainStruct.validate();
// Encode data (it could be written directly into a stream)
_encoder.encode(mainStruct);
}
catch (Asn1ValidationException avex)
{
System.out.println("ERROR WHILE VALIDATING pdu : "
+ avex.getMessage());
return;
}
catch (Asn1Exception aex)
{
System.out.println("ERROR WHILE ENCODING pdu : "
+ aex.getMessage());
return;
}

// dump data
System.out.println("mainStruct encoding :");
byte[] mainStruct_encoding = _encoder.getData();
System.out.println(ByteArray.byteArrayToHexString(mainStruct_encoding, null, -1));

// decode an encoding
mainStruct = new MainStruct();
try
{
// Decode data (it could be read directly from a stream).
_decoder.decode(mainStruct_encoding, mainStruct);
// ensure type is valid
mainStruct.validate();
}
catch (Asn1ValidationException avex)
{
// display already decoded values...
System.out.println(mainStruct.toString());
System.out.println("ERROR WHILE VALIDATING pdu : "
+ ex.getMessage());
return;
}
catch (Asn1Exception aex)
{
// display already decoded values...
System.out.println(mainStruct.toString());
System.out.println("decoder stopped at "+_decoder.usedBytes());
System.out.println("ERROR WHILE DECODING pdu : "
+ aex.getMessage());
return;
}

// access the value
String _name = mainStruct.getName();
long _age = mainStruct.getAge();

// using toString() with mainStruct
System.out.println(mainStruct.toString());

The main generated files are:

  • Sample/src/cSharp/Sample/SampleFactory.cs
  • Sample/src/cSharp/SampleModule/MainStruct.cs

SampleFactory is a factory class to enable encoders and decoders creation. MainStruct is the class generated for the ASN.1 type MainStruct. It contains the properties for accessing the values of the components "name" and "age". An example of use is:

using IEncoder = Unigone.Asn1RT.IEncoder;
using IDecoder = Unigone.Asn1RT.IDecoder;
using Asn1Exception = Unigone.Asn1RT.Asn1Exception;
using ByteArray = Unigone.Asn1RT.Util.ByteArray;

using Sample;
using Sample.SampleModule;

...

/* encoder/decoder creation */
_encoder = SampleFactory.CreateEncoder();
_decoder = SampleFactory.CreateDecoder();

// fill a value
MainStruct mainStruct = new MainStruct();
mainStruct.Name = "ABC";
mainStruct.Age = 7;

try
{
// ensure type is valid before encoding it
mainStruct.Validate();
// Encode data (it could be written directly into a stream)
_encoder.Encode(mainStruct);
}
catch (Asn1ValidationException avex)
{
Console.Out.WriteLine("ERROR WHILE VALIDATING pdu : "
+ avex.Message);
return;
}
catch (Asn1Exception aex)
{
Console.Out.WriteLine("ERROR WHILE ENCODING pdu : "
+ aex.Message);
return;
}

// dump data
Console.Out.WriteLine("mainStruct encoding :");
byte[] mainStruct_encoding = _encoder.Data;
Console.Out.WriteLine(ByteArray.ByteArrayToHexString(mainStruct_encoding, null, -1));

// decode an encoding
mainStruct = new MainStruct();
try
{
// Decode data (it could be read directly from a stream).
_decoder.Decode(mainStruct_encoding, mainStruct);
// ensure type is valid
mainStruct.Validate();
}
catch (Asn1ValidationException avex)
{
// display already decoded values...
Console.Out.WriteLine(mainStruct.ToString());
Console.Out.WriteLine("ERROR WHILE VALIDATING pdu : "
+ avex.Message);
return;
}
catch (Asn1Exception aex)
{
// display already decoded values...
Console.Out.WriteLine(mainStruct.ToString());
Console.Out.WriteLine("decoder stopped at "+_decoder.UsedBytes());
Console.Out.WriteLine("ERROR WHILE DECODING pdu : "
+ aex.Message);
return;
}

// access the value
string _name = mainStruct.Name;
long _age = mainStruct.Age;

// using ToString() with mainStruct
Console.Out.WriteLine(mainStruct.ToString());