mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-29 20:19:22 +03:00
#89 Improved handling of OpenPGP.js stored keys
This commit is contained in:
parent
ff7e41ad08
commit
9ab72e7a34
6 changed files with 73 additions and 151 deletions
|
|
@ -1,53 +0,0 @@
|
|||
import ko from 'ko';
|
||||
|
||||
import { arrayLength } from 'Common/Utils';
|
||||
import { AbstractModel } from 'Knoin/AbstractModel';
|
||||
|
||||
export class OpenPgpKeyModel extends AbstractModel {
|
||||
/**
|
||||
* @param {string} guID
|
||||
* @param {string} ID
|
||||
* @param {array} IDs
|
||||
* @param {array} userIDs
|
||||
* @param {array} emails
|
||||
* @param {string} armor
|
||||
* @param {string} userID
|
||||
*/
|
||||
constructor(guID, ID, IDs, userIDs, emails, armor, userID) {
|
||||
super();
|
||||
|
||||
this.id = ID;
|
||||
this.ids = arrayLength(IDs) ? IDs : [ID];
|
||||
this.guid = guID;
|
||||
this.user = '';
|
||||
this.users = userIDs;
|
||||
this.email = '';
|
||||
this.emails = emails;
|
||||
this.armor = armor;
|
||||
|
||||
if (this.users) {
|
||||
const index = this.users.indexOf(userID);
|
||||
if (-1 !== index) {
|
||||
this.user = this.users[index];
|
||||
this.email = this.emails[index];
|
||||
}
|
||||
}
|
||||
|
||||
this.deleteAccess = ko.observable(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* OpenPGP.js
|
||||
*/
|
||||
getNativeKeys() {
|
||||
try {
|
||||
let key = openpgp.key.readArmored(this.armor);
|
||||
if (key && !key.err && key.keys && key.keys[0]) {
|
||||
return key.keys;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue