Skip to content

Commit

Permalink
Merge pull request #10 from highmtworks/fix-high-tag-number
Browse files Browse the repository at this point in the history
Fix high tag number decoding
  • Loading branch information
atesgoral committed Jan 16, 2021
2 parents 2688b0a + 987c1f9 commit 5943f8d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 12 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down

0 comments on commit 5943f8d

Please sign in to comment.