Skip to content

Commit

Permalink
feat: add decrypt+verify and updated encrypt+sign (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerson authored May 20, 2024
1 parent e2a7549 commit 7a22f92
Show file tree
Hide file tree
Showing 16 changed files with 265 additions and 75 deletions.
Binary file modified android/src/main/jniLibs/arm64-v8a/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/armeabi-v7a/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86/libopenpgp_bridge.so
Binary file not shown.
Binary file modified android/src/main/jniLibs/x86_64/libopenpgp_bridge.so
Binary file not shown.
52 changes: 52 additions & 0 deletions example/integration_test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,58 @@ void main() {
}, timeout: Timeout(Duration(seconds: 60)));
});

group('EncryptSign and DecryptVerify', () {
final parent = find.byKey(ValueKey("encrypt-sign-decrypt-verify"));

testWidgets('Encrypt / Decrypt', (WidgetTester tester) async {
final instance = app.MyApp();
await tester.pumpWidget(instance);
await tester.pumpAndSettle();

var container = find.descendant(
of: parent,
matching: find.byKey(ValueKey("encrypt")),
);
await tester.scrollUntilVisible(container, dyScroll, scrollable: list);
await tester.pumpAndSettle();

await tester.enterText(
find.descendant(
of: container, matching: find.byKey(ValueKey("message"))),
input);
await tester.tap(
find.descendant(
of: container, matching: find.byKey(ValueKey("button"))),
);
await tester.pumpAndSettle(Duration(seconds: 3));
var resultSelector = find.descendant(
of: container, matching: find.byKey(ValueKey("result")));

await expectLater(resultSelector, findsWidgets);
var result = resultSelector.evaluate().single.widget as Text;
expect(result.data != "", equals(true));

container = find.descendant(
of: parent,
matching: find.byKey(ValueKey("decrypt")),
);
await tester.scrollUntilVisible(container, dyScroll, scrollable: list);
await tester.pumpAndSettle();

await tester.tap(
find.descendant(
of: container, matching: find.byKey(ValueKey("button"))),
);
await tester.pumpAndSettle(Duration(seconds: 3));
resultSelector = find.descendant(
of: container, matching: find.byKey(ValueKey("result")));
await expectLater(resultSelector, findsWidgets);

result = resultSelector.evaluate().single.widget as Text;
expect(result.data, equals(input));
}, timeout: Timeout(Duration(seconds: 60)));
});

group('Encrypt and Decrypt Bytes', () {
final parent = find.byKey(ValueKey("encrypt-decrypt-bytes"));

Expand Down
89 changes: 89 additions & 0 deletions example/lib/encrypt_sign_decrypt_verify.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'package:openpgp/openpgp.dart';
import 'package:openpgp_example/main.dart';
import 'package:openpgp_example/shared/button_widget.dart';
import 'package:openpgp_example/shared/input_widget.dart';
import 'package:openpgp_example/shared/title_widget.dart';

class EncryptSignAndDecryptVerify extends StatefulWidget {
const EncryptSignAndDecryptVerify({
Key? key,
required this.title,
required KeyPair? keyPair,
}) : keyPair = keyPair,
super(key: key);

final KeyPair? keyPair;
final String title;

@override
_EncryptSignAndDecryptVerifyState createState() =>
_EncryptSignAndDecryptVerifyState();
}

class _EncryptSignAndDecryptVerifyState
extends State<EncryptSignAndDecryptVerify> {
String _encrypted = "";
String _decrypted = "";

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10),
child: Card(
child: Column(
children: [
TitleWidget(widget.title),
InputWidget(
title: "EncryptSign",
key: Key("encrypt"),
result: _encrypted,
onPressed: (controller) async {
try {
var entity = Entity();
entity.privateKey = widget.keyPair!.privateKey;
entity.passphrase = passphrase;
var encrypted = await OpenPGP.encrypt(
controller.text,
widget.keyPair!.publicKey,
signed: entity,
);
setState(() {
_encrypted = encrypted;
});
} catch (e) {
print(e.toString());
}
},
),
ButtonWidget(
title: "DecryptVerify",
key: Key("decrypt"),
result: _decrypted,
onPressed: () async {
try {
var entity = Entity();
entity.publicKey = widget.keyPair!.publicKey;
var decrypted = await OpenPGP.decrypt(
_encrypted,
widget.keyPair!.privateKey,
passphrase,
signed: entity,
);
setState(() {
_decrypted = decrypted;
});
} catch (e) {
print(e.toString());
}
},
),
],
),
),
);
}
}
6 changes: 6 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';

import 'package:openpgp/openpgp.dart';
import 'package:openpgp_example/encrypt_sign_decrypt_verify.dart';
import 'package:openpgp_example/encrypt_decrypt.dart';
import 'package:openpgp_example/encrypt_decrypt_bytes.dart';
import 'package:openpgp_example/encrypt_decrypt_file.dart';
Expand Down Expand Up @@ -125,6 +126,11 @@ class _MyAppState extends State<MyApp> {
keyPair: _defaultKeyPair,
key: Key("encrypt-decrypt"),
),
EncryptSignAndDecryptVerify(
title: "EncryptSign And DecryptVerify",
keyPair: _defaultKeyPair,
key: Key("encrypt-sign-decrypt-verify"),
),
if (false)
EncryptAndDecryptFile(
title: "Encrypt And Decrypt file",
Expand Down
Loading

0 comments on commit 7a22f92

Please sign in to comment.