JavaScript generic ASN.1 parser (mirror)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add some JSDoc. https://jsdoc.app/

+14 -3
+14 -3
asn1.js
··· 56 56 } 57 57 } 58 58 59 + /** Class to manage a stream of bytes, with a zero-copy approach. 60 + * It uses an existing array or binary string and advances a position index. */ 59 61 class Stream { 60 62 61 63 constructor(enc, pos) { ··· 68 70 this.pos = pos; 69 71 } 70 72 } 73 + /** Get the byte at current position (and increment it) or at a specified position (and avoid moving current position). 74 + * @param {?number} pos read position if specified, else current position (and increment it) */ 71 75 get(pos) { 72 76 if (pos === undefined) 73 77 pos = this.pos++; ··· 75 79 throw new Error('Requesting byte offset ' + pos + ' on a stream of length ' + this.enc.length); 76 80 return (typeof this.enc == 'string') ? this.enc.charCodeAt(pos) : this.enc[pos]; 77 81 } 78 - hexByte(b) { 82 + /** Convert a single byte to an hexadcimal string (of length 2). 83 + * @param {number} b */ 84 + static hexByte(b) { 79 85 return hexDigits.charAt((b >> 4) & 0xF) + hexDigits.charAt(b & 0xF); 80 86 } 81 - /** Hexadecimal dump. 82 - * @param type 'raw', 'byte' or 'dump' */ 87 + /** Hexadecimal dump of a specified region of the stream. 88 + * @param {number} start starting position (included) 89 + * @param {number} end ending position (excluded) 90 + * @param {string} type 'raw', 'byte' or 'dump' */ 83 91 hexDump(start, end, type = 'dump') { 84 92 let s = ''; 85 93 for (let i = start; i < end; ++i) { ··· 95 103 } 96 104 return s; 97 105 } 106 + /** Base-64 dump of a specified region of the stream. 107 + * @param {number} start starting position (included) 108 + * @param {number} end ending position (excluded) */ 98 109 b64Dump(start, end) { 99 110 let extra = (end - start) % 3, 100 111 s = '',