Skip to content

Commit

Permalink
feat: add sign with data (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerson committed Sep 8, 2023
1 parent e25c064 commit 68bddea
Show file tree
Hide file tree
Showing 23 changed files with 1,259 additions and 861 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
## 3.7.0

- Add SignData methods for compatibility with other platform implementations
- Updated binaries to v1.9.0


## 3.6.1

- Fixed macOS podspec issue when signing apps
Expand Down
12 changes: 10 additions & 2 deletions README.md
Expand Up @@ -94,8 +94,12 @@ import 'package:fast_rsa/rsa.dart';
void main() async {
var bytesSample = Uint8List.fromList('data'.codeUnits);
var result = await OpenPGP.sign("text","[publicKey here]","[privateKey here]","[passphrase here]");
var result = await OpenPGP.signBytesToString(bytesSample,"[publicKey here]","[privateKey here]","[passphrase here]");
var result = await OpenPGP.sign("text","[privateKey here]","[passphrase here]");
var result = await OpenPGP.signBytesToString(bytesSample,"[privateKey here]","[passphrase here]");
// sign including data
var result = await OpenPGP.signData("text","[privateKey here]","[passphrase here]");
var result = await OpenPGP.signDataBytesToString(bytesSample,"[privateKey here]","[passphrase here]");
}
Expand All @@ -111,6 +115,10 @@ void main() async {
var result = await OpenPGP.verify("text signed","text","[publicKey here]");
var result = await OpenPGP.verifyBytes("text signed", bytesSample,"[publicKey here]");
// verify signed with data
var result = await OpenPGP.verifyData("text signed","[publicKey here]");
var result = await OpenPGP.verifyDataBytes(bytesSample,"[publicKey here]");
}
Expand Down
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.
100 changes: 100 additions & 0 deletions example/integration_test/app_test.dart
Expand Up @@ -268,6 +268,56 @@ void main() {
}, timeout: Timeout(Duration(seconds: 60)));
});

group('Sign And Verify Data', () {
final parent = find.byKey(ValueKey("sign-verify-data"));

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

var container = find.descendant(
of: parent,
matching: find.byKey(ValueKey("sign")),
);
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")));
expect(resultSelector, findsOneWidget);
var result = resultSelector.evaluate().single.widget as Text;
expect(result.data != "", equals(true));

container = find.descendant(
of: parent,
matching: find.byKey(ValueKey("verify")),
);
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")));
expect(resultSelector, findsOneWidget);
result = resultSelector.evaluate().single.widget as Text;
expect(result.data, "VALID");
}, timeout: Timeout(Duration(seconds: 60)));
});

group('Sign And Verify Bytes', () {
final parent = find.byKey(ValueKey("sign-verify-bytes"));

Expand Down Expand Up @@ -318,6 +368,56 @@ void main() {
}, timeout: Timeout(Duration(seconds: 60)));
});

group('Sign And Verify Data Bytes', () {
final parent = find.byKey(ValueKey("sign-verify-data-bytes"));

testWidgets('Sign / Verify Data Bytes', (WidgetTester tester) async {
final instance = app.MyApp();
await tester.pumpWidget(instance);
await tester.pumpAndSettle();

var container = find.descendant(
of: parent,
matching: find.byKey(ValueKey("sign")),
);
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")));
expect(resultSelector, findsOneWidget);
var result = resultSelector.evaluate().single.widget as Text;
expect(result.data != "", equals(true));

container = find.descendant(
of: parent,
matching: find.byKey(ValueKey("verify")),
);
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")));
expect(resultSelector, findsOneWidget);
result = resultSelector.evaluate().single.widget as Text;
expect(result.data, "VALID");
}, timeout: Timeout(Duration(seconds: 60)));
});

group('Generate', () {
final parent = find.byKey(ValueKey("generate"));

Expand Down
12 changes: 12 additions & 0 deletions example/lib/main.dart
Expand Up @@ -13,10 +13,12 @@ import 'package:openpgp_example/encrypt_decrypt_symmetric.dart';
import 'package:openpgp_example/encrypt_decrypt_symmetric_bytes.dart';
import 'package:openpgp_example/generate.dart';
import 'package:openpgp_example/sign_verify.dart';
import 'package:openpgp_example/sign_verify_data.dart';
import 'package:openpgp_example/metadata.dart';
import 'package:openpgp_example/armor.dart';
import 'package:openpgp_example/convert.dart';
import 'package:openpgp_example/sign_verify_bytes.dart';
import 'package:openpgp_example/sign_verify_data_bytes.dart';

const passphrase = 'test';

Expand Down Expand Up @@ -149,11 +151,21 @@ class _MyAppState extends State<MyApp> {
keyPair: _defaultKeyPair,
key: Key("sign-verify"),
),
SignAndVerifyData(
title: "Sign And Verify Data",
keyPair: _defaultKeyPair,
key: Key("sign-verify-data"),
),
SignAndVerifyBytes(
title: "Sign And Verify Bytes",
keyPair: _defaultKeyPair,
key: Key("sign-verify-bytes"),
),
SignAndVerifyDataBytes(
title: "Sign And Verify Data Bytes",
keyPair: _defaultKeyPair,
key: Key("sign-verify-data-bytes"),
),
Generate(
title: "Generate",
key: Key("generate"),
Expand Down
1 change: 0 additions & 1 deletion example/lib/sign_verify.dart
Expand Up @@ -43,7 +43,6 @@ class _SignAndVerifyState extends State<SignAndVerify> {
onPressed: (controller) async {
var result = await OpenPGP.sign(
controller.text,
widget.keyPair!.publicKey,
widget.keyPair!.privateKey,
passphrase,
);
Expand Down
2 changes: 0 additions & 2 deletions example/lib/sign_verify_bytes.dart
Expand Up @@ -47,7 +47,6 @@ class _SignAndVerifyBytesState extends State<SignAndVerifyBytes> {
onPressed: (controller) async {
var result = await OpenPGP.signBytesToString(
Uint8List.fromList(controller.text.codeUnits),
widget.keyPair!.publicKey,
widget.keyPair!.privateKey,
passphrase,
);
Expand Down Expand Up @@ -79,7 +78,6 @@ class _SignAndVerifyBytesState extends State<SignAndVerifyBytes> {
onPressed: (controller) async {
var result = await OpenPGP.signBytes(
Uint8List.fromList(controller.text.codeUnits),
widget.keyPair!.publicKey,
widget.keyPair!.privateKey,
passphrase,
);
Expand Down
72 changes: 72 additions & 0 deletions example/lib/sign_verify_data.dart
@@ -0,0 +1,72 @@
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 SignAndVerifyData extends StatefulWidget {
const SignAndVerifyData({
Key? key,
required this.title,
required KeyPair? keyPair,
}) : keyPair = keyPair,
super(key: key);

final KeyPair? keyPair;
final String title;

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

class _SignAndVerifyDataState extends State<SignAndVerifyData> {
String _signed = "";
String _verify = "";

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10),
child: Card(
child: Column(
children: [
TitleWidget(widget.title),
InputWidget(
title: "Sign",
key: Key("sign"),
result: _signed,
onPressed: (controller) async {
var result = await OpenPGP.signData(
controller.text,
widget.keyPair!.privateKey,
passphrase,
);
setState(() {
_signed = result;
});
},
),
ButtonWidget(
title: "Verify",
key: Key("verify"),
result: _verify,
onPressed: () async {
var result = await OpenPGP.verifyData(
_signed,
widget.keyPair!.publicKey,
);
setState(() {
_verify = result ? "VALID" : "INVALID";
});
},
),
],
),
),
);
}
}
76 changes: 76 additions & 0 deletions example/lib/sign_verify_data_bytes.dart
@@ -0,0 +1,76 @@
import 'dart:convert';
import 'dart:typed_data';

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 SignAndVerifyDataBytes extends StatefulWidget {
const SignAndVerifyDataBytes({
Key? key,
required this.title,
required KeyPair? keyPair,
}) : keyPair = keyPair,
super(key: key);

final KeyPair? keyPair;
final String title;

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

class _SignAndVerifyDataBytesState extends State<SignAndVerifyDataBytes> {
String _signed = "";
String _signedBytes = "";
String _verify = "";

@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(10),
child: Card(
child: Column(
children: [
TitleWidget(widget.title),
InputWidget(
title: "Sign",
key: Key("sign"),
result: _signed,
onPressed: (controller) async {
var result = await OpenPGP.signDataBytes(
Uint8List.fromList(controller.text.codeUnits),
widget.keyPair!.privateKey,
passphrase,
);
setState(() {
_signed = base64Encode(result);
});
},
),
ButtonWidget(
title: "Verify",
key: Key("verify"),
result: _verify,
onPressed: () async {
var result = await OpenPGP.verifyDataBytes(
base64Decode(_signed),
widget.keyPair!.publicKey,
);
setState(() {
_verify = result ? "VALID" : "INVALID";
});
},
),
],
),
),
);
}
}

0 comments on commit 68bddea

Please sign in to comment.