Skip to content

Commit

Permalink
Use secure random generator by default
Browse files Browse the repository at this point in the history
  • Loading branch information
dipu-bd committed Jul 6, 2024
1 parent c6ac6dc commit 24f8f46
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 1.19.0
# 1.19.1

- Improve support for random generator
- `HashlibRandom` class for generating random number, bool, strings etc.
Expand All @@ -9,6 +9,7 @@
- `consumeAs` is renamed to `stringStraem` .
- Introduced `byteStream`
- Adds `fillNumbers` to fill List<int> with random integers.
- Use secure random generator by default

# 1.18.1

Expand Down
10 changes: 5 additions & 5 deletions lib/src/random.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export 'package:hashlib/src/core/hashlib_random.dart';
@pragma('vm:prefer-inline')
Uint8List randomBytes(
int length, {
RandomGenerator generator = RandomGenerator.system,
RandomGenerator generator = RandomGenerator.secure,
}) =>
HashlibRandom(generator).nextBytes(length);

/// Generate a list of random 32-bit numbers of size [length]
@pragma('vm:prefer-inline')
Uint32List randomNumbers(
int length, {
RandomGenerator generator = RandomGenerator.system,
RandomGenerator generator = RandomGenerator.secure,
}) =>
HashlibRandom(generator).nextNumbers(length);

Expand All @@ -31,7 +31,7 @@ void fillRandom(
ByteBuffer buffer, {
int start = 0,
int? length,
RandomGenerator generator = RandomGenerator.system,
RandomGenerator generator = RandomGenerator.secure,
}) =>
HashlibRandom(generator).fill(buffer, start, length);

Expand All @@ -42,7 +42,7 @@ void fillNumbers(
List<int> list, {
int start = 0,
int? length,
RandomGenerator generator = RandomGenerator.system,
RandomGenerator generator = RandomGenerator.secure,
}) {
int n = length ?? list.length;
if (n == 0) return;
Expand All @@ -65,7 +65,7 @@ String randomString(
bool? punctuations,
List<int>? whitelist,
List<int>? blacklist,
RandomGenerator generator = RandomGenerator.system,
RandomGenerator generator = RandomGenerator.secure,
}) =>
HashlibRandom(generator).nextString(
length,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: hashlib
description: Secure hash functions, checksum generators, and key derivation algorithms optimized for Dart.
homepage: https://github.com/bitanon/hashlib
version: 1.19.0
version: 1.19.1

environment:
sdk: '>=2.14.0 <4.0.0'
Expand Down

0 comments on commit 24f8f46

Please sign in to comment.