| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * SHA-1. | 6 * SHA-1. |
| 7 * Ripped from package:crypto. | 7 * Ripped from package:crypto. |
| 8 */ | 8 */ |
| 9 library sha1; | 9 library sha1; |
| 10 | 10 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 int _rotl32(int val, int shift) { | 71 int _rotl32(int val, int shift) { |
| 72 var mod_shift = shift & 31; | 72 var mod_shift = shift & 31; |
| 73 return ((val << mod_shift) & _MASK_32) | | 73 return ((val << mod_shift) & _MASK_32) | |
| 74 ((val & _MASK_32) >> (32 - mod_shift)); | 74 ((val & _MASK_32) >> (32 - mod_shift)); |
| 75 } | 75 } |
| 76 | 76 |
| 77 // Base class encapsulating common behavior for cryptographic hash | 77 // Base class encapsulating common behavior for cryptographic hash |
| 78 // functions. | 78 // functions. |
| 79 abstract class _HashBase implements Hash { | 79 abstract class _HashBase implements Hash { |
| 80 final int _chunkSizeInWords; | 80 final int _chunkSizeInWords; |
| 81 final int _digestSizeInWords; | |
| 82 final bool _bigEndianWords; | 81 final bool _bigEndianWords; |
| 83 final List<int> _currentChunk; | 82 final List<int> _currentChunk; |
| 84 final List<int> _h; | 83 final List<int> _h; |
| 85 int _lengthInBytes = 0; | 84 int _lengthInBytes = 0; |
| 86 List<int> _pendingData; | 85 List<int> _pendingData; |
| 87 bool _digestCalled = false; | 86 bool _digestCalled = false; |
| 88 | 87 |
| 89 _HashBase( | 88 _HashBase( |
| 90 int chunkSizeInWords, int digestSizeInWords, bool this._bigEndianWords) | 89 int chunkSizeInWords, int digestSizeInWords, bool this._bigEndianWords) |
| 91 : _pendingData = [], | 90 : _pendingData = [], |
| 92 _currentChunk = new List(chunkSizeInWords), | 91 _currentChunk = new List(chunkSizeInWords), |
| 93 _h = new List(digestSizeInWords), | 92 _h = new List(digestSizeInWords), |
| 94 _chunkSizeInWords = chunkSizeInWords, | 93 _chunkSizeInWords = chunkSizeInWords; |
| 95 _digestSizeInWords = digestSizeInWords; | |
| 96 | 94 |
| 97 // Update the hasher with more data. | 95 // Update the hasher with more data. |
| 98 void add(List<int> data) { | 96 void add(List<int> data) { |
| 99 if (_digestCalled) { | 97 if (_digestCalled) { |
| 100 throw new StateError( | 98 throw new StateError( |
| 101 'Hash update method called after digest was retrieved'); | 99 'Hash update method called after digest was retrieved'); |
| 102 } | 100 } |
| 103 _lengthInBytes += data.length; | 101 _lengthInBytes += data.length; |
| 104 _pendingData.addAll(data); | 102 _pendingData.addAll(data); |
| 105 _iterate(); | 103 _iterate(); |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 int y = bytes[i + 1]; | 359 int y = bytes[i + 1]; |
| 362 out[j++] = lookup.codeUnitAt(x >> 2); | 360 out[j++] = lookup.codeUnitAt(x >> 2); |
| 363 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F); | 361 out[j++] = lookup.codeUnitAt(((x << 4) | (y >> 4)) & 0x3F); |
| 364 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F); | 362 out[j++] = lookup.codeUnitAt((y << 2) & 0x3F); |
| 365 out[j++] = PAD; | 363 out[j++] = PAD; |
| 366 } | 364 } |
| 367 | 365 |
| 368 return new String.fromCharCodes(out); | 366 return new String.fromCharCodes(out); |
| 369 } | 367 } |
| 370 } | 368 } |
| OLD | NEW |