Skip to content

Commit

Permalink
tslint
Browse files Browse the repository at this point in the history
  • Loading branch information
dpronin committed Dec 18, 2017
1 parent 2269412 commit 82de1f8
Show file tree
Hide file tree
Showing 10 changed files with 662 additions and 431 deletions.
55 changes: 31 additions & 24 deletions lib/asn1js/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
Expand All @@ -14,31 +14,37 @@
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

/*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
let decoder;
let decoder:{ [index:string]:number | string };
export const Base64 = {
decode: function (a) {
var i;
decode(a:string) {
let i;
if (decoder === undefined) {
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
ignore = "= \f\n\r\t\u00A0\u2028\u2029";
decoder = [];
for (i = 0; i < 64; ++i)
const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const ignore = "= \f\n\r\t\u00A0\u2028\u2029";
decoder = Object.create(null);
for (i = 0; i < 64; ++i) {
decoder[b64.charAt(i)] = i;
for (i = 0; i < ignore.length; ++i)
}
for (i = 0; i < ignore.length; ++i) {
decoder[ignore.charAt(i)] = -1;
}
}
var out = [];
var bits = 0, char_count = 0;
const out = [];
let bits = 0;
let char_count = 0;
for (i = 0; i < a.length; ++i) {
var c = a.charAt(i);
if (c == '=')
let c:string|number = a.charAt(i);
if (c == "=") {
break;
}
c = decoder[c];
if (c == -1)
if (c == -1) {
continue;
if (c === undefined)
throw 'Illegal character at offset ' + i;
bits |= c;
}
if (c === undefined) {
throw new Error("Illegal character at offset " + i);
}
bits |= c as number;
if (++char_count >= 4) {
out[out.length] = (bits >> 16);
out[out.length] = (bits >> 8) & 0xFF;
Expand All @@ -51,7 +57,7 @@ export const Base64 = {
}
switch (char_count) {
case 1:
throw "Base64 encoding incomplete: at least 2 bits missing";
throw new Error("Base64 encoding incomplete: at least 2 bits missing");
case 2:
out[out.length] = (bits >> 10);
break;
Expand All @@ -63,15 +69,16 @@ export const Base64 = {
return out;
},
re: /-----BEGIN [^-]+-----([A-Za-z0-9+\/=\s]+)-----END [^-]+-----|begin-base64[^\n]+\n([A-Za-z0-9+\/=\s]+)====/,
unarmor: function (a) {
var m = Base64.re.exec(a);
unarmor(a:string) {
const m = Base64.re.exec(a);
if (m) {
if (m[1])
if (m[1]) {
a = m[1];
else if (m[2])
} else if (m[2]) {
a = m[2];
else
throw "RegExp out of sync";
} else {
throw new Error("RegExp out of sync");
}
}
return Base64.decode(a);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/asn1js/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
Expand Down
2 changes: 1 addition & 1 deletion lib/asn1js/int10.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
Expand Down
125 changes: 64 additions & 61 deletions lib/jsbn/base64.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,76 @@
import {int2char} from "./util";

var b64map="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var b64pad="=";
const b64map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const b64pad = "=";

export function hex2b64(h) {
var i;
var c;
var ret = "";
for(i = 0; i+3 <= h.length; i+=3) {
c = parseInt(h.substring(i,i+3),16);
ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
}
if(i+1 == h.length) {
c = parseInt(h.substring(i,i+1),16);
ret += b64map.charAt(c << 2);
}
else if(i+2 == h.length) {
c = parseInt(h.substring(i,i+2),16);
ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
}
while((ret.length & 3) > 0) ret += b64pad;
return ret;
export function hex2b64(h:string) {
let i;
let c;
let ret = "";
for (i = 0; i + 3 <= h.length; i += 3) {
c = parseInt(h.substring(i, i + 3), 16);
ret += b64map.charAt(c >> 6) + b64map.charAt(c & 63);
}
if (i + 1 == h.length) {
c = parseInt(h.substring(i, i + 1), 16);
ret += b64map.charAt(c << 2);
} else if (i + 2 == h.length) {
c = parseInt(h.substring(i, i + 2), 16);
ret += b64map.charAt(c >> 2) + b64map.charAt((c & 3) << 4);
}
while ((ret.length & 3) > 0) {
ret += b64pad;
}
return ret;
}

// convert a base64 string to hex
export function b64tohex(s) {
var ret = ""
var i;
var k = 0; // b64 state, 0-3
var slop;
for(i = 0; i < s.length; ++i) {
if(s.charAt(i) == b64pad) break;
let v = b64map.indexOf(s.charAt(i));
if(v < 0) continue;
if(k == 0) {
ret += int2char(v >> 2);
slop = v & 3;
k = 1;
export function b64tohex(s:string) {
let ret = "";
let i;
let k = 0; // b64 state, 0-3
let slop = 0;
for (i = 0; i < s.length; ++i) {
if (s.charAt(i) == b64pad) {
break;
}
const v = b64map.indexOf(s.charAt(i));
if (v < 0) {
continue;
}
if (k == 0) {
ret += int2char(v >> 2);
slop = v & 3;
k = 1;
} else if (k == 1) {
ret += int2char((slop << 2) | (v >> 4));
slop = v & 0xf;
k = 2;
} else if (k == 2) {
ret += int2char(slop);
ret += int2char(v >> 2);
slop = v & 3;
k = 3;
} else {
ret += int2char((slop << 2) | (v >> 4));
ret += int2char(v & 0xf);
k = 0;
}
}
else if(k == 1) {
ret += int2char((slop << 2) | (v >> 4));
slop = v & 0xf;
k = 2;
if (k == 1) {
ret += int2char(slop << 2);
}
else if(k == 2) {
ret += int2char(slop);
ret += int2char(v >> 2);
slop = v & 3;
k = 3;
}
else {
ret += int2char((slop << 2) | (v >> 4));
ret += int2char(v & 0xf);
k = 0;
}
}
if(k == 1)
ret += int2char(slop << 2);
return ret;
return ret;
}

// convert a base64 string to a byte/number array
export function b64toBA(s) {
//piggyback on b64tohex for now, optimize later
var h = b64tohex(s);
var i;
var a = new Array();
for(i = 0; 2*i < h.length; ++i) {
a[i] = parseInt(h.substring(2*i,2*i+2),16);
}
return a;
export function b64toBA(s:string) {
// piggyback on b64tohex for now, optimize later
const h = b64tohex(s);
let i;
const a = [];
for (i = 0; 2 * i < h.length; ++i) {
a[i] = parseInt(h.substring(2 * i, 2 * i + 2), 16);
}
return a;
}
Loading

0 comments on commit 82de1f8

Please sign in to comment.