JavaScript generic ASN.1 parser (mirror)
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Use a code style closer to trunk branch.

+21 -36
+10 -11
context.js
··· 12 12 const valueEnabled = type != 'SET' && type != 'SEQUENCE'; 13 13 node.onclick = function (event) { 14 14 // do not show the menu in case of clicking the icon 15 - if (event.srcElement.nodeName === 'SPAN') { 16 - contextMenu.style.left = event.pageX + 'px'; 17 - contextMenu.style.top = event.pageY + 'px'; 18 - contextMenu.style.visibility = 'visible'; 19 - contextMenu.node = this; 20 - btnHideTree.innerText = (node.className == 'node') ? 'Hide subtree' : 'Show subtree'; 21 - btnHideTree.style.display = node.className.startsWith('node') ? 'block' : 'none'; 22 - btnCopyValue.style.display = valueEnabled ? 'block' : 'none'; 23 - event.preventDefault(); 24 - event.stopPropagation(); 25 - } 15 + if (event.srcElement.nodeName != 'SPAN') return; 16 + contextMenu.style.left = event.pageX + 'px'; 17 + contextMenu.style.top = event.pageY + 'px'; 18 + contextMenu.style.visibility = 'visible'; 19 + contextMenu.node = this; 20 + btnHideTree.innerText = (node.className == 'node') ? 'Hide subtree' : 'Show subtree'; 21 + btnHideTree.style.display = node.className.startsWith('node') ? 'block' : 'none'; 22 + btnCopyValue.style.display = valueEnabled ? 'block' : 'none'; 23 + event.preventDefault(); 24 + event.stopPropagation(); 26 25 }; 27 26 } 28 27
+8 -22
dom.js
··· 4 4 // Permission to use, copy, modify, and/or distribute this software for any 5 5 // purpose with or without fee is hereby granted, provided that the above 6 6 // copyright notice and this permission notice appear in all copies. 7 - // 7 + // 8 8 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 9 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 10 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ··· 24 24 ellipsis: '\u2026', 25 25 tag: function (tagName, className, text) { 26 26 let t = document.createElement(tagName); 27 - t.className = className; 27 + if (className) t.className = className; 28 28 if (text) t.innerText = text; 29 29 return t; 30 30 }, ··· 52 52 }; 53 53 54 54 export class ASN1DOM extends ASN1 { 55 - 56 - buf2hex(buffer) { 57 - return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join(' '); 58 - } 59 55 60 56 toDOM(spaces) { 61 57 spaces = spaces || ''; 62 58 let isOID = (typeof oids === 'object') && (this.tag.isUniversal() && (this.tag.tagNumber == 0x06) || (this.tag.tagNumber == 0x0D)); 63 - let node; 64 - node = document.createElement('li'); 65 - node.asn1 = this; 59 + let node = DOM.tag('li'); 60 + node.asn1 = this; 66 61 let head = DOM.tag('span', 'head'); 67 62 const typeName = this.typeName().replace(/_/g, ' '); 68 63 if (this.def) { ··· 79 74 head.appendChild(DOM.space()); 80 75 } 81 76 } 82 - head.setAttribute('pos', this.posStart()); 83 - head.setAttribute('end', this.posEnd()); 84 77 head.appendChild(DOM.text(typeName)); 85 78 let content; 86 79 try { ··· 131 124 // summary.setAttribute('class', 'node'); 132 125 contentNode = summary; 133 126 childNode = details; 134 - } 135 - else { 127 + } else { 136 128 contentNode = node; 137 129 contentNode.setAttribute('class', 'node'); 138 130 contentNode.appendChild(head); 139 131 } 140 - 141 132 this.node = contentNode; 142 133 this.head = head; 143 134 let value = DOM.tag('div', 'value'); ··· 162 153 } 163 154 value.innerHTML = s; 164 155 contentNode.appendChild(value); 165 - let sub = DOM.tag('div', 'sub'); 166 156 if (this.sub !== null) { 167 - let ul = document.createElement('ul'); 168 - childNode.appendChild(ul); 169 - 157 + let sub = DOM.tag('ul'); 158 + childNode.appendChild(sub); 170 159 spaces += '\xA0 '; 171 160 for (let i = 0, max = this.sub.length; i < max; ++i) 172 - ul.appendChild(this.sub[i].toDOM(spaces)); 161 + sub.appendChild(this.sub[i].toDOM(spaces)); 173 162 } 174 163 bindContextMenu(node); 175 164 return node; ··· 228 217 node.appendChild(skip); 229 218 } 230 219 } 231 - // set the current start and end position as an attribute at the node to know the selected area 232 - node.setAttribute('pos', this.posStart()); 233 - node.setAttribute('end', this.posEnd()); 234 220 this.toHexDOM_sub(node, 'tag', this.stream, this.posStart(), this.posLen()); 235 221 this.toHexDOM_sub(node, (this.length >= 0) ? 'dlen' : 'ulen', this.stream, this.posLen(), this.posContent()); 236 222 if (this.sub === null) {
+1 -1
index.js
··· 229 229 let treecollapse = document.querySelector(':root'); 230 230 treecollapse.style.setProperty('--zoom-fix', '-1.5px'); 231 231 } 232 - console.log(window.devicePixelRatio); 232 + console.log(window.devicePixelRatio);
+2 -2
package.json
··· 13 13 "license": "ISC", 14 14 "bugs": { "url": "https://github.com/lapo-luchini/asn1js/issues" }, 15 15 "homepage": "https://lapo.it/asn1js/", 16 - "files": [ "asn1.js", "base64.js", "hex.js", "int10.js", "defs.js", "oids.js", "rfcdef.js", "dumpASN1.js" ], 16 + "files": [ "asn1.js", "base64.js", "hex.js", "int10.js", "dom.js", "defs.js", "oids.js", "rfcdef.js", "dumpASN1.js" ], 17 17 "scripts": { 18 - "lint": "npx eslint asn1.js base64.js hex.js int10.js defs.js oids.js rfcdef.js tags.js context.js index.js parseRFC.js dumpASN1.js test.js testDefs.js vite.config.js theme.js", 18 + "lint": "npx eslint asn1.js base64.js hex.js int10.js dom.js defs.js oids.js rfcdef.js tags.js context.js index.js parseRFC.js dumpASN1.js test.js testDefs.js vite.config.js theme.js", 19 19 "lint-action": "npx @action-validator/cli .github/workflows/node.js.yml", 20 20 "build": "vite build", 21 21 "serve": "echo 'Connect to http://localhost:3000/' ; npx statik --port 3000 .",