diff options
author | Maximilian Krambach <[email protected]> | 2018-07-27 18:36:21 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-07-27 18:36:21 +0000 |
commit | 94ee0988d4eaac27785de6efb7c19ca9976e1e9c (patch) | |
tree | b9a06e35d1a2831cb0750177daa978314b9be481 /lang/js/src/gpgmejs.js | |
parent | js: clean up test extension (diff) | |
download | gpgme-94ee0988d4eaac27785de6efb7c19ca9976e1e9c.tar.gz gpgme-94ee0988d4eaac27785de6efb7c19ca9976e1e9c.zip |
js: change the write access for js class methods
--
* src/ [Connection, Error, Key, Keyring, MEssage, Signature, gpgmejs]:
Functions and values that are not meant to be overwritten are now
moved into their constructors, thus eliminating the possibility of
overwrites after initialization.
* Key: The mode of use (synchronous cached, or async promises) ivs now
determined at initialization of that Key. The property Key.isAsync
reflects this state.
* unittests: fixed old Key syntax for testing.
* Message.js isComplete is now a method and not a getter anymore.
* Added some startup tests.
Diffstat (limited to '')
-rw-r--r-- | lang/js/src/gpgmejs.js | 77 |
1 files changed, 50 insertions, 27 deletions
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js index 3f6dc947..f587e854 100644 --- a/lang/js/src/gpgmejs.js +++ b/lang/js/src/gpgmejs.js @@ -22,8 +22,8 @@ */ -import {GPGME_Message, createMessage} from './Message'; -import {toKeyIdArray} from './Helpers'; +import { GPGME_Message, createMessage } from './Message'; +import { toKeyIdArray } from './Helpers'; import { gpgme_error } from './Errors'; import { GPGME_Keyring } from './Keyring'; import { createSignature } from './Signature'; @@ -85,23 +85,27 @@ import { createSignature } from './Signature'; export class GpgME { constructor(){ - } + let _Keyring = null; - set Keyring(keyring){ - if (keyring && keyring instanceof GPGME_Keyring){ - this._Keyring = keyring; - } - } + /** + * Sets a new Keyring to be used + * @param {GPGME_Keyring} keyring + */ + this.setKeyring = function(keyring){ + if (keyring && keyring instanceof GPGME_Keyring){ + _Keyring = keyring; + } + }; - /** - * Accesses the {@link GPGME_Keyring}. - */ - get Keyring(){ - if (!this._Keyring){ - this._Keyring = new GPGME_Keyring; - } - return this._Keyring; - } + /** + * Accesses the {@link GPGME_Keyring}. + */ + this.getKeyring = function(){ + if (!_Keyring){ + _Keyring = new GPGME_Keyring; + } + return _Keyring; + }; /** * Encrypt (and optionally sign) data @@ -123,8 +127,8 @@ export class GpgME { * message and additional info. * @async */ - encrypt(data, publicKeys, secretKeys, base64=false, armor=true, - wildcard=false, additional = {} + this.encrypt = function (data, publicKeys, secretKeys, base64=false, + armor=true, wildcard=false, additional = {} ){ let msg = createMessage('encrypt'); if (msg instanceof Error){ @@ -152,12 +156,12 @@ export class GpgME { additional[additional_Keys[k]]); } } - if (msg.isComplete === true){ + if (msg.isComplete() === true){ return msg.post(); } else { return Promise.reject(gpgme_error('MSG_INCOMPLETE')); } - } + }; /** * Decrypts a Message @@ -168,7 +172,7 @@ export class GpgME { * @returns {Promise<decrypt_result>} Decrypted Message and information * @async */ - decrypt(data, base64=false){ + this.decrypt = function (data, base64=false){ if (data === undefined){ return Promise.reject(gpgme_error('MSG_EMPTY')); } @@ -203,7 +207,7 @@ export class GpgME { reject(error); }); }); - } + }; /** * Sign a Message @@ -217,7 +221,7 @@ export class GpgME { * @returns {Promise<signResult>} * @async */ - sign(data, keys, mode='clearsign', base64=false) { + this.sign = function (data, keys, mode='clearsign', base64=false) { if (data === undefined){ return Promise.reject(gpgme_error('MSG_EMPTY')); } @@ -252,7 +256,7 @@ export class GpgME { reject(error); }); }); - } + }; /** * Verifies data. @@ -264,7 +268,7 @@ export class GpgME { * @returns {Promise<verifyResult>} *@async */ - verify(data, signature, base64 = false){ + this.verify= function (data, signature, base64 = false){ let msg = createMessage('verify'); let dt = putData(msg, data); if (dt instanceof Error){ @@ -297,6 +301,25 @@ export class GpgME { reject(error); }); }); + }; +} + + /** + * setter for {@link setKeyring}. + * @param {GPGME_Keyring} keyring A Keyring to use + */ + set Keyring(keyring){ + this.setKeyring(keyring); + } + + /** + * Accesses the {@link GPGME_Keyring}. + */ + get Keyring(){ + if (!this._Keyring){ + this._Keyring = new GPGME_Keyring; + } + return this._Keyring; } } @@ -309,7 +332,7 @@ export class GpgME { * @private */ function putData(message, data){ - if (!message || !(message instanceof GPGME_Message) ) { + if (!message || !message instanceof GPGME_Message) { return gpgme_error('PARAM_WRONG'); } if (!data){ |