···1+# ChangeLog
2+3+## 2.1.0 - 2025-08-03
4+5+### Changed
6+7+- when fields are CHOICEs now both the field name and the choice name are shown (fixes GitHub #102)
8+- upgrade minimum NodeJS version supported from 12.20.0 to 14.6.0 due to usage of ?. and ?? operators in defs.js (ECMAScript 2020); older code is still linted against ECMAScript 2015 for now
9+10+### Added
11+12+- add tests to check expected decoding
13+14+## 2.0.6 - 2025-07-29
15+16+### Added
17+18+- add proper support for standard Base64 (we previously only supported Base64url) (fixes GitHub #99)
19+- improve test harness
20+21+## 2.0.5 - 2025-04-12
22+23+### Added
24+25+- add `index-local.html` for local `file://` usage without needing a web server
26+- add definitions support for `LDAPMessage`
27+- #TODO continue producing old ChangeLog entries
+1-1
LICENSE
···1ISC License
23-Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
45Permission to use, copy, modify, and/or distribute this software for any
6purpose with or without fee is hereby granted, provided that the above
···1ISC License
23+Copyright (c) 2008-2025 Lapo Luchini <lapo@lapo.it>
45Permission to use, copy, modify, and/or distribute this software for any
6purpose with or without fee is hereby granted, provided that the above
+17-3
README.md
···34asn1js is a JavaScript generic ASN.1 parser/decoder that can decode any valid ASN.1 DER or BER structures.
56-An example page that can decode Base64-encoded (raw base64, PEM armoring and `begin-base64` are recognized) or Hex-encoded (or local files with some browsers) is included and can be used both [online on the official website](https://lapo.it/asn1js/) or [offline (ZIP file)](https://lapo.it/asn1js/asn1js.zip).
78Usage with `nodejs`
9-------------------
···64</script>
65```
660000000000000067ISC license
68-----------
6970-ASN.1 JavaScript decoder Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
7172Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
73···8990- [official website](https://lapo.it/asn1js/)
91- [dedicated domain](https://asn1js.eu/)
92-- [single-file version working locally](https://asn1js.eu/index-local.html) (just save this link)
93- [InDefero tracker](http://idf.lapo.it/p/asn1js/)
94- [GitHub mirror](https://github.com/lapo-luchini/asn1js)
095- [Ohloh code stats](https://www.openhub.net/p/asn1js)
···34asn1js is a JavaScript generic ASN.1 parser/decoder that can decode any valid ASN.1 DER or BER structures.
56+An example page that can decode Base64-encoded (raw base64, PEM armoring and `begin-base64` are recognized) or Hex-encoded (or local files with some browsers) is included and can be used both [online on the official website](https://asn1js.eu/) or [offline (ZIP file)](https://lapo.it/asn1js/asn1js.zip) by opening `index-local.html`.
78Usage with `nodejs`
9-------------------
···64</script>
65```
6667+Local usage
68+--------------------
69+70+Since unfortunately ESM modules are not working on `file:` protocol due to [CORS issues](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#other_differences_between_modules_and_standard_scripts), there is a bundled [single-file version working locally](https://asn1js.eu/index-local.html). It doesn't work online (due to [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) restrictions about inline content) but can be saved locally and opened in a browser.
71+72+Usage from CLI
73+--------------------
74+75+You can dump an ASN.1 structure from the command line using the following command (no need to even install it):
76+77+```sh
78+npx @lapo/asn1js ed25519.cer
79+```
80+81ISC license
82-----------
8384+ASN.1 JavaScript decoder Copyright (c) 2008-2025 Lapo Luchini <lapo@lapo.it>
8586Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
87···103104- [official website](https://lapo.it/asn1js/)
105- [dedicated domain](https://asn1js.eu/)
0106- [InDefero tracker](http://idf.lapo.it/p/asn1js/)
107- [GitHub mirror](https://github.com/lapo-luchini/asn1js)
108+- [ChangeLog on GitHub](https://github.com/lapo-luchini/asn1js/blob/trunk/CHANGELOG.md)
109- [Ohloh code stats](https://www.openhub.net/p/asn1js)
+55-24
asn1.js
···1// ASN.1 JavaScript decoder
2-// Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7-//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···21 reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|(-(?:0\d|1[0-2])|[+](?:0\d|1[0-4]))([0-5]\d)?)?$/,
22 reTimeL = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|(-(?:0\d|1[0-2])|[+](?:0\d|1[0-4]))([0-5]\d)?)?$/,
23 hexDigits = '0123456789ABCDEF',
24- b64Safe = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
025 tableT61 = [
26 ['', ''],
27 ['AEIOUaeiou', 'รรรรรร รจรฌรฒรน'], // Grave
···56 }
57}
5859-class Stream {
0060000061 constructor(enc, pos) {
62 if (enc instanceof Stream) {
63 this.enc = enc.enc;
64 this.pos = enc.pos;
65 } else {
66- // enc should be an array or a binary string
67 this.enc = enc;
68 this.pos = pos;
69 }
0000000070 }
0071 get(pos) {
72 if (pos === undefined)
73 pos = this.pos++;
74 if (pos >= this.enc.length)
75 throw new Error('Requesting byte offset ' + pos + ' on a stream of length ' + this.enc.length);
76- return (typeof this.enc == 'string') ? this.enc.charCodeAt(pos) : this.enc[pos];
77 }
78- hexByte(b) {
0079 return hexDigits.charAt((b >> 4) & 0xF) + hexDigits.charAt(b & 0xF);
80 }
81- /** Hexadecimal dump.
82- * @param type 'raw', 'byte' or 'dump' */
0083 hexDump(start, end, type = 'dump') {
84 let s = '';
85 for (let i = start; i < end; ++i) {
86 if (type == 'byte' && i > start)
87 s += ' ';
88- s += this.hexByte(this.get(i));
89 if (type == 'dump')
90 switch (i & 0xF) {
91 case 0x7: s += ' '; break;
···95 }
96 return s;
97 }
98- b64Dump(start, end) {
0000099 let extra = (end - start) % 3,
100 s = '',
101 i, c;
102 for (i = start; i + 2 < end; i += 3) {
103 c = this.get(i) << 16 | this.get(i + 1) << 8 | this.get(i + 2);
104- s += b64Safe.charAt(c >> 18 & 0x3F);
105- s += b64Safe.charAt(c >> 12 & 0x3F);
106- s += b64Safe.charAt(c >> 6 & 0x3F);
107- s += b64Safe.charAt(c & 0x3F);
108 }
109 if (extra > 0) {
110 c = this.get(i) << 16;
111 if (extra > 1) c |= this.get(i + 1) << 8;
112- s += b64Safe.charAt(c >> 18 & 0x3F);
113- s += b64Safe.charAt(c >> 12 & 0x3F);
114- if (extra == 2) s += b64Safe.charAt(c >> 6 & 0x3F);
0115 }
116 return s;
117 }
···269 s = this.parseStringUTF(start, end, maxLength);
270 checkPrintable(s.str);
271 return { size: end - start, str: s.str };
272- } catch (e) {
273 // ignore
274 }
275 maxLength /= 2; // we work in bytes
···277 end = start + maxLength;
278 s = '';
279 for (let i = start; i < end; ++i)
280- s += this.hexByte(this.get(i));
281 if (len > maxLength)
282 s += ellipsis;
283 return { size: len, str: s };
···435 }
436 switch (this.tag.tagNumber) {
437 case 0x01: // BOOLEAN
0438 return (this.stream.get(content) === 0) ? 'false' : 'true';
439 case 0x02: // INTEGER
0440 return this.stream.parseInteger(content, content + len);
441 case 0x03: { // BIT_STRING
442 let d = recurse(this, 'parseBitString', maxLength);
443 return '(' + d.size + ' bit)\n' + d.str;
444 }
445 case 0x04: { // OCTET_STRING
0446 let d = recurse(this, 'parseOctetString', maxLength);
447 return '(' + d.size + ' byte)\n' + d.str;
448 }
···535 toHexString(type = 'raw') {
536 return this.stream.hexDump(this.posStart(), this.posEnd(), type);
537 }
538- /** Base64 dump of the node. */
539- toB64String() {
540- return this.stream.b64Dump(this.posStart(), this.posEnd());
00541 }
542 static decodeLength(stream) {
543 let buf = stream.get(),
···610 throw new Error('Unable to parse content: ' + e);
611 }
612 }
613- } catch (e) {
614 // but silently ignore when they don't
615 sub = null;
616 //DEBUG console.log('Could not decode structure at ' + start + ':', e);
···1// ASN.1 JavaScript decoder
2+// Copyright (c) 2008 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7+//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···21 reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|(-(?:0\d|1[0-2])|[+](?:0\d|1[0-4]))([0-5]\d)?)?$/,
22 reTimeL = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|(-(?:0\d|1[0-2])|[+](?:0\d|1[0-4]))([0-5]\d)?)?$/,
23 hexDigits = '0123456789ABCDEF',
24+ b64Std = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
25+ b64URL = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_',
26 tableT61 = [
27 ['', ''],
28 ['AEIOUaeiou', 'รรรรรร รจรฌรฒรน'], // Grave
···57 }
58}
5960+/** Class to manage a stream of bytes, with a zero-copy approach.
61+ * It uses an existing array or binary string and advances a position index. */
62+export class Stream {
6364+ /**
65+ * @param {Stream|array|string} enc data (will not be copied)
66+ * @param {?number} pos starting position (mandatory when `end` is not a Stream)
67+ */
68 constructor(enc, pos) {
69 if (enc instanceof Stream) {
70 this.enc = enc.enc;
71 this.pos = enc.pos;
72 } else {
073 this.enc = enc;
74 this.pos = pos;
75 }
76+ if (typeof this.pos != 'number')
77+ throw new Error('"pos" must be a numeric value');
78+ if (typeof this.enc == 'string')
79+ this.getRaw = pos => this.enc.charCodeAt(pos);
80+ else if (typeof this.enc[0] == 'number')
81+ this.getRaw = pos => this.enc[pos];
82+ else
83+ throw new Error('"enc" must be a numeric array or a string');
84 }
85+ /** Get the byte at current position (and increment it) or at a specified position (and avoid moving current position).
86+ * @param {?number} pos read position if specified, else current position (and increment it) */
87 get(pos) {
88 if (pos === undefined)
89 pos = this.pos++;
90 if (pos >= this.enc.length)
91 throw new Error('Requesting byte offset ' + pos + ' on a stream of length ' + this.enc.length);
92+ return this.getRaw(pos);
93 }
94+ /** Convert a single byte to an hexadcimal string (of length 2).
95+ * @param {number} b */
96+ static hexByte(b) {
97 return hexDigits.charAt((b >> 4) & 0xF) + hexDigits.charAt(b & 0xF);
98 }
99+ /** Hexadecimal dump of a specified region of the stream.
100+ * @param {number} start starting position (included)
101+ * @param {number} end ending position (excluded)
102+ * @param {string} type 'raw', 'byte' or 'dump' (default) */
103 hexDump(start, end, type = 'dump') {
104 let s = '';
105 for (let i = start; i < end; ++i) {
106 if (type == 'byte' && i > start)
107 s += ' ';
108+ s += Stream.hexByte(this.get(i));
109 if (type == 'dump')
110 switch (i & 0xF) {
111 case 0x7: s += ' '; break;
···115 }
116 return s;
117 }
118+ /** Base64url dump of a specified region of the stream (according to RFC 4648 section 5).
119+ * @param {number} start starting position (included)
120+ * @param {number} end ending position (excluded)
121+ * @param {string} type 'url' (default, section 5 without padding) or 'std' (section 4 with padding) */
122+ b64Dump(start, end, type = 'url') {
123+ const b64 = type === 'url' ? b64URL : b64Std;
124 let extra = (end - start) % 3,
125 s = '',
126 i, c;
127 for (i = start; i + 2 < end; i += 3) {
128 c = this.get(i) << 16 | this.get(i + 1) << 8 | this.get(i + 2);
129+ s += b64.charAt(c >> 18 & 0x3F);
130+ s += b64.charAt(c >> 12 & 0x3F);
131+ s += b64.charAt(c >> 6 & 0x3F);
132+ s += b64.charAt(c & 0x3F);
133 }
134 if (extra > 0) {
135 c = this.get(i) << 16;
136 if (extra > 1) c |= this.get(i + 1) << 8;
137+ s += b64.charAt(c >> 18 & 0x3F);
138+ s += b64.charAt(c >> 12 & 0x3F);
139+ if (extra == 2) s += b64.charAt(c >> 6 & 0x3F);
140+ if (b64 === b64Std) s += '==='.slice(0, 3 - extra);
141 }
142 return s;
143 }
···295 s = this.parseStringUTF(start, end, maxLength);
296 checkPrintable(s.str);
297 return { size: end - start, str: s.str };
298+ } catch (ignore) {
299 // ignore
300 }
301 maxLength /= 2; // we work in bytes
···303 end = start + maxLength;
304 s = '';
305 for (let i = start; i < end; ++i)
306+ s += Stream.hexByte(this.get(i));
307 if (len > maxLength)
308 s += ellipsis;
309 return { size: len, str: s };
···461 }
462 switch (this.tag.tagNumber) {
463 case 0x01: // BOOLEAN
464+ if (len === 0) return 'invalid length 0';
465 return (this.stream.get(content) === 0) ? 'false' : 'true';
466 case 0x02: // INTEGER
467+ if (len === 0) return 'invalid length 0';
468 return this.stream.parseInteger(content, content + len);
469 case 0x03: { // BIT_STRING
470 let d = recurse(this, 'parseBitString', maxLength);
471 return '(' + d.size + ' bit)\n' + d.str;
472 }
473 case 0x04: { // OCTET_STRING
474+ if (len === 0) return 'invalid length 0';
475 let d = recurse(this, 'parseOctetString', maxLength);
476 return '(' + d.size + ' byte)\n' + d.str;
477 }
···564 toHexString(type = 'raw') {
565 return this.stream.hexDump(this.posStart(), this.posEnd(), type);
566 }
567+ /** Base64url dump of the node (according to RFC 4648 section 5).
568+ * @param {string} type 'url' (default, section 5 without padding) or 'std' (section 4 with padding)
569+ */
570+ toB64String(type = 'url') {
571+ return this.stream.b64Dump(this.posStart(), this.posEnd(), type);
572 }
573 static decodeLength(stream) {
574 let buf = stream.get(),
···641 throw new Error('Unable to parse content: ' + e);
642 }
643 }
644+ } catch (ignore) {
645 // but silently ignore when they don't
646 sub = null;
647 //DEBUG console.log('Could not decode structure at ' + start + ':', e);
+8-7
base64.js
···1// Base64 JavaScript decoder
2-// Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7-//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···31 decoder[b64.charCodeAt(i)] = i;
32 for (i = 0; i < ignore.length; ++i)
33 decoder[ignore.charCodeAt(i)] = -1;
34- // RFC 3548 URL & file safe encoding
35 decoder['-'.charCodeAt(0)] = decoder['+'.charCodeAt(0)];
36 decoder['_'.charCodeAt(0)] = decoder['/'.charCodeAt(0)];
37 }
···7576 static pretty(str) {
77 // fix padding
78- if (str.length % 4 > 0)
79- str = (str + '===').slice(0, str.length + str.length % 4);
80- // convert RFC 3548 to standard Base64
081 str = str.replace(/-/g, '+').replace(/_/g, '/');
82 // 80 column width
83- return str.replace(/(.{80})/g, '$1\n');
84 }
8586 static unarmor(a) {
···1// Base64 JavaScript decoder
2+// Copyright (c) 2008 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7+//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···31 decoder[b64.charCodeAt(i)] = i;
32 for (i = 0; i < ignore.length; ++i)
33 decoder[ignore.charCodeAt(i)] = -1;
34+ // also support decoding Base64url (RFC 4648 section 5)
35 decoder['-'.charCodeAt(0)] = decoder['+'.charCodeAt(0)];
36 decoder['_'.charCodeAt(0)] = decoder['/'.charCodeAt(0)];
37 }
···7576 static pretty(str) {
77 // fix padding
78+ let pad = 4 - str.length % 4;
79+ if (pad < 4)
80+ str += '==='.slice(0, pad);
81+ // convert Base64url (RFC 4648 section 5) to standard Base64 (RFC 4648 section 4)
82 str = str.replace(/-/g, '+').replace(/_/g, '/');
83 // 80 column width
84+ return str.replace(/.{80}/g, '$&\n');
85 }
8687 static unarmor(a) {
···1+CRL example from RFC5280 as found here:
2+https://csrc.nist.gov/projects/pki-testing/sample-certificates-and-crls
3+4+begin-base64 644 crl-rfc5280.der
5+MIIBYDCBygIBATANBgkqhkiG9w0BAQUFADBDMRMwEQYKCZImiZPyLGQBGRYDY29tMRcwFQYKCZIm
6+iZPyLGQBGRYHZXhhbXBsZTETMBEGA1UEAxMKRXhhbXBsZSBDQRcNMDUwMjA1MTIwMDAwWhcNMDUw
7+MjA2MTIwMDAwWjAiMCACARIXDTA0MTExOTE1NTcwM1owDDAKBgNVHRUEAwoBAaAvMC0wHwYDVR0j
8+BBgwFoAUCGivhTPIOUp6+IKTjnBqSiCELDIwCgYDVR0UBAMCAQwwDQYJKoZIhvcNAQEFBQADgYEA
9+ItwYffcIzsx10NBqm60Q9HYjtIFutW2+DvsVFGzIF20f7pAXom9g5L2qjFXejoRvkvifEBInr0rU
10+L4XiNkR9qqNMJTgV/wD9Pn7uPSYS69jnK2LiK8NGgO94gtEVxtCccmrLznrtZ5mLbnCBfUNCdMGm
11+r8FVF6IzTNYGmCuk/C4=
12+====
+45
examples/crl-rfc5280.b64.dump
···000000000000000000000000000000000000000000000
···1+CertificateList SEQUENCE @0+352 (constructed): (3 elem)
2+ tbsCertList TBSCertList SEQUENCE @4+202 (constructed): (7 elem)
3+ version Version INTEGER @7+1: 1
4+ signature AlgorithmIdentifier SEQUENCE @10+13 (constructed): (2 elem)
5+ algorithm OBJECT_IDENTIFIER @12+9: 1.2.840.113549.1.1.5|sha1WithRSAEncryption|PKCS #1
6+ parameters ANY NULL @23+0
7+ issuer rdnSequence Name SEQUENCE @25+67 (constructed): (3 elem)
8+ RelativeDistinguishedName SET @27+19 (constructed): (1 elem)
9+ AttributeTypeAndValue SEQUENCE @29+17 (constructed): (2 elem)
10+ type AttributeType OBJECT_IDENTIFIER @31+10: 0.9.2342.19200300.100.1.25|domainComponent|Men are from Mars, this OID is from Pluto
11+ value AttributeValue [?] IA5String @43+3: com
12+ RelativeDistinguishedName SET @48+23 (constructed): (1 elem)
13+ AttributeTypeAndValue SEQUENCE @50+21 (constructed): (2 elem)
14+ type AttributeType OBJECT_IDENTIFIER @52+10: 0.9.2342.19200300.100.1.25|domainComponent|Men are from Mars, this OID is from Pluto
15+ value AttributeValue [?] IA5String @64+7: example
16+ RelativeDistinguishedName SET @73+19 (constructed): (1 elem)
17+ AttributeTypeAndValue SEQUENCE @75+17 (constructed): (2 elem)
18+ type AttributeType OBJECT_IDENTIFIER @77+3: 2.5.4.3|commonName|X.520 DN component
19+ value AttributeValue [?] PrintableString @82+10: Example CA
20+ thisUpdate utcTime Time UTCTime @94+13: 2005-02-05 12:00:00 UTC
21+ nextUpdate utcTime Time UTCTime @109+13: 2005-02-06 12:00:00 UTC
22+ revokedCertificates SEQUENCE @124+34 (constructed): (1 elem)
23+ SEQUENCE @126+32 (constructed): (3 elem)
24+ userCertificate CertificateSerialNumber INTEGER @128+1: 18
25+ revocationDate utcTime Time UTCTime @131+13: 2004-11-19 15:57:03 UTC
26+ crlEntryExtensions Extensions SEQUENCE @146+12 (constructed): (1 elem)
27+ Extension SEQUENCE @148+10 (constructed): (2 elem)
28+ extnID OBJECT_IDENTIFIER @150+3: 2.5.29.21|cRLReason|X.509 extension
29+ extnValue OCTET_STRING @155+3 (encapsulates): (3 byte)|0A0101
30+ ENUMERATED @157+1: 1
31+ crlExtensions [0] @160+47 (constructed): (1 elem)
32+ Extensions SEQUENCE @162+45 (constructed): (2 elem)
33+ Extension SEQUENCE @164+31 (constructed): (2 elem)
34+ extnID OBJECT_IDENTIFIER @166+3: 2.5.29.35|authorityKeyIdentifier|X.509 extension
35+ extnValue OCTET_STRING @171+24 (encapsulates): (24 byte)|301680140868AF8533C8394A7AF882938E706A4A20842C32
36+ SEQUENCE @173+22 (constructed): (1 elem)
37+ [0] @175+20: (20 byte)|0868AF8533C8394A7AF882938E706A4A20842C32
38+ Extension SEQUENCE @197+10 (constructed): (2 elem)
39+ extnID OBJECT_IDENTIFIER @199+3: 2.5.29.20|cRLNumber|X.509 extension
40+ extnValue OCTET_STRING @204+3 (encapsulates): (3 byte)|02010C
41+ INTEGER @206+1: 12
42+ signatureAlgorithm AlgorithmIdentifier SEQUENCE @209+13 (constructed): (2 elem)
43+ algorithm OBJECT_IDENTIFIER @211+9: 1.2.840.113549.1.1.5|sha1WithRSAEncryption|PKCS #1
44+ parameters ANY NULL @222+0
45+ signature BIT_STRING @224+129: (1024 bit)|0010001011011100000110000111110111110111000010001100111011001100011101011101000011010000011010101001101110101101000100001111010001110110001000111011010010000001011011101011010101101101101111100000111011111011000101010001010001101100110010000001011101101101000111111110111010010000000101111010001001101111011000001110010010111101101010101000110001010101110111101000111010000100011011111001001011111000100111110001000000010010001001111010111101001010110101000010111110000101111000100011011001000100011111011010101010100011010011000010010100111000000101011111111100000000111111010011111001111110111011100011110100100110000100101110101111011000111001110010101101100010111000100010101111000011010001101000000011101111011110001000001011010001000101011100011011010000100111000111001001101010110010111100111001111010111011010110011110011001100010110110111001110000100000010111110101000011010000100111010011000001101001101010111111000001010101010001011110100010001100110100110011010110000001101001100000101011101001001111110000101110
···1+LDAPMessage example as found on ldap.com.
2+3+Original link:
4+https://ldap.com/ldapv3-wire-protocol-reference-ldap-message/
5+6+begin-base64 644 ldapmessage.der
7+MDUCAQVKEWRjPWV4YW1wbGUsZGM9Y29toB0wGwQWMS4yLjg0MC4xMTM1NTYuMS40LjgwNQEB/w==
8+====
···1// Hex JavaScript decoder
2-// Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7-//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···1// Hex JavaScript decoder
2+// Copyright (c) 2008 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7+//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···01import { ASN1DOM } from './dom.js';
2import { Base64 } from './base64.js';
3import { Hex } from './hex.js';
···15 area = id('area'),
16 file = id('file'),
17 examples = id('examples'),
18- selectTheme = id('theme-select'),
19 selectDefs = id('definitions'),
20 selectTag = id('tags');
21···41function show(asn1) {
42 tree.innerHTML = '';
43 dump.innerHTML = '';
44- tree.appendChild(asn1.toDOM());
00045 if (wantHex.checked) dump.appendChild(asn1.toHexDOM(undefined, trimHex.checked));
46}
47export function decode(der, offset) {
···83 if (area.value === '') area.value = Base64.pretty(b64);
84 try {
85 window.location.hash = hash = '#' + b64;
86- } catch (e) {
87 // fails with "Access Denied" on IE with URLs longer than ~2048 chars
88 window.location.hash = hash = '#';
89 }
···119 else if (Base64.re.test(str)) der = Base64.unarmor(str);
120 else der = str;
121 decode(der);
122- } catch (e) {
123 text(tree, 'Cannot decode file.');
124 dump.innerHTML = '';
125 }
···157 let elem = id(name);
158 if (elem)
159 elem.onclick = onClick;
160-}
161-// set dark theme depending on OS settings
162-function setTheme() {
163- if (!selectTheme) {
164- console.log('Themes are currently not working with single file version.');
165- return;
166- }
167- let storedTheme = localStorage.getItem('theme');
168- let theme = 'os';
169- if (storedTheme)
170- theme = storedTheme;
171- selectTheme.value = theme;
172- if (theme == 'os') {
173- let prefersDarkScheme = window.matchMedia('(prefers-color-scheme: dark)');
174- theme = prefersDarkScheme.matches ? 'dark': 'light';
175- }
176- if (theme == 'dark') {
177- const css1 = id('theme-base');
178- const css2 = css1.cloneNode();
179- css2.id = 'theme-override';
180- css2.href = 'index-' + theme + '.css';
181- css1.parentElement.appendChild(css2);
182- } else {
183- const css2 = id('theme-override');
184- if (css2) css2.remove();
185- }
186-}
187-setTheme();
188-if (selectTheme) {
189- selectTheme.addEventListener('change', function () {
190- localStorage.setItem('theme', selectTheme.value);
191- setTheme();
192- });
193}
194// this is only used if window.FileReader
195function read(f) {
···1+import './theme.js';
2import { ASN1DOM } from './dom.js';
3import { Base64 } from './base64.js';
4import { Hex } from './hex.js';
···16 area = id('area'),
17 file = id('file'),
18 examples = id('examples'),
019 selectDefs = id('definitions'),
20 selectTag = id('tags');
21···41function show(asn1) {
42 tree.innerHTML = '';
43 dump.innerHTML = '';
44+ let ul = document.createElement('ul');
45+ ul.className = 'treecollapse';
46+ tree.appendChild(ul);
47+ ul.appendChild(asn1.toDOM());
48 if (wantHex.checked) dump.appendChild(asn1.toHexDOM(undefined, trimHex.checked));
49}
50export function decode(der, offset) {
···86 if (area.value === '') area.value = Base64.pretty(b64);
87 try {
88 window.location.hash = hash = '#' + b64;
89+ } catch (ignore) {
90 // fails with "Access Denied" on IE with URLs longer than ~2048 chars
91 window.location.hash = hash = '#';
92 }
···122 else if (Base64.re.test(str)) der = Base64.unarmor(str);
123 else der = str;
124 decode(der);
125+ } catch (ignore) {
126 text(tree, 'Cannot decode file.');
127 dump.innerHTML = '';
128 }
···160 let elem = id(name);
161 if (elem)
162 elem.onclick = onClick;
000000000000000000000000000000000163}
164// this is only used if window.FileReader
165function read(f) {
+15-9
int10.js
···1// Big integer base-10 printing library
2-// Copyright (c) 2008-2024 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7-//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1516-let max = 10000000000000; // biggest 10^n integer that can still fit 2^53 when multiplied by 256
01718export class Int10 {
19 /**
···2627 /**
28 * Multiply value by m and add c.
29- * @param {number} m - multiplier, must be < =256
30- * @param {number} c - value to add
31 */
32 mulAdd(m, c) {
033 // assert(m <= 256)
034 let b = this.buf,
35 l = b.length,
36 i, t;
···7172 /**
73 * Convert to decimal string representation.
74- * @param {*} base - optional value, only value accepted is 10
075 */
76- toString(base) {
77- if ((base || 10) != 10)
78- throw 'only base 10 is supported';
79 let b = this.buf,
80 s = b[b.length - 1].toString();
81 for (let i = b.length - 2; i >= 0; --i)
···86 /**
87 * Convert to Number value representation.
88 * Will probably overflow 2^53 and thus become approximate.
089 */
90 valueOf() {
91 let b = this.buf,
···9798 /**
99 * Return value as a simple Number (if it is <= 10000000000000), or return this.
0100 */
101 simplify() {
102 let b = this.buf;
···1// Big integer base-10 printing library
2+// Copyright (c) 2008 Lapo Luchini <lapo@lapo.it>
34// Permission to use, copy, modify, and/or distribute this software for any
5// purpose with or without fee is hereby granted, provided that the above
6// copyright notice and this permission notice appear in all copies.
7+//
8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
···13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1516+/** Biggest 10^n integer that can still fit 2^53 when multiplied by 256. */
17+const max = 10000000000000;
1819export class Int10 {
20 /**
···2728 /**
29 * Multiply value by m and add c.
30+ * @param {number} m - multiplier, must be 0<m<=256
31+ * @param {number} c - value to add, must be c>=0
32 */
33 mulAdd(m, c) {
34+ // assert(m > 0)
35 // assert(m <= 256)
36+ // assert(c >= 0)
37 let b = this.buf,
38 l = b.length,
39 i, t;
···7475 /**
76 * Convert to decimal string representation.
77+ * @param {number} [base=10] - optional value, only value accepted is 10
78+ * @returns {string} The decimal string representation.
79 */
80+ toString(base = 10) {
81+ if (base != 10)
82+ throw new Error('only base 10 is supported');
83 let b = this.buf,
84 s = b[b.length - 1].toString();
85 for (let i = b.length - 2; i >= 0; --i)
···90 /**
91 * Convert to Number value representation.
92 * Will probably overflow 2^53 and thus become approximate.
93+ * @returns {number} The numeric value.
94 */
95 valueOf() {
96 let b = this.buf,
···102103 /**
104 * Return value as a simple Number (if it is <= 10000000000000), or return this.
105+ * @returns {number | Int10} The simplified value.
106 */
107 simplify() {
108 let b = this.buf;
···1-// content parsed from ASN.1 definitions as found in the following RFCs: 5280 5208 3369 3161 2986 4211 4210 8017
2// Copyright (C) The IETF Trust (2008)
3// as far as I can tell this file is allowed under the following clause:
4// It is acceptable under the current IETF rules (RFC 5378) to modify extracted code if necessary.
···1983 "CountryName": {
1984 "name": "CountryName",
1985 "type": {
1986- "name": "[1]",
1987 "type": "tag",
1988 "class": "APPLICATION",
1989 "explicit": true,
···2015 "AdministrationDomainName": {
2016 "name": "AdministrationDomainName",
2017 "type": {
2018- "name": "[2]",
2019 "type": "tag",
2020 "class": "APPLICATION",
2021 "explicit": true,
···10369 "type": {
10370 "name": "AlgorithmIdentifier",
10371 "type": "defined"
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010372 }
10373 }
10374 }