Skip to content

Commit

Permalink
Migrate to null safety (flutter#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
natebosch authored Aug 10, 2020
1 parent 925a88c commit f7c48b3
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 37 deletions.
36 changes: 24 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
language: dart

dart:
- 2.3.0
- stable
- dev

dart_task:
- test: -p vm
- test: -p chrome
- dartanalyzer: --fatal-warnings --fatal-infos .

matrix:
jobs:
include:
# Only validate formatting using the dev release
- dart: dev
dart_task: dartfmt
- stage: analyze_and_format
name: "Analyze"
os: linux
script: dartanalyzer --fatal-warnings --fatal-infos .
- stage: analyze_and_format
name: "Format"
os: linux
script: dartfmt -n --set-exit-if-changed .
- stage: test
name: "Vm Tests"
os: linux
script: pub run --enable-experiment=non-nullable test -p vm
- stage: test
name: "Web Tests"
os: linux
script: pub run --enable-experiment=non-nullable test -p chrome

stages:
- analyze_and_format
- test


# Only building master means that we don't run two builds for each pull request.
branches:
only: [master]
only: [master, null_safety]

cache:
directories:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 2.2.0-nullsafety

Pre-release for the null safety migration of this package.

Note that 2.2.0 may not be the final stable null safety release version, we
reserve the right to release it as a 3.0.0 breaking change.

This release will be pinned to only allow pre-release sdk versions starting from
2.10.0-2.0.dev, which is the first version where this package will appear in the
null safety allow list.

## 2.1.5

* Improve example and package description to address package site maintenance
Expand Down
4 changes: 4 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ include: package:pedantic/analysis_options.yaml
analyzer:
strong-mode:
implicit-casts: false

enable-experiment:
- non-nullable

linter:
rules:
- avoid_empty_else
Expand Down
2 changes: 1 addition & 1 deletion example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:crypto/crypto.dart';
final _usage = 'Usage: dart hash.dart <md5|sha1|sha256> <input_filename>';

Future main(List<String> args) async {
if (args == null || args.length != 2) {
if (args.length != 2) {
print(_usage);
exitCode = 64; // Command was used incorrectly.
return;
Expand Down
11 changes: 4 additions & 7 deletions lib/src/digest_sink.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ import 'digest.dart';
/// A sink used to get a digest value out of `Hash.startChunkedConversion`.
class DigestSink extends Sink<Digest> {
/// The value added to the sink, if any.
Digest get value {
assert(_value != null);
return _value;
}
Digest get value => _value;

Digest _value;
late final Digest _value;

/// Adds [value] to the sink.
///
/// Unlike most sinks, this may only be called once.
@override
void add(Digest value) {
assert(_value == null);
_value = value;
}

@override
void close() {
assert(_value != null);
// Ensure late final field was assigned before closing.
assert((_value as dynamic) != null);
}
}
2 changes: 1 addition & 1 deletion lib/src/hmac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class _HmacSink extends ByteConversionSink {
final _innerResultSink = DigestSink();

/// The sink for the inner hash computation.
ByteConversionSink _innerSink;
late final ByteConversionSink _innerSink;

/// Whether [close] has been called.
bool _isClosed = false;
Expand Down
18 changes: 11 additions & 7 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
name: crypto
version: 2.1.5
version: 2.2.0-nullsafety
description: Implementations of SHA, MD5, and HMAC cryptographic functions
homepage: https://www.github.com/dart-lang/crypto

environment:
sdk: '>=2.3.0 <3.0.0'
sdk: '>=2.10.0-2.0.dev <2.10.0'

dependencies:
collection: '^1.0.0'
convert: '>=1.0.0 <3.0.0'
typed_data: '^1.0.0'
collection: ^1.15.0-nullsafety
convert: ^2.2.0-nullsafety
typed_data: ^1.3.0-nullsafety

dev_dependencies:
pedantic: ^1.0.0
test: ^1.0.0
pedantic: ^1.10.0-nullsafety
test: ^1.16.0-nullsafety

dependency_overrides:
convert:
git: git://github.com/dart-lang/convert.git
14 changes: 7 additions & 7 deletions test/hmac_sha2_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ void main() {
}

void testCase({
String name,
String key,
String data,
String hmacSha224,
String hmacSha256,
String hmacSha384,
String hmacSha512,
required String name,
required String key,
required String data,
required String hmacSha224,
required String hmacSha256,
required String hmacSha384,
required String hmacSha512,
bool truncation = false,
}) {
test(name, () {
Expand Down
2 changes: 1 addition & 1 deletion test/sha_monte_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void monteTest(String name, Hash hash, String seed, List<String> expected) {
md0 = (Uint8List.fromList(_seed));
md1 = (Uint8List.fromList(_seed));
md2 = (Uint8List.fromList(_seed));
Digest mdI;
late Digest mdI;
for (var i = 3; i < 1003; i++) {
var mI = [...md0, ...md1, ...md2];
mdI = hash.convert(mI);
Expand Down
2 changes: 1 addition & 1 deletion test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final toupleMatch = RegExp('([0-9a-fA-F]{2})');
Uint8List bytesFromHexString(String message) {
var bytes = <int>[];
for (var match in toupleMatch.allMatches(message)) {
bytes.add(int.parse(match.group(0), radix: 16));
bytes.add(int.parse(match.group(0)!, radix: 16));
}
return Uint8List.fromList(bytes);
}

0 comments on commit f7c48b3

Please sign in to comment.