@complycloud/asn1

Javascript library for parsing Abstract Syntax Notation One (ASN.1)

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Sep 26, 2017Mar 8, 2017Minified + gzip package size for @complycloud/asn1 in KB

Readme

@complycloud/asn1

Javascript library for Abstract Syntax Notation One (ASN.1).

Provides a programmatic interface for building an ASN.1 object model along with JSON serialization / deserialization.

Installation

npm install @complycloud/asn1

Usage

import { JSONDeserializer, JSONSerializer, Universal } from '@complycloud/asn1';

// Create an ASN.1 object model programmatically
const { Bool, Integer, Null, PrintableString, Sequence } = Universal;
const sequence = new Sequence([
  new Integer(-Number.MAX_SAFE_INTEGER),
  new Integer(Number.MAX_SAFE_INTEGER),
  new Integer('424242424242424242424242424242424242'), // big integer
  new Null(),
  new Bool(true),
  new PrintableString('nice marmot'),
]);

// Serialize the object model to JSON
const serialize = new JSONSerializer();
const json = serialize(sequence);

// Deserialize back to an ASN.1 object model
const deserialize = new JSONDeserializer();
const asn1ObjectModel = deserialize(json);

Encoders

There are a multitude of encoding rules available for ASN.1. Known encoders are shown below.

Format Implementation Serialization Deserialization Comments
JSON Included w/ this library Yes Yes A library specific JSON format as no JSON encoding rules exist as part of the ASN.1 standards
DER @complycloud/asn1-der Yes Planned Distinguished Encoding Rules (DER) are the standard ASN.1 encoding rules for public key cryptography (certificates, RSA keys, et al.)
PEM @complycloud/asn1-der Yes Planned Privacy Enhanced Mail (PEM) is a base64-encoded and specially formatted version of DER commonly used to distribute X.509 certificates

Debugging

This library uses the @complyify/debug library for debugging. To enable debug messages, simply set the DEBUG environment variable.

# enable all debugging messages in this library
DEBUG=complycloud:asn1:* <your-exec-here>
# enable all debug messages except the bit twiddling messages
DEBUG=complycloud:asn1:*,-complycloud:asn1:*:binary <your-exec-here>

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.