diff --git a/packages/native_crypto/pubspec.yaml b/packages/native_crypto/pubspec.yaml index e78c351..f5b311c 100644 --- a/packages/native_crypto/pubspec.yaml +++ b/packages/native_crypto/pubspec.yaml @@ -33,14 +33,14 @@ dependencies: dev_dependencies: flutter_test: { sdk: flutter } - mockito: ^5.3.2 - plugin_platform_interface: ^2.1.3 + mockito: ^5.4.0 + plugin_platform_interface: ^2.1.4 wyatt_analysis: hosted: url: https://git.wyatt-studio.fr/api/packages/Wyatt-FOSS/pub/ name: wyatt_analysis - version: 2.4.0 + version: 2.4.1 flutter: plugin: diff --git a/packages/native_crypto/test/mocks/mock_native_crypto_api.dart b/packages/native_crypto/test/mocks/mock_native_crypto_api.dart index e8b4afa..d2e1831 100644 --- a/packages/native_crypto/test/mocks/mock_native_crypto_api.dart +++ b/packages/native_crypto/test/mocks/mock_native_crypto_api.dart @@ -6,7 +6,7 @@ import 'dart:typed_data'; -import 'package:native_crypto_platform_interface/native_crypto_platform_interface.dart'; +import 'package:native_crypto_platform_interface/native_crypto_platform_interface_gen.dart'; class MockNativeCryptoAPI implements NativeCryptoAPI { static Uint8List? Function(int length)? generateSecureRandomFn; @@ -41,6 +41,13 @@ class MockNativeCryptoAPI implements NativeCryptoAPI { String algorithm, )? encryptFn; + static Uint8List? Function( + Uint8List plainText, + Uint8List key, + Uint8List iv, + String algorithm, + )? encryptWithIVFn; + static bool? Function( String plainTextPath, String cipherTextPath, @@ -48,12 +55,13 @@ class MockNativeCryptoAPI implements NativeCryptoAPI { String algorithm, )? encryptFileFn; - static Uint8List? Function( - Uint8List plainText, + static bool? Function( + String plainTextPath, + String cipherTextPath, Uint8List key, Uint8List iv, String algorithm, - )? encryptWithIVFn; + )? encryptFileWithIVFn; static Uint8List? Function( Uint8List password, @@ -64,130 +72,158 @@ class MockNativeCryptoAPI implements NativeCryptoAPI { )? pbkdf2Fn; @override - Future decrypt(DecryptRequest argRequest) async => - decryptFn != null - ? DecryptResponse( - plainText: decryptFn!( - argRequest.cipherText!, - argRequest.key!, - argRequest.algorithm!, - ), - ) - : DecryptResponse( - plainText: Uint8List.fromList([1, 2, 3]), - ); + Future decrypt( + Uint8List argCiphertext, + Uint8List argKey, + CipherAlgorithm argAlgorithm, + ) async { + if (decryptFn != null) { + return decryptFn!(argCiphertext, argKey, argAlgorithm.toString()); + } else { + return Uint8List.fromList([1, 2, 3]); + } + } @override - Future decryptFile( - DecryptFileRequest argRequest, - ) async => - decryptFileFn != null - ? DecryptFileResponse( - success: decryptFileFn!( - argRequest.cipherTextPath!, - argRequest.plainTextPath!, - argRequest.key!, - argRequest.algorithm!, - ), - ) - : DecryptFileResponse(success: true); + Future decryptFile( + String argCiphertextpath, + String argPlaintextpath, + Uint8List argKey, + CipherAlgorithm argAlgorithm, + ) async { + if (decryptFileFn != null) { + return decryptFileFn!( + argCiphertextpath, + argPlaintextpath, + argKey, + argAlgorithm.toString(), + ); + } else { + return Future.value(true); + } + } @override - Future encrypt(EncryptRequest argRequest) async => - encryptFn != null - ? EncryptResponse( - cipherText: encryptFn!( - argRequest.plainText!, - argRequest.key!, - argRequest.algorithm!, - ), - ) - : EncryptResponse( - cipherText: Uint8List.fromList([1, 2, 3]), - ); + Future encrypt( + Uint8List argPlaintext, + Uint8List argKey, + CipherAlgorithm argAlgorithm, + ) async { + if (encryptFn != null) { + return encryptFn!(argPlaintext, argKey, argAlgorithm.toString()); + } else { + return Uint8List.fromList([1, 2, 3]); + } + } @override - Future encryptFile( - EncryptFileRequest argRequest, - ) async => - encryptFileFn != null - ? EncryptFileResponse( - success: encryptFileFn!( - argRequest.plainTextPath!, - argRequest.cipherTextPath!, - argRequest.key!, - argRequest.algorithm!, - ), - ) - : EncryptFileResponse(success: true); + Future encryptFile( + String argPlaintextpath, + String argCiphertextpath, + Uint8List argKey, + CipherAlgorithm argAlgorithm, + ) async { + if (encryptFileFn != null) { + return encryptFileFn!( + argPlaintextpath, + argCiphertextpath, + argKey, + argAlgorithm.toString(), + ); + } else { + return Future.value(true); + } + } @override - Future encryptWithIV( - EncryptWithIVRequest argRequest, - ) async => - encryptWithIVFn != null - ? EncryptResponse( - cipherText: encryptWithIVFn!( - argRequest.plainText!, - argRequest.key!, - argRequest.iv!, - argRequest.algorithm!, - ), - ) - : EncryptResponse( - cipherText: Uint8List.fromList([1, 2, 3]), - ); + Future encryptFileWithIV( + String argPlaintextpath, + String argCiphertextpath, + Uint8List argIv, + Uint8List argKey, + CipherAlgorithm argAlgorithm, + ) async { + if (encryptFileWithIVFn != null) { + return encryptFileWithIVFn!( + argPlaintextpath, + argCiphertextpath, + argKey, + argIv, + argAlgorithm.toString(), + ); + } else { + return Future.value(true); + } + } @override - Future generateSecureRandom( - GenerateSecureRandomRequest argRequest, - ) async => - generateSecureRandomFn != null - ? GenerateSecureRandomResponse( - random: generateSecureRandomFn!(argRequest.length!), - ) - : GenerateSecureRandomResponse( - random: Uint8List.fromList([1, 2, 3]), - ); + Future encryptWithIV( + Uint8List argPlaintext, + Uint8List argIv, + Uint8List argKey, + CipherAlgorithm argAlgorithm, + ) async { + if (encryptWithIVFn != null) { + return encryptWithIVFn!( + argPlaintext, + argKey, + argIv, + argAlgorithm.toString(), + ); + } else { + return Future.value(Uint8List.fromList([1, 2, 3])); + } + } @override - Future hash(HashRequest argRequest) async => hashFn != null - ? HashResponse( - hash: hashFn!( - argRequest.data!, - argRequest.algorithm!, - ), - ) - : HashResponse( - hash: Uint8List.fromList([1, 2, 3]), - ); + Future generateSecureRandom(int argLength) { + if (generateSecureRandomFn != null) { + return Future.value(generateSecureRandomFn!(argLength)); + } else { + return Future.value(Uint8List.fromList([1, 2, 3])); + } + } @override - Future hmac(HmacRequest argRequest) async => hmacFn != null - ? HmacResponse( - hmac: hmacFn!( - argRequest.data!, - argRequest.key!, - argRequest.algorithm!, - ), - ) - : HmacResponse( - hmac: Uint8List.fromList([1, 2, 3]), - ); + Future hash(Uint8List argData, HashAlgorithm argAlgorithm) { + if (hashFn != null) { + return Future.value(hashFn!(argData, argAlgorithm.toString())); + } else { + return Future.value(Uint8List.fromList([1, 2, 3])); + } + } @override - Future pbkdf2(Pbkdf2Request argRequest) async => - pbkdf2Fn != null - ? Pbkdf2Response( - key: pbkdf2Fn!( - argRequest.password!, - argRequest.salt!, - argRequest.iterations!, - argRequest.length!, - argRequest.hashAlgorithm!, - ), - ) - : Pbkdf2Response( - key: Uint8List.fromList([1, 2, 3]), - ); + Future hmac( + Uint8List argData, + Uint8List argKey, + HashAlgorithm argAlgorithm, + ) { + if (hmacFn != null) { + return Future.value(hmacFn!(argData, argKey, argAlgorithm.toString())); + } else { + return Future.value(Uint8List.fromList([1, 2, 3])); + } + } + + @override + Future pbkdf2( + Uint8List argPassword, + Uint8List argSalt, + int argLength, + int argIterations, + HashAlgorithm argAlgorithm, + ) { + if (pbkdf2Fn != null) { + return Future.value(pbkdf2Fn!( + argPassword, + argSalt, + argIterations, + argLength, + argAlgorithm.toString(), + ),); + } else { + return Future.value(Uint8List.fromList([1, 2, 3])); + } + } }