Skip to content

Commit

Permalink
Close underlying Hash sinks.
Browse files Browse the repository at this point in the history
Closes #33

R=kevmoo@google.com

Review URL: https://codereview.chromium.org//1906093002 .
  • Loading branch information
nex3 committed Apr 21, 2016
1 parent aa022ca commit d257280
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,8 @@
## 1.1.1

* Properly close sinks passed to `Hash.startChunkedConversion()` when
`ByteConversionSink.close()` is called.

## 1.1.0

* `Hmac` and `Hash` now extend the new `ChunkedConverter` class from
Expand Down
1 change: 1 addition & 0 deletions lib/src/hash_sink.dart
Expand Up @@ -70,6 +70,7 @@ abstract class HashSink implements Sink<List<int>> {
_iterate();
assert(_pendingData.isEmpty);
_sink.add(new Digest(_byteDigest()));
_sink.close();
}

Uint8List _byteDigest() {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: crypto
version: 1.1.0
version: 1.1.1
author: Dart Team <misc@dartlang.org>
description: Library of cryptographic functions.
homepage: https://www.github.com/dart-lang/crypto
Expand Down
13 changes: 13 additions & 0 deletions test/sha1_test.dart
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import "dart:async";
import "dart:convert";

import "package:crypto/crypto.dart";
import "package:test/test.dart";
Expand All @@ -24,6 +25,18 @@ void main() {
sink.close();
sink.close();
});

test('close closes the underlying sink', () {
var inner = new ChunkedConversionSink<Digest>.withCallback(
expectAsync((accumulated) {
expect(accumulated.length, equals(1));
expect(accumulated.first.toString(),
equals("da39a3ee5e6b4b0d3255bfef95601890afd80709"));
}));

var outer = sha1.startChunkedConversion(inner);
outer.close();
});
});

group("standard vector", () {
Expand Down
16 changes: 16 additions & 0 deletions test/sha256_test.dart
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import "dart:async";
import "dart:convert";

import "package:test/test.dart";
import "package:crypto/crypto.dart";
Expand All @@ -24,6 +25,21 @@ void main() {
sink.close();
sink.close();
});

test('close closes the underlying sink', () {
var inner = new ChunkedConversionSink<Digest>.withCallback(
expectAsync((accumulated) {
expect(accumulated.length, equals(1));
expect(
accumulated.first.toString(),
equals(
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8"
"55"));
}));

var outer = sha256.startChunkedConversion(inner);
outer.close();
});
});

group("standard vector", () {
Expand Down

0 comments on commit d257280

Please sign in to comment.