Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: lib/src/hash_sink.dart

Issue 1906093002: Close underlying Hash sinks. (Closed) Base URL: git@github.com:dart-lang/crypto@master
Patch Set: cr Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 import 'dart:typed_data'; 5 import 'dart:typed_data';
6 6
7 import 'package:typed_data/typed_data.dart'; 7 import 'package:typed_data/typed_data.dart';
8 8
9 import 'digest.dart'; 9 import 'digest.dart';
10 import 'utils.dart'; 10 import 'utils.dart';
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 } 63 }
64 64
65 void close() { 65 void close() {
66 if (_isClosed) return; 66 if (_isClosed) return;
67 _isClosed = true; 67 _isClosed = true;
68 68
69 _finalizeData(); 69 _finalizeData();
70 _iterate(); 70 _iterate();
71 assert(_pendingData.isEmpty); 71 assert(_pendingData.isEmpty);
72 _sink.add(new Digest(_byteDigest())); 72 _sink.add(new Digest(_byteDigest()));
73 _sink.close();
73 } 74 }
74 75
75 Uint8List _byteDigest() { 76 Uint8List _byteDigest() {
76 if (_endian == Endianness.HOST_ENDIAN) return digest.buffer.asUint8List(); 77 if (_endian == Endianness.HOST_ENDIAN) return digest.buffer.asUint8List();
77 78
78 var byteDigest = new Uint8List(digest.lengthInBytes); 79 var byteDigest = new Uint8List(digest.lengthInBytes);
79 var byteData = byteDigest.buffer.asByteData(); 80 var byteData = byteDigest.buffer.asByteData();
80 for (var i = 0; i < digest.length; i++) { 81 for (var i = 0; i < digest.length; i++) {
81 byteData.setUint32(i * bytesPerWord, digest[i]); 82 byteData.setUint32(i * bytesPerWord, digest[i]);
82 } 83 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } else { 142 } else {
142 byteData.setUint32(offset, lowBits, _endian); 143 byteData.setUint32(offset, lowBits, _endian);
143 byteData.setUint32(offset + bytesPerWord, highBits, _endian); 144 byteData.setUint32(offset + bytesPerWord, highBits, _endian);
144 } 145 }
145 } 146 }
146 147
147 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of 148 /// Rounds [val] up to the next multiple of [n], as long as [n] is a power of
148 /// two. 149 /// two.
149 int _roundUp(int val, int n) => (val + n - 1) & -n; 150 int _roundUp(int val, int n) => (val + n - 1) & -n;
150 } 151 }
OLDNEW
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698