Package Exports
- asn1-ts
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (asn1-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ASN.1 TypeScript Library
- Author: Jonathan M. Wilbur <jonathan@wilbur.space>
- Copyright Year: 2019
- License: MIT License
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.jsis the root for usage in NodeJS.dist/asn1.min.jsis the entire ASN.1 library for the web browser, which is minified, and accessible under the variableasn1.dist/ber.min.jsis only the Basic Encoding Rules (BER), minified.dist/der.min.jsis 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; // Now the data is encoded.
console.log(el.integer); // Logs '1433'... 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); // Logs '1433'Tests under the test directory can also serve as examples.
Future Development
- Support
EXTERNALtype. - Support
EmbeddedPDVtype. - Support
CharacterStringtype. - Use default exports for everything.
- Encode
REALin Base-2 format in the DER encoder, because X.509 forbids base-10 encoding. - Implement these codecs:
- Octet Encoding Rules
- JSON Encoding Rules (May require changes to ASN1Element)
- Canonical Encoding Rules
- Lightweight Encoding Rules
- BACNet Encoding Rules? (ISO 16484-5:2017)
- Packed Encoding Rules
- Basic Aligned Packed Encoding Rules (PER) (This is used by MCS / T.125, which is used by RDP.)
- Basic Unaligned Packed Encoding Rules (UPER) (May require changes to ASN1Element) (Used by 3GPP RRC)
- Canonical Aligned Packed Encoding Rules (CPER)
- Canonical Unaligned Packed Encoding Rules (CUPER) (May require changes to ASN1Element)
- Internationalized strings.
- Fix the indices (They do not export everything)
- Serverless Functions
-
ValidateSize -
ValidateRange - A function to encode almost every type.
- A function to decode almost every type.
- All things relating to JSON Encoding Rules.
-
- Compatibility-breaking changes
- Error UUIDs.
- Use the
namefield in errors. - Pass in the offending element into errors.
See Also
- X.680 - Abstract Syntax Notation One (ASN.1), published by the International Telecommunications Union.
- X.690 - ASN.1 encoding rules, published by the International Telecommunications Union.
- ASN.1: Communication Between Heterogeneous Systems by Olivier Dubuisson