@lapo/asn1js 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/asn1.js +5 -5
- package/dumpASN1.js +9 -3
- package/package.json +8 -8
package/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
ISC License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2008-
|
|
3
|
+
Copyright (c) 2008-2026 Lapo Luchini <lapo@lapo.it>
|
|
4
4
|
|
|
5
5
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
purpose with or without fee is hereby granted, provided that the above
|
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ npx @lapo/asn1js ed25519.cer
|
|
|
81
81
|
ISC license
|
|
82
82
|
-----------
|
|
83
83
|
|
|
84
|
-
ASN.1 JavaScript decoder Copyright (c) 2008-
|
|
84
|
+
ASN.1 JavaScript decoder Copyright (c) 2008-2026 Lapo Luchini <lapo@lapo.it>
|
|
85
85
|
|
|
86
86
|
Permission 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
87
|
|
package/asn1.js
CHANGED
|
@@ -76,7 +76,7 @@ export class Stream {
|
|
|
76
76
|
/**
|
|
77
77
|
* Creates a new Stream object.
|
|
78
78
|
* @param {Stream|array|string} enc data (will not be copied)
|
|
79
|
-
* @param {?number} pos starting position (mandatory when `
|
|
79
|
+
* @param {?number} pos starting position (mandatory when `enc` is not a Stream)
|
|
80
80
|
*/
|
|
81
81
|
constructor(enc, pos) {
|
|
82
82
|
if (enc instanceof Stream) {
|
|
@@ -773,7 +773,7 @@ export class ASN1 {
|
|
|
773
773
|
throw new Error('Length over 48 bits not supported at position ' + (stream.pos - 1));
|
|
774
774
|
let value = 0;
|
|
775
775
|
for (let i = 0; i < len; ++i)
|
|
776
|
-
value = (value
|
|
776
|
+
value = (value * 256) + stream.get();
|
|
777
777
|
return value;
|
|
778
778
|
}
|
|
779
779
|
|
|
@@ -795,15 +795,13 @@ export class ASN1 {
|
|
|
795
795
|
tagLen = stream.pos - streamStart.pos,
|
|
796
796
|
len = ASN1.decodeLength(stream),
|
|
797
797
|
start = stream.pos,
|
|
798
|
+
end = (len !== null) ? (start + len) : null,
|
|
798
799
|
header = start - streamStart.pos,
|
|
799
800
|
sub = null,
|
|
800
801
|
getSub = function () {
|
|
801
802
|
sub = [];
|
|
802
803
|
if (len !== null) {
|
|
803
804
|
// definite length
|
|
804
|
-
let end = start + len;
|
|
805
|
-
if (end > stream.enc.length)
|
|
806
|
-
throw new Error('Container at offset ' + start + ' has a length of ' + len + ', which is past the end of the stream');
|
|
807
805
|
while (stream.pos < end)
|
|
808
806
|
sub[sub.length] = type.decode(stream);
|
|
809
807
|
if (stream.pos != end)
|
|
@@ -823,6 +821,8 @@ export class ASN1 {
|
|
|
823
821
|
}
|
|
824
822
|
}
|
|
825
823
|
};
|
|
824
|
+
if (end !== null && end > stream.enc.length)
|
|
825
|
+
throw new Error('Element at offset ' + start + ' has a length of ' + len + ', which is past the end of the stream');
|
|
826
826
|
if (tag.tagConstructed) {
|
|
827
827
|
// must have valid content
|
|
828
828
|
getSub();
|
package/dumpASN1.js
CHANGED
|
@@ -3,8 +3,10 @@
|
|
|
3
3
|
// usage:
|
|
4
4
|
// ./dumpASN1.js filename
|
|
5
5
|
// ./dumpASN1.js data:base64,MDMCAQFjLgQACgEACgEAAgEAAgEAAQEAoA+jDQQFTnRWZXIEBAEAAAAwCgQITmV0bG9nb24===
|
|
6
|
+
// cat file.der | ./dumpASN1.js -
|
|
6
7
|
|
|
7
8
|
import * as fs from 'node:fs';
|
|
9
|
+
import { text as streamAsString } from 'node:stream/consumers';
|
|
8
10
|
import { Base64 } from './base64.js';
|
|
9
11
|
import { ASN1 } from './asn1.js';
|
|
10
12
|
import { Defs } from './defs.js';
|
|
@@ -46,10 +48,14 @@ function print(value, indent) {
|
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
const filename = process.argv[2];
|
|
51
|
+
let content;
|
|
49
52
|
const match = reDataURI.exec(filename);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
if (match)
|
|
54
|
+
content = Buffer.from(match[1]);
|
|
55
|
+
else if (filename == '-') // stdin
|
|
56
|
+
content = await streamAsString(process.stdin);
|
|
57
|
+
else
|
|
58
|
+
content = fs.readFileSync(filename);
|
|
53
59
|
try { // try PEM first
|
|
54
60
|
content = Base64.unarmor(content);
|
|
55
61
|
} catch (ignore) { // try DER/BER then
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lapo/asn1js",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Generic ASN.1 parser/decoder that can decode any valid ASN.1 DER or BER structures.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "asn1.js",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
},
|
|
47
47
|
"packageManager": "pnpm@7.33.7",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@eslint/eslintrc": "^3.3.
|
|
50
|
-
"@eslint/js": "^9.
|
|
51
|
-
"@rollup/wasm-node": "^4.
|
|
52
|
-
"diff": "^8.0.
|
|
53
|
-
"eslint": "^9.
|
|
54
|
-
"globals": "^16.
|
|
49
|
+
"@eslint/eslintrc": "^3.3.4",
|
|
50
|
+
"@eslint/js": "^9.39.3",
|
|
51
|
+
"@rollup/wasm-node": "^4.59.0",
|
|
52
|
+
"diff": "^8.0.3",
|
|
53
|
+
"eslint": "^9.39.3",
|
|
54
|
+
"globals": "^16.5.0",
|
|
55
55
|
"htmlparser2": "^9.1.0",
|
|
56
|
-
"vite": "^7.1
|
|
56
|
+
"vite": "^7.3.1",
|
|
57
57
|
"vite-plugin-dom": "^1.0.5",
|
|
58
58
|
"vite-plugin-singlefile": "^2.3.0"
|
|
59
59
|
},
|