Cleanup OpenPgpImportPopupView code

This commit is contained in:
the-djmaze 2024-02-22 00:33:20 +01:00
parent 0efc0bbe3a
commit f94fc34d4f

View file

@ -78,22 +78,19 @@ export class OpenPgpImportPopupView extends AbstractViewPopup {
this.keyError(!keyTrimmed);
this.keyErrorMessage('');
if (!keyTrimmed) {
return;
}
if (keyTrimmed) {
let match = null,
count = 30,
done = false;
const GnuPG = this.saveGnuPG() && GnuPGUserStore.isSupported(),
backup = this.saveServer(),
// eslint-disable-next-line max-len
const reg = /[-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}[\s\S]+?[-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}/gi;
reg = /[-]{3,6}BEGIN[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}[\s\S]+?[-]{3,6}END[\s]PGP[\s](PRIVATE|PUBLIC)[\s]KEY[\s]BLOCK[-]{3,6}/gi;
do {
match = reg.exec(keyTrimmed);
if (match && 0 < count) {
if (match[0] && match[1] && match[2] && match[1] === match[2]) {
const GnuPG = this.saveGnuPG() && GnuPGUserStore.isSupported(),
backup = this.saveServer();
PgpUserStore.importKey(this.key(), GnuPG, backup);
}
--count;
@ -103,12 +100,9 @@ export class OpenPgpImportPopupView extends AbstractViewPopup {
}
} while (!done);
if (this.keyError()) {
return;
}
this.close();
}
}
onShow(key) {
this.key(key || '');