Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace substr to substring #275

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions bin/jsencrypt.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/jsencrypt.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/lib/asn1js/asn1.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ var ASN1 = /** @class */ (function () {
var hexString = this.toHexString();
var offset = this.header * 2;
var length = this.length * 2;
return hexString.substr(offset, length);
return hexString.substring(offset, offset + length);
};
ASN1.decode = function (str) {
var stream;
Expand Down
2 changes: 1 addition & 1 deletion lib/lib/jsbn/jsbn.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ var BigInteger = /** @class */ (function () {
var r = "";
this.divRemTo(d, y, z);
while (y.signum() > 0) {
r = (a + z.intValue()).toString(b).substr(1) + r;
r = (a + z.intValue()).toString(b).substring(1) + r;
y.divRemTo(d, y, z);
}
return z.intValue().toString(b) + r;
Expand Down
4 changes: 2 additions & 2 deletions lib/lib/jsbn/rsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,8 +357,8 @@ function removeDigestHeader(str) {
if (DIGEST_HEADERS.hasOwnProperty(name_1)) {
var header = DIGEST_HEADERS[name_1];
var len = header.length;
if (str.substr(0, len) == header) {
return str.substr(len);
if (str.substring(0, len) == header) {
return str.substring(len);
}
}
}
Expand Down
26 changes: 14 additions & 12 deletions lib/lib/jsrsasign/asn1-1.0.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ KJUR.asn1.ASN1Util = new function () {
};
this.bigIntToMinTwosComplementsHex = function (bigIntegerValue) {
var h = bigIntegerValue.toString(16);
if (h.substr(0, 1) != '-') {
if (h.substring(0, 1) != '-') {
if (h.length % 2 == 1) {
h = '0' + h;
}
Expand All @@ -114,7 +114,7 @@ KJUR.asn1.ASN1Util = new function () {
}
}
else {
var hPos = h.substr(1);
var hPos = h.substring(1);
var xorLen = hPos.length;
if (xorLen % 2 == 1) {
xorLen += 1;
Expand Down Expand Up @@ -264,9 +264,11 @@ KJUR.asn1.ASN1Util = new function () {
if (Object.prototype.toString.call(tagParam) === '[object Array]' &&
tagParam.length == 3) {
var obj = _newObject(tagParam[2]);
return new _DERTaggedObject({ tag: tagParam[0],
return new _DERTaggedObject({
tag: tagParam[0],
explicit: tagParam[1],
obj: obj });
obj: obj
});
}
else {
var newParam = {};
Expand Down Expand Up @@ -316,16 +318,16 @@ KJUR.asn1.ASN1Util = new function () {
*/
KJUR.asn1.ASN1Util.oidHexToInt = function (hex) {
var s = "";
var i01 = parseInt(hex.substr(0, 2), 16);
var i01 = parseInt(hex.substring(0, 2), 16);
var i0 = Math.floor(i01 / 40);
var i1 = i01 % 40;
var s = i0 + "." + i1;
var binbuf = "";
for (var i = 2; i < hex.length; i += 2) {
var value = parseInt(hex.substr(i, 2), 16);
var value = parseInt(hex.substring(i, i + 2), 16);
var bin = ("00000000" + value.toString(2)).slice(-8);
binbuf = binbuf + bin.substr(1, 7);
if (bin.substr(0, 1) == "0") {
binbuf = binbuf + bin.substring(1, 8);
if (bin.substring(0, 1) == "0") {
var bi = new BigInteger(binbuf, 2);
s = s + "." + bi.toString(10);
binbuf = "";
Expand Down Expand Up @@ -367,7 +369,7 @@ KJUR.asn1.ASN1Util.oidIntToHex = function (oidString) {
bPad += '0';
b = bPad + b;
for (var i = 0; i < b.length - 1; i += 7) {
var b8 = b.substr(i, 7);
var b8 = b.substring(i, i + 7);
if (i != b.length - 7)
b8 = '1' + b8;
h += itox(parseInt(b8, 2));
Expand Down Expand Up @@ -581,7 +583,7 @@ KJUR.asn1.DERAbstractTime = function (params) {
var d = this.localDateToUTC(dateObject);
var year = String(d.getFullYear());
if (type == 'utc')
year = year.substr(2, 2);
year = year.substring(2, 4);
var month = pad(String(d.getMonth() + 1), 2);
var day = pad(String(d.getDate()), 2);
var hour = pad(String(d.getHours()), 2);
Expand Down Expand Up @@ -891,7 +893,7 @@ KJUR.asn1.DERBitString = function (params) {
}
var h = '';
for (var i = 0; i < binaryString.length - 1; i += 8) {
var b = binaryString.substr(i, 8);
var b = binaryString.substring(i, i + 8);
var x = parseInt(b, 2).toString(16);
if (x.length == 1)
x = '0' + x;
Expand Down Expand Up @@ -1061,7 +1063,7 @@ KJUR.asn1.DERObjectIdentifier = function (params) {
bPad += '0';
b = bPad + b;
for (var i = 0; i < b.length - 1; i += 7) {
var b8 = b.substr(i, 7);
var b8 = b.substring(i, i + 7);
if (i != b.length - 7)
b8 = '1' + b8;
h += itox(parseInt(b8, 2));
Expand Down
2 changes: 1 addition & 1 deletion src/lib/asn1js/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
78 changes: 39 additions & 39 deletions src/lib/asn1js/asn1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
/*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
/*global oids */

import {Int10} from "./int10";
import { Int10 } from "./int10";

const ellipsis = "\u2026";
const reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
const reTimeS = /^(\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;
const reTimeL = /^(\d\d\d\d)(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])([01]\d|2[0-3])(?:([0-5]\d)(?:([0-5]\d)(?:[.,](\d{1,3}))?)?)?(Z|[-+](?:[0]\d|1[0-2])([0-5]\d)?)?$/;

function stringCut(str:string, len:number) {
function stringCut(str: string, len: number) {
if (str.length > len) {
str = str.substring(0, len) + ellipsis;
}
return str;
}

export class Stream {
constructor(enc:Stream|number[], pos?:number) {
constructor(enc: Stream | number[], pos?: number) {
if (enc instanceof Stream) {
this.enc = enc.enc;
this.pos = enc.pos;
Expand All @@ -41,10 +41,10 @@ export class Stream {
}
}

private enc:string|number[];
public pos:number;
private enc: string | number[];
public pos: number;

public get(pos?:number) {
public get(pos?: number) {
if (pos === undefined) {
pos = this.pos++;
}
Expand All @@ -56,11 +56,11 @@ export class Stream {

public hexDigits = "0123456789ABCDEF";

public hexByte(b:number) {
public hexByte(b: number) {
return this.hexDigits.charAt((b >> 4) & 0xF) + this.hexDigits.charAt(b & 0xF);
}

public hexDump(start:number, end:number, raw:boolean) {
public hexDump(start: number, end: number, raw: boolean) {
let s = "";
for (let i = start; i < end; ++i) {
s += this.hexByte(this.get(i));
Expand All @@ -80,7 +80,7 @@ export class Stream {
return s;
}

public isASCII(start:number, end:number) {
public isASCII(start: number, end: number) {
for (let i = start; i < end; ++i) {
const c = this.get(i);
if (c < 32 || c > 176) {
Expand All @@ -90,15 +90,15 @@ export class Stream {
return true;
}

public parseStringISO(start:number, end:number) {
public parseStringISO(start: number, end: number) {
let s = "";
for (let i = start; i < end; ++i) {
s += String.fromCharCode(this.get(i));
}
return s;
}

public parseStringUTF(start:number, end:number) {
public parseStringUTF(start: number, end: number) {
let s = "";
for (let i = start; i < end;) {
const c = this.get(i++);
Expand All @@ -113,7 +113,7 @@ export class Stream {
return s;
}

public parseStringBMP(start:number, end:number) {
public parseStringBMP(start: number, end: number) {
let str = "";
let hi;
let lo;
Expand All @@ -125,9 +125,9 @@ export class Stream {
return str;
}

public parseTime(start:number, end:number, shortYear:boolean) {
public parseTime(start: number, end: number, shortYear: boolean) {
let s = this.parseStringISO(start, end);
const m:Array<number|string> = (shortYear ? reTimeS : reTimeL).exec(s);
const m: Array<number | string> = (shortYear ? reTimeS : reTimeL).exec(s);
if (!m) {
return "Unrecognized time: " + s;
}
Expand Down Expand Up @@ -159,12 +159,12 @@ export class Stream {
return s;
}

public parseInteger(start:number, end:number) {
public parseInteger(start: number, end: number) {
let v = this.get(start);
const neg = (v > 127);
const pad = neg ? 255 : 0;
let len;
let s:string | number = "";
let s: string | number = "";
// skip unuseful bits (not allowed in DER)
while (v == pad && ++start < end) {
v = this.get(start);
Expand Down Expand Up @@ -194,7 +194,7 @@ export class Stream {
return s + n.toString();
}

public parseBitString(start:number, end:number, maxLength:number) {
public parseBitString(start: number, end: number, maxLength: number) {
const unusedBit = this.get(start);
const lenBit = ((end - start - 1) << 3) - unusedBit;
const intro = "(" + lenBit + " bit)\n";
Expand All @@ -212,7 +212,7 @@ export class Stream {
return intro + s;
}

public parseOctetString(start:number, end:number, maxLength:number) {
public parseOctetString(start: number, end: number, maxLength: number) {
if (this.isASCII(start, end)) {
return stringCut(this.parseStringISO(start, end), maxLength);
}
Expand All @@ -231,9 +231,9 @@ export class Stream {
return s;
}

public parseOID(start:number, end:number, maxLength:number) {
public parseOID(start: number, end: number, maxLength: number) {
let s = "";
let n:number|Int10 = new Int10();
let n: number | Int10 = new Int10();
let bits = 0;
for (let i = start; i < end; ++i) {
const v = this.get(i);
Expand Down Expand Up @@ -266,7 +266,7 @@ export class Stream {
}
}
export class ASN1 {
constructor(stream:Stream, header:number, length:number, tag:ASN1Tag, sub:ASN1[]) {
constructor(stream: Stream, header: number, length: number, tag: ASN1Tag, sub: ASN1[]) {
if (!(tag instanceof ASN1Tag)) {
throw new Error("Invalid tag value.");
}
Expand All @@ -277,11 +277,11 @@ export class ASN1 {
this.sub = sub;
}

private stream:Stream;
private header:number;
private length:number;
private tag:ASN1Tag;
public sub:ASN1[];
private stream: Stream;
private header: number;
private length: number;
private tag: ASN1Tag;
public sub: ASN1[];

public typeName() {
switch (this.tag.tagClass) {
Expand Down Expand Up @@ -352,7 +352,7 @@ export class ASN1 {
}
}

public content(maxLength:number) { // a preview of the content (intended for humans)
public content(maxLength: number) { // a preview of the content (intended for humans)
if (this.tag === undefined) {
return null;
}
Expand Down Expand Up @@ -418,7 +418,7 @@ export class ASN1 {
return this.typeName() + "@" + this.stream.pos + "[header:" + this.header + ",length:" + this.length + ",sub:" + ((this.sub === null) ? "null" : this.sub.length) + "]";
}

public toPrettyString(indent:string) {
public toPrettyString(indent: string) {
if (indent === undefined) {
indent = "";
}
Expand Down Expand Up @@ -458,7 +458,7 @@ export class ASN1 {
return this.stream.hexDump(this.posStart(), this.posEnd(), true);
}

public static decodeLength(stream:Stream):number {
public static decodeLength(stream: Stream): number {
let buf = stream.get();
const len = buf & 0x7F;
if (len == buf) {
Expand All @@ -484,15 +484,15 @@ export class ASN1 {
* @returns {string}
* @public
*/
public getHexStringValue():string {
public getHexStringValue(): string {
const hexString = this.toHexString();
const offset = this.header * 2;
const length = this.length * 2;
return hexString.substr(offset, length);
return hexString.substring(offset, offset + length);
}

public static decode(str:Stream|number[]) {
let stream:Stream;
public static decode(str: Stream | number[]) {
let stream: Stream;

if (!(str instanceof Stream)) {
stream = new Stream(str, 0);
Expand All @@ -506,7 +506,7 @@ export class ASN1 {
const start = stream.pos;
const header = start - streamStart.pos;
let sub = null;
const getSub:() => ASN1[] = function () {
const getSub: () => ASN1[] = function () {
const ret = [];
if (len !== null) {
// definite length
Expand Down Expand Up @@ -569,7 +569,7 @@ export class ASN1 {


export class ASN1Tag {
constructor(stream:Stream) {
constructor(stream: Stream) {
let buf = stream.get();
this.tagClass = buf >> 6;
this.tagConstructed = ((buf & 0x20) !== 0);
Expand All @@ -584,9 +584,9 @@ export class ASN1Tag {
}
}

public tagClass:number;
public tagConstructed:boolean;
public tagNumber:number | Int10;
public tagClass: number;
public tagConstructed: boolean;
public tagNumber: number | Int10;

public isUniversal() {
return this.tagClass === 0x00;
Expand Down
Loading