{"library":"parse-asn1","title":"ASN.1 Parser Utility","description":"parse-asn1 is a utility library designed for parsing Abstract Syntax Notation One (ASN.1) encoded data. It is primarily used within the `crypto-browserify` ecosystem, serving as a dependency for libraries like `browserify-sign` to handle cryptographic artifacts such as X.509 certificates and private keys. The current stable version is 5.1.9, with the last update approximately 7 months ago, indicating a maintenance-focused release cadence. The library provides a JavaScript implementation for interpreting BER/DER encoded binary data into a structured JavaScript object. A key differentiator is its role in providing browser compatibility for Node.js's crypto functionalities, though ASN.1 parsing itself is inherently complex and a common source of security vulnerabilities if not handled robustly.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install parse-asn1"],"cli":null},"imports":["import parseASN1 from 'parse-asn1';\n// Or for CommonJS:\nconst parseASN1 = require('parse-asn1');"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import parseASN1 from 'parse-asn1';\nimport { Buffer } from 'buffer';\n\n// Example: A simple DER-encoded ASN.1 sequence\n// This represents a SEQUENCE containing an INTEGER (value 1) and a BOOLEAN (value true)\n// 30 07         -- Sequence, length 7\n//   02 01 01    -- Integer, length 1, value 1\n//   01 01 ff    -- Boolean, length 1, value true\nconst asn1DerBuffer = Buffer.from([\n  0x30, 0x07,\n  0x02, 0x01, 0x01,\n  0x01, 0x01, 0xFF\n]);\n\ntry {\n  const parsed = parseASN1(asn1DerBuffer);\n  console.log('Successfully parsed ASN.1 data:');\n  console.log(JSON.stringify(parsed, null, 2));\n\n  // Accessing elements (example output structure might vary slightly)\n  if (parsed && Array.isArray(parsed.value)) {\n    const integerNode = parsed.value[0];\n    const booleanNode = parsed.value[1];\n    console.log(`First element (Integer): Type ${integerNode.type}, Value ${integerNode.value.toString('hex')}`);\n    console.log(`Second element (Boolean): Type ${booleanNode.type}, Value ${booleanNode.value.toString('hex')}`);\n  }\n\n} catch (error) {\n  console.error('Error parsing ASN.1 data:', error.message);\n}\n\n// Another example: a simple OID\n// 06 03 2A 86 48 (1.2.840)\nconst oidBuffer = Buffer.from([0x06, 0x03, 0x2A, 0x86, 0x48]);\ntry {\n  const parsedOid = parseASN1(oidBuffer);\n  console.log('\\nSuccessfully parsed OID:');\n  console.log(JSON.stringify(parsedOid, null, 2));\n} catch (error) {\n  console.error('Error parsing OID:', error.message);\n}","lang":"javascript","description":"This quickstart demonstrates how to use `parse-asn1` to decode a simple DER-encoded ASN.1 sequence and an Object Identifier (OID) from a Buffer and print the resulting JavaScript object structure.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}