diff --git a/asn1.js b/asn1.js index 014631a..4ebb83b 100644 --- a/asn1.js +++ b/asn1.js @@ -13,10 +13,14 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -/*jshint browser: true, strict: true, globalstrict: true, immed: true, latedef: true, undef: true, regexdash: false */ +/*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */ /*global oids */ +(function (undefined) { "use strict"; +var hardLimit = 100, + ellipsis = "\u2026"; + function Stream(enc, pos) { if (enc instanceof Stream) { this.enc = enc.enc; @@ -26,7 +30,6 @@ function Stream(enc, pos) { this.pos = pos; } } -Stream.prototype.ellipsis = "\u2026"; Stream.prototype.get = function (pos) { if (pos === undefined) pos = this.pos++; @@ -58,17 +61,15 @@ Stream.prototype.parseStringISO = function (start, end) { return s; }; Stream.prototype.parseStringUTF = function (start, end) { - var s = "", - c = 0; + var s = ""; for (var i = start; i < end; ) { - c = this.get(i++); + var c = this.get(i++); if (c < 128) s += String.fromCharCode(c); else if ((c > 191) && (c < 224)) s += String.fromCharCode(((c & 0x1F) << 6) | (this.get(i++) & 0x3F)); else s += String.fromCharCode(((c & 0x0F) << 12) | ((this.get(i++) & 0x3F) << 6) | (this.get(i++) & 0x3F)); - //TODO: this doesn't check properly 'end', some char could begin before and end after } return s; }; @@ -136,12 +137,12 @@ Stream.prototype.parseBitString = function (start, end) { Stream.prototype.parseOctetString = function (start, end) { var len = end - start, s = "(" + len + " byte) "; - if (len > 20) - end = start + 20; + if (len > hardLimit) + end = start + hardLimit; for (var i = start; i < end; ++i) - s += this.hexByte(this.get(i)); - if (len > 20) - s += Stream.ellipsis; + s += this.hexByte(this.get(i)); //TODO: also try Latin1? + if (len > hardLimit) + s += ellipsis; return s; }; Stream.prototype.parseOID = function (start, end) { @@ -225,9 +226,10 @@ ASN1.prototype.content = function () { if (tagClass !== 0) { // universal if (this.sub !== null) return "(" + this.sub.length + " elem)"; - var s = this.stream.parseStringISO(content, content + len); + //TODO: TRY TO PARSE ASCII STRING + var s = this.stream.parseStringISO(content, content + Math.min(len, hardLimit)); if (this.reSeemsASCII.test(s)) - return s.substring(0, 40) + ((s.length > 40) ? this.stream.ellipsis : ""); + return s.substring(0, 2 * hardLimit) + ((s.length > 2 * hardLimit) ? ellipsis : ""); else return this.stream.parseOctetString(content, content + len); } @@ -354,9 +356,7 @@ ASN1.prototype.toDOM = function () { sub.appendChild(this.sub[i].toDOM()); } node.appendChild(sub); - head.switchNode = node; head.onclick = function () { - var node = this.switchNode; node.className = (node.className == "node collapsed") ? "node" : "node collapsed"; }; return node; @@ -515,3 +515,7 @@ ASN1.test = function () { document.write("In test[" + i + "] expected " + test[i].expected + " got " + res + "\n"); } }; + +// export globals +window.ASN1 = ASN1; +})(); diff --git a/base64.js b/base64.js index 4ac31b4..de786ba 100644 --- a/base64.js +++ b/base64.js @@ -13,22 +13,23 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -/*jshint browser: true, strict: true, globalstrict: true, immed: true, latedef: true, undef: true, regexdash: false */ +/*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */ +(function (undefined) { "use strict"; -var Base64 = {}; +var Base64 = {}, + decoder; Base64.decode = function (a) { var i; - if (Base64.decoder === undefined) { + if (decoder === undefined) { var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", - allow = "= \f\n\r\t\u00A0\u2028\u2029", - dec = []; + ignore = "= \f\n\r\t\u00A0\u2028\u2029"; + decoder = []; for (i = 0; i < 64; ++i) - dec[b64.charAt(i)] = i; - for (i = 0; i < allow.length; ++i) - dec[allow.charAt(i)] = -1; - Base64.decoder = dec; + decoder[b64.charAt(i)] = i; + for (i = 0; i < ignore.length; ++i) + decoder[ignore.charAt(i)] = -1; } var out = []; var bits = 0, char_count = 0; @@ -36,7 +37,7 @@ Base64.decode = function (a) { var c = a.charAt(i); if (c == '=') break; - c = Base64.decoder[c]; + c = decoder[c]; if (c == -1) continue; if (c === undefined) @@ -79,3 +80,7 @@ Base64.unarmor = function (a) { } return Base64.decode(a); }; + +// export globals +window.Base64 = Base64; +})(); diff --git a/hex.js b/hex.js index 1050615..573f497 100644 --- a/hex.js +++ b/hex.js @@ -13,25 +13,26 @@ // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -/*jshint browser: true, strict: true, globalstrict: true, immed: true, latedef: true, undef: true, regexdash: false */ +/*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */ +(function (undefined) { "use strict"; -var Hex = {}; +var Hex = {}, + decoder; Hex.decode = function(a) { var i; - if (Hex.decoder === undefined) { + if (decoder === undefined) { var hex = "0123456789ABCDEF", - allow = " \f\n\r\t\u00A0\u2028\u2029", - dec = []; + ignore = " \f\n\r\t\u00A0\u2028\u2029"; + decoder = []; for (i = 0; i < 16; ++i) - dec[hex.charAt(i)] = i; + decoder[hex.charAt(i)] = i; hex = hex.toLowerCase(); for (i = 10; i < 16; ++i) - dec[hex.charAt(i)] = i; - for (i = 0; i < allow.length; ++i) - dec[allow.charAt(i)] = -1; - Hex.decoder = dec; + decoder[hex.charAt(i)] = i; + for (i = 0; i < ignore.length; ++i) + decoder[ignore.charAt(i)] = -1; } var out = [], bits = 0, @@ -40,7 +41,7 @@ Hex.decode = function(a) { var c = a.charAt(i); if (c == '=') break; - c = Hex.decoder[c]; + c = decoder[c]; if (c == -1) continue; if (c === undefined) @@ -58,3 +59,7 @@ Hex.decode = function(a) { throw "Hex encoding incomplete: 4 bits missing"; return out; }; + +// export globals +window.Hex = Hex; +})();