aboutsummaryrefslogtreecommitdiffstats
path: root/lang/js/src/gpgmejs.js
diff options
context:
space:
mode:
authorMaximilian Krambach <[email protected]>2018-04-25 17:45:39 +0000
committerMaximilian Krambach <[email protected]>2018-04-25 17:45:39 +0000
commit3685913bf510a14b8cb324d980217d90489e6453 (patch)
treeeb1acbdee90bf747f2dfbd4c9a61ed83d41c2b8f /lang/js/src/gpgmejs.js
parentjs: Configuration and Error handling (diff)
downloadgpgme-3685913bf510a14b8cb324d980217d90489e6453.tar.gz
gpgme-3685913bf510a14b8cb324d980217d90489e6453.zip
js: First testing and improvements
-- * Introduced Mocha/chai as testsuite. After development build 'npm test' should run the unit tests. Functionality exclusive to Browsers/WebExtensions cannot be run this way, so some other testing is still needed. - package.json: Added required development packages - .babelrc indirect configuration for mocha. ES6 transpiling needs some babel configuration, but mocha has no setting for it. - test/mocha.opts Vonfiguration for mocha runs * Fixed errors: - Helpers.js toKeyIdArray; isLongId is now exported - Key.js Key constructor failed - Message.js will not throw an Error during construction, a new message is now created with createMessage, which can return an Error or a GPGME_Message object * Tests: - test/Helpers: exports from Helpers.js, GPGME_Error handling - test/Message: first init test with bad parameters
Diffstat (limited to '')
-rw-r--r--lang/js/src/gpgmejs.js31
1 files changed, 21 insertions, 10 deletions
diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js
index b504a457..2ddf2964 100644
--- a/lang/js/src/gpgmejs.js
+++ b/lang/js/src/gpgmejs.js
@@ -19,7 +19,7 @@
*/
import {Connection} from "./Connection"
-import {GPGME_Message} from './Message'
+import {GPGME_Message, createMessage} from './Message'
import {toKeyIdArray} from "./Helpers"
import { gpgme_error } from "./Errors"
import { GPGME_Keyring } from "./Keyring";
@@ -71,8 +71,10 @@ export class GpgME {
*/
encrypt(data, publicKeys, wildcard=false){
- let msg = new GPGME_Message('encrypt');
-
+ let msg = createMessage('encrypt');
+ if (msg instanceof Error){
+ return Promise.reject(msg)
+ }
// TODO temporary
msg.setParameter('armor', true);
msg.setParameter('always-trust', true);
@@ -101,7 +103,10 @@ export class GpgME {
if (data === undefined){
return Promise.reject(gpgme_error('MSG_EMPTY'));
}
- let msg = new GPGME_Message('decrypt');
+ let msg = createMessage('decrypt');
+ if (msg instanceof Error){
+ return Promise.reject(msg);
+ }
putData(msg, data);
return this.connection.post(msg);
@@ -109,21 +114,27 @@ export class GpgME {
deleteKey(key, delete_secret = false, no_confirm = false){
return Promise.reject(gpgme_error('NOT_YET_IMPLEMENTED'));
- let msg = new GPGME_Message('deletekey');
+ let msg = createMessage('deletekey');
+ if (msg instanceof Error){
+ return Promise.reject(msg);
+ }
let key_arr = toKeyIdArray(key);
if (key_arr.length !== 1){
- throw('TODO');
- //should always be ONE key
+ return Promise.reject(
+ gpgme_error('GENERIC_ERROR'));
+ // TBD should always be ONE key?
}
msg.setParameter('key', key_arr[0]);
if (delete_secret === true){
- msg.setParameter('allow_secret', true); //TBD
+ msg.setParameter('allow_secret', true);
+ // TBD
}
if (no_confirm === true){ //TODO: Do we want this hidden deep in the code?
- msg.setParameter('delete_force', true); //TBD
+ msg.setParameter('delete_force', true);
+ // TBD
}
this.connection.post(msg).then(function(success){
- //TODO: it seems that there is always errors coming back:
+ // TODO: it seems that there is always errors coming back:
}, function(error){
switch (error.msg){
case 'ERR_NO_ERROR':