Skip to content

Commit 913ca2a

Browse files
kevmoocommit-bot@chromium.org
authored andcommitted
dart:_http: cleanup implementation of crypto
Remove unused members Add return types to functions Use Uint32List instead of List<int> Change-Id: I0772467075978aabfa65c07eb4f457e5c7db2bff Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217803 Auto-Submit: Kevin Moore <[email protected]> Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Kevin Moore <[email protected]>
1 parent 6a386a6 commit 913ca2a

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

sdk/lib/_http/crypto.dart

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ abstract class _HashBase {
3636
final bool _bigEndianWords;
3737
int _lengthInBytes = 0;
3838
List<int> _pendingData;
39-
final List<int> _currentChunk;
40-
final List<int> _h;
39+
final Uint32List _currentChunk;
40+
final Uint32List _h;
4141
bool _digestCalled = false;
4242

4343
_HashBase(this._chunkSizeInWords, int digestSizeInWords, this._bigEndianWords)
4444
: _pendingData = [],
45-
_currentChunk = List.filled(_chunkSizeInWords, 0),
46-
_h = List.filled(digestSizeInWords, 0);
45+
_currentChunk = Uint32List(_chunkSizeInWords),
46+
_h = Uint32List(digestSizeInWords);
4747

4848
// Update the hasher with more data.
49-
add(List<int> data) {
49+
void add(List<int> data) {
5050
if (_digestCalled) {
5151
throw StateError('Hash update method called after digest was retrieved');
5252
}
@@ -72,11 +72,8 @@ abstract class _HashBase {
7272
return _chunkSizeInWords * _BYTES_PER_WORD;
7373
}
7474

75-
// Create a fresh instance of this Hash.
76-
newInstance();
77-
7875
// One round of the hash computation.
79-
_updateHash(List<int> m);
76+
_updateHash(Uint32List m);
8077

8178
// Helper methods.
8279
int _add32(int x, int y) => (x + y) & _MASK_32;
@@ -99,7 +96,7 @@ abstract class _HashBase {
9996
}
10097

10198
// Converts a list of bytes to a chunk of 32-bit words.
102-
_bytesToChunk(List<int> data, int dataIndex) {
99+
void _bytesToChunk(List<int> data, int dataIndex) {
103100
assert((data.length - dataIndex) >= (_chunkSizeInWords * _BYTES_PER_WORD));
104101

105102
for (var wordIndex = 0; wordIndex < _chunkSizeInWords; wordIndex++) {
@@ -128,7 +125,7 @@ abstract class _HashBase {
128125

129126
// Iterate through data updating the hash computation for each
130127
// chunk.
131-
_iterate() {
128+
void _iterate() {
132129
var len = _pendingData.length;
133130
var chunkSizeInBytes = _chunkSizeInWords * _BYTES_PER_WORD;
134131
if (len >= chunkSizeInBytes) {
@@ -143,7 +140,7 @@ abstract class _HashBase {
143140

144141
// Finalize the data. Add a 1 bit to the end of the message. Expand with
145142
// 0 bits and add the length of the message.
146-
_finalizeData() {
143+
void _finalizeData() {
147144
_pendingData.add(0x80);
148145
var contentsLength = _lengthInBytes + 9;
149146
var chunkSizeInBytes = _chunkSizeInWords * _BYTES_PER_WORD;
@@ -173,11 +170,6 @@ class _MD5 extends _HashBase {
173170
_h[3] = 0x10325476;
174171
}
175172

176-
// Returns a new instance of this Hash.
177-
_MD5 newInstance() {
178-
return _MD5();
179-
}
180-
181173
static const _k = [
182174
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, //
183175
0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, //
@@ -201,7 +193,7 @@ class _MD5 extends _HashBase {
201193

202194
// Compute one iteration of the MD5 algorithm with a chunk of
203195
// 16 32-bit pieces.
204-
void _updateHash(List<int> m) {
196+
void _updateHash(Uint32List m) {
205197
assert(m.length == 16);
206198

207199
var a = _h[0];
@@ -257,14 +249,9 @@ class _SHA1 extends _HashBase {
257249
_h[4] = 0xC3D2E1F0;
258250
}
259251

260-
// Returns a new instance of this Hash.
261-
_SHA1 newInstance() {
262-
return _SHA1();
263-
}
264-
265252
// Compute one iteration of the SHA1 algorithm with a chunk of
266253
// 16 32-bit pieces.
267-
void _updateHash(List<int> m) {
254+
void _updateHash(Uint32List m) {
268255
assert(m.length == 16);
269256

270257
var a = _h[0];

0 commit comments

Comments
 (0)