Skip to content

Commit f7c48b3

Browse files
authored
Migrate to null safety (flutter#99)
1 parent 925a88c commit f7c48b3

File tree

10 files changed

+65
-37
lines changed

10 files changed

+65
-37
lines changed

.travis.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
language: dart
22

33
dart:
4-
- 2.3.0
5-
- stable
4+
- dev
65

7-
dart_task:
8-
- test: -p vm
9-
- test: -p chrome
10-
- dartanalyzer: --fatal-warnings --fatal-infos .
11-
12-
matrix:
6+
jobs:
137
include:
14-
# Only validate formatting using the dev release
15-
- dart: dev
16-
dart_task: dartfmt
8+
- stage: analyze_and_format
9+
name: "Analyze"
10+
os: linux
11+
script: dartanalyzer --fatal-warnings --fatal-infos .
12+
- stage: analyze_and_format
13+
name: "Format"
14+
os: linux
15+
script: dartfmt -n --set-exit-if-changed .
16+
- stage: test
17+
name: "Vm Tests"
18+
os: linux
19+
script: pub run --enable-experiment=non-nullable test -p vm
20+
- stage: test
21+
name: "Web Tests"
22+
os: linux
23+
script: pub run --enable-experiment=non-nullable test -p chrome
24+
25+
stages:
26+
- analyze_and_format
27+
- test
28+
1729

1830
# Only building master means that we don't run two builds for each pull request.
1931
branches:
20-
only: [master]
32+
only: [master, null_safety]
2133

2234
cache:
2335
directories:

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
## 2.2.0-nullsafety
2+
3+
Pre-release for the null safety migration of this package.
4+
5+
Note that 2.2.0 may not be the final stable null safety release version, we
6+
reserve the right to release it as a 3.0.0 breaking change.
7+
8+
This release will be pinned to only allow pre-release sdk versions starting from
9+
2.10.0-2.0.dev, which is the first version where this package will appear in the
10+
null safety allow list.
11+
112
## 2.1.5
213

314
* Improve example and package description to address package site maintenance

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ include: package:pedantic/analysis_options.yaml
22
analyzer:
33
strong-mode:
44
implicit-casts: false
5+
6+
enable-experiment:
7+
- non-nullable
8+
59
linter:
610
rules:
711
- avoid_empty_else

example/example.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'package:crypto/crypto.dart';
1010
final _usage = 'Usage: dart hash.dart <md5|sha1|sha256> <input_filename>';
1111

1212
Future main(List<String> args) async {
13-
if (args == null || args.length != 2) {
13+
if (args.length != 2) {
1414
print(_usage);
1515
exitCode = 64; // Command was used incorrectly.
1616
return;

lib/src/digest_sink.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,21 @@ import 'digest.dart';
77
/// A sink used to get a digest value out of `Hash.startChunkedConversion`.
88
class DigestSink extends Sink<Digest> {
99
/// The value added to the sink, if any.
10-
Digest get value {
11-
assert(_value != null);
12-
return _value;
13-
}
10+
Digest get value => _value;
1411

15-
Digest _value;
12+
late final Digest _value;
1613

1714
/// Adds [value] to the sink.
1815
///
1916
/// Unlike most sinks, this may only be called once.
2017
@override
2118
void add(Digest value) {
22-
assert(_value == null);
2319
_value = value;
2420
}
2521

2622
@override
2723
void close() {
28-
assert(_value != null);
24+
// Ensure late final field was assigned before closing.
25+
assert((_value as dynamic) != null);
2926
}
3027
}

lib/src/hmac.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class _HmacSink extends ByteConversionSink {
6060
final _innerResultSink = DigestSink();
6161

6262
/// The sink for the inner hash computation.
63-
ByteConversionSink _innerSink;
63+
late final ByteConversionSink _innerSink;
6464

6565
/// Whether [close] has been called.
6666
bool _isClosed = false;

pubspec.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
name: crypto
2-
version: 2.1.5
2+
version: 2.2.0-nullsafety
33
description: Implementations of SHA, MD5, and HMAC cryptographic functions
44
homepage: https://www.github.com/dart-lang/crypto
55

66
environment:
7-
sdk: '>=2.3.0 <3.0.0'
7+
sdk: '>=2.10.0-2.0.dev <2.10.0'
88

99
dependencies:
10-
collection: '^1.0.0'
11-
convert: '>=1.0.0 <3.0.0'
12-
typed_data: '^1.0.0'
10+
collection: ^1.15.0-nullsafety
11+
convert: ^2.2.0-nullsafety
12+
typed_data: ^1.3.0-nullsafety
1313

1414
dev_dependencies:
15-
pedantic: ^1.0.0
16-
test: ^1.0.0
15+
pedantic: ^1.10.0-nullsafety
16+
test: ^1.16.0-nullsafety
17+
18+
dependency_overrides:
19+
convert:
20+
git: git://github.com/dart-lang/convert.git

test/hmac_sha2_test.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ void main() {
103103
}
104104

105105
void testCase({
106-
String name,
107-
String key,
108-
String data,
109-
String hmacSha224,
110-
String hmacSha256,
111-
String hmacSha384,
112-
String hmacSha512,
106+
required String name,
107+
required String key,
108+
required String data,
109+
required String hmacSha224,
110+
required String hmacSha256,
111+
required String hmacSha384,
112+
required String hmacSha512,
113113
bool truncation = false,
114114
}) {
115115
test(name, () {

test/sha_monte_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void monteTest(String name, Hash hash, String seed, List<String> expected) {
6565
md0 = (Uint8List.fromList(_seed));
6666
md1 = (Uint8List.fromList(_seed));
6767
md2 = (Uint8List.fromList(_seed));
68-
Digest mdI;
68+
late Digest mdI;
6969
for (var i = 3; i < 1003; i++) {
7070
var mI = [...md0, ...md1, ...md2];
7171
mdI = hash.convert(mI);

test/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final toupleMatch = RegExp('([0-9a-fA-F]{2})');
1818
Uint8List bytesFromHexString(String message) {
1919
var bytes = <int>[];
2020
for (var match in toupleMatch.allMatches(message)) {
21-
bytes.add(int.parse(match.group(0), radix: 16));
21+
bytes.add(int.parse(match.group(0)!, radix: 16));
2222
}
2323
return Uint8List.fromList(bytes);
2424
}

0 commit comments

Comments
 (0)