feat: Also hash the file on encryption and decryption
This commit is contained in:
@@ -16,17 +16,32 @@ extension CipherAlgorithmToIntExtension on CipherAlgorithm {
|
||||
}
|
||||
}
|
||||
|
||||
class CryptographyResult {
|
||||
|
||||
const CryptographyResult(this.plaintextHash, this.ciphertextHash);
|
||||
final Uint8List plaintextHash;
|
||||
final Uint8List ciphertextHash;
|
||||
}
|
||||
|
||||
/// Wrapper around platform-native cryptography APIs
|
||||
abstract class CryptographyImplementation {
|
||||
/// Encrypt the file at [sourcePath] using [algorithm] and write the result back to
|
||||
/// [destPath]. Note that this function runs off-thread as to not block the UI thread.
|
||||
/// [destPath]. [hashSpec] is the name of the Hash function to use, i.e. "SHA-256".
|
||||
/// Note that this function runs off-thread as to not block the UI thread.
|
||||
///
|
||||
/// Resolves to true if the encryption was successful. Resolves to fale on failure.
|
||||
Future<bool> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm);
|
||||
Future<CryptographyResult?> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec);
|
||||
|
||||
/// Decrypt the file at [sourcePath] using [algorithm] and write the result back to
|
||||
/// [destPath]. Note that this function runs off-thread as to not block the UI thread.
|
||||
/// [destPath]. [hashSpec] is the name of the Hash function to use, i.e. "SHA-256".
|
||||
/// Note that this function runs off-thread as to not block the UI thread.
|
||||
///
|
||||
/// Resolves to true if the encryption was successful. Resolves to fale on failure.
|
||||
Future<bool> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm);
|
||||
Future<CryptographyResult?> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec);
|
||||
|
||||
/// Hashes the file at [path] using the Hash function with name [hashSpec].
|
||||
/// Note that this function runs off-thread as to not block the UI thread.
|
||||
///
|
||||
/// Returns the hash of the file.
|
||||
Future<Uint8List?> hashFile(String path, String hashSpec);
|
||||
}
|
||||
|
||||
@@ -3,12 +3,17 @@ import 'package:moxplatform_platform_interface/src/crypto.dart';
|
||||
|
||||
class StubCryptographyImplementation extends CryptographyImplementation {
|
||||
@override
|
||||
Future<bool> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm) async {
|
||||
return false;
|
||||
Future<CryptographyResult?> encryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async {
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm) async {
|
||||
return false;
|
||||
Future<CryptographyResult?> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm, String hashSpec) async {
|
||||
return null;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List?> hashFile(String path, String hashSpec) async {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user