Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
The asn1 npm package is a library for encoding and decoding Abstract Syntax Notation One (ASN.1) data structures. ASN.1 is a standard interface description language for defining data structures that can be serialized and deserialized in a cross-platform way.
BER Encoding
This feature allows you to encode data structures using Basic Encoding Rules (BER), which is one of the encoding rules provided by ASN.1.
const asn1 = require('asn1');
const Ber = asn1.Ber;
const writer = new Ber.Writer();
writer.writeInt(123);
const buffer = writer.buffer;
BER Decoding
This feature allows you to decode data structures that were encoded using BER. You can read various types of data, such as integers, from the buffer.
const asn1 = require('asn1');
const Ber = asn1.Ber;
const reader = new Ber.Reader(buffer);
const number = reader.readInt();
Defining ASN.1 Structures
This feature allows you to define custom ASN.1 structures using a fluent API and then encode them. The example shows how to define a structure with an integer and an octet string.
const asn1 = require('asn1');
const ASN1 = asn1.define('MyStructure', function() {
this.seq().obj(
this.key('id').int(),
this.key('value').octstr()
);
});
const encoded = ASN1.encode({ id: 1, value: Buffer.from('hello') }, 'der');
asn1.js is a similar package that provides a comprehensive set of tools for ASN.1 parsing and serialization in JavaScript. It allows for both DER and BER encoding and is often used in cryptographic operations. It is similar to asn1 but may offer a different API and additional features for handling ASN.1 data structures.
node-forge is a JavaScript library that includes various cryptography tools, including ASN.1 parsing and serialization. While it offers a broader range of cryptographic functions, its ASN.1 capabilities are similar to those of the asn1 package. It differs in that it is part of a larger suite of cryptographic tools rather than being focused solely on ASN.1.
pkijs is a pure JavaScript library that provides the means to work with the Public Key Infrastructure (PKI) built on Web Cryptography API. It includes ASN.1 parsing and serialization as part of its feature set. It is more specialized for PKI operations compared to asn1, which is a general-purpose ASN.1 library.
node-asn1 is a library for encoding and decoding ASN.1 datatypes in pure JS. Currently BER encoding is supported; at some point I'll likely have to do DER.
Mostly, if you're actually needing to read and write ASN.1, you probably don't need this readme to explain what and why. If you have no idea what ASN.1 is, see this: ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc
The source is pretty much self-explanatory, and has read/write methods for the common types out there.
The following reads an ASN.1 sequence with a boolean.
var Ber = require('asn1').Ber;
var reader = new Ber.Reader(Buffer.from([0x30, 0x03, 0x01, 0x01, 0xff]));
reader.readSequence();
console.log('Sequence len: ' + reader.length);
if (reader.peek() === Ber.Boolean)
console.log(reader.readBoolean());
The following generates the same payload as above.
var Ber = require('asn1').Ber;
var writer = new Ber.Writer();
writer.startSequence();
writer.writeBoolean(true);
writer.endSequence();
console.log(writer.buffer);
npm install asn1
MIT.
FAQs
Contains parsers and serializers for ASN.1 (currently BER only)
The npm package asn1 receives a total of 14,535,400 weekly downloads. As such, asn1 popularity was classified as popular.
We found that asn1 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.