JavaScript generic ASN.1 parser (mirror)
1
fork

Configure Feed

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

Better support for integers.

+14 -3
+14 -3
asn1.js
··· 87 87 return s; 88 88 } 89 89 Stream.prototype.parseInteger = function(start, end) { 90 - if ((end - start) > 4) 91 - return undefined; 92 90 //TODO support negative numbers 91 + var len = end - start; 92 + if (len > 4) { 93 + len <<= 3; 94 + var s = this.get(start); 95 + if (s == 0) 96 + len -= 8; 97 + else 98 + while (s < 128) { 99 + short <<= 1; 100 + --len; 101 + } 102 + return "(" + len + " bit)"; 103 + } 93 104 var n = 0; 94 105 for (var i = start; i < end; ++i) 95 106 n = (n << 8) | this.get(i); ··· 105 116 if (s == undefined) 106 117 s = parseInt(n / 40) + "." + (n % 40); 107 118 else 108 - s += "." + ((bits >= 31) ? "big" : n); 119 + s += "." + ((bits >= 31) ? "bigint" : n); 109 120 n = bits = 0; 110 121 } 111 122 s += String.fromCharCode();