meta: Implement access to AES encryption (but fast)

This commit is contained in:
2022-10-04 23:37:32 +02:00
parent 4a89958351
commit 98c3355b44
35 changed files with 858 additions and 0 deletions

View File

@@ -1,5 +1,7 @@
library moxplatform_platform_interface;
export 'src/crypto.dart';
export 'src/crypto_stub.dart';
export 'src/interface.dart';
export 'src/isolate.dart';
export 'src/isolate_stub.dart';

View File

@@ -0,0 +1,32 @@
import 'dart:typed_data';
enum CipherAlgorithm {
aes128GcmNoPadding,
aes256GcmNoPadding,
aes256CbcPkcs7,
}
extension CipherAlgorithmToIntExtension on CipherAlgorithm {
int toInt() {
switch (this) {
case CipherAlgorithm.aes128GcmNoPadding: return 0;
case CipherAlgorithm.aes256GcmNoPadding: return 1;
case CipherAlgorithm.aes256CbcPkcs7: return 2;
}
}
}
/// 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.
///
/// 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);
/// 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.
///
/// 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);
}

View File

@@ -0,0 +1,14 @@
import 'dart:typed_data';
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;
}
@override
Future<bool> decryptFile(String sourcePath, String destPath, Uint8List key, Uint8List iv, CipherAlgorithm algorithm) async {
return false;
}
}

View File

@@ -1,3 +1,5 @@
import 'package:moxplatform_platform_interface/src/crypto.dart';
import 'package:moxplatform_platform_interface/src/crypto_stub.dart';
import 'package:moxplatform_platform_interface/src/isolate.dart';
import 'package:moxplatform_platform_interface/src/isolate_stub.dart';
import 'package:moxplatform_platform_interface/src/media.dart';
@@ -11,6 +13,7 @@ abstract class MoxplatformInterface extends PlatformInterface {
static IsolateHandler handler = StubIsolateHandler();
static MediaScannerImplementation media = StubMediaScannerImplementation();
static CryptographyImplementation crypto = StubCryptographyImplementation();
/// Return the current platform name.
Future<String?> getPlatformName();