Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
analyzer:
strong-mode: true

linter:
rules:
- camel_case_types
- empty_constructor_bodies
- always_declare_return_types
- camel_case_types
- constant_identifier_names
- empty_constructor_bodies
- implementation_imports
- library_names
- library_prefixes
Expand All @@ -18,7 +13,6 @@ linter:
- package_prefixed_library_names
- prefer_is_not_empty
- slash_for_doc_comments
- super_goes_last
- type_annotate_public_apis
- type_init_formals
- unnecessary_getters_setters
Expand All @@ -34,14 +28,12 @@ linter:
- iterable_contains_unrelated_type
- list_remove_unrelated_type
- test_types_in_equals
- throw_in_finally
- valid_regexps
- annotate_overrides
- avoid_init_to_null
- avoid_return_types_on_setters
- await_only_futures
- empty_catches
- prefer_is_not_empty
- sort_constructors_first
- sort_unnamed_constructors_first
- unawaited_futures
22 changes: 11 additions & 11 deletions lib/pbkdf2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ class PBKDF2 {
/// Creates instance capable of generating a key.
///
/// [hashAlgorithm] defaults to [sha256].
PBKDF2({Hash hashAlgorithm}) {
PBKDF2({Hash? hashAlgorithm}) {
this.hashAlgorithm = hashAlgorithm ?? sha256;
}

Hash get hashAlgorithm => _hashAlgorithm;
set hashAlgorithm(Hash algorithm) {
Hash? get hashAlgorithm => _hashAlgorithm;
set hashAlgorithm(Hash? algorithm) {
_hashAlgorithm = algorithm;
_blockSize = _hashAlgorithm.convert([1, 2, 3]).bytes.length;
_blockSize = _hashAlgorithm!.convert([1, 2, 3]).bytes.length;
}

Hash _hashAlgorithm;
int _blockSize;
Hash? _hashAlgorithm;
late int _blockSize;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think that since _blockSize depends on _hashAlgorithm, _blockSize would need to be nullable.


/// Hashes a [password] with a given [salt].
///
Expand All @@ -40,7 +40,7 @@ class PBKDF2 {
}

var numberOfBlocks = (keyLength / _blockSize).ceil();
var hmac = new Hmac(hashAlgorithm, utf8.encode(password));
var hmac = new Hmac(hashAlgorithm!, utf8.encode(password));
var key = new ByteData(keyLength);
var offset = 0;

Expand Down Expand Up @@ -90,7 +90,7 @@ class PBKDF2Exception implements Exception {

class _XORDigestSink extends Sink<Digest> {
_XORDigestSink(ByteData inputBuffer, Hmac hmac) {
lastDigest = hmac.convert(inputBuffer.buffer.asUint8List()).bytes;
lastDigest = hmac.convert(inputBuffer.buffer.asUint8List()).bytes as Uint8List;
bytes = new ByteData(lastDigest.length)
..buffer.asUint8List().setRange(0, lastDigest.length, lastDigest);
}
Expand All @@ -109,12 +109,12 @@ class _XORDigestSink extends Sink<Digest> {
return hashSink.bytes.buffer.asUint8List();
}

ByteData bytes;
Uint8List lastDigest;
late ByteData bytes;
late Uint8List lastDigest;

@override
void add(Digest digest) {
lastDigest = digest.bytes;
lastDigest = digest.bytes as Uint8List;
for (var i = 0; i < digest.bytes.length; i++) {
bytes.setUint8(i, bytes.getUint8(i) ^ lastDigest[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ homepage: https://github.com/stablekernel/dart-password-hash
description: PBKDF2 password hashing utility

environment:
sdk: ">=2.0.0 <3.0.0"
sdk: '>=2.12.0-133.7.beta <3.0.0'

dependencies:
crypto: ^2.0.0
crypto: ^3.0.0

dev_dependencies:
test: ^1.3.0
Expand Down