diff options
author | Maximilian Krambach <[email protected]> | 2018-04-23 15:18:46 +0000 |
---|---|---|
committer | Maximilian Krambach <[email protected]> | 2018-04-23 15:18:46 +0000 |
commit | d62f66b1fb47f2075770d896f672748a4136e70b (patch) | |
tree | 57cd622c1bfa8e3b9c22ef5a21b14915c3223c65 /lang/js/src/Message.js | |
parent | js: encrypt improvement and decrypt method (diff) | |
download | gpgme-d62f66b1fb47f2075770d896f672748a4136e70b.tar.gz gpgme-d62f66b1fb47f2075770d896f672748a4136e70b.zip |
js: Key handling stubs, Error handling, refactoring
--
* Error handling: introduced GPGMEJS_Error class that handles errors
at a more centralized and consistent position
* src/Connection.js:
The nativeMessaging port now opens per session instead of per
message. Some methods were added that reflect this change
- added methods disconnect() and reconnect()
- added connection status query
* src/gpgmejs.js
- stub for key deletion
- error handling
- high level API for changing connection status
* src/gpgmejs_openpgpjs.js
- added stubs for Key/Keyring handling according to current
state of discussion. It is still subject to change
* src/Helpers.js
- toKeyIdArray creates an array of KeyIds, now accepting
fingerprints, GPGMEJS_Key objects and openpgp Key objects.
* Key objects (src/Key.js) Querying information about a key
directly from gnupg. Currently a stub, only the Key.fingerprint is
functional.
* Keyring queries (src/Keyring.js): Listing and searching keys.
Currently a stub.
Diffstat (limited to '')
-rw-r--r-- | lang/js/src/Message.js | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/lang/js/src/Message.js b/lang/js/src/Message.js index 90b554a1..6a93b6f4 100644 --- a/lang/js/src/Message.js +++ b/lang/js/src/Message.js @@ -18,21 +18,24 @@ * SPDX-License-Identifier: LGPL-2.1+ */ import { permittedOperations } from './permittedOperations' - +import { GPGMEJS_Error } from './Errors' export class GPGME_Message { //TODO getter - constructor(){ + constructor(operation){ + if (operation){ + this.operation(operation); + } } /** * Defines the operation this message will have - * @param {String} operation Mus be defined in permittedOperations + * @param {String} operation Must be defined in permittedOperations * TODO: move to constructor? */ set operation (operation){ if (!operation || typeof(operation) !== 'string'){ - throw('ERR_WRONG_PARAM'); + return new GPGMEJS_Error('WRONGPARAM'); } if (operation in permittedOperations){ if (!this._msg){ @@ -40,10 +43,14 @@ export class GPGME_Message { } this._msg.op = operation; } else { - throw('ERR_NOT_IMPLEMENTED'); + return new GPGMEJS_Error('WRONG_OP'); } } + get operation(){ + return this._msg.op; + } + /** * Sets a parameter for the message. Note that the operation has to be set * first, to be able to check if the parameter is permittted @@ -53,25 +60,20 @@ export class GPGME_Message { */ setParameter(param,value){ if (!param || typeof(param) !== 'string'){ - throw('ERR_WRONG_PARAM'); + return new GPGMEJS_Error('WRONGPARAM', 'type check failed'); } if (!this._msg || !this._msg.op){ - console.log('There is no operation specified yet. '+ - 'The parameter cannot be set'); - return false; + return new GPGMEJS_Error('MSG_OP_PENDING'); } let po = permittedOperations[this._msg.op]; if (!po){ - throw('LAZY_PROGRAMMER'); - //TODO - return false; + return new GPGMEJS_Error('WRONG_OP', param); } if (po.required.indexOf(param) >= 0 || po.optional.indexOf(param) >= 0){ this._msg[param] = value; return true; } - console.log('' + param + ' is invalid and could not be set'); - return false; + return new GPGMEJS_Error('WRONGPARAM', param); } /** @@ -85,7 +87,9 @@ export class GPGME_Message { } let reqParams = permittedOperations[this._msg.op].required; for (let i=0; i < reqParams.length; i++){ - if (!reqParams[i] in this._msg){ + + if (!this._msg.hasOwnProperty(reqParams[i])){ + console.log(reqParams[i] + 'missing'); return false; } } |