Skip to content

Commit 0152865

Browse files
authored
Merge pull request #159 from terrier989/master
Raises Dart SDK version minimum to 3.1.0 and other changes
2 parents 76b9bbc + 0b2071a commit 0152865

File tree

30 files changed

+810
-760
lines changed

30 files changed

+810
-760
lines changed

cryptography/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ Any feedback, issue reports, or pull requests are appreciated!
2727
# Getting started
2828

2929
If you use Flutter, it's recommended (but not necessarily) that you also import our sibling package
30-
[cryptography_flutter](https://pub.dev/packages/cryptography_flutter), which improves performance
31-
by using operating system APIs.
30+
[cryptography_flutter](https://pub.dev/packages/cryptography_flutter), which delegates calls to
31+
Android / iOS / Mac OS X operating system APIs whenever possible.
3232

3333
In _pubspec.yaml_:
3434
```yaml
3535
dependencies:
36-
cryptography: ^2.5.0
37-
cryptography_flutter: ^2.3.0 # Remove if you don't use Flutter
36+
cryptography: ^2.5.1
37+
cryptography_flutter: ^2.3.1 # Remove if you don't use Flutter
3838
```
3939
4040
You are ready to go!
@@ -207,7 +207,8 @@ faster because this package automatically uses Web Crypto API.
207207
208208
## Random number generators
209209
210-
We continue to use the old good `Random.secure()` as the default random number in all APIs.
210+
We use Dart SDK [Random.secure()](https://api.dart.dev/stable/3.1.0/dart-math/Random/Random.secure.html)
211+
as the default random number in all APIs.
211212
212213
If you do want much faster cryptographically reasonably strong random numbers, this package contains
213214
[SecureRandom.fast](https://pub.dev/documentation/cryptography/latest/cryptography/SecureRandom/fast.html).
@@ -353,17 +354,14 @@ authentication code).
353354
When you decrypt, you need the _SecretBox_ and the secret key.
354355

355356
In the following example, we encrypt a message
356-
with [AesCtr](https://pub.dev/documentation/cryptography/latest/cryptography/AesCtr-class.html)
357-
and a [Hmac](https://pub.dev/documentation/cryptography/latest/cryptography/Hmac-class.html) message
358-
authentication code that uses [Sha256](https://pub.dev/documentation/cryptography/latest/cryptography/Sha256-class.html)
359-
hash algorithm:
357+
with [AesGcm](https://pub.dev/documentation/cryptography/latest/cryptography/AesGcm-class.html):
360358
```dart
361359
import 'dart:convert';
362360
import 'package:cryptography/cryptography.dart';
363361
364362
Future<void> main() async {
365363
// Choose the cipher
366-
final algorithm = AesCtr(macAlgorithm: Hmac.sha256());
364+
final algorithm = AesGcm.with256bits();
367365
368366
// Generate a random secret key.
369367
final secretKey = await algorithm.newSecretKey();

cryptography/lib/src/cryptography/cipher.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,17 +399,16 @@ abstract class Cipher {
399399
String clearText, {
400400
required SecretKey secretKey,
401401
}) async {
402-
final bytes = utf8.encode(clearText);
402+
final bytes = utf8.encode(clearText) as Uint8List;
403403
final secretBox = await encrypt(
404404
bytes,
405405
secretKey: secretKey,
406-
possibleBuffer: bytes is Uint8List ? bytes : null,
406+
possibleBuffer: bytes,
407407
);
408408

409409
// Overwrite `bytes` if it was not overwritten by the cipher.
410410
final cipherText = secretBox.cipherText;
411-
if (bytes is! Uint8List ||
412-
cipherText is! Uint8List ||
411+
if (cipherText is! Uint8List ||
413412
!identical(bytes.buffer, cipherText.buffer)) {
414413
bytes.fillRange(0, bytes.length, 0);
415414
}

cryptography/lib/src/cryptography/cipher_wand.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,17 +175,16 @@ abstract class CipherWand extends Wand {
175175
/// }
176176
/// ```
177177
Future<SecretBox> encryptString(String clearText) async {
178-
final bytes = utf8.encode(clearText);
178+
final bytes = utf8.encode(clearText) as Uint8List;
179179
final secretBox = await encrypt(
180180
bytes,
181-
possibleBuffer: bytes is Uint8List ? bytes : null,
181+
possibleBuffer: bytes,
182182
);
183183

184184
// Cut the amount of possibly sensitive data in the heap.
185185
// This should be a cheap operation relative to encryption.
186186
final cipherText = secretBox.cipherText;
187-
if (bytes is! Uint8List ||
188-
cipherText is! Uint8List ||
187+
if (cipherText is! Uint8List ||
189188
!identical(bytes.buffer, cipherText.buffer)) {
190189
bytes.fillRange(0, bytes.length, 0);
191190
}

cryptography/lib/src/cryptography/mac_algorithm.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,28 @@ import 'package:cryptography/dart.dart';
2121

2222
/// A Message Authentication Code (MAC) algorithm.
2323
///
24+
/// You can compute a [Mac] by calling [calculateMac] or [newMacSink].
25+
///
2426
/// ## Available algorithms
2527
/// * [Hmac]
26-
/// * [MacAlgorithm.empty]
2728
/// * [Poly1305]
29+
///
30+
/// ## Not using MAC?
31+
///
32+
/// If are sure you don't need a MAC, you can use [MacAlgorithm.empty]:
33+
/// ```
34+
/// final example = ChaCha20(macAlgorithm: MacAlgorithm.empty);
35+
/// ```
2836
abstract class MacAlgorithm {
2937
/// MAC algorithm that always returns [Mac.empty].
3038
static const MacAlgorithm empty = _EmptyMacAlgorithm();
3139

3240
const MacAlgorithm();
3341

42+
/// Number of bytes in key stream used to initialize the MAC algorithm.
43+
///
44+
/// In [Chacha20.poly1305Aead], the first block of the ChaCha20 stream is used
45+
/// as the Poly1305 key (thus [keyStreamUsed] is 64).
3446
int get keyStreamUsed => 0;
3547

3648
/// Number of bytes in the message authentication code.
@@ -39,6 +51,7 @@ abstract class MacAlgorithm {
3951
/// Whether the algorithm supports Associated Authenticated Data (AAD).
4052
bool get supportsAad => false;
4153

54+
/// Whether the algorithm supports key stream index.
4255
bool get supportsKeyStreamIndex => keyStreamUsed == 0;
4356

4457
/// Calculates message authentication code.

cryptography/lib/src/dart/_helpers.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void checkSystemIsLittleEndian() {
2929
}
3030

3131
/// A helper for using "package:crypto" hash algorithms.
32-
class PackageCryptoDigestCaptureSink extends Sink<other.Digest> {
32+
class PackageCryptoDigestCaptureSink implements Sink<other.Digest> {
3333
Hash? _result;
3434

3535
PackageCryptoDigestCaptureSink();

cryptography/pubspec.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
name: cryptography
2-
version: 2.5.0
2+
version: 2.5.1
33
homepage: https://github.com/dint-dev/cryptography
44
description:
55
Cryptographic algorithms for encryption, digital signatures, key agreement, authentication, and
66
hashing. AES, Chacha20, ED25519, X25519, and more. Good cross-platform support.
77

88
environment:
9-
sdk: '>=2.17.0 <3.0.0'
9+
sdk: '>=3.1.0 <4.0.0'
1010

1111
dependencies:
1212
#
13-
# Packages by the Google:
13+
# Packages by Google:
1414
#
15-
collection: ^1.16.0
16-
crypto: ^3.0.0
17-
js: ^0.6.2
18-
meta: ^1.3.0
15+
collection: ^1.17.0
16+
crypto: ^3.0.3
17+
js: ^0.6.7
18+
meta: ^1.8.0
1919
typed_data: ^1.3.0
2020

2121
dev_dependencies:
2222
#
23-
# Packages by the Google:
23+
# Packages by Google:
2424
#
25-
lints: ^2.0.1
26-
test: ^1.19.0
25+
lints: ^2.1.1
26+
test: ^1.24.0

cryptography/test/algorithms/pbkdf2_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ void _main() {
4747
test('deriveKey(...): Hmac(sha256), 10k iterations in 300ms', () async {
4848
final macAlgorithm = Hmac.sha256();
4949
final n = 10 * 1000;
50-
const maxDuration = Duration(milliseconds: 300);
50+
const maxDuration = Duration(milliseconds: 1000);
5151

5252
final pbkdf2 = Pbkdf2(
5353
macAlgorithm: macAlgorithm,

cryptography/test/algorithms/poly1305_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ void main() {
2727
..[0] = 1
2828
..[2] = 2;
2929
var k = SecretKey(secretKeyBytes);
30-
var state = utf8.encode('Hello world');
30+
List<int> state = utf8.encode('Hello world');
3131
for (var i = 0; i < 100000; i++) {
3232
final mac = await algorithm.calculateMac(
3333
state,

cryptography_flutter/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ In _pubspec.yaml_:
4949

5050
```yaml
5151
dependencies:
52-
cryptography: ^2.5.0
53-
cryptography_flutter: ^2.3.0
52+
cryptography: ^2.5.1
53+
cryptography_flutter: ^2.3.1
5454
```
5555
5656
That's it!
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
PODS:
2+
- cryptography_flutter (0.2.0):
3+
- Flutter
4+
- Flutter (1.0.0)
5+
6+
DEPENDENCIES:
7+
- cryptography_flutter (from `.symlinks/plugins/cryptography_flutter/ios`)
8+
- Flutter (from `Flutter`)
9+
10+
EXTERNAL SOURCES:
11+
cryptography_flutter:
12+
:path: ".symlinks/plugins/cryptography_flutter/ios"
13+
Flutter:
14+
:path: Flutter
15+
16+
SPEC CHECKSUMS:
17+
cryptography_flutter: 381bdacc984abcfbe3ca45ef7c76566ff061614c
18+
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
19+
20+
PODFILE CHECKSUM: ef19549a9bc3046e7bb7d2fab4d021637c0c58a3
21+
22+
COCOAPODS: 1.11.2

0 commit comments

Comments
 (0)