js: Key object adjustments after discussion
-- * src/aKey.js changed fingerprint to setter (to avoid overwrites) * src/gpgmejs_openpgpjs.js - Added a class GPGME_Key_openpgpmode, which allows for renaming and deviation from GPGME. - renamed classes *_openPGPCompatibility to *_openpgpmode. They are not fully compatible, but only offer a subset of properties. Also, the name seems less clunky
This commit is contained in:
parent
461dd0c8b4
commit
e2aa8066a9
@ -32,10 +32,12 @@ import {GPGMEJS_Error} from './Errors'
|
|||||||
export class GPGME_Key {
|
export class GPGME_Key {
|
||||||
|
|
||||||
constructor(fingerprint){
|
constructor(fingerprint){
|
||||||
if (isFingerprint(fingerprint) === true){
|
this.fingerprint = fingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
set fingerprint(fpr){
|
||||||
|
if (isFingerprint(fpr) === true && !this._fingerprint){
|
||||||
this._fingerprint = fingerprint;
|
this._fingerprint = fingerprint;
|
||||||
} else {
|
|
||||||
return new GPGMEJS_Error('WRONGPARAM', 'Key.js: invalid fingerprint');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
import { GPGMEJS_Error } from './Errors'
|
import { GPGMEJS_Error } from './Errors'
|
||||||
|
|
||||||
|
|
||||||
export class GpgME_openPGPCompatibility {
|
export class GpgME_openpgpmode {
|
||||||
|
|
||||||
constructor(connection){
|
constructor(connection){
|
||||||
this.initGpgME(connection);
|
this.initGpgME(connection);
|
||||||
@ -46,7 +46,7 @@ export class GpgME_openPGPCompatibility {
|
|||||||
|
|
||||||
initGpgME(connection){
|
initGpgME(connection){
|
||||||
this._GpgME = new GpgME(connection);
|
this._GpgME = new GpgME(connection);
|
||||||
this._Keyring = new GPGME_Keyring_openPGPCompatibility(connection);
|
this._Keyring = new GPGME_Keyring_openpgpmode(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
get GpgME(){
|
get GpgME(){
|
||||||
@ -150,7 +150,7 @@ export class GpgME_openPGPCompatibility {
|
|||||||
* Translation layer offering basic Keyring API to be used in Mailvelope.
|
* Translation layer offering basic Keyring API to be used in Mailvelope.
|
||||||
* It may still be changed/expanded/merged with GPGME_Keyring
|
* It may still be changed/expanded/merged with GPGME_Keyring
|
||||||
*/
|
*/
|
||||||
class GPGME_Keyring_openPGPCompatibility {
|
class GPGME_Keyring_openpgpmode {
|
||||||
constructor(connection){
|
constructor(connection){
|
||||||
this._gpgme_keyring = new GPGME_Keyring(connection);
|
this._gpgme_keyring = new GPGME_Keyring(connection);
|
||||||
}
|
}
|
||||||
@ -161,15 +161,13 @@ class GPGME_Keyring_openPGPCompatibility {
|
|||||||
* the difference that Key.armored will NOT contain any secret information.
|
* the difference that Key.armored will NOT contain any secret information.
|
||||||
* Please also note that a GPGME_Key does not offer full openpgpjs- Key
|
* Please also note that a GPGME_Key does not offer full openpgpjs- Key
|
||||||
* compatibility.
|
* compatibility.
|
||||||
* @returns {Array<GPGME_Key>} with the objects offering at least:
|
* @returns {Array<GPGME_Key_openpgpmode>}
|
||||||
* @property {String} armored The armored key block (does not include secret blocks)
|
|
||||||
* @property {Boolean} hasSecret Indicator if a private/secret key exists
|
|
||||||
* @property {Boolean} isDefault Indicator if private key exists and is the default key in this keyring
|
|
||||||
* @property {String} fingerprint The fingerprint identifying this key
|
|
||||||
* //TODO: Check if IsDefault is also always hasSecret
|
* //TODO: Check if IsDefault is also always hasSecret
|
||||||
|
* TODO Check if async is required
|
||||||
*/
|
*/
|
||||||
getPublicKeys(){
|
getPublicKeys(){
|
||||||
return this._gpgme_keyring.getKeys(null, true);
|
return translateKeys(
|
||||||
|
this._gpgme_keyring.getKeys(null, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -181,7 +179,8 @@ class GPGME_Keyring_openPGPCompatibility {
|
|||||||
getDefaultKey(){
|
getDefaultKey(){
|
||||||
this._gpgme_keyring.getSubset({defaultKey: true}).then(function(result){
|
this._gpgme_keyring.getSubset({defaultKey: true}).then(function(result){
|
||||||
if (result.length === 1){
|
if (result.length === 1){
|
||||||
return Promise.resolve(result[0]);
|
return Promise.resolve(
|
||||||
|
translateKeys(result)[0]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: Can there be "no default key"?
|
// TODO: Can there be "no default key"?
|
||||||
@ -212,3 +211,51 @@ class GPGME_Keyring_openPGPCompatibility {
|
|||||||
return key_to_delete.deleteKey(key.secret);
|
return key_to_delete.deleteKey(key.secret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO error handling.
|
||||||
|
* Offers the Key information as the openpgpmode wants
|
||||||
|
*/
|
||||||
|
class GPGME_Key_openpgpmode {
|
||||||
|
constructor(value){
|
||||||
|
this.init = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
set init (value){
|
||||||
|
if (!this._GPGME_Key && value instanceof GPGME_Key){
|
||||||
|
this._GPGME_Key = value;
|
||||||
|
} else if (!this._GPGME_Key && isFingerprint(fpr)){
|
||||||
|
this._GPGME_Key = new GPGME_Key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get fingerprint(){
|
||||||
|
return this._GPGME_Key.fingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
get armor(){
|
||||||
|
return this._GPGME_Key.armored;
|
||||||
|
}
|
||||||
|
|
||||||
|
get secret(){
|
||||||
|
return this._GPGME_Key.hasSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
get default(){
|
||||||
|
return this._GPGME_Key.isDefault;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates GPGME_Key_openpgpmode from GPGME_Keys
|
||||||
|
*/
|
||||||
|
function translateKeys(input){
|
||||||
|
if (!Array.isArray(input)){
|
||||||
|
input = [input];
|
||||||
|
}
|
||||||
|
let resultset;
|
||||||
|
for (let i=0; i< input.length; i++){
|
||||||
|
resultset.push(new GPGME_Key_openpgpmode(input[i]));
|
||||||
|
}
|
||||||
|
return resultset;
|
||||||
|
}
|
@ -19,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { GpgME } from "./gpgmejs";
|
import { GpgME } from "./gpgmejs";
|
||||||
import { GpgME_openPGPCompatibility } from "./gpgmejs_openpgpjs";
|
import { GpgME_openpgpmode } from "./gpgmejs_openpgpjs";
|
||||||
import { Connection } from "./Connection";
|
import { Connection } from "./Connection";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,7 +40,7 @@ function init( config = {
|
|||||||
let gpgme = null;
|
let gpgme = null;
|
||||||
if (config.api_style && config.api_style === 'gpgme_openpgpjs'){
|
if (config.api_style && config.api_style === 'gpgme_openpgpjs'){
|
||||||
resolve(
|
resolve(
|
||||||
new GpgME_openPGPCompatibility(connection));
|
new GpgME_openpgpmode(connection));
|
||||||
} else {
|
} else {
|
||||||
resolve(new GpgME(connection));
|
resolve(new GpgME(connection));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user