rm: field password of PrivateKeyInfo

This commit is contained in:
lollipopkit
2023-08-04 23:47:22 +08:00
parent ee3e30d9b5
commit d88a078cd6
7 changed files with 45 additions and 52 deletions

View File

@@ -22,9 +22,9 @@ import '../../../locator.dart';
const _format = 'text/plain';
class PrivateKeyEditPage extends StatefulWidget {
const PrivateKeyEditPage({Key? key, this.info}) : super(key: key);
const PrivateKeyEditPage({Key? key, this.pki}) : super(key: key);
final PrivateKeyInfo? info;
final PrivateKeyInfo? pki;
@override
_PrivateKeyEditPageState createState() => _PrivateKeyEditPageState();
@@ -68,13 +68,13 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
}
PreferredSizeWidget _buildAppBar() {
final actions = widget.info == null
final actions = widget.pki == null
? null
: [
IconButton(
tooltip: _s.delete,
onPressed: () {
_provider.delete(widget.info!);
_provider.delete(widget.pki!);
context.pop();
},
icon: const Icon(Icons.delete))
@@ -100,9 +100,14 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
setState(() {
_loading = centerSizedLoading;
});
final info = PrivateKeyInfo(id: name, key: key);
try {
info.key = await compute(decyptPem, [key, pwd]);
final decrypted = await compute(decyptPem, [key, pwd]);
final pki = PrivateKeyInfo(id: name, key: decrypted);
if (widget.pki != null) {
_provider.update(widget.pki!, pki);
} else {
_provider.add(pki);
}
} catch (e) {
showSnackBar(context, Text(e.toString()));
rethrow;
@@ -111,11 +116,6 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
_loading = nil;
});
}
if (widget.info != null) {
_provider.update(widget.info!, info);
} else {
_provider.add(info);
}
context.pop();
},
child: const Icon(Icons.save),
@@ -192,9 +192,9 @@ class _PrivateKeyEditPageState extends State<PrivateKeyEditPage>
@override
Future<void> afterFirstLayout(BuildContext context) async {
if (widget.info != null) {
_nameController.text = widget.info!.id;
_keyController.text = widget.info!.key;
if (widget.pki != null) {
_nameController.text = widget.pki!.id;
_keyController.text = widget.pki!.key;
} else {
final clipdata = ((await Clipboard.getData(_format))?.text ?? '').trim();
if (clipdata.startsWith('-----BEGIN') && clipdata.endsWith('-----')) {