snappymail/dev/View/Popup/OpenPgpKey.js

128 lines
3 KiB
JavaScript
Raw Normal View History

import { addObservablesTo } from 'External/ko';
import { doc, addShortcut } from 'Common/Globals';
import { AbstractViewPopup } from 'Knoin/AbstractViews';
2022-02-24 21:01:41 +08:00
export class OpenPgpKeyPopupView extends AbstractViewPopup {
constructor() {
super('OpenPgpKey');
addObservablesTo(this, {
key: '',
keyDom: null
});
}
selectKey() {
const el = this.keyDom();
2019-07-05 03:19:24 +08:00
if (el) {
let sel = getSelection(),
range = doc.createRange();
sel.removeAllRanges();
range.selectNodeContents(el);
sel.addRange(range);
}
if (navigator.clipboard) {
navigator.clipboard.writeText(this.key()).then(
() => console.log('Copied to clipboard'),
err => console.error(err)
);
}
2016-06-30 08:02:45 +08:00
}
2016-09-30 21:42:38 +08:00
onShow(openPgpKey) {
// TODO: show more info
2021-11-03 21:58:34 +08:00
this.key(openPgpKey ? openPgpKey.armor : '');
2022-01-31 18:51:15 +08:00
/*
this.key = key;
const aEmails = [];
if (key.users) {
key.users.forEach(user => user.userID.email && aEmails.push(user.userID.email));
}
this.id = key.getKeyID().toHex();
this.fingerprint = key.getFingerprint();
this.can_encrypt = !!key.getEncryptionKey();
this.can_sign = !!key.getSigningKey();
this.emails = aEmails;
this.armor = armor;
this.askDelete = ko.observable(false);
this.openForDeletion = ko.observable(null).askDeleteHelper();
key.id = key.subkeys[0].keyid;
key.fingerprint = key.subkeys[0].fingerprint;
key.uids.forEach(uid => uid.email && aEmails.push(uid.email));
key.emails = aEmails;
"disabled": false,
"expired": false,
"revoked": false,
"is_secret": true,
"can_sign": true,
"can_decrypt": true
"can_verify": true
"can_encrypt": true,
"uids": [
{
"name": "demo",
"comment": "",
"email": "demo@snappymail.eu",
"uid": "demo <demo@snappymail.eu>",
"revoked": false,
"invalid": false
}
],
"subkeys": [
{
"fingerprint": "2C223F20EA2ADB4CB68F81D95F3A5CDC09AD8AE3",
"keyid": "5F3A5CDC09AD8AE3",
"timestamp": 1643381672,
"expires": 0,
"is_secret": false,
"invalid": false,
"can_encrypt": false,
"can_sign": true,
"disabled": false,
"expired": false,
"revoked": false,
"can_certify": true,
"can_authenticate": false,
"is_qualified": false,
"is_de_vs": false,
"pubkey_algo": 303,
"length": 256,
"keygrip": "5A1A6C7310D0508C68E8E74F15068301E83FD1AE",
"is_cardkey": false,
"curve": "ed25519"
},
{
"fingerprint": "3CD720549D8833872C267D08F1230DCE2A561ADE",
"keyid": "F1230DCE2A561ADE",
"timestamp": 1643381672,
"expires": 0,
"is_secret": false,
"invalid": false,
"can_encrypt": true,
"can_sign": false,
"disabled": false,
"expired": false,
"revoked": false,
"can_certify": false,
"can_authenticate": false,
"is_qualified": false,
"is_de_vs": false,
"pubkey_algo": 302,
"length": 256,
"keygrip": "886921A7E06BE56F8E8C51797BB476BB26DF21BF",
"is_cardkey": false,
"curve": "cv25519"
}
]
*/
2016-06-30 08:02:45 +08:00
}
2015-09-02 03:50:30 +08:00
onBuild() {
addShortcut('a', 'meta', 'OpenPgpKey', () => {
this.selectKey();
return false;
});
}
}