Skip to content

Commit 028a749

Browse files
authored
Merge pull request #275 from JiatLn/master
refactor: replace substr to substring
2 parents d82ea10 + 1e8d2f5 commit 028a749

File tree

24 files changed

+2393
-2389
lines changed

24 files changed

+2393
-2389
lines changed

bin/jsencrypt.js

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/jsencrypt.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/lib/asn1js/asn1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ var ASN1 = /** @class */ (function () {
458458
var hexString = this.toHexString();
459459
var offset = this.header * 2;
460460
var length = this.length * 2;
461-
return hexString.substr(offset, length);
461+
return hexString.substring(offset, offset + length);
462462
};
463463
ASN1.decode = function (str) {
464464
var stream;

lib/lib/jsbn/jsbn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ var BigInteger = /** @class */ (function () {
10661066
var r = "";
10671067
this.divRemTo(d, y, z);
10681068
while (y.signum() > 0) {
1069-
r = (a + z.intValue()).toString(b).substr(1) + r;
1069+
r = (a + z.intValue()).toString(b).substring(1) + r;
10701070
y.divRemTo(d, y, z);
10711071
}
10721072
return z.intValue().toString(b) + r;

lib/lib/jsbn/rsa.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,8 @@ function removeDigestHeader(str) {
357357
if (DIGEST_HEADERS.hasOwnProperty(name_1)) {
358358
var header = DIGEST_HEADERS[name_1];
359359
var len = header.length;
360-
if (str.substr(0, len) == header) {
361-
return str.substr(len);
360+
if (str.substring(0, len) == header) {
361+
return str.substring(len);
362362
}
363363
}
364364
}

lib/lib/jsrsasign/asn1-1.0.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ KJUR.asn1.ASN1Util = new function () {
103103
};
104104
this.bigIntToMinTwosComplementsHex = function (bigIntegerValue) {
105105
var h = bigIntegerValue.toString(16);
106-
if (h.substr(0, 1) != '-') {
106+
if (h.substring(0, 1) != '-') {
107107
if (h.length % 2 == 1) {
108108
h = '0' + h;
109109
}
@@ -114,7 +114,7 @@ KJUR.asn1.ASN1Util = new function () {
114114
}
115115
}
116116
else {
117-
var hPos = h.substr(1);
117+
var hPos = h.substring(1);
118118
var xorLen = hPos.length;
119119
if (xorLen % 2 == 1) {
120120
xorLen += 1;
@@ -264,9 +264,11 @@ KJUR.asn1.ASN1Util = new function () {
264264
if (Object.prototype.toString.call(tagParam) === '[object Array]' &&
265265
tagParam.length == 3) {
266266
var obj = _newObject(tagParam[2]);
267-
return new _DERTaggedObject({ tag: tagParam[0],
267+
return new _DERTaggedObject({
268+
tag: tagParam[0],
268269
explicit: tagParam[1],
269-
obj: obj });
270+
obj: obj
271+
});
270272
}
271273
else {
272274
var newParam = {};
@@ -316,16 +318,16 @@ KJUR.asn1.ASN1Util = new function () {
316318
*/
317319
KJUR.asn1.ASN1Util.oidHexToInt = function (hex) {
318320
var s = "";
319-
var i01 = parseInt(hex.substr(0, 2), 16);
321+
var i01 = parseInt(hex.substring(0, 2), 16);
320322
var i0 = Math.floor(i01 / 40);
321323
var i1 = i01 % 40;
322324
var s = i0 + "." + i1;
323325
var binbuf = "";
324326
for (var i = 2; i < hex.length; i += 2) {
325-
var value = parseInt(hex.substr(i, 2), 16);
327+
var value = parseInt(hex.substring(i, i + 2), 16);
326328
var bin = ("00000000" + value.toString(2)).slice(-8);
327-
binbuf = binbuf + bin.substr(1, 7);
328-
if (bin.substr(0, 1) == "0") {
329+
binbuf = binbuf + bin.substring(1, 8);
330+
if (bin.substring(0, 1) == "0") {
329331
var bi = new BigInteger(binbuf, 2);
330332
s = s + "." + bi.toString(10);
331333
binbuf = "";
@@ -367,7 +369,7 @@ KJUR.asn1.ASN1Util.oidIntToHex = function (oidString) {
367369
bPad += '0';
368370
b = bPad + b;
369371
for (var i = 0; i < b.length - 1; i += 7) {
370-
var b8 = b.substr(i, 7);
372+
var b8 = b.substring(i, i + 7);
371373
if (i != b.length - 7)
372374
b8 = '1' + b8;
373375
h += itox(parseInt(b8, 2));
@@ -581,7 +583,7 @@ KJUR.asn1.DERAbstractTime = function (params) {
581583
var d = this.localDateToUTC(dateObject);
582584
var year = String(d.getFullYear());
583585
if (type == 'utc')
584-
year = year.substr(2, 2);
586+
year = year.substring(2, 4);
585587
var month = pad(String(d.getMonth() + 1), 2);
586588
var day = pad(String(d.getDate()), 2);
587589
var hour = pad(String(d.getHours()), 2);
@@ -891,7 +893,7 @@ KJUR.asn1.DERBitString = function (params) {
891893
}
892894
var h = '';
893895
for (var i = 0; i < binaryString.length - 1; i += 8) {
894-
var b = binaryString.substr(i, 8);
896+
var b = binaryString.substring(i, i + 8);
895897
var x = parseInt(b, 2).toString(16);
896898
if (x.length == 1)
897899
x = '0' + x;
@@ -1061,7 +1063,7 @@ KJUR.asn1.DERObjectIdentifier = function (params) {
10611063
bPad += '0';
10621064
b = bPad + b;
10631065
for (var i = 0; i < b.length - 1; i += 7) {
1064-
var b8 = b.substr(i, 7);
1066+
var b8 = b.substring(i, i + 7);
10651067
if (i != b.length - 7)
10661068
b8 = '1' + b8;
10671069
h += itox(parseInt(b8, 2));

src/lib/asn1js/LICENSE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1313
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1414
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1515
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

src/lib/asn1js/asn1.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
/*jshint browser: true, strict: true, immed: true, latedef: true, undef: true, regexdash: false */
1717
/*global oids */
1818

19-
import {Int10} from "./int10";
19+
import { Int10 } from "./int10";
2020

2121
const ellipsis = "\u2026";
22-
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)?)?$/;
22+
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)?)?$/;
2323
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)?)?$/;
2424

25-
function stringCut(str:string, len:number) {
25+
function stringCut(str: string, len: number) {
2626
if (str.length > len) {
2727
str = str.substring(0, len) + ellipsis;
2828
}
2929
return str;
3030
}
3131

3232
export class Stream {
33-
constructor(enc:Stream|number[], pos?:number) {
33+
constructor(enc: Stream | number[], pos?: number) {
3434
if (enc instanceof Stream) {
3535
this.enc = enc.enc;
3636
this.pos = enc.pos;
@@ -41,10 +41,10 @@ export class Stream {
4141
}
4242
}
4343

44-
private enc:string|number[];
45-
public pos:number;
44+
private enc: string | number[];
45+
public pos: number;
4646

47-
public get(pos?:number) {
47+
public get(pos?: number) {
4848
if (pos === undefined) {
4949
pos = this.pos++;
5050
}
@@ -56,11 +56,11 @@ export class Stream {
5656

5757
public hexDigits = "0123456789ABCDEF";
5858

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

63-
public hexDump(start:number, end:number, raw:boolean) {
63+
public hexDump(start: number, end: number, raw: boolean) {
6464
let s = "";
6565
for (let i = start; i < end; ++i) {
6666
s += this.hexByte(this.get(i));
@@ -80,7 +80,7 @@ export class Stream {
8080
return s;
8181
}
8282

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

93-
public parseStringISO(start:number, end:number) {
93+
public parseStringISO(start: number, end: number) {
9494
let s = "";
9595
for (let i = start; i < end; ++i) {
9696
s += String.fromCharCode(this.get(i));
9797
}
9898
return s;
9999
}
100100

101-
public parseStringUTF(start:number, end:number) {
101+
public parseStringUTF(start: number, end: number) {
102102
let s = "";
103103
for (let i = start; i < end;) {
104104
const c = this.get(i++);
@@ -113,7 +113,7 @@ export class Stream {
113113
return s;
114114
}
115115

116-
public parseStringBMP(start:number, end:number) {
116+
public parseStringBMP(start: number, end: number) {
117117
let str = "";
118118
let hi;
119119
let lo;
@@ -125,9 +125,9 @@ export class Stream {
125125
return str;
126126
}
127127

128-
public parseTime(start:number, end:number, shortYear:boolean) {
128+
public parseTime(start: number, end: number, shortYear: boolean) {
129129
let s = this.parseStringISO(start, end);
130-
const m:Array<number|string> = (shortYear ? reTimeS : reTimeL).exec(s);
130+
const m: Array<number | string> = (shortYear ? reTimeS : reTimeL).exec(s);
131131
if (!m) {
132132
return "Unrecognized time: " + s;
133133
}
@@ -159,12 +159,12 @@ export class Stream {
159159
return s;
160160
}
161161

162-
public parseInteger(start:number, end:number) {
162+
public parseInteger(start: number, end: number) {
163163
let v = this.get(start);
164164
const neg = (v > 127);
165165
const pad = neg ? 255 : 0;
166166
let len;
167-
let s:string | number = "";
167+
let s: string | number = "";
168168
// skip unuseful bits (not allowed in DER)
169169
while (v == pad && ++start < end) {
170170
v = this.get(start);
@@ -194,7 +194,7 @@ export class Stream {
194194
return s + n.toString();
195195
}
196196

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

215-
public parseOctetString(start:number, end:number, maxLength:number) {
215+
public parseOctetString(start: number, end: number, maxLength: number) {
216216
if (this.isASCII(start, end)) {
217217
return stringCut(this.parseStringISO(start, end), maxLength);
218218
}
@@ -231,9 +231,9 @@ export class Stream {
231231
return s;
232232
}
233233

234-
public parseOID(start:number, end:number, maxLength:number) {
234+
public parseOID(start: number, end: number, maxLength: number) {
235235
let s = "";
236-
let n:number|Int10 = new Int10();
236+
let n: number | Int10 = new Int10();
237237
let bits = 0;
238238
for (let i = start; i < end; ++i) {
239239
const v = this.get(i);
@@ -266,7 +266,7 @@ export class Stream {
266266
}
267267
}
268268
export class ASN1 {
269-
constructor(stream:Stream, header:number, length:number, tag:ASN1Tag, sub:ASN1[]) {
269+
constructor(stream: Stream, header: number, length: number, tag: ASN1Tag, sub: ASN1[]) {
270270
if (!(tag instanceof ASN1Tag)) {
271271
throw new Error("Invalid tag value.");
272272
}
@@ -277,11 +277,11 @@ export class ASN1 {
277277
this.sub = sub;
278278
}
279279

280-
private stream:Stream;
281-
private header:number;
282-
private length:number;
283-
private tag:ASN1Tag;
284-
public sub:ASN1[];
280+
private stream: Stream;
281+
private header: number;
282+
private length: number;
283+
private tag: ASN1Tag;
284+
public sub: ASN1[];
285285

286286
public typeName() {
287287
switch (this.tag.tagClass) {
@@ -352,7 +352,7 @@ export class ASN1 {
352352
}
353353
}
354354

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

421-
public toPrettyString(indent:string) {
421+
public toPrettyString(indent: string) {
422422
if (indent === undefined) {
423423
indent = "";
424424
}
@@ -458,7 +458,7 @@ export class ASN1 {
458458
return this.stream.hexDump(this.posStart(), this.posEnd(), true);
459459
}
460460

461-
public static decodeLength(stream:Stream):number {
461+
public static decodeLength(stream: Stream): number {
462462
let buf = stream.get();
463463
const len = buf & 0x7F;
464464
if (len == buf) {
@@ -484,15 +484,15 @@ export class ASN1 {
484484
* @returns {string}
485485
* @public
486486
*/
487-
public getHexStringValue():string {
487+
public getHexStringValue(): string {
488488
const hexString = this.toHexString();
489489
const offset = this.header * 2;
490490
const length = this.length * 2;
491-
return hexString.substr(offset, length);
491+
return hexString.substring(offset, offset + length);
492492
}
493493

494-
public static decode(str:Stream|number[]) {
495-
let stream:Stream;
494+
public static decode(str: Stream | number[]) {
495+
let stream: Stream;
496496

497497
if (!(str instanceof Stream)) {
498498
stream = new Stream(str, 0);
@@ -506,7 +506,7 @@ export class ASN1 {
506506
const start = stream.pos;
507507
const header = start - streamStart.pos;
508508
let sub = null;
509-
const getSub:() => ASN1[] = function () {
509+
const getSub: () => ASN1[] = function () {
510510
const ret = [];
511511
if (len !== null) {
512512
// definite length
@@ -569,7 +569,7 @@ export class ASN1 {
569569

570570

571571
export class ASN1Tag {
572-
constructor(stream:Stream) {
572+
constructor(stream: Stream) {
573573
let buf = stream.get();
574574
this.tagClass = buf >> 6;
575575
this.tagConstructed = ((buf & 0x20) !== 0);
@@ -584,9 +584,9 @@ export class ASN1Tag {
584584
}
585585
}
586586

587-
public tagClass:number;
588-
public tagConstructed:boolean;
589-
public tagNumber:number | Int10;
587+
public tagClass: number;
588+
public tagConstructed: boolean;
589+
public tagNumber: number | Int10;
590590

591591
public isUniversal() {
592592
return this.tagClass === 0x00;

0 commit comments

Comments
 (0)