feat(interface)!: set pigeon as default implementation
This commit is contained in:
parent
c8ff1149d7
commit
f570ed076a
@ -2,7 +2,7 @@ NativeCrypto - Platform Interface
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 - 2022 Hugo Pointcheval
|
||||
Copyright (c) 2019 - 2023 Hugo Pointcheval
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -20,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
SOFTWARE.
|
||||
|
@ -8,5 +8,13 @@ This interface allows platform-specific implementations of the `native_crypto` p
|
||||
|
||||
To implement a new platform-specific implementation of `native_crypto`, extend [`NativeCryptoPlatform`][2] with an implementation that performs the platform-specific behavior, and when you register your plugin, set the default `NativeCryptoPlatform` by calling `NativeCryptoPlatform.instance = MyNativeCryptoPlatform()`.
|
||||
|
||||
## Pigeon
|
||||
|
||||
This package uses [Pigeon](https://pub.dev/packages/pigeon) to generate the platform interface code.
|
||||
|
||||
Run generator with `flutter pub run pigeon --input pigeons/messages.dart`.
|
||||
|
||||
> Note: Make sure the `lib/src/gen` folder exists before running the generator.
|
||||
|
||||
[1]: ../native_crypto
|
||||
[2]: lib/native_crypto_platform_interface.dart
|
||||
[2]: lib/native_crypto_platform_interface.dart
|
||||
|
@ -1,6 +1 @@
|
||||
include: package:wyatt_analysis/analysis_options.flutter.yaml
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
- "**/*.pigeon.dart"
|
||||
- "lib/src/pigeon/test_api.dart"
|
@ -10,8 +10,6 @@ library native_crypto_platform_interface;
|
||||
export 'src/core/enums/exception_code.dart';
|
||||
export 'src/core/enums/methods.dart';
|
||||
export 'src/core/exceptions/exception.dart';
|
||||
export 'src/gen/test.g.dart';
|
||||
export 'src/implementations/basic_message_channel_native_crypto.dart';
|
||||
export 'src/implementations/method_channel_native_crypto.dart';
|
||||
export 'src/interface/native_crypto_platform.dart';
|
||||
export 'src/pigeon/messages.pigeon.dart';
|
||||
export 'src/pigeon/test_api.dart';
|
||||
|
@ -0,0 +1,11 @@
|
||||
// Copyright 2019-2023 Hugo Pointcheval
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
/// The interface that implementations of native_crypto must implement.
|
||||
library native_crypto_platform_interface;
|
||||
|
||||
export 'src/gen/messages.g.dart';
|
||||
export 'src/gen/test.g.dart';
|
@ -0,0 +1,27 @@
|
||||
// Copyright 2019-2023 Hugo Pointcheval
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import 'package:native_crypto_platform_interface/src/gen/messages.g.dart';
|
||||
|
||||
abstract class EnumParser {
|
||||
static HashAlgorithm hashAlgorithmFromString(String value) {
|
||||
for (final algorithm in HashAlgorithm.values) {
|
||||
if (algorithm.name == value) {
|
||||
return algorithm;
|
||||
}
|
||||
}
|
||||
throw ArgumentError('Invalid algorithm: $value');
|
||||
}
|
||||
|
||||
static CipherAlgorithm cipherAlgorithmFromString(String value) {
|
||||
for (final algorithm in CipherAlgorithm.values) {
|
||||
if (algorithm.name == value) {
|
||||
return algorithm;
|
||||
}
|
||||
}
|
||||
throw ArgumentError('Invalid algorithm: $value');
|
||||
}
|
||||
}
|
@ -0,0 +1,256 @@
|
||||
// Copyright 2019-2023 Hugo Pointcheval
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
// --
|
||||
// Autogenerated from Pigeon (v9.2.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
|
||||
|
||||
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
enum HashAlgorithm {
|
||||
sha256,
|
||||
sha384,
|
||||
sha512,
|
||||
}
|
||||
|
||||
enum CipherAlgorithm {
|
||||
aes,
|
||||
}
|
||||
|
||||
class NativeCryptoAPI {
|
||||
/// Constructor for [NativeCryptoAPI]. The [binaryMessenger] named argument is
|
||||
/// available for dependency injection. If it is left null, the default
|
||||
/// BinaryMessenger will be used which routes to the host platform.
|
||||
NativeCryptoAPI({BinaryMessenger? binaryMessenger})
|
||||
: _binaryMessenger = binaryMessenger;
|
||||
final BinaryMessenger? _binaryMessenger;
|
||||
|
||||
static const MessageCodec<Object?> codec = StandardMessageCodec();
|
||||
|
||||
Future<Uint8List?> hash(Uint8List arg_data, HashAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hash', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_data, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Uint8List?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> hmac(Uint8List arg_data, Uint8List arg_key, HashAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hmac', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_data, arg_key, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Uint8List?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> generateSecureRandom(int arg_length) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_length]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Uint8List?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> pbkdf2(Uint8List arg_password, Uint8List arg_salt, int arg_length, int arg_iterations, HashAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.pbkdf2', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_password, arg_salt, arg_length, arg_iterations, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Uint8List?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> encrypt(Uint8List arg_plainText, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encrypt', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_plainText, arg_key, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Uint8List?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> encryptWithIV(Uint8List arg_plainText, Uint8List arg_iv, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_plainText, arg_iv, arg_key, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Uint8List?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Uint8List?> decrypt(Uint8List arg_cipherText, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decrypt', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_cipherText, arg_key, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Uint8List?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool?> encryptFile(String arg_plainTextPath, String arg_cipherTextPath, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptFile', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_plainTextPath, arg_cipherTextPath, arg_key, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as bool?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool?> encryptFileWithIV(String arg_plainTextPath, String arg_cipherTextPath, Uint8List arg_iv, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_plainTextPath, arg_cipherTextPath, arg_iv, arg_key, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as bool?);
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool?> decryptFile(String arg_cipherTextPath, String arg_plainTextPath, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decryptFile', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_cipherTextPath, arg_plainTextPath, arg_key, arg_algorithm.index]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as bool?);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,307 @@
|
||||
// Copyright 2019-2023 Hugo Pointcheval
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
// --
|
||||
// Autogenerated from Pigeon (v9.2.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
|
||||
// ignore_for_file: avoid_relative_lib_imports
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
|
||||
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'messages.g.dart';
|
||||
|
||||
abstract class TestNativeCryptoAPI {
|
||||
static TestDefaultBinaryMessengerBinding? get _testBinaryMessengerBinding => TestDefaultBinaryMessengerBinding.instance;
|
||||
static const MessageCodec<Object?> codec = StandardMessageCodec();
|
||||
|
||||
Uint8List? hash(Uint8List data, HashAlgorithm algorithm);
|
||||
|
||||
Uint8List? hmac(Uint8List data, Uint8List key, HashAlgorithm algorithm);
|
||||
|
||||
Uint8List? generateSecureRandom(int length);
|
||||
|
||||
Uint8List? pbkdf2(Uint8List password, Uint8List salt, int length, int iterations, HashAlgorithm algorithm);
|
||||
|
||||
Uint8List? encrypt(Uint8List plainText, Uint8List key, CipherAlgorithm algorithm);
|
||||
|
||||
Uint8List? encryptWithIV(Uint8List plainText, Uint8List iv, Uint8List key, CipherAlgorithm algorithm);
|
||||
|
||||
Uint8List? decrypt(Uint8List cipherText, Uint8List key, CipherAlgorithm algorithm);
|
||||
|
||||
bool? encryptFile(String plainTextPath, String cipherTextPath, Uint8List key, CipherAlgorithm algorithm);
|
||||
|
||||
bool? encryptFileWithIV(String plainTextPath, String cipherTextPath, Uint8List iv, Uint8List key, CipherAlgorithm algorithm);
|
||||
|
||||
bool? decryptFile(String cipherTextPath, String plainTextPath, Uint8List key, CipherAlgorithm algorithm);
|
||||
|
||||
static void setup(TestNativeCryptoAPI? api, {BinaryMessenger? binaryMessenger}) {
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hash', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hash was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Uint8List? arg_data = (args[0] as Uint8List?);
|
||||
assert(arg_data != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hash was null, expected non-null Uint8List.');
|
||||
final HashAlgorithm? arg_algorithm = args[1] == null ? null : HashAlgorithm.values[args[1] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hash was null, expected non-null HashAlgorithm.');
|
||||
final Uint8List? output = api.hash(arg_data!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hmac', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hmac was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Uint8List? arg_data = (args[0] as Uint8List?);
|
||||
assert(arg_data != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hmac was null, expected non-null Uint8List.');
|
||||
final Uint8List? arg_key = (args[1] as Uint8List?);
|
||||
assert(arg_key != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hmac was null, expected non-null Uint8List.');
|
||||
final HashAlgorithm? arg_algorithm = args[2] == null ? null : HashAlgorithm.values[args[2] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hmac was null, expected non-null HashAlgorithm.');
|
||||
final Uint8List? output = api.hmac(arg_data!, arg_key!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final int? arg_length = (args[0] as int?);
|
||||
assert(arg_length != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom was null, expected non-null int.');
|
||||
final Uint8List? output = api.generateSecureRandom(arg_length!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.pbkdf2', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Uint8List? arg_password = (args[0] as Uint8List?);
|
||||
assert(arg_password != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null, expected non-null Uint8List.');
|
||||
final Uint8List? arg_salt = (args[1] as Uint8List?);
|
||||
assert(arg_salt != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null, expected non-null Uint8List.');
|
||||
final int? arg_length = (args[2] as int?);
|
||||
assert(arg_length != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null, expected non-null int.');
|
||||
final int? arg_iterations = (args[3] as int?);
|
||||
assert(arg_iterations != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null, expected non-null int.');
|
||||
final HashAlgorithm? arg_algorithm = args[4] == null ? null : HashAlgorithm.values[args[4] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null, expected non-null HashAlgorithm.');
|
||||
final Uint8List? output = api.pbkdf2(arg_password!, arg_salt!, arg_length!, arg_iterations!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encrypt', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encrypt was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Uint8List? arg_plainText = (args[0] as Uint8List?);
|
||||
assert(arg_plainText != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encrypt was null, expected non-null Uint8List.');
|
||||
final Uint8List? arg_key = (args[1] as Uint8List?);
|
||||
assert(arg_key != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encrypt was null, expected non-null Uint8List.');
|
||||
final CipherAlgorithm? arg_algorithm = args[2] == null ? null : CipherAlgorithm.values[args[2] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encrypt was null, expected non-null CipherAlgorithm.');
|
||||
final Uint8List? output = api.encrypt(arg_plainText!, arg_key!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Uint8List? arg_plainText = (args[0] as Uint8List?);
|
||||
assert(arg_plainText != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV was null, expected non-null Uint8List.');
|
||||
final Uint8List? arg_iv = (args[1] as Uint8List?);
|
||||
assert(arg_iv != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV was null, expected non-null Uint8List.');
|
||||
final Uint8List? arg_key = (args[2] as Uint8List?);
|
||||
assert(arg_key != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV was null, expected non-null Uint8List.');
|
||||
final CipherAlgorithm? arg_algorithm = args[3] == null ? null : CipherAlgorithm.values[args[3] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV was null, expected non-null CipherAlgorithm.');
|
||||
final Uint8List? output = api.encryptWithIV(arg_plainText!, arg_iv!, arg_key!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decrypt', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decrypt was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Uint8List? arg_cipherText = (args[0] as Uint8List?);
|
||||
assert(arg_cipherText != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decrypt was null, expected non-null Uint8List.');
|
||||
final Uint8List? arg_key = (args[1] as Uint8List?);
|
||||
assert(arg_key != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decrypt was null, expected non-null Uint8List.');
|
||||
final CipherAlgorithm? arg_algorithm = args[2] == null ? null : CipherAlgorithm.values[args[2] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decrypt was null, expected non-null CipherAlgorithm.');
|
||||
final Uint8List? output = api.decrypt(arg_cipherText!, arg_key!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptFile', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFile was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final String? arg_plainTextPath = (args[0] as String?);
|
||||
assert(arg_plainTextPath != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFile was null, expected non-null String.');
|
||||
final String? arg_cipherTextPath = (args[1] as String?);
|
||||
assert(arg_cipherTextPath != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFile was null, expected non-null String.');
|
||||
final Uint8List? arg_key = (args[2] as Uint8List?);
|
||||
assert(arg_key != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFile was null, expected non-null Uint8List.');
|
||||
final CipherAlgorithm? arg_algorithm = args[3] == null ? null : CipherAlgorithm.values[args[3] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFile was null, expected non-null CipherAlgorithm.');
|
||||
final bool? output = api.encryptFile(arg_plainTextPath!, arg_cipherTextPath!, arg_key!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final String? arg_plainTextPath = (args[0] as String?);
|
||||
assert(arg_plainTextPath != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV was null, expected non-null String.');
|
||||
final String? arg_cipherTextPath = (args[1] as String?);
|
||||
assert(arg_cipherTextPath != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV was null, expected non-null String.');
|
||||
final Uint8List? arg_iv = (args[2] as Uint8List?);
|
||||
assert(arg_iv != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV was null, expected non-null Uint8List.');
|
||||
final Uint8List? arg_key = (args[3] as Uint8List?);
|
||||
assert(arg_key != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV was null, expected non-null Uint8List.');
|
||||
final CipherAlgorithm? arg_algorithm = args[4] == null ? null : CipherAlgorithm.values[args[4] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV was null, expected non-null CipherAlgorithm.');
|
||||
final bool? output = api.encryptFileWithIV(arg_plainTextPath!, arg_cipherTextPath!, arg_iv!, arg_key!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decryptFile', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, null);
|
||||
} else {
|
||||
_testBinaryMessengerBinding!.defaultBinaryMessenger.setMockDecodedMessageHandler<Object?>(channel, (Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decryptFile was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final String? arg_cipherTextPath = (args[0] as String?);
|
||||
assert(arg_cipherTextPath != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decryptFile was null, expected non-null String.');
|
||||
final String? arg_plainTextPath = (args[1] as String?);
|
||||
assert(arg_plainTextPath != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decryptFile was null, expected non-null String.');
|
||||
final Uint8List? arg_key = (args[2] as Uint8List?);
|
||||
assert(arg_key != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decryptFile was null, expected non-null Uint8List.');
|
||||
final CipherAlgorithm? arg_algorithm = args[3] == null ? null : CipherAlgorithm.values[args[3] as int];
|
||||
assert(arg_algorithm != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decryptFile was null, expected non-null CipherAlgorithm.');
|
||||
final bool? output = api.decryptFile(arg_cipherTextPath!, arg_plainTextPath!, arg_key!, arg_algorithm!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,8 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:native_crypto_platform_interface/native_crypto_platform_interface.dart';
|
||||
import 'package:native_crypto_platform_interface/src/core/utils/enum_parser.dart';
|
||||
import 'package:native_crypto_platform_interface/src/gen/messages.g.dart';
|
||||
|
||||
/// An implementation of [NativeCryptoPlatform] that uses Pigeon generated code.
|
||||
class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
|
||||
@ -22,14 +24,10 @@ class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
|
||||
@override
|
||||
Future<Uint8List?> hash(Uint8List data, {required String algorithm}) async {
|
||||
try {
|
||||
return api
|
||||
.hash(
|
||||
HashRequest(
|
||||
data: data,
|
||||
algorithm: algorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.hash);
|
||||
return api.hash(
|
||||
data,
|
||||
EnumParser.hashAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
@ -42,15 +40,11 @@ class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api
|
||||
.hmac(
|
||||
HmacRequest(
|
||||
data: data,
|
||||
key: key,
|
||||
algorithm: algorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.hmac);
|
||||
return api.hmac(
|
||||
data,
|
||||
key,
|
||||
EnumParser.hashAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
@ -59,13 +53,7 @@ class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
|
||||
@override
|
||||
Future<Uint8List?> generateSecureRandom(int length) async {
|
||||
try {
|
||||
return api
|
||||
.generateSecureRandom(
|
||||
GenerateSecureRandomRequest(
|
||||
length: length,
|
||||
),
|
||||
)
|
||||
.then((value) => value.random);
|
||||
return api.generateSecureRandom(length);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
@ -80,17 +68,13 @@ class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
|
||||
required String hashAlgorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api
|
||||
.pbkdf2(
|
||||
Pbkdf2Request(
|
||||
password: password,
|
||||
salt: salt,
|
||||
length: length,
|
||||
iterations: iterations,
|
||||
hashAlgorithm: hashAlgorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.key);
|
||||
return api.pbkdf2(
|
||||
password,
|
||||
salt,
|
||||
length,
|
||||
iterations,
|
||||
EnumParser.hashAlgorithmFromString(hashAlgorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
@ -103,82 +87,11 @@ class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api
|
||||
.encrypt(
|
||||
EncryptRequest(
|
||||
plainText: plainText,
|
||||
key: key,
|
||||
algorithm: algorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.cipherText);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List?> decrypt(
|
||||
Uint8List cipherText, {
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api
|
||||
.decrypt(
|
||||
DecryptRequest(
|
||||
cipherText: cipherText,
|
||||
key: key,
|
||||
algorithm: algorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.plainText);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> encryptFile({
|
||||
required String plainTextPath,
|
||||
required String cipherTextPath,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api
|
||||
.encryptFile(
|
||||
EncryptFileRequest(
|
||||
plainTextPath: plainTextPath,
|
||||
cipherTextPath: cipherTextPath,
|
||||
key: key,
|
||||
algorithm: algorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.success);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> decryptFile({
|
||||
required String cipherTextPath,
|
||||
required String plainTextPath,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api
|
||||
.decryptFile(
|
||||
DecryptFileRequest(
|
||||
cipherTextPath: cipherTextPath,
|
||||
plainTextPath: plainTextPath,
|
||||
key: key,
|
||||
algorithm: algorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.success);
|
||||
return api.encrypt(
|
||||
plainText,
|
||||
key,
|
||||
EnumParser.cipherAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
@ -192,16 +105,88 @@ class BasicMessageChannelNativeCrypto extends NativeCryptoPlatform {
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api
|
||||
.encryptWithIV(
|
||||
EncryptWithIVRequest(
|
||||
plainText: plainText,
|
||||
iv: iv,
|
||||
key: key,
|
||||
algorithm: algorithm,
|
||||
),
|
||||
)
|
||||
.then((value) => value.cipherText);
|
||||
return api.encryptWithIV(
|
||||
plainText,
|
||||
iv,
|
||||
key,
|
||||
EnumParser.cipherAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Uint8List?> decrypt(
|
||||
Uint8List cipherText, {
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api.decrypt(
|
||||
cipherText,
|
||||
key,
|
||||
EnumParser.cipherAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> encryptFile({
|
||||
required String plainTextPath,
|
||||
required String cipherTextPath,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api.encryptFile(
|
||||
plainTextPath,
|
||||
cipherTextPath,
|
||||
key,
|
||||
EnumParser.cipherAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> encryptFileWithIV({
|
||||
required String plainTextPath,
|
||||
required String cipherTextPath,
|
||||
required Uint8List iv,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api.encryptFileWithIV(
|
||||
plainTextPath,
|
||||
cipherTextPath,
|
||||
iv,
|
||||
key,
|
||||
EnumParser.cipherAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool?> decryptFile({
|
||||
required String cipherTextPath,
|
||||
required String plainTextPath,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) async {
|
||||
try {
|
||||
return api.decryptFile(
|
||||
cipherTextPath,
|
||||
plainTextPath,
|
||||
key,
|
||||
EnumParser.cipherAlgorithmFromString(algorithm),
|
||||
);
|
||||
} catch (e, s) {
|
||||
NativeCryptoException.convertPlatformException(e, s);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:native_crypto_platform_interface/native_crypto_platform_interface.dart';
|
||||
import 'package:native_crypto_platform_interface/src/implementations/method_channel_native_crypto.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
/// The interface that implementations of native_crypto must implement.
|
||||
@ -24,11 +23,11 @@ abstract class NativeCryptoPlatform extends PlatformInterface {
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static NativeCryptoPlatform _instance = MethodChannelNativeCrypto();
|
||||
static NativeCryptoPlatform _instance = BasicMessageChannelNativeCrypto();
|
||||
|
||||
/// The default instance of [NativeCryptoPlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelNativeCrypto].
|
||||
/// Defaults to [BasicMessageChannelNativeCrypto].
|
||||
static NativeCryptoPlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific plugins should set this with their own platform-specific
|
||||
@ -77,6 +76,18 @@ abstract class NativeCryptoPlatform extends PlatformInterface {
|
||||
throw UnimplementedError('encrypt is not implemented');
|
||||
}
|
||||
|
||||
/// Encrypts the given data using the given key, algorithm and iv.
|
||||
///
|
||||
/// Users should use [encrypt] instead if they don't need to specify the iv.
|
||||
Future<Uint8List?> encryptWithIV({
|
||||
required Uint8List plainText,
|
||||
required Uint8List iv,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) {
|
||||
throw UnimplementedError('encryptWithIV is not implemented');
|
||||
}
|
||||
|
||||
/// Decrypts the given data using the given key and algorithm.
|
||||
Future<Uint8List?> decrypt(
|
||||
Uint8List cipherText, {
|
||||
@ -96,6 +107,20 @@ abstract class NativeCryptoPlatform extends PlatformInterface {
|
||||
throw UnimplementedError('encryptFile is not implemented');
|
||||
}
|
||||
|
||||
/// Encrypts the given file using the given key, algorithm and iv.
|
||||
///
|
||||
/// Users should use [encryptFile] instead if they don't need to specify
|
||||
/// the iv.
|
||||
Future<bool?> encryptFileWithIV({
|
||||
required String plainTextPath,
|
||||
required String cipherTextPath,
|
||||
required Uint8List iv,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) {
|
||||
throw UnimplementedError('encryptFileWithIV is not implemented');
|
||||
}
|
||||
|
||||
/// Decrypts the given file using the given key and algorithm.
|
||||
Future<bool?> decryptFile({
|
||||
required String cipherTextPath,
|
||||
@ -105,16 +130,4 @@ abstract class NativeCryptoPlatform extends PlatformInterface {
|
||||
}) {
|
||||
throw UnimplementedError('decryptFile is not implemented');
|
||||
}
|
||||
|
||||
/// Encrypts the given data using the given key, algorithm and iv.
|
||||
///
|
||||
/// Users should use [encrypt] instead if they don't need to specify the iv.
|
||||
Future<Uint8List?> encryptWithIV({
|
||||
required Uint8List plainText,
|
||||
required Uint8List iv,
|
||||
required Uint8List key,
|
||||
required String algorithm,
|
||||
}) {
|
||||
throw UnimplementedError('encryptWithIV is not implemented');
|
||||
}
|
||||
}
|
||||
|
@ -1,829 +0,0 @@
|
||||
// Copyright 2019-2023 Hugo Pointcheval
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
// --
|
||||
// Autogenerated from Pigeon (v9.0.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, prefer_null_aware_operators, omit_local_variable_types, unused_shown_name, unnecessary_import
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
|
||||
|
||||
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class HashRequest {
|
||||
HashRequest({
|
||||
this.data,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
Uint8List? data;
|
||||
|
||||
String? algorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
data,
|
||||
algorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static HashRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return HashRequest(
|
||||
data: result[0] as Uint8List?,
|
||||
algorithm: result[1] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HashResponse {
|
||||
HashResponse({
|
||||
this.hash,
|
||||
});
|
||||
|
||||
Uint8List? hash;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
hash,
|
||||
];
|
||||
}
|
||||
|
||||
static HashResponse decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return HashResponse(
|
||||
hash: result[0] as Uint8List?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HmacRequest {
|
||||
HmacRequest({
|
||||
this.data,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
Uint8List? data;
|
||||
|
||||
Uint8List? key;
|
||||
|
||||
String? algorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
data,
|
||||
key,
|
||||
algorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static HmacRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return HmacRequest(
|
||||
data: result[0] as Uint8List?,
|
||||
key: result[1] as Uint8List?,
|
||||
algorithm: result[2] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class HmacResponse {
|
||||
HmacResponse({
|
||||
this.hmac,
|
||||
});
|
||||
|
||||
Uint8List? hmac;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
hmac,
|
||||
];
|
||||
}
|
||||
|
||||
static HmacResponse decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return HmacResponse(
|
||||
hmac: result[0] as Uint8List?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GenerateSecureRandomRequest {
|
||||
GenerateSecureRandomRequest({
|
||||
this.length,
|
||||
});
|
||||
|
||||
int? length;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
length,
|
||||
];
|
||||
}
|
||||
|
||||
static GenerateSecureRandomRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return GenerateSecureRandomRequest(
|
||||
length: result[0] as int?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class GenerateSecureRandomResponse {
|
||||
GenerateSecureRandomResponse({
|
||||
this.random,
|
||||
});
|
||||
|
||||
Uint8List? random;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
random,
|
||||
];
|
||||
}
|
||||
|
||||
static GenerateSecureRandomResponse decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return GenerateSecureRandomResponse(
|
||||
random: result[0] as Uint8List?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Pbkdf2Request {
|
||||
Pbkdf2Request({
|
||||
this.password,
|
||||
this.salt,
|
||||
this.length,
|
||||
this.iterations,
|
||||
this.hashAlgorithm,
|
||||
});
|
||||
|
||||
Uint8List? password;
|
||||
|
||||
Uint8List? salt;
|
||||
|
||||
int? length;
|
||||
|
||||
int? iterations;
|
||||
|
||||
String? hashAlgorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
password,
|
||||
salt,
|
||||
length,
|
||||
iterations,
|
||||
hashAlgorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static Pbkdf2Request decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return Pbkdf2Request(
|
||||
password: result[0] as Uint8List?,
|
||||
salt: result[1] as Uint8List?,
|
||||
length: result[2] as int?,
|
||||
iterations: result[3] as int?,
|
||||
hashAlgorithm: result[4] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class Pbkdf2Response {
|
||||
Pbkdf2Response({
|
||||
this.key,
|
||||
});
|
||||
|
||||
Uint8List? key;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
key,
|
||||
];
|
||||
}
|
||||
|
||||
static Pbkdf2Response decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return Pbkdf2Response(
|
||||
key: result[0] as Uint8List?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EncryptRequest {
|
||||
EncryptRequest({
|
||||
this.plainText,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
Uint8List? plainText;
|
||||
|
||||
Uint8List? key;
|
||||
|
||||
String? algorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
plainText,
|
||||
key,
|
||||
algorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static EncryptRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return EncryptRequest(
|
||||
plainText: result[0] as Uint8List?,
|
||||
key: result[1] as Uint8List?,
|
||||
algorithm: result[2] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EncryptResponse {
|
||||
EncryptResponse({
|
||||
this.cipherText,
|
||||
});
|
||||
|
||||
Uint8List? cipherText;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
cipherText,
|
||||
];
|
||||
}
|
||||
|
||||
static EncryptResponse decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return EncryptResponse(
|
||||
cipherText: result[0] as Uint8List?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DecryptRequest {
|
||||
DecryptRequest({
|
||||
this.cipherText,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
Uint8List? cipherText;
|
||||
|
||||
Uint8List? key;
|
||||
|
||||
String? algorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
cipherText,
|
||||
key,
|
||||
algorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static DecryptRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return DecryptRequest(
|
||||
cipherText: result[0] as Uint8List?,
|
||||
key: result[1] as Uint8List?,
|
||||
algorithm: result[2] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DecryptResponse {
|
||||
DecryptResponse({
|
||||
this.plainText,
|
||||
});
|
||||
|
||||
Uint8List? plainText;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
plainText,
|
||||
];
|
||||
}
|
||||
|
||||
static DecryptResponse decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return DecryptResponse(
|
||||
plainText: result[0] as Uint8List?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EncryptFileRequest {
|
||||
EncryptFileRequest({
|
||||
this.plainTextPath,
|
||||
this.cipherTextPath,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
String? plainTextPath;
|
||||
|
||||
String? cipherTextPath;
|
||||
|
||||
Uint8List? key;
|
||||
|
||||
String? algorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
plainTextPath,
|
||||
cipherTextPath,
|
||||
key,
|
||||
algorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static EncryptFileRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return EncryptFileRequest(
|
||||
plainTextPath: result[0] as String?,
|
||||
cipherTextPath: result[1] as String?,
|
||||
key: result[2] as Uint8List?,
|
||||
algorithm: result[3] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EncryptFileResponse {
|
||||
EncryptFileResponse({
|
||||
this.success,
|
||||
});
|
||||
|
||||
bool? success;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
success,
|
||||
];
|
||||
}
|
||||
|
||||
static EncryptFileResponse decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return EncryptFileResponse(
|
||||
success: result[0] as bool?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DecryptFileRequest {
|
||||
DecryptFileRequest({
|
||||
this.cipherTextPath,
|
||||
this.plainTextPath,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
String? cipherTextPath;
|
||||
|
||||
String? plainTextPath;
|
||||
|
||||
Uint8List? key;
|
||||
|
||||
String? algorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
cipherTextPath,
|
||||
plainTextPath,
|
||||
key,
|
||||
algorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static DecryptFileRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return DecryptFileRequest(
|
||||
cipherTextPath: result[0] as String?,
|
||||
plainTextPath: result[1] as String?,
|
||||
key: result[2] as Uint8List?,
|
||||
algorithm: result[3] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class DecryptFileResponse {
|
||||
DecryptFileResponse({
|
||||
this.success,
|
||||
});
|
||||
|
||||
bool? success;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
success,
|
||||
];
|
||||
}
|
||||
|
||||
static DecryptFileResponse decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return DecryptFileResponse(
|
||||
success: result[0] as bool?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EncryptWithIVRequest {
|
||||
EncryptWithIVRequest({
|
||||
this.plainText,
|
||||
this.iv,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
Uint8List? plainText;
|
||||
|
||||
Uint8List? iv;
|
||||
|
||||
Uint8List? key;
|
||||
|
||||
String? algorithm;
|
||||
|
||||
Object encode() {
|
||||
return <Object?>[
|
||||
plainText,
|
||||
iv,
|
||||
key,
|
||||
algorithm,
|
||||
];
|
||||
}
|
||||
|
||||
static EncryptWithIVRequest decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return EncryptWithIVRequest(
|
||||
plainText: result[0] as Uint8List?,
|
||||
iv: result[1] as Uint8List?,
|
||||
key: result[2] as Uint8List?,
|
||||
algorithm: result[3] as String?,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NativeCryptoAPICodec extends StandardMessageCodec {
|
||||
const _NativeCryptoAPICodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is DecryptFileRequest) {
|
||||
buffer.putUint8(128);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is DecryptFileResponse) {
|
||||
buffer.putUint8(129);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is DecryptRequest) {
|
||||
buffer.putUint8(130);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is DecryptResponse) {
|
||||
buffer.putUint8(131);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptFileRequest) {
|
||||
buffer.putUint8(132);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptFileResponse) {
|
||||
buffer.putUint8(133);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptRequest) {
|
||||
buffer.putUint8(134);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptResponse) {
|
||||
buffer.putUint8(135);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptWithIVRequest) {
|
||||
buffer.putUint8(136);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is GenerateSecureRandomRequest) {
|
||||
buffer.putUint8(137);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is GenerateSecureRandomResponse) {
|
||||
buffer.putUint8(138);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HashRequest) {
|
||||
buffer.putUint8(139);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HashResponse) {
|
||||
buffer.putUint8(140);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HmacRequest) {
|
||||
buffer.putUint8(141);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HmacResponse) {
|
||||
buffer.putUint8(142);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is Pbkdf2Request) {
|
||||
buffer.putUint8(143);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is Pbkdf2Response) {
|
||||
buffer.putUint8(144);
|
||||
writeValue(buffer, value.encode());
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
case 128:
|
||||
return DecryptFileRequest.decode(readValue(buffer)!);
|
||||
case 129:
|
||||
return DecryptFileResponse.decode(readValue(buffer)!);
|
||||
case 130:
|
||||
return DecryptRequest.decode(readValue(buffer)!);
|
||||
case 131:
|
||||
return DecryptResponse.decode(readValue(buffer)!);
|
||||
case 132:
|
||||
return EncryptFileRequest.decode(readValue(buffer)!);
|
||||
case 133:
|
||||
return EncryptFileResponse.decode(readValue(buffer)!);
|
||||
case 134:
|
||||
return EncryptRequest.decode(readValue(buffer)!);
|
||||
case 135:
|
||||
return EncryptResponse.decode(readValue(buffer)!);
|
||||
case 136:
|
||||
return EncryptWithIVRequest.decode(readValue(buffer)!);
|
||||
case 137:
|
||||
return GenerateSecureRandomRequest.decode(readValue(buffer)!);
|
||||
case 138:
|
||||
return GenerateSecureRandomResponse.decode(readValue(buffer)!);
|
||||
case 139:
|
||||
return HashRequest.decode(readValue(buffer)!);
|
||||
case 140:
|
||||
return HashResponse.decode(readValue(buffer)!);
|
||||
case 141:
|
||||
return HmacRequest.decode(readValue(buffer)!);
|
||||
case 142:
|
||||
return HmacResponse.decode(readValue(buffer)!);
|
||||
case 143:
|
||||
return Pbkdf2Request.decode(readValue(buffer)!);
|
||||
case 144:
|
||||
return Pbkdf2Response.decode(readValue(buffer)!);
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NativeCryptoAPI {
|
||||
/// Constructor for [NativeCryptoAPI]. The [binaryMessenger] named argument is
|
||||
/// available for dependency injection. If it is left null, the default
|
||||
/// BinaryMessenger will be used which routes to the host platform.
|
||||
NativeCryptoAPI({BinaryMessenger? binaryMessenger})
|
||||
: _binaryMessenger = binaryMessenger;
|
||||
final BinaryMessenger? _binaryMessenger;
|
||||
|
||||
static const MessageCodec<Object?> codec = _NativeCryptoAPICodec();
|
||||
|
||||
Future<HashResponse> hash(HashRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hash', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as HashResponse?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<HmacResponse> hmac(HmacRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hmac', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as HmacResponse?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<GenerateSecureRandomResponse> generateSecureRandom(GenerateSecureRandomRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as GenerateSecureRandomResponse?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<Pbkdf2Response> pbkdf2(Pbkdf2Request arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.pbkdf2', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as Pbkdf2Response?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<EncryptResponse> encrypt(EncryptRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encrypt', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as EncryptResponse?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DecryptResponse> decrypt(DecryptRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decrypt', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as DecryptResponse?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<EncryptFileResponse> encryptFile(EncryptFileRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptFile', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as EncryptFileResponse?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<DecryptFileResponse> decryptFile(DecryptFileRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decryptFile', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as DecryptFileResponse?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<EncryptResponse> encryptWithIV(EncryptWithIVRequest arg_request) async {
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV', codec,
|
||||
binaryMessenger: _binaryMessenger);
|
||||
final List<Object?>? replyList =
|
||||
await channel.send(<Object?>[arg_request]) as List<Object?>?;
|
||||
if (replyList == null) {
|
||||
throw PlatformException(
|
||||
code: 'channel-error',
|
||||
message: 'Unable to establish connection on channel.',
|
||||
);
|
||||
} else if (replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: replyList[0]! as String,
|
||||
message: replyList[1] as String?,
|
||||
details: replyList[2],
|
||||
);
|
||||
} else if (replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (replyList[0] as EncryptResponse?)!;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,316 +0,0 @@
|
||||
// Copyright 2019-2023 Hugo Pointcheval
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
// --
|
||||
// Autogenerated from Pigeon (v9.0.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
// ignore_for_file: public_member_api_docs, non_constant_identifier_names, avoid_as, unused_import, unnecessary_parenthesis, unnecessary_import
|
||||
// ignore_for_file: avoid_relative_lib_imports
|
||||
import 'dart:async';
|
||||
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
|
||||
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'messages.pigeon.dart';
|
||||
|
||||
class _TestNativeCryptoAPICodec extends StandardMessageCodec {
|
||||
const _TestNativeCryptoAPICodec();
|
||||
@override
|
||||
void writeValue(WriteBuffer buffer, Object? value) {
|
||||
if (value is DecryptFileRequest) {
|
||||
buffer.putUint8(128);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is DecryptFileResponse) {
|
||||
buffer.putUint8(129);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is DecryptRequest) {
|
||||
buffer.putUint8(130);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is DecryptResponse) {
|
||||
buffer.putUint8(131);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptFileRequest) {
|
||||
buffer.putUint8(132);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptFileResponse) {
|
||||
buffer.putUint8(133);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptRequest) {
|
||||
buffer.putUint8(134);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptResponse) {
|
||||
buffer.putUint8(135);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is EncryptWithIVRequest) {
|
||||
buffer.putUint8(136);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is GenerateSecureRandomRequest) {
|
||||
buffer.putUint8(137);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is GenerateSecureRandomResponse) {
|
||||
buffer.putUint8(138);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HashRequest) {
|
||||
buffer.putUint8(139);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HashResponse) {
|
||||
buffer.putUint8(140);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HmacRequest) {
|
||||
buffer.putUint8(141);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is HmacResponse) {
|
||||
buffer.putUint8(142);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is Pbkdf2Request) {
|
||||
buffer.putUint8(143);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is Pbkdf2Response) {
|
||||
buffer.putUint8(144);
|
||||
writeValue(buffer, value.encode());
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Object? readValueOfType(int type, ReadBuffer buffer) {
|
||||
switch (type) {
|
||||
case 128:
|
||||
return DecryptFileRequest.decode(readValue(buffer)!);
|
||||
case 129:
|
||||
return DecryptFileResponse.decode(readValue(buffer)!);
|
||||
case 130:
|
||||
return DecryptRequest.decode(readValue(buffer)!);
|
||||
case 131:
|
||||
return DecryptResponse.decode(readValue(buffer)!);
|
||||
case 132:
|
||||
return EncryptFileRequest.decode(readValue(buffer)!);
|
||||
case 133:
|
||||
return EncryptFileResponse.decode(readValue(buffer)!);
|
||||
case 134:
|
||||
return EncryptRequest.decode(readValue(buffer)!);
|
||||
case 135:
|
||||
return EncryptResponse.decode(readValue(buffer)!);
|
||||
case 136:
|
||||
return EncryptWithIVRequest.decode(readValue(buffer)!);
|
||||
case 137:
|
||||
return GenerateSecureRandomRequest.decode(readValue(buffer)!);
|
||||
case 138:
|
||||
return GenerateSecureRandomResponse.decode(readValue(buffer)!);
|
||||
case 139:
|
||||
return HashRequest.decode(readValue(buffer)!);
|
||||
case 140:
|
||||
return HashResponse.decode(readValue(buffer)!);
|
||||
case 141:
|
||||
return HmacRequest.decode(readValue(buffer)!);
|
||||
case 142:
|
||||
return HmacResponse.decode(readValue(buffer)!);
|
||||
case 143:
|
||||
return Pbkdf2Request.decode(readValue(buffer)!);
|
||||
case 144:
|
||||
return Pbkdf2Response.decode(readValue(buffer)!);
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class TestNativeCryptoAPI {
|
||||
static const MessageCodec<Object?> codec = _TestNativeCryptoAPICodec();
|
||||
|
||||
HashResponse hash(HashRequest request);
|
||||
|
||||
HmacResponse hmac(HmacRequest request);
|
||||
|
||||
GenerateSecureRandomResponse generateSecureRandom(GenerateSecureRandomRequest request);
|
||||
|
||||
Pbkdf2Response pbkdf2(Pbkdf2Request request);
|
||||
|
||||
EncryptResponse encrypt(EncryptRequest request);
|
||||
|
||||
DecryptResponse decrypt(DecryptRequest request);
|
||||
|
||||
EncryptFileResponse encryptFile(EncryptFileRequest request);
|
||||
|
||||
DecryptFileResponse decryptFile(DecryptFileRequest request);
|
||||
|
||||
EncryptResponse encryptWithIV(EncryptWithIVRequest request);
|
||||
|
||||
static void setup(TestNativeCryptoAPI? api, {BinaryMessenger? binaryMessenger}) {
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hash', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hash was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final HashRequest? arg_request = (args[0] as HashRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hash was null, expected non-null HashRequest.');
|
||||
final HashResponse output = api.hash(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.hmac', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hmac was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final HmacRequest? arg_request = (args[0] as HmacRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.hmac was null, expected non-null HmacRequest.');
|
||||
final HmacResponse output = api.hmac(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final GenerateSecureRandomRequest? arg_request = (args[0] as GenerateSecureRandomRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom was null, expected non-null GenerateSecureRandomRequest.');
|
||||
final GenerateSecureRandomResponse output = api.generateSecureRandom(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.pbkdf2', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final Pbkdf2Request? arg_request = (args[0] as Pbkdf2Request?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.pbkdf2 was null, expected non-null Pbkdf2Request.');
|
||||
final Pbkdf2Response output = api.pbkdf2(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encrypt', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encrypt was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final EncryptRequest? arg_request = (args[0] as EncryptRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encrypt was null, expected non-null EncryptRequest.');
|
||||
final EncryptResponse output = api.encrypt(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decrypt', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decrypt was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final DecryptRequest? arg_request = (args[0] as DecryptRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decrypt was null, expected non-null DecryptRequest.');
|
||||
final DecryptResponse output = api.decrypt(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptFile', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFile was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final EncryptFileRequest? arg_request = (args[0] as EncryptFileRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptFile was null, expected non-null EncryptFileRequest.');
|
||||
final EncryptFileResponse output = api.encryptFile(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.decryptFile', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decryptFile was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final DecryptFileRequest? arg_request = (args[0] as DecryptFileRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.decryptFile was null, expected non-null DecryptFileRequest.');
|
||||
final DecryptFileResponse output = api.decryptFile(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
{
|
||||
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
|
||||
'dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV', codec,
|
||||
binaryMessenger: binaryMessenger);
|
||||
if (api == null) {
|
||||
channel.setMockMessageHandler(null);
|
||||
} else {
|
||||
channel.setMockMessageHandler((Object? message) async {
|
||||
assert(message != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV was null.');
|
||||
final List<Object?> args = (message as List<Object?>?)!;
|
||||
final EncryptWithIVRequest? arg_request = (args[0] as EncryptWithIVRequest?);
|
||||
assert(arg_request != null,
|
||||
'Argument for dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV was null, expected non-null EncryptWithIVRequest.');
|
||||
final EncryptResponse output = api.encryptWithIV(arg_request!);
|
||||
return <Object?>[output];
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,3 @@
|
||||
// ignore_for_file: public_member_api_docs, sort_constructors_first
|
||||
// Copyright 2019-2023 Hugo Pointcheval
|
||||
//
|
||||
// Use of this source code is governed by an MIT-style
|
||||
@ -10,213 +9,80 @@ import 'package:pigeon/pigeon.dart';
|
||||
@ConfigurePigeon(
|
||||
PigeonOptions(
|
||||
copyrightHeader: 'pigeons/copyright_header.txt',
|
||||
dartOut: 'lib/src/pigeon/messages.pigeon.dart',
|
||||
dartOut: 'lib/src/gen/messages.g.dart',
|
||||
// We export in the lib folder to expose the class to other packages.
|
||||
dartTestOut: 'lib/src/pigeon/test_api.dart',
|
||||
javaOut:
|
||||
'../native_crypto_android/android/src/main/java/fr/pointcheval/native_crypto_android/GeneratedAndroidNativeCrypto.java',
|
||||
javaOptions: JavaOptions(
|
||||
dartTestOut: 'lib/src/gen/test.g.dart',
|
||||
kotlinOut:
|
||||
'../native_crypto_android/android/src/main/kotlin/fr/pointcheval/native_crypto_android/Pigeon.kt',
|
||||
kotlinOptions: KotlinOptions(
|
||||
package: 'fr.pointcheval.native_crypto_android',
|
||||
className: 'GeneratedAndroidNativeCrypto',
|
||||
),
|
||||
objcHeaderOut: '../native_crypto_ios/ios/Classes/Public/messages.g.h',
|
||||
objcSourceOut: '../native_crypto_ios/ios/Classes/messages.g.m',
|
||||
swiftOut: '../native_crypto_ios/ios/Classes/messages.g.swift',
|
||||
),
|
||||
)
|
||||
class HashRequest {
|
||||
const HashRequest({
|
||||
this.data,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
final Uint8List? data;
|
||||
final String? algorithm;
|
||||
enum HashAlgorithm {
|
||||
sha256,
|
||||
sha384,
|
||||
sha512;
|
||||
}
|
||||
|
||||
class HashResponse {
|
||||
const HashResponse({
|
||||
this.hash,
|
||||
});
|
||||
|
||||
final Uint8List? hash;
|
||||
}
|
||||
|
||||
class HmacRequest {
|
||||
const HmacRequest({
|
||||
this.data,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
final Uint8List? data;
|
||||
final Uint8List? key;
|
||||
final String? algorithm;
|
||||
}
|
||||
|
||||
class HmacResponse {
|
||||
const HmacResponse({
|
||||
this.hmac,
|
||||
});
|
||||
|
||||
final Uint8List? hmac;
|
||||
}
|
||||
|
||||
class GenerateSecureRandomRequest {
|
||||
const GenerateSecureRandomRequest({
|
||||
this.length,
|
||||
});
|
||||
|
||||
final int? length;
|
||||
}
|
||||
|
||||
class GenerateSecureRandomResponse {
|
||||
const GenerateSecureRandomResponse({
|
||||
this.random,
|
||||
});
|
||||
|
||||
final Uint8List? random;
|
||||
}
|
||||
|
||||
class Pbkdf2Request {
|
||||
const Pbkdf2Request({
|
||||
this.password,
|
||||
this.salt,
|
||||
this.length,
|
||||
this.iterations,
|
||||
this.hashAlgorithm,
|
||||
});
|
||||
|
||||
final Uint8List? password;
|
||||
final Uint8List? salt;
|
||||
final int? length;
|
||||
final int? iterations;
|
||||
final String? hashAlgorithm;
|
||||
}
|
||||
|
||||
class Pbkdf2Response {
|
||||
const Pbkdf2Response({
|
||||
this.key,
|
||||
});
|
||||
|
||||
final Uint8List? key;
|
||||
}
|
||||
|
||||
class EncryptRequest {
|
||||
const EncryptRequest({
|
||||
this.plainText,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
final Uint8List? plainText;
|
||||
final Uint8List? key;
|
||||
final String? algorithm;
|
||||
}
|
||||
|
||||
class EncryptResponse {
|
||||
const EncryptResponse({
|
||||
this.cipherText,
|
||||
});
|
||||
|
||||
final Uint8List? cipherText;
|
||||
}
|
||||
|
||||
class DecryptRequest {
|
||||
const DecryptRequest({
|
||||
this.cipherText,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
final Uint8List? cipherText;
|
||||
final Uint8List? key;
|
||||
final String? algorithm;
|
||||
}
|
||||
|
||||
class DecryptResponse {
|
||||
const DecryptResponse({
|
||||
this.plainText,
|
||||
});
|
||||
|
||||
final Uint8List? plainText;
|
||||
}
|
||||
|
||||
class EncryptFileRequest {
|
||||
const EncryptFileRequest({
|
||||
this.plainTextPath,
|
||||
this.cipherTextPath,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
final String? plainTextPath;
|
||||
final String? cipherTextPath;
|
||||
final Uint8List? key;
|
||||
final String? algorithm;
|
||||
}
|
||||
|
||||
class EncryptFileResponse {
|
||||
const EncryptFileResponse({
|
||||
this.success,
|
||||
});
|
||||
|
||||
final bool? success;
|
||||
}
|
||||
|
||||
class DecryptFileRequest {
|
||||
const DecryptFileRequest({
|
||||
this.cipherTextPath,
|
||||
this.plainTextPath,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
final String? cipherTextPath;
|
||||
final String? plainTextPath;
|
||||
final Uint8List? key;
|
||||
final String? algorithm;
|
||||
}
|
||||
|
||||
class DecryptFileResponse {
|
||||
const DecryptFileResponse({
|
||||
this.success,
|
||||
});
|
||||
|
||||
final bool? success;
|
||||
}
|
||||
|
||||
class EncryptWithIVRequest {
|
||||
const EncryptWithIVRequest({
|
||||
this.plainText,
|
||||
this.iv,
|
||||
this.key,
|
||||
this.algorithm,
|
||||
});
|
||||
|
||||
final Uint8List? plainText;
|
||||
final Uint8List? iv;
|
||||
final Uint8List? key;
|
||||
final String? algorithm;
|
||||
enum CipherAlgorithm {
|
||||
aes;
|
||||
}
|
||||
|
||||
@HostApi(dartHostTestHandler: 'TestNativeCryptoAPI')
|
||||
abstract class NativeCryptoAPI {
|
||||
HashResponse hash(HashRequest request);
|
||||
HmacResponse hmac(HmacRequest request);
|
||||
Uint8List? hash(Uint8List data, HashAlgorithm algorithm);
|
||||
Uint8List? hmac(Uint8List data, Uint8List key, HashAlgorithm algorithm);
|
||||
Uint8List? generateSecureRandom(int length);
|
||||
|
||||
GenerateSecureRandomResponse generateSecureRandom(
|
||||
GenerateSecureRandomRequest request,
|
||||
Uint8List? pbkdf2(
|
||||
Uint8List password,
|
||||
Uint8List salt,
|
||||
int length,
|
||||
int iterations,
|
||||
HashAlgorithm algorithm,
|
||||
);
|
||||
|
||||
Pbkdf2Response pbkdf2(Pbkdf2Request request);
|
||||
Uint8List? encrypt(
|
||||
Uint8List plainText,
|
||||
Uint8List key,
|
||||
CipherAlgorithm algorithm,
|
||||
);
|
||||
|
||||
EncryptResponse encrypt(EncryptRequest request);
|
||||
Uint8List? encryptWithIV(
|
||||
Uint8List plainText,
|
||||
Uint8List iv,
|
||||
Uint8List key,
|
||||
CipherAlgorithm algorithm,
|
||||
);
|
||||
|
||||
DecryptResponse decrypt(DecryptRequest request);
|
||||
Uint8List? decrypt(
|
||||
Uint8List cipherText,
|
||||
Uint8List key,
|
||||
CipherAlgorithm algorithm,
|
||||
);
|
||||
|
||||
EncryptFileResponse encryptFile(EncryptFileRequest request);
|
||||
bool? encryptFile(
|
||||
String plainTextPath,
|
||||
String cipherTextPath,
|
||||
Uint8List key,
|
||||
CipherAlgorithm algorithm,
|
||||
);
|
||||
|
||||
DecryptFileResponse decryptFile(DecryptFileRequest request);
|
||||
bool? encryptFileWithIV(
|
||||
String plainTextPath,
|
||||
String cipherTextPath,
|
||||
Uint8List iv,
|
||||
Uint8List key,
|
||||
CipherAlgorithm algorithm,
|
||||
);
|
||||
|
||||
bool? decryptFile(
|
||||
String cipherTextPath,
|
||||
String plainTextPath,
|
||||
Uint8List key,
|
||||
CipherAlgorithm algorithm,
|
||||
);
|
||||
|
||||
EncryptResponse encryptWithIV(EncryptWithIVRequest request);
|
||||
}
|
||||
|
@ -10,16 +10,16 @@ dependencies:
|
||||
equatable: ^2.0.5
|
||||
flutter: { sdk: flutter }
|
||||
|
||||
plugin_platform_interface: ^2.1.3
|
||||
plugin_platform_interface: ^2.1.4
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test: { sdk: flutter }
|
||||
|
||||
mockito: ^5.3.2
|
||||
pigeon: ^9.0.0
|
||||
mockito: ^5.4.0
|
||||
pigeon: ^9.2.0
|
||||
|
||||
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
|
||||
|
@ -4,18 +4,18 @@
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:native_crypto_platform_interface/src/implementations/basic_message_channel_native_crypto.dart';
|
||||
import 'package:native_crypto_platform_interface/src/implementations/method_channel_native_crypto.dart';
|
||||
import 'package:native_crypto_platform_interface/src/interface/native_crypto_platform.dart';
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
class ImplementsNativeCryptoPlatform
|
||||
// ignore: prefer_mixin
|
||||
with Mock
|
||||
implements NativeCryptoPlatform {}
|
||||
with
|
||||
Mock
|
||||
implements
|
||||
NativeCryptoPlatform {}
|
||||
|
||||
class ExtendsNativeCryptoPlatform extends NativeCryptoPlatform {}
|
||||
|
||||
@ -31,10 +31,6 @@ void main() {
|
||||
|
||||
group('$NativeCryptoPlatform', () {
|
||||
// should allow read of default app from native
|
||||
test('$MethodChannelNativeCrypto is the default instance', () {
|
||||
expect(NativeCryptoPlatform.instance, isA<MethodChannelNativeCrypto>());
|
||||
});
|
||||
|
||||
test('Can be extended', () {
|
||||
NativeCryptoPlatform.instance = ExtendsNativeCryptoPlatform();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user