diff --git a/asn1.js b/asn1.js index 9012784..ce362c5 100644 --- a/asn1.js +++ b/asn1.js @@ -279,7 +279,7 @@ Stream.prototype.parseOctetString = function (start, end, maxLength) { s += ellipsis; return { size: len, str: s }; }; -Stream.prototype.parseOID = function (start, end, maxLength) { +Stream.prototype.parseOID = function (start, end, maxLength, isRelative) { var s = '', n = new Int10(), bits = 0; @@ -307,7 +307,14 @@ Stream.prototype.parseOID = function (start, end, maxLength) { } if (bits > 0) s += ".incomplete"; - if (typeof oids === 'object') { + if (isRelative) { + if (s.length > 2) { + const prefix = s.slice(0, 2); + if ("0." == prefix) { + s = s.slice(2); + } + } + } else if (typeof oids === 'object') { var oid = oids[s]; if (oid) { if (oid.d) s += "\n" + oid.d; @@ -344,6 +351,7 @@ ASN1.prototype.typeName = function () { case 0x0A: return "ENUMERATED"; case 0x0B: return "EMBEDDED_PDV"; case 0x0C: return "UTF8String"; + case 0x0D: return "RELATIVE-OID" case 0x10: return "SEQUENCE"; case 0x11: return "SET"; case 0x12: return "NumericString"; @@ -411,13 +419,15 @@ ASN1.prototype.content = function (maxLength) { return "(" + d.size + " byte)\n" + d.str; //case 0x05: // NULL case 0x06: // OBJECT_IDENTIFIER - return this.stream.parseOID(content, content + len, maxLength); + return this.stream.parseOID(content, content + len, maxLength, false); //case 0x07: // ObjectDescriptor //case 0x08: // EXTERNAL //case 0x09: // REAL case 0x0A: // ENUMERATED return this.stream.parseInteger(content, content + len); //case 0x0B: // EMBEDDED_PDV + case 0x0D: // RELATIVE-OID + return this.stream.parseOID(content, content + len, maxLength, true); case 0x10: // SEQUENCE case 0x11: // SET if (this.sub !== null) diff --git a/dom.js b/dom.js index eb24327..381fce6 100644 --- a/dom.js +++ b/dom.js @@ -58,7 +58,7 @@ var ASN1 = require('./asn1'), ASN1.prototype.toDOM = function (spaces) { spaces = spaces || ''; - var isOID = (typeof oids === 'object') && (this.tag.isUniversal() && (this.tag.tagNumber == 0x06)); + var isOID = (typeof oids === 'object') && (this.tag.isUniversal() && (this.tag.tagNumber == 0x06) || (this.tag.tagNumber == 0x0D)); var node = DOM.tag("div", "node"); node.asn1 = this; var head = DOM.tag("div", "head"); diff --git a/test.js b/test.js index c526d71..b2eb992 100755 --- a/test.js +++ b/test.js @@ -83,6 +83,7 @@ const tests = [ ['0420041EE4E3B7ED350CC24D034E436D9A1CB15BB1E328D37062FB82E84618AB0A3C', '(32 byte)\n041EE4E3B7ED350CC24D034E436D9A1CB15BB1E328D37062FB82E84618AB0A3C', 'Do not mix encapsulated and structured octet strings'], // GitHub issue #47 ['181531393835313130363231303632372E332D31323334', '1985-11-06 21:06:27.3 UTC-12:34', 'UTC offsets with minutes'], // GitHub issue #54 ['181331393835313130363231303632372E332B3134', '1985-11-06 21:06:27.3 UTC+14:00', 'UTC offset +13 and +14'], // GitHub issue #54 + ['0D0A0102030405060708090A','1.2.3.4.5.6.7.8.9.10', 'RELATIVE-OID'] ]; let