@@ -4,26 +4,28 @@ export class WordArray {
44 words : number [ ] ;
55 sigBytes : number ;
66
7- constructor ( words ?, sigBytes ?) {
7+ constructor ( words ?, sigBytes ?) {
88 words = this . words = words || [ ] ;
99
1010 this . sigBytes = sigBytes !== undefined ? sigBytes : words . length * 4 ;
1111 }
1212
13- toString ( encoder ?) : string {
13+ toString ( encoder ?) : string {
1414 return ( encoder || Hex ) . stringify ( this ) ;
1515 }
1616
17- concat ( wordArray : WordArray ) {
17+ concat ( wordArray : WordArray ) {
1818 // Clamp excess bits
1919 this . clamp ( ) ;
2020
2121 // Concat
2222 if ( this . sigBytes % 4 ) {
2323 // Copy one byte at a time
2424 for ( let i = 0 ; i < wordArray . sigBytes ; i ++ ) {
25- const thatByte = ( wordArray . words [ i >>> 2 ] >>> ( 24 - ( i % 4 ) * 8 ) ) & 0xFF ;
26- this . words [ ( this . sigBytes + i ) >>> 2 ] |= thatByte << ( 24 - ( ( this . sigBytes + i ) % 4 ) * 8 ) ;
25+ const thatByte =
26+ ( wordArray . words [ i >>> 2 ] >>> ( 24 - ( i % 4 ) * 8 ) ) & 0xff ;
27+ this . words [ ( this . sigBytes + i ) >>> 2 ] |=
28+ thatByte << ( 24 - ( ( this . sigBytes + i ) % 4 ) * 8 ) ;
2729 }
2830 } else {
2931 // Copy one word at a time
@@ -37,89 +39,90 @@ export class WordArray {
3739 return this ;
3840 }
3941
40- clamp ( ) {
42+ clamp ( ) {
4143 // Clamp
42- this . words [ this . sigBytes >>> 2 ] &= 0xFF_FF_FF_FF << ( 32 - ( this . sigBytes % 4 ) * 8 ) ;
44+ this . words [ this . sigBytes >>> 2 ] &=
45+ 0xff_ff_ff_ff << ( 32 - ( this . sigBytes % 4 ) * 8 ) ;
4346 this . words . length = Math . ceil ( this . sigBytes / 4 ) ;
4447 }
4548
46- clone ( ) {
49+ clone ( ) {
4750 return new WordArray ( [ ...this . words ] ) ;
4851 }
4952}
5053
5154export const Hex = {
52- stringify ( wordArray : WordArray ) {
55+ stringify ( wordArray : WordArray ) {
5356 // Convert
5457 const hexChars : string [ ] = [ ] ;
5558 for ( let i = 0 ; i < wordArray . sigBytes ; i ++ ) {
56- const bite = ( wordArray . words [ i >>> 2 ] >>> ( 24 - ( i % 4 ) * 8 ) ) & 0xFF ;
57- hexChars . push (
58- ( bite >>> 4 ) . toString ( 16 ) ,
59- ( bite & 0x0F ) . toString ( 16 )
60- ) ;
59+ const bite = ( wordArray . words [ i >>> 2 ] >>> ( 24 - ( i % 4 ) * 8 ) ) & 0xff ;
60+ hexChars . push ( ( bite >>> 4 ) . toString ( 16 ) , ( bite & 0x0f ) . toString ( 16 ) ) ;
6161 }
6262
6363 return hexChars . join ( "" ) ;
64- }
64+ } ,
6565} ;
6666
6767export const Base64 = {
68- stringify ( wordArray : WordArray ) {
69- const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
68+ stringify ( wordArray : WordArray ) {
69+ const keyStr =
70+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
7071 const base64Chars : string [ ] = [ ] ;
7172 for ( let i = 0 ; i < wordArray . sigBytes ; i += 3 ) {
72- const byte1 = ( wordArray . words [ i >>> 2 ] >>> ( 24 - ( i % 4 ) * 8 ) ) & 0xFF ;
73- const byte2 = ( wordArray . words [ ( i + 1 ) >>> 2 ] >>> ( 24 - ( ( i + 1 ) % 4 ) * 8 ) ) & 0xFF ;
74- const byte3 = ( wordArray . words [ ( i + 2 ) >>> 2 ] >>> ( 24 - ( ( i + 2 ) % 4 ) * 8 ) ) & 0xFF ;
73+ const byte1 = ( wordArray . words [ i >>> 2 ] >>> ( 24 - ( i % 4 ) * 8 ) ) & 0xff ;
74+ const byte2 =
75+ ( wordArray . words [ ( i + 1 ) >>> 2 ] >>> ( 24 - ( ( i + 1 ) % 4 ) * 8 ) ) & 0xff ;
76+ const byte3 =
77+ ( wordArray . words [ ( i + 2 ) >>> 2 ] >>> ( 24 - ( ( i + 2 ) % 4 ) * 8 ) ) & 0xff ;
7578
7679 const triplet = ( byte1 << 16 ) | ( byte2 << 8 ) | byte3 ;
77- for ( let j = 0 ; ( j < 4 ) && ( i * 8 + j * 6 < wordArray . sigBytes * 8 ) ; j ++ ) {
78- base64Chars . push ( keyStr . charAt ( ( triplet >>> ( 6 * ( 3 - j ) ) ) & 0x3F ) ) ;
80+ for ( let j = 0 ; j < 4 && i * 8 + j * 6 < wordArray . sigBytes * 8 ; j ++ ) {
81+ base64Chars . push ( keyStr . charAt ( ( triplet >>> ( 6 * ( 3 - j ) ) ) & 0x3f ) ) ;
7982 }
8083 }
8184 return base64Chars . join ( "" ) ;
82- }
85+ } ,
8386} ;
8487
8588export const Latin1 = {
86- parse ( latin1Str ) {
89+ parse ( latin1Str ) {
8790 // Shortcut
8891 const latin1StrLength = latin1Str . length ;
8992
9093 // Convert
9194 const words = [ ] ;
9295 for ( let i = 0 ; i < latin1StrLength ; i ++ ) {
93- words [ i >>> 2 ] |= ( latin1Str . charCodeAt ( i ) & 0xFF ) << ( 24 - ( i % 4 ) * 8 ) ;
96+ words [ i >>> 2 ] |= ( latin1Str . charCodeAt ( i ) & 0xff ) << ( 24 - ( i % 4 ) * 8 ) ;
9497 }
9598
9699 return new WordArray ( words , latin1StrLength ) ;
97- }
100+ } ,
98101} ;
99102
100103export const Utf8 = {
101- parse ( utf8Str ) {
104+ parse ( utf8Str ) {
102105 return Latin1 . parse ( unescape ( encodeURIComponent ( utf8Str ) ) ) ;
103- }
106+ } ,
104107} ;
105108
106109export class BufferedBlockAlgorithm {
107110 _data : WordArray ;
108111 _nDataBytes : number ;
109- _minBufferSize : number = 0 ;
112+ _minBufferSize = 0 ;
110113 blockSize = 512 / 32 ;
111114
112- constructor ( ) {
115+ constructor ( ) {
113116 this . reset ( ) ;
114117 }
115118
116- reset ( ) {
119+ reset ( ) {
117120 // Initial values
118121 this . _data = new WordArray ( ) ;
119122 this . _nDataBytes = 0 ;
120123 }
121124
122- _append ( data ) {
125+ _append ( data ) {
123126 // Convert string to WordArray, else assume WordArray already
124127 if ( typeof data === "string" ) {
125128 data = Utf8 . parse ( data ) ;
@@ -130,13 +133,14 @@ export class BufferedBlockAlgorithm {
130133 this . _nDataBytes += data . sigBytes ;
131134 }
132135
133- _doProcessBlock ( _dataWords , _offset ) { }
136+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
137+ _doProcessBlock ( _dataWords , _offset ) { }
134138
135- _process ( doFlush ?: Boolean ) {
139+ _process ( doFlush ?: boolean ) {
136140 let processedWords ;
137141
138142 // Count blocks ready
139- let nBlocksReady = this . _data . sigBytes / ( this . blockSize * 4 /* bytes */ ) ;
143+ let nBlocksReady = this . _data . sigBytes / ( this . blockSize * 4 ) ; /* bytes */
140144 if ( doFlush ) {
141145 // Round up to include partial blocks
142146 nBlocksReady = Math . ceil ( nBlocksReady ) ;
@@ -170,7 +174,7 @@ export class BufferedBlockAlgorithm {
170174}
171175
172176export class Hasher extends BufferedBlockAlgorithm {
173- update ( messageUpdate ) {
177+ update ( messageUpdate ) {
174178 // Append
175179 this . _append ( messageUpdate ) ;
176180
@@ -181,7 +185,7 @@ export class Hasher extends BufferedBlockAlgorithm {
181185 return this ;
182186 }
183187
184- finalize ( messageUpdate ) {
188+ finalize ( messageUpdate ) {
185189 // Final message update
186190 if ( messageUpdate ) {
187191 this . _append ( messageUpdate ) ;
0 commit comments