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
2121const ellipsis = "\u2026" ;
22- const reTimeS = / ^ ( \d \d ) ( 0 [ 1 - 9 ] | 1 [ 0 - 2 ] ) ( 0 [ 1 - 9 ] | [ 1 2 ] \d | 3 [ 0 1 ] ) ( [ 0 1 ] \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 ] | [ 1 2 ] \d | 3 [ 0 1 ] ) ( [ 0 1 ] \d | 2 [ 0 - 3 ] ) (?: ( [ 0 - 5 ] \d ) (?: ( [ 0 - 5 ] \d ) (?: [ . , ] ( \d { 1 , 3 } ) ) ? ) ? ) ? ( Z | [ - + ] (?: [ 0 ] \d | 1 [ 0 - 2 ] ) ( [ 0 - 5 ] \d ) ? ) ? $ / ;
2323const reTimeL = / ^ ( \d \d \d \d ) ( 0 [ 1 - 9 ] | 1 [ 0 - 2 ] ) ( 0 [ 1 - 9 ] | [ 1 2 ] \d | 3 [ 0 1 ] ) ( [ 0 1 ] \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
3232export 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}
268268export 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
571571export 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