[git] GPGME - branch, javascript-binding, updated. gpgme-1.11.1-9-ge2aa806
by Maximilian Krambach
cvs at cvs.gnupg.org
Tue Apr 24 19:33:21 CEST 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GnuPG Made Easy".
The branch, javascript-binding has been updated
via e2aa8066a9b3ce694169ad9fcc26cae486a804af (commit)
from 461dd0c8b41683a91073b362d100ee5217ec53f6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit e2aa8066a9b3ce694169ad9fcc26cae486a804af
Author: Maximilian Krambach <maximilian.krambach at intevation.de>
Date: Tue Apr 24 19:29:32 2018 +0200
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
diff --git a/lang/js/src/Key.js b/lang/js/src/Key.js
index d8f16c5..f59b990 100644
--- a/lang/js/src/Key.js
+++ b/lang/js/src/Key.js
@@ -32,10 +32,12 @@ import {GPGMEJS_Error} from './Errors'
export class GPGME_Key {
constructor(fingerprint){
- if (isFingerprint(fingerprint) === true){
+ this.fingerprint = fingerprint;
+ }
+
+ set fingerprint(fpr){
+ if (isFingerprint(fpr) === true && !this._fingerprint){
this._fingerprint = fingerprint;
- } else {
- return new GPGMEJS_Error('WRONGPARAM', 'Key.js: invalid fingerprint');
}
}
diff --git a/lang/js/src/gpgmejs_openpgpjs.js b/lang/js/src/gpgmejs_openpgpjs.js
index f1ddb5d..2307656 100644
--- a/lang/js/src/gpgmejs_openpgpjs.js
+++ b/lang/js/src/gpgmejs_openpgpjs.js
@@ -31,7 +31,7 @@
import { GPGMEJS_Error } from './Errors'
-export class GpgME_openPGPCompatibility {
+ export class GpgME_openpgpmode {
constructor(connection){
this.initGpgME(connection);
@@ -46,7 +46,7 @@ export class GpgME_openPGPCompatibility {
initGpgME(connection){
this._GpgME = new GpgME(connection);
- this._Keyring = new GPGME_Keyring_openPGPCompatibility(connection);
+ this._Keyring = new GPGME_Keyring_openpgpmode(connection);
}
get GpgME(){
@@ -150,7 +150,7 @@ export class GpgME_openPGPCompatibility {
* Translation layer offering basic Keyring API to be used in Mailvelope.
* It may still be changed/expanded/merged with GPGME_Keyring
*/
-class GPGME_Keyring_openPGPCompatibility {
+class GPGME_Keyring_openpgpmode {
constructor(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.
* Please also note that a GPGME_Key does not offer full openpgpjs- Key
* compatibility.
- * @returns {Array<GPGME_Key>} with the objects offering at least:
- * @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
+ * @returns {Array<GPGME_Key_openpgpmode>}
* //TODO: Check if IsDefault is also always hasSecret
+ * TODO Check if async is required
*/
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(){
this._gpgme_keyring.getSubset({defaultKey: true}).then(function(result){
if (result.length === 1){
- return Promise.resolve(result[0]);
+ return Promise.resolve(
+ translateKeys(result)[0]);
}
else {
// TODO: Can there be "no default key"?
@@ -212,3 +211,51 @@ class GPGME_Keyring_openPGPCompatibility {
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;
+}
\ No newline at end of file
diff --git a/lang/js/src/index.js b/lang/js/src/index.js
index 0e2beda..0cb2301 100644
--- a/lang/js/src/index.js
+++ b/lang/js/src/index.js
@@ -19,7 +19,7 @@
*/
import { GpgME } from "./gpgmejs";
-import { GpgME_openPGPCompatibility } from "./gpgmejs_openpgpjs";
+import { GpgME_openpgpmode } from "./gpgmejs_openpgpjs";
import { Connection } from "./Connection";
/**
@@ -40,7 +40,7 @@ function init( config = {
let gpgme = null;
if (config.api_style && config.api_style === 'gpgme_openpgpjs'){
resolve(
- new GpgME_openPGPCompatibility(connection));
+ new GpgME_openpgpmode(connection));
} else {
resolve(new GpgME(connection));
}
-----------------------------------------------------------------------
Summary of changes:
lang/js/src/Key.js | 8 +++--
lang/js/src/gpgmejs_openpgpjs.js | 67 ++++++++++++++++++++++++++++++++++------
lang/js/src/index.js | 4 +--
3 files changed, 64 insertions(+), 15 deletions(-)
hooks/post-receive
--
GnuPG Made Easy
http://git.gnupg.org
More information about the Gnupg-commits
mailing list