@@ -21,7 +21,7 @@ class _CryptoUtils {
21
21
// -1 : '\r' or '\n'
22
22
// 0 : = (Padding character).
23
23
// >0 : Base 64 alphabet index of given byte.
24
- static const List <int > _decodeTable = const [
24
+ static const List <int > _decodeTable = [
25
25
- 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 1 , - 2 , - 2 , - 1 , - 2 , - 2 , //
26
26
- 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , //
27
27
- 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , 62 , - 2 , 62 , - 2 , 63 , //
@@ -40,18 +40,16 @@ class _CryptoUtils {
40
40
- 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2 , - 2
41
41
];
42
42
43
- static Random _rng = new Random .secure ();
44
-
45
43
static Uint8List getRandomBytes (int count) {
46
- final Uint8List result = new Uint8List (count);
44
+ final Uint8List result = Uint8List (count);
47
45
for (int i = 0 ; i < count; i++ ) {
48
- result[i] = _rng .nextInt (0xff );
46
+ result[i] = Random . secure () .nextInt (0xff );
49
47
}
50
48
return result;
51
49
}
52
50
53
51
static String bytesToHex (List <int > bytes) {
54
- var result = new StringBuffer ();
52
+ var result = StringBuffer ();
55
53
for (var part in bytes) {
56
54
result.write ('${part < 16 ? '0' : '' }${part .toRadixString (16 )}' );
57
55
}
@@ -66,15 +64,15 @@ class _CryptoUtils {
66
64
}
67
65
final String lookup = urlSafe ? _encodeTableUrlSafe : _encodeTable;
68
66
// Size of 24 bit chunks.
69
- final int remainderLength = len.remainder (3 ) as int ;
67
+ final int remainderLength = len.remainder (3 );
70
68
final int chunkLength = len - remainderLength;
71
69
// Size of base output.
72
70
int outputLen = ((len ~ / 3 ) * 4 ) + ((remainderLength > 0 ) ? 4 : 0 );
73
71
// Add extra for line separators.
74
72
if (addLineSeparator) {
75
73
outputLen += ((outputLen - 1 ) ~ / LINE_LENGTH ) << 1 ;
76
74
}
77
- List <int > out = new List <int >.filled (outputLen, 0 );
75
+ List <int > out = List <int >.filled (outputLen, 0 );
78
76
79
77
// Encode 24 bit chunks.
80
78
int j = 0 , i = 0 , c = 0 ;
@@ -111,14 +109,14 @@ class _CryptoUtils {
111
109
out[j++ ] = PAD ;
112
110
}
113
111
114
- return new String .fromCharCodes (out);
112
+ return String .fromCharCodes (out);
115
113
}
116
114
117
115
static List <int > base64StringToBytes (String input,
118
116
[bool ignoreInvalidCharacters = true ]) {
119
117
int len = input.length;
120
118
if (len == 0 ) {
121
- return new List <int >.empty ();
119
+ return List <int >.empty ();
122
120
}
123
121
124
122
// Count '\r', '\n' and illegal characters, For illegal characters,
@@ -129,13 +127,13 @@ class _CryptoUtils {
129
127
if (c < 0 ) {
130
128
extrasLen++ ;
131
129
if (c == - 2 && ! ignoreInvalidCharacters) {
132
- throw new FormatException ('Invalid character: ${input [i ]}' );
130
+ throw FormatException ('Invalid character: ${input [i ]}' );
133
131
}
134
132
}
135
133
}
136
134
137
135
if ((len - extrasLen) % 4 != 0 ) {
138
- throw new FormatException ('''Size of Base 64 characters in Input
136
+ throw FormatException ('''Size of Base 64 characters in Input
139
137
must be a multiple of 4. Input: $input ''' );
140
138
}
141
139
@@ -147,7 +145,7 @@ class _CryptoUtils {
147
145
if (currentCodeUnit == PAD ) padLength++ ;
148
146
}
149
147
int outputLen = (((len - extrasLen) * 6 ) >> 3 ) - padLength;
150
- List <int > out = new List <int >.filled (outputLen, 0 );
148
+ List <int > out = List <int >.filled (outputLen, 0 );
151
149
152
150
for (int i = 0 , o = 0 ; o < outputLen;) {
153
151
// Accumulate 4 valid 6 bit Base 64 characters into an int.
@@ -183,20 +181,19 @@ abstract class _HashBase {
183
181
final bool _bigEndianWords;
184
182
int _lengthInBytes = 0 ;
185
183
List <int > _pendingData;
186
- List <int > _currentChunk;
187
- List <int > _h;
184
+ final List <int > _currentChunk;
185
+ final List <int > _h;
188
186
bool _digestCalled = false ;
189
187
190
188
_HashBase (this ._chunkSizeInWords, int digestSizeInWords, this ._bigEndianWords)
191
189
: _pendingData = [],
192
- _currentChunk = new List .filled (_chunkSizeInWords, 0 ),
193
- _h = new List .filled (digestSizeInWords, 0 );
190
+ _currentChunk = List .filled (_chunkSizeInWords, 0 ),
191
+ _h = List .filled (digestSizeInWords, 0 );
194
192
195
193
// Update the hasher with more data.
196
194
add (List <int > data) {
197
195
if (_digestCalled) {
198
- throw new StateError (
199
- 'Hash update method called after digest was retrieved' );
196
+ throw StateError ('Hash update method called after digest was retrieved' );
200
197
}
201
198
_lengthInBytes += data.length;
202
199
_pendingData.addAll (data);
@@ -211,7 +208,7 @@ abstract class _HashBase {
211
208
_digestCalled = true ;
212
209
_finalizeData ();
213
210
_iterate ();
214
- assert (_pendingData.length == 0 );
211
+ assert (_pendingData.isEmpty );
215
212
return _resultAsBytes ();
216
213
}
217
214
@@ -227,8 +224,8 @@ abstract class _HashBase {
227
224
_updateHash (List <int > m);
228
225
229
226
// Helper methods.
230
- _add32 (x, y) => (x + y) & _MASK_32 ;
231
- _roundUp (val, n) => (val + n - 1 ) & - n;
227
+ int _add32 (int x, int y) => (x + y) & _MASK_32 ;
228
+ int _roundUp (int val, int n) => (val + n - 1 ) & - n;
232
229
233
230
// Rotate left limiting to unsigned 32-bit values.
234
231
int _rotl32 (int val, int shift) {
@@ -266,7 +263,7 @@ abstract class _HashBase {
266
263
267
264
// Convert a 32-bit word to four bytes.
268
265
List <int > _wordToBytes (int word) {
269
- List <int > bytes = new List .filled (_BYTES_PER_WORD , 0 );
266
+ List <int > bytes = List .filled (_BYTES_PER_WORD , 0 );
270
267
bytes[0 ] = (word >> (_bigEndianWords ? 24 : 0 )) & _MASK_8 ;
271
268
bytes[1 ] = (word >> (_bigEndianWords ? 16 : 8 )) & _MASK_8 ;
272
269
bytes[2 ] = (word >> (_bigEndianWords ? 8 : 16 )) & _MASK_8 ;
@@ -323,10 +320,10 @@ class _MD5 extends _HashBase {
323
320
324
321
// Returns a new instance of this Hash.
325
322
_MD5 newInstance () {
326
- return new _MD5 ();
323
+ return _MD5 ();
327
324
}
328
325
329
- static const _k = const [
326
+ static const _k = [
330
327
0xd76aa478 , 0xe8c7b756 , 0x242070db , 0xc1bdceee , 0xf57c0faf , 0x4787c62a , //
331
328
0xa8304613 , 0xfd469501 , 0x698098d8 , 0x8b44f7af , 0xffff5bb1 , 0x895cd7be , //
332
329
0x6b901122 , 0xfd987193 , 0xa679438e , 0x49b40821 , 0xf61e2562 , 0xc040b340 , //
@@ -340,7 +337,7 @@ class _MD5 extends _HashBase {
340
337
0xf7537e82 , 0xbd3af235 , 0x2ad7d2bb , 0xeb86d391
341
338
];
342
339
343
- static const _r = const [
340
+ static const _r = [
344
341
7 , 12 , 17 , 22 , 7 , 12 , 17 , 22 , 7 , 12 , 17 , 22 , 7 , 12 , 17 , 22 , 5 , 9 , 14 , //
345
342
20 , 5 , 9 , 14 , 20 , 5 , 9 , 14 , 20 , 5 , 9 , 14 , 20 , 4 , 11 , 16 , 23 , 4 , 11 , //
346
343
16 , 23 , 4 , 11 , 16 , 23 , 4 , 11 , 16 , 23 , 6 , 10 , 15 , 21 , 6 , 10 , 15 , 21 , 6 , //
@@ -357,8 +354,8 @@ class _MD5 extends _HashBase {
357
354
var c = _h[2 ];
358
355
var d = _h[3 ];
359
356
360
- var t0;
361
- var t1;
357
+ int t0;
358
+ int t1;
362
359
363
360
for (var i = 0 ; i < 64 ; i++ ) {
364
361
if (i < 16 ) {
@@ -392,7 +389,7 @@ class _MD5 extends _HashBase {
392
389
393
390
// The SHA1 hasher is used to compute an SHA1 message digest.
394
391
class _SHA1 extends _HashBase {
395
- List <int > _w;
392
+ final List <int > _w;
396
393
397
394
// Construct a SHA1 hasher object.
398
395
_SHA1 ()
@@ -407,7 +404,7 @@ class _SHA1 extends _HashBase {
407
404
408
405
// Returns a new instance of this Hash.
409
406
_SHA1 newInstance () {
410
- return new _SHA1 ();
407
+ return _SHA1 ();
411
408
}
412
409
413
410
// Compute one iteration of the SHA1 algorithm with a chunk of
0 commit comments