ASN.1 TypeScript Library
This library was based off of my D ASN.1 Library.
What is ASN.1?
ASN.1 stands for Abstract Syntax Notation. ASN.1 was first specified in
X.680 - Abstract Syntax Notation One (ASN.1),
by the International Telecommunications Union.
ASN.1 messages can be encoded in one of several encoding/decoding standards.
It provides a system of types that are extensible, and can presumably describe
every protocol. You can think of it as a protocol for describing other protocols
as well as a family of standards for encoding and decoding said protocols.
It is similar to Google's Protocol Buffers,
or Sun Microsystems' External Data Representation (XDR).
For more information on what ASN.1 is, see documentation/asn1.md
.
Building
You can build this library by running npm run build
.
The outputs will all be in dist
.
dist/index.js
is the root for usage in NodeJS.dist/asn1.min.js
is the entire ASN.1 library for the web browser, which is
minified, and accessible under the variable asn1
.dist/ber.min.js
is only the Basic Encoding Rules (BER), minified.dist/der.min.js
is only the Distinguished Encoding Rules (DER), minified.
In many cases, you will only need one set of encoding rules or the other, so it
is recommended to use either ber.min.js
or der.min.js
in your web
application instead of asn1.min.js
.
Library Usage
For each codec in the library, usage entails instantiating the class,
then using that class' properties to get and set the encoded value.
For all classes, the empty constructor creates an END OF CONTENT
element. The remaining constructors will be codec-specific.
Here is a TypeScript example of encoding with Basic Encoding Rules, using the
BERElement
class.
let el : BERElement = new BERElement();
el.typeTag = ASN1UniversalType.integer;
el.integer = 1433;
console.log(el.integer);
... and here is how you would decode that same element:
let encodedData : Uint8Array = el.toBytes();
let el2 : BERElement = new BERElement();
el2.fromBytes(encodedData);
console.log(el2.integer);
Tests under the test
directory can also serve as examples.
Future Development
See Also