Skip to content

Commit 33f2f44

Browse files
committed
support null safety
1 parent ce6a9c5 commit 33f2f44

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

lib/src/argon2.dart

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class DArgon2 {
5757
/// Returns a [Future] containing a [DArgon2Result] with the hashed password,
5858
/// encoded hash, and various conversion options for the hash and encoded bytes.
5959
Future<DArgon2Result> hashPasswordString(String password,
60-
{@required Salt salt,
60+
{required Salt salt,
6161
int iterations = 32,
6262
int memory = 256,
6363
int parallelism = 2,
@@ -85,7 +85,7 @@ class DArgon2 {
8585
/// Returns a [Future] containing a [DArgon2Result] with the hashed password,
8686
/// encoded hash, and various conversion options for the hash and encoded bytes.
8787
Future<DArgon2Result> hashPasswordBytes(List<int> password,
88-
{@required Salt salt,
88+
{required Salt salt,
8989
int iterations = 32,
9090
int memory = 256,
9191
int parallelism = 2,
@@ -114,7 +114,7 @@ class DArgon2 {
114114
/// Returns a [DArgon2Result] with the hashed password, encoded hash, and various
115115
/// conversion options for the hash and encoded bytes.
116116
DArgon2Result hashPasswordStringSync(String password,
117-
{@required Salt salt,
117+
{required Salt salt,
118118
int iterations = 32,
119119
int memory = 256,
120120
int parallelism = 2,
@@ -142,14 +142,13 @@ class DArgon2 {
142142
/// Returns a [DArgon2Result] with the hashed password, encoded hash, and various
143143
/// conversion options for the hash and encoded bytes.
144144
DArgon2Result hashPasswordBytesSync(List<int> password,
145-
{@required Salt salt,
145+
{required Salt salt,
146146
int iterations = 32,
147147
int memory = 256,
148148
int parallelism = 2,
149149
int length = 32,
150150
Argon2Type type = Argon2Type.i,
151151
Argon2Version version = Argon2Version.V13}) {
152-
assert(salt != null);
153152
//Create pointers to pass to the C method
154153
var passPointer = _setPtr(password);
155154
var saltPointer = _setPtr(salt.bytes);
@@ -265,7 +264,7 @@ class DArgon2 {
265264
/// Returns a [Pointer] of type [Uint8] to be used for Argon2 computations.
266265
Pointer<Uint8> _setPtr(Iterable<int> iterable) {
267266
//Allocate a pointer in memory and set the values from the given list
268-
var p = malloc<Uint8>(Uint8List.fromList(iterable).length);
267+
var p = malloc<Uint8>(Uint8List.fromList(iterable.toList()).length);
269268
p.asTypedList(iterable.length).setAll(0, iterable);
270269
return p;
271270
}

lib/src/native/loaders/dart_lib_loader.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class DartLibLoader implements LibLoader {
3333
rootPath = File.fromUri(Platform.script).parent.path;
3434
} else {
3535
final rootLibrary = 'package:dargon2/dargon2.dart';
36-
rootPath = waitFor(Isolate.resolvePackageUri(Uri.parse(rootLibrary)))
36+
rootPath = waitFor(Isolate.resolvePackageUri(Uri.parse(rootLibrary)))!
3737
.resolve('src/blobs/')
3838
.toFilePath(windows: Platform.isWindows);
3939
}

lib/src/native/local_binder.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,32 +124,31 @@ typedef _Argon2ErrorMessage = Pointer<Utf8> Function(int error_code);
124124
/// there should be no reason to change this.
125125
class LocalBinder {
126126
/// Create an instanced class in order to allow the dylib to stay loaded through the session.
127-
static LocalBinder _privateInstance;
127+
static final LocalBinder _privateInstance = LocalBinder._();
128128

129129
/// Callable method of type [_Argon2Hash] that binds to [_argon2_hash].
130-
_Argon2Hash getHash;
130+
late _Argon2Hash getHash;
131131

132132
/// Callable method of type [_Argon2Verify] that binds to [_argon2_verify].
133-
_Argon2Verify verifyHash;
133+
late _Argon2Verify verifyHash;
134134

135135
/// Callable method of type [_Argon2Encodedlen] that binds to [_argon2_encodedlen].
136-
_Argon2Encodedlen getEncodedHashLength;
136+
late _Argon2Encodedlen getEncodedHashLength;
137137

138138
/// Callable method of type [_Argon2ErrorMessage] that binds to [_argon2_error_message].
139-
_Argon2ErrorMessage getErrorMessage;
139+
late _Argon2ErrorMessage getErrorMessage;
140140

141141
/// The getter for the main instance, which returns the private instance if set correctly.
142142
/// If not, a new Instance is created and set as the private instance, then returned.
143143
static LocalBinder get instance {
144-
_privateInstance ??= LocalBinder();
145144
return _privateInstance;
146145
}
147146

148147
/// The class constructor, which handles loading the dylib and mapping each method to their
149148
/// respective C equivalents
150149
///
151150
/// Opens the C library using dart's ffi and maps all of the main methods
152-
LocalBinder() {
151+
LocalBinder._() {
153152
var argon2lib = LibLoader().loadLib();
154153
getHash = argon2lib
155154
.lookup<NativeFunction<_argon2_hash>>('argon2_hash')

0 commit comments

Comments
 (0)