Skip to content

Commit f570ed0

Browse files
committed
feat(interface)!: set pigeon as default implementation
1 parent c8ff114 commit f570ed0

File tree

15 files changed

+778
-1461
lines changed

15 files changed

+778
-1461
lines changed

packages/native_crypto_platform_interface/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ NativeCrypto - Platform Interface
22

33
MIT License
44

5-
Copyright (c) 2019 - 2022 Hugo Pointcheval
5+
Copyright (c) 2019 - 2023 Hugo Pointcheval
66

77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
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
2020
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2121
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2222
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23-
SOFTWARE.
23+
SOFTWARE.

packages/native_crypto_platform_interface/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,13 @@ This interface allows platform-specific implementations of the `native_crypto` p
88

99
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()`.
1010

11+
## Pigeon
12+
13+
This package uses [Pigeon](https://pub.dev/packages/pigeon) to generate the platform interface code.
14+
15+
Run generator with `flutter pub run pigeon --input pigeons/messages.dart`.
16+
17+
> Note: Make sure the `lib/src/gen` folder exists before running the generator.
18+
1119
[1]: ../native_crypto
12-
[2]: lib/native_crypto_platform_interface.dart
20+
[2]: lib/native_crypto_platform_interface.dart
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
include: package:wyatt_analysis/analysis_options.flutter.yaml
2-
3-
analyzer:
4-
exclude:
5-
- "**/*.pigeon.dart"
6-
- "lib/src/pigeon/test_api.dart"

packages/native_crypto_platform_interface/lib/native_crypto_platform_interface.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ library native_crypto_platform_interface;
1010
export 'src/core/enums/exception_code.dart';
1111
export 'src/core/enums/methods.dart';
1212
export 'src/core/exceptions/exception.dart';
13+
export 'src/gen/test.g.dart';
1314
export 'src/implementations/basic_message_channel_native_crypto.dart';
14-
export 'src/implementations/method_channel_native_crypto.dart';
1515
export 'src/interface/native_crypto_platform.dart';
16-
export 'src/pigeon/messages.pigeon.dart';
17-
export 'src/pigeon/test_api.dart';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019-2023 Hugo Pointcheval
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file or at
5+
// https://opensource.org/licenses/MIT.
6+
7+
/// The interface that implementations of native_crypto must implement.
8+
library native_crypto_platform_interface;
9+
10+
export 'src/gen/messages.g.dart';
11+
export 'src/gen/test.g.dart';
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2019-2023 Hugo Pointcheval
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file or at
5+
// https://opensource.org/licenses/MIT.
6+
7+
import 'package:native_crypto_platform_interface/src/gen/messages.g.dart';
8+
9+
abstract class EnumParser {
10+
static HashAlgorithm hashAlgorithmFromString(String value) {
11+
for (final algorithm in HashAlgorithm.values) {
12+
if (algorithm.name == value) {
13+
return algorithm;
14+
}
15+
}
16+
throw ArgumentError('Invalid algorithm: $value');
17+
}
18+
19+
static CipherAlgorithm cipherAlgorithmFromString(String value) {
20+
for (final algorithm in CipherAlgorithm.values) {
21+
if (algorithm.name == value) {
22+
return algorithm;
23+
}
24+
}
25+
throw ArgumentError('Invalid algorithm: $value');
26+
}
27+
}
Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
// Copyright 2019-2023 Hugo Pointcheval
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file or at
5+
// https://opensource.org/licenses/MIT.
6+
// --
7+
// Autogenerated from Pigeon (v9.2.0), do not edit directly.
8+
// See also: https://pub.dev/packages/pigeon
9+
// 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
10+
11+
import 'dart:async';
12+
import 'dart:typed_data' show Float64List, Int32List, Int64List, Uint8List;
13+
14+
import 'package:flutter/foundation.dart' show ReadBuffer, WriteBuffer;
15+
import 'package:flutter/services.dart';
16+
17+
enum HashAlgorithm {
18+
sha256,
19+
sha384,
20+
sha512,
21+
}
22+
23+
enum CipherAlgorithm {
24+
aes,
25+
}
26+
27+
class NativeCryptoAPI {
28+
/// Constructor for [NativeCryptoAPI]. The [binaryMessenger] named argument is
29+
/// available for dependency injection. If it is left null, the default
30+
/// BinaryMessenger will be used which routes to the host platform.
31+
NativeCryptoAPI({BinaryMessenger? binaryMessenger})
32+
: _binaryMessenger = binaryMessenger;
33+
final BinaryMessenger? _binaryMessenger;
34+
35+
static const MessageCodec<Object?> codec = StandardMessageCodec();
36+
37+
Future<Uint8List?> hash(Uint8List arg_data, HashAlgorithm arg_algorithm) async {
38+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
39+
'dev.flutter.pigeon.NativeCryptoAPI.hash', codec,
40+
binaryMessenger: _binaryMessenger);
41+
final List<Object?>? replyList =
42+
await channel.send(<Object?>[arg_data, arg_algorithm.index]) as List<Object?>?;
43+
if (replyList == null) {
44+
throw PlatformException(
45+
code: 'channel-error',
46+
message: 'Unable to establish connection on channel.',
47+
);
48+
} else if (replyList.length > 1) {
49+
throw PlatformException(
50+
code: replyList[0]! as String,
51+
message: replyList[1] as String?,
52+
details: replyList[2],
53+
);
54+
} else {
55+
return (replyList[0] as Uint8List?);
56+
}
57+
}
58+
59+
Future<Uint8List?> hmac(Uint8List arg_data, Uint8List arg_key, HashAlgorithm arg_algorithm) async {
60+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
61+
'dev.flutter.pigeon.NativeCryptoAPI.hmac', codec,
62+
binaryMessenger: _binaryMessenger);
63+
final List<Object?>? replyList =
64+
await channel.send(<Object?>[arg_data, arg_key, arg_algorithm.index]) as List<Object?>?;
65+
if (replyList == null) {
66+
throw PlatformException(
67+
code: 'channel-error',
68+
message: 'Unable to establish connection on channel.',
69+
);
70+
} else if (replyList.length > 1) {
71+
throw PlatformException(
72+
code: replyList[0]! as String,
73+
message: replyList[1] as String?,
74+
details: replyList[2],
75+
);
76+
} else {
77+
return (replyList[0] as Uint8List?);
78+
}
79+
}
80+
81+
Future<Uint8List?> generateSecureRandom(int arg_length) async {
82+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
83+
'dev.flutter.pigeon.NativeCryptoAPI.generateSecureRandom', codec,
84+
binaryMessenger: _binaryMessenger);
85+
final List<Object?>? replyList =
86+
await channel.send(<Object?>[arg_length]) as List<Object?>?;
87+
if (replyList == null) {
88+
throw PlatformException(
89+
code: 'channel-error',
90+
message: 'Unable to establish connection on channel.',
91+
);
92+
} else if (replyList.length > 1) {
93+
throw PlatformException(
94+
code: replyList[0]! as String,
95+
message: replyList[1] as String?,
96+
details: replyList[2],
97+
);
98+
} else {
99+
return (replyList[0] as Uint8List?);
100+
}
101+
}
102+
103+
Future<Uint8List?> pbkdf2(Uint8List arg_password, Uint8List arg_salt, int arg_length, int arg_iterations, HashAlgorithm arg_algorithm) async {
104+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
105+
'dev.flutter.pigeon.NativeCryptoAPI.pbkdf2', codec,
106+
binaryMessenger: _binaryMessenger);
107+
final List<Object?>? replyList =
108+
await channel.send(<Object?>[arg_password, arg_salt, arg_length, arg_iterations, arg_algorithm.index]) as List<Object?>?;
109+
if (replyList == null) {
110+
throw PlatformException(
111+
code: 'channel-error',
112+
message: 'Unable to establish connection on channel.',
113+
);
114+
} else if (replyList.length > 1) {
115+
throw PlatformException(
116+
code: replyList[0]! as String,
117+
message: replyList[1] as String?,
118+
details: replyList[2],
119+
);
120+
} else {
121+
return (replyList[0] as Uint8List?);
122+
}
123+
}
124+
125+
Future<Uint8List?> encrypt(Uint8List arg_plainText, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
126+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
127+
'dev.flutter.pigeon.NativeCryptoAPI.encrypt', codec,
128+
binaryMessenger: _binaryMessenger);
129+
final List<Object?>? replyList =
130+
await channel.send(<Object?>[arg_plainText, arg_key, arg_algorithm.index]) as List<Object?>?;
131+
if (replyList == null) {
132+
throw PlatformException(
133+
code: 'channel-error',
134+
message: 'Unable to establish connection on channel.',
135+
);
136+
} else if (replyList.length > 1) {
137+
throw PlatformException(
138+
code: replyList[0]! as String,
139+
message: replyList[1] as String?,
140+
details: replyList[2],
141+
);
142+
} else {
143+
return (replyList[0] as Uint8List?);
144+
}
145+
}
146+
147+
Future<Uint8List?> encryptWithIV(Uint8List arg_plainText, Uint8List arg_iv, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
148+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
149+
'dev.flutter.pigeon.NativeCryptoAPI.encryptWithIV', codec,
150+
binaryMessenger: _binaryMessenger);
151+
final List<Object?>? replyList =
152+
await channel.send(<Object?>[arg_plainText, arg_iv, arg_key, arg_algorithm.index]) as List<Object?>?;
153+
if (replyList == null) {
154+
throw PlatformException(
155+
code: 'channel-error',
156+
message: 'Unable to establish connection on channel.',
157+
);
158+
} else if (replyList.length > 1) {
159+
throw PlatformException(
160+
code: replyList[0]! as String,
161+
message: replyList[1] as String?,
162+
details: replyList[2],
163+
);
164+
} else {
165+
return (replyList[0] as Uint8List?);
166+
}
167+
}
168+
169+
Future<Uint8List?> decrypt(Uint8List arg_cipherText, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
170+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
171+
'dev.flutter.pigeon.NativeCryptoAPI.decrypt', codec,
172+
binaryMessenger: _binaryMessenger);
173+
final List<Object?>? replyList =
174+
await channel.send(<Object?>[arg_cipherText, arg_key, arg_algorithm.index]) as List<Object?>?;
175+
if (replyList == null) {
176+
throw PlatformException(
177+
code: 'channel-error',
178+
message: 'Unable to establish connection on channel.',
179+
);
180+
} else if (replyList.length > 1) {
181+
throw PlatformException(
182+
code: replyList[0]! as String,
183+
message: replyList[1] as String?,
184+
details: replyList[2],
185+
);
186+
} else {
187+
return (replyList[0] as Uint8List?);
188+
}
189+
}
190+
191+
Future<bool?> encryptFile(String arg_plainTextPath, String arg_cipherTextPath, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
192+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
193+
'dev.flutter.pigeon.NativeCryptoAPI.encryptFile', codec,
194+
binaryMessenger: _binaryMessenger);
195+
final List<Object?>? replyList =
196+
await channel.send(<Object?>[arg_plainTextPath, arg_cipherTextPath, arg_key, arg_algorithm.index]) as List<Object?>?;
197+
if (replyList == null) {
198+
throw PlatformException(
199+
code: 'channel-error',
200+
message: 'Unable to establish connection on channel.',
201+
);
202+
} else if (replyList.length > 1) {
203+
throw PlatformException(
204+
code: replyList[0]! as String,
205+
message: replyList[1] as String?,
206+
details: replyList[2],
207+
);
208+
} else {
209+
return (replyList[0] as bool?);
210+
}
211+
}
212+
213+
Future<bool?> encryptFileWithIV(String arg_plainTextPath, String arg_cipherTextPath, Uint8List arg_iv, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
214+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
215+
'dev.flutter.pigeon.NativeCryptoAPI.encryptFileWithIV', codec,
216+
binaryMessenger: _binaryMessenger);
217+
final List<Object?>? replyList =
218+
await channel.send(<Object?>[arg_plainTextPath, arg_cipherTextPath, arg_iv, arg_key, arg_algorithm.index]) as List<Object?>?;
219+
if (replyList == null) {
220+
throw PlatformException(
221+
code: 'channel-error',
222+
message: 'Unable to establish connection on channel.',
223+
);
224+
} else if (replyList.length > 1) {
225+
throw PlatformException(
226+
code: replyList[0]! as String,
227+
message: replyList[1] as String?,
228+
details: replyList[2],
229+
);
230+
} else {
231+
return (replyList[0] as bool?);
232+
}
233+
}
234+
235+
Future<bool?> decryptFile(String arg_cipherTextPath, String arg_plainTextPath, Uint8List arg_key, CipherAlgorithm arg_algorithm) async {
236+
final BasicMessageChannel<Object?> channel = BasicMessageChannel<Object?>(
237+
'dev.flutter.pigeon.NativeCryptoAPI.decryptFile', codec,
238+
binaryMessenger: _binaryMessenger);
239+
final List<Object?>? replyList =
240+
await channel.send(<Object?>[arg_cipherTextPath, arg_plainTextPath, arg_key, arg_algorithm.index]) as List<Object?>?;
241+
if (replyList == null) {
242+
throw PlatformException(
243+
code: 'channel-error',
244+
message: 'Unable to establish connection on channel.',
245+
);
246+
} else if (replyList.length > 1) {
247+
throw PlatformException(
248+
code: replyList[0]! as String,
249+
message: replyList[1] as String?,
250+
details: replyList[2],
251+
);
252+
} else {
253+
return (replyList[0] as bool?);
254+
}
255+
}
256+
}

0 commit comments

Comments
 (0)