From 7c54cca339e991affffad7d41dbcc1a94b2fba60 Mon Sep 17 00:00:00 2001 From: highmtworks <1973003+highmtworks@users.noreply.github.com> Date: Sat, 16 Jan 2021 12:32:57 +0900 Subject: [PATCH 1/2] Add a test case for a high tag with three octets --- test/index.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/index.js b/test/index.js index 91fda28..3f68dcc 100644 --- a/test/index.js +++ b/test/index.js @@ -50,6 +50,18 @@ test('decode: tagCode 50 (extended tag / aka high tag)', (t) => { ); }); +test('decode: tagCode 257 (extended tag / aka high tag with three octets)', (t) => { + t.deepEqual( + asn1Tree.decode(b(tag(CLS_CONTEXT_SPECIFIC, FORM_PRIMITIVE, 31), 130, 1, 3, f(3))), + { + cls: CLS_CONTEXT_SPECIFIC, + form: FORM_PRIMITIVE, + tagCode: 257, + value: f(3) + } + ); +}); + test('decode: primitive: element with length 0', (t) => { t.deepEqual( asn1Tree.decode(b(tag(CLS_UNIVERSAL, FORM_PRIMITIVE, TAG_NULL), 0)), From 987c1f97466d1638b36698b6a4419366b8666860 Mon Sep 17 00:00:00 2001 From: highmtworks <1973003+highmtworks@users.noreply.github.com> Date: Sat, 16 Jan 2021 12:40:04 +0900 Subject: [PATCH 2/2] Fix high tag number decoding --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 8a9af47..4c9a0a6 100644 --- a/index.js +++ b/index.js @@ -17,7 +17,7 @@ function decode(buffer) { do { byte = buffer.readUInt8(bytesRead); bytesRead += 1; - tagCode = (tagCode << 8) | (byte & 0x7f); + tagCode = (tagCode << 7) | (byte & 0x7f); } while (byte & 0x80); }