From 24f8f462de92440e31ba7fefd8fd13253e6c1795 Mon Sep 17 00:00:00 2001 From: Sudipto Chandra Date: Sat, 6 Jul 2024 10:03:28 +0400 Subject: [PATCH] Use secure random generator by default --- CHANGELOG.md | 3 ++- lib/src/random.dart | 10 +++++----- pubspec.yaml | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93689d0..d5014c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# 1.19.0 +# 1.19.1 - Improve support for random generator - `HashlibRandom` class for generating random number, bool, strings etc. @@ -9,6 +9,7 @@ - `consumeAs` is renamed to `stringStraem` . - Introduced `byteStream` - Adds `fillNumbers` to fill List with random integers. + - Use secure random generator by default # 1.18.1 diff --git a/lib/src/random.dart b/lib/src/random.dart index 62d6860..1f0f4d3 100644 --- a/lib/src/random.dart +++ b/lib/src/random.dart @@ -11,7 +11,7 @@ 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); @@ -19,7 +19,7 @@ Uint8List randomBytes( @pragma('vm:prefer-inline') Uint32List randomNumbers( int length, { - RandomGenerator generator = RandomGenerator.system, + RandomGenerator generator = RandomGenerator.secure, }) => HashlibRandom(generator).nextNumbers(length); @@ -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); @@ -42,7 +42,7 @@ void fillNumbers( List list, { int start = 0, int? length, - RandomGenerator generator = RandomGenerator.system, + RandomGenerator generator = RandomGenerator.secure, }) { int n = length ?? list.length; if (n == 0) return; @@ -65,7 +65,7 @@ String randomString( bool? punctuations, List? whitelist, List? blacklist, - RandomGenerator generator = RandomGenerator.system, + RandomGenerator generator = RandomGenerator.secure, }) => HashlibRandom(generator).nextString( length, diff --git a/pubspec.yaml b/pubspec.yaml index ff6eb3b..241c42c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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'