Abstract Syntax Notation One (ASN.1) is a standard and notation that describes rules and structures for representing, encoding, transmitting, and decoding data in telecommunications and computer networking. [ASN1.ts] is a cross platform ASN1 library written in typescript. It supports encoding and (schema supported) decoding of ber encoded asn1 structures. ASN.1 is the basis of all X.509 related data structures and numerous other protocols used on the web. Yury Strozhevsky, GMO GlobalSign and Peculiar Ventures are the authors of the library. estos extends this library as some bits and pieces have been missing. To get to know the additions see [What has been added by estos] below
[ASN1.ts] is the first library for BER encoding/decoding in Javascript designed for browser use. BER is the basic encoding rules for ASN.1 that all others are based on, [DER] is the encoding rules used by PKI applications - it is a subset of BER. The [ASN1.ts] library was tested against freely available ASN.1:2008 test suite, with some limitations related to JavaScript language.
When playing around an online asn1 ber decoder is a helpfull tool to have on hand. e.g. https://lapo.it/asn1ts
How to create a simple ASN structures// Creating a simple asn1 sequence const seq = new asn1ts.Sequence({ value: [ new asn1ts.Utf8String({ value: "string" }), new asn1ts.Integer({ value: 1 }), new asn1ts.Boolean({ value: true }) ] }); // Encode the data into an ArrayBuffer const encoded = seq.toBER(); // 300e0c06737472696e670201010101ff console.log(Buffer.from(new Uint8Array(encoded)).toString("hex"));How to validate data against a scheme
// Creating a simple asn1 sequence const seq = new asn1ts.Sequence({ value: [ new asn1ts.Utf8String({ value: "string" }), new asn1ts.Integer({ value: 1 }), new asn1ts.Boolean({ value: true }) ] }); // Encode the data into an ArrayBuffer const encoded = seq.toBER(); // Create the scheme we want to validate against const scheme = new asn1ts.Sequence({ name: "sequence", value: [ new asn1ts.Utf8String({name: "string_value"}), new asn1ts.Integer({name: "integer_value"}), new asn1ts.Boolean({name: "boolean_value"}), ] }); // Verify the data against the schema const result = asn1ts.verifySchema(encoded, scheme); if (result.verified) { // Schema has been verified, let´s get the property "integer_value" const asn1tsInteger = result.result.getTypedValueByName(asn1ts.Integer, "integer_value"); if (asn1tsInteger) { // 1 console.log(asn1tsInteger.getValue()); } } else { console.log(result.errors); }How to use implicit optional properties (smaller footprint when asn1 encoded, the schema tells the decoder what it shall decode)
// Creating a simple asn1 sequence with an implicitly encoded integer const seq = new asn1ts.Sequence({ value: [ new asn1ts.Utf8String({ value: "string" }), new asn1ts.Integer({ value: 2, idBlock: { optionalID: 0 } }), ] }); // Encode the data into an ArrayBuffer const encoded = seq.toBER(); // 300b0c06737472696e67800101 console.log(Buffer.from(new Uint8Array(encoded)).toString("hex")); // Create the scheme we want to validate against const scheme = new asn1ts.Sequence({ name: "sequence", value: [ new asn1ts.Utf8String({name: "string_value"}), new asn1ts.Integer({name: "integer_value", idBlock: { optionalID: 0 }}), ] }); // Verify the data against the schema const result = asn1ts.verifySchema(encoded, scheme); if (result.verified) { // Schema has been verified, let´s get the property "integer_value" const asn1tsInteger = result.result.getTypedValueByName(asn1ts.Integer, "integer_value"); if (asn1tsInteger) { // 2 console.log(asn1tsInteger.getValue()); } } else { console.log(result.errors); }
Check the test directory as these contain use case driven tests for different scenarios.
We are using asn1ts in combination with other asn1 ber encoders decoders. Interoperability is our daily business between different communication systems and devices. We are using a mixed product ecosystem where asn1 ber data is encoded decoded by the esnacc compiler as well as products from Objective Systems.
There are several commercial products, enterprise solutions as well as open source project based on versions of ASN1js. You should, however, do your own code and security review before utilization in a production application before utilizing any open source library to ensure it will meet your needs.
Copyright (c) 2014, GMO GlobalSign Copyright (c) 2015-2022, Peculiar Ventures Copyright (c) 2022, estos GmbH for extensions and missing features (see README.md) All rights reserved.
Author 2014-2018, Yury Strozhevsky Author 2019-2022, Peculiar Ventures Author from 2022, estos GmbH
estos created a fork of the library, mainly written by Yury Strozhevsky and Peculiar Ventures, in 2022 to add extensions, missing features. Details about those in the README.md
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4