js: Tests and improvements for openpgp mode

--

* Added openpgp - Mode tests to the browsertest Extension. These tests
  require openpgp, which should not be a hard dependency for the main
  project. Packing openpgpjs into the extension is still TODO

* Fixes:
  - openpgp mode API now correctly handles parameters as an object,
    similar to openpgpjs
  - proper check and parsing of openpgpjs Message Objects
This commit is contained in:
Maximilian Krambach 2018-05-14 16:23:24 +02:00
parent c92326cc25
commit 987b317468
10 changed files with 346 additions and 161 deletions

View File

@ -34,6 +34,13 @@
Functionality tests with larger/longer running data sets.
</a>
</li>
<li>
<a href="openpgpModeTest.html">
Testing openPGP mode.
</a> - Please notice that, due to comparing
the inputs and outputs with openpgpjs objects, this test
requires a copy of openpgpjs in libs.
</li>
</ul>
</p>
</body>

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link href="libs/mocha.css" rel="stylesheet" />
</head>
<body>
<h3>Openpgp mode test</h3>
<div id="mocha"></div>
<!-- load unit tests -->
<script src="libs/mocha.js"></script>
<script src="libs/chai.js"></script>
<script src="setup_testing.js"></script>
<script src="libs/gpgmejs.bundle.js"></script>
<script src="libs/openpgp.min.js"></script>
<script src="tests/inputvalues.js"></script>
<script src="tests/inputValues_openpgpjs.js"></script>
<!-- insert tests here-->
<script src="tests/openpgpModeTest.js"></script>
<!-- run tests -->
<script src="runbrowsertest.js"></script>
</body>
</html>

View File

@ -99,8 +99,7 @@ describe('Encryption and Decryption', function () {
}).timeout(5000);
};
it('Encrypt-decrypt simple non-ascii', function (done) {
//FAILS TODO: Check newline at the end
it('Decrypt simple non-ascii', function (done) {
let prm = Gpgmejs.init();
prm.then(function (context) {
data = encryptedData;
@ -108,18 +107,10 @@ describe('Encryption and Decryption', function () {
function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(inputvalues.encrypt.good.data_nonascii);
context.encrypt(inputvalues.encrypt.good.data_nonascii, inputvalues.encrypt.good.fingerprint).then(
function(result){
context.decrypt(result.data).then(function(answer){
expect(answer.data).to.equal('¡Äußerste µ€ før ñoquis@hóme! Добрый день');
context.connection.disconnect();
done();
});
});
});
expect(result.data).to.equal(
'¡Äußerste µ€ før ñoquis@hóme! Добрый день\n');
done();
});
});
}).timeout(6000);
}).timeout(3000);
});

View File

@ -0,0 +1,32 @@
const openpgpInputs = {
pubKeyArmored: '-----BEGIN PGP PUBLIC KEY BLOCK-----\n'
+ '\n'
+ 'mQENBFrsKEkBCADKw4Wt8J6M/88qD8PO6lSMCxH1cpwH8iK0uPaFFYsJkkXo7kWf\n'
+ 'PTAtrV+REqF/o80dvYcdLvRsV21pvncZz/HXLu1yQ18mC3XObrKokbdgrTTKA5XE\n'
+ 'BZkNsqyaMMJauT18H4hYkSg62/tTdO1cu/zWv/LFf7Xyn6+uA74ovXCJlO1s0N2c\n'
+ 'PShtr98QRzPMf2owgVk37JnDNp4gGVDGHxSZOuUwxgYAZYnA8SFc+c+3ZrQfY870\n'
+ '+O4j3Mz4p7yD13AwP4buQLBsb/icxekeQCqpRJhLH9f7MdEcGXa1x36RcEkHdu+M\n'
+ 'yJ392eMgD+dKNfRCtyTPhjZTxvbNELIBYICfABEBAAG0EHRlc3RAZXhhbXBsZS5v\n'
+ 'cmeJAVQEEwEIAD4WIQTUFzW5Ejb9uIIEjFojAWNe7/DLBQUCWuwoSQIbAwUJA8Jn\n'
+ 'AAULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRAjAWNe7/DLBf9kB/wOQ/S60HGw\n'
+ 'Fq07W9N01HWULyhHKoMmcHL6rfZ64oDqLxolPSasz7WAMW1jN4qtWJ0mFzwO83V6\n'
+ 'kaBe+wF6Kqir6udFSBW9rPcFg6/VZXPltT0a6uacIHq6DyQ5iMW4YQWbVy9OR2rN\n'
+ 'GkYo1JCBR0XdRJYCSX3yB4TWv/eXnZ37/WjmiTOIZh35rjs+NuU/S5JPDfAp2/k7\n'
+ '0DevQeBsv+UjVXjWpNTZmPbvDnd995uSmC6UY4hzyP84ORYMYn9n1QAR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:{
data : 'Hello World.',
// Fingerprint of a key that has been imported to gnupg (i.e. see testkey.pub; testkey.sec)
fingerprint : 'D41735B91236FDB882048C5A2301635EEFF0CB05',
data_nonascii: '¡Äußerste µ€ før ñoquis@hóme! Добрый день',
// used for checking encoding consistency in > 2MB messages.
data_nonascii_32: [
'K€K€K€K€K€K€K€K€K€K€K€K€K€K€K€K€',
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€', //fails result has 3 chars more
'€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€', //fails 3 chars
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€',
'€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€€',
'²³²³²³²³²³²³²³²³²³²³²³²³²³²³²³²³',
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€A€µ€µ€µ€µ€', //fails 2 chars
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µAµ€µ€µ€µ€', //is okay if 2 chunksizes.
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€A€µ€µ€µ€µ€',
'µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µ€µAµ€µ€µ€µ€',
'üüüüüüüüüüüüüüüüüüüüüüüüüüüüüüüü',
'µAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA€',
'µAAAAµAAAAAAAAAAAAAAAAAAAAAAAAA€',
@ -42,15 +45,21 @@ var inputvalues = {
]
},
bad: {
// valid Hex value, but not usable (not imported to gnupg, or bogus fingerprint)
fingerprint: 'CDC3A2B2860625CCBFC5AAAAAC6D1B604967FC4A'
}
},
init: {
invalid_startups: [{all_passwords: true}, 'openpgpmode', {api_style:"frankenstein"}]
// some parameters
invalid_startups: [
{all_passwords: true},
'openpgpmode',
{api_style:"frankenstein"}
]
}
};
// (Pseudo-)Random String from a Uint8Array, given approx. size in Megabytes
function bigString(megabytes){
let maxlength = 1024 * 1024 * megabytes;
let uint = new Uint8Array(maxlength);
@ -60,6 +69,7 @@ function bigString(megabytes){
return new TextDecoder('utf-8').decode(uint);
}
// (Pseudo-)Random Uint8Array, given size in Megabytes
function bigUint8(megabytes){
let maxlength = 1024 * 1024 * megabytes;
let uint = new Uint8Array(maxlength);
@ -69,6 +79,7 @@ function bigUint8(megabytes){
return uint;
}
// (Pseudo-)Random string with very limited charset (ascii only, no control chars)
function bigBoringString(megabytes){
let maxlength = 1024 * 1024 * megabytes;
let string = '';
@ -79,24 +90,22 @@ function bigBoringString(megabytes){
return string;
}
// Some String with simple chars, with different characteristics, but still
// expected to occur in an averag message
function slightlyLessBoringString(megabytes, set){
let maxlength = 1024 * 1024 * megabytes;
let string = '';
let chars = '';
if (!set){
} else if (set ===1 ) {
if (set ===1 ) {
chars = '\n\"\r \'';
} else if (set === 2 ) {
chars = '()=?`#+-{}[]';
} else if (set === 3){
chars = '^°/';
//'*<>\\^°/';
} else if (set ===4) {
chars = 'äüßµüþÖ~ɁÑ||@';
} else {
chars = '*<>\n\"\r§$%&/()=?`#+-{}[] \''; //fails!
chars = '*<>\n\"\r§$%&/()=?`#+-{}[] \'';
}
for (let i= 0; i < maxlength; i++){
string = string + chars[Math.floor(Math.random() * chars.length)];
@ -104,6 +113,7 @@ function slightlyLessBoringString(megabytes, set){
return string;
}
// Data encrypted with testKey
var encryptedData =
'-----BEGIN PGP MESSAGE-----\n' +
'\n' +
@ -118,100 +128,3 @@ var encryptedData =
'kSAQYOHplfA7YJWkrlRm\n' +
'=zap6\n' +
'-----END PGP MESSAGE-----\n';
var encryptedBroken = '-----BEGIN PGP MESSAGE-----\n' +
'\n' +
'hQEMA6B8jfIUScGEAQf/bUYF70KRCHWITfNH7zaYaLa8P+QoCo+NpFzc3U9J4mty\n' +
'FxjIpoNwxEvQ9UUEMi6LgHhvURYCbWrCV5XYjo/sE66CRXsEuNirfYkAzXVNcUf7\n' +
'BaAzio/QzyyvBfzwHHqMLSxAcNggs+f5lob+TcBnBghwpn1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sE07FX8/xrEQVkJfzgl/v+mQ66TCb+/g13QPgZI\n' +
'UftRS6hLeKNTd0pZc8+CTbNzgrCDGqbYn5ZpyPFYF+fVGZnqqLUid5NTjkwI1IoD\n' +
'PgOSHQEo+pIlNfTtR2DCYgqOiMaBSZ4bc4b6SohAKGJkPhNmlMJ61MwGN2J8pFpl\n' +
'1uG2MO3TUo6MxQAkCcKe4twwy1bQh4kO3kReUqTDW/VTnp6HfZhqtYc1tBGLcahu\n' +
'C0ZX7B/8Wbu1PWN4Y34F7ouuSu2l6ASnoAc/Ek1S9R1uyiwLtaPuK58oUbVisDh3\n' +
'cYmnjP0DelYq8FpJPWPrSGwqlERotf3KU3L1k84SHYUB1pHFYPF46KAKYH5qTrsO\n' +
'T3id3CO3mt1gtgWAEGRkEQ+qVmvWtINBOwyFYVAD9ZqXflzF83ZGvdmvdJ6kzRZ7\n' +
'fY5ACZGMghb3f4mfLlbF81WluDbk2k+t186qmRFrJFtJPvAl3VxXczo8pw5bSAdK\n' +
'R6c7cagA6ql4QaYqtbIHpFbgz7iQ9ESe23Q2+o82lkTbUFdG+GDhnZFOL+ldWf/g\n' +
'ufSCqY7IlNxj3hYxgTpaXb2lWvVVdo7C4VhPHyIDbQUCdUE80t2cDgJqPFABe3la\n' +
'Y+UsW9W787mGGuuNSF/iI0tANw5twlQjdRQtqxnF1yETh/hFA4bgD9bmBOBFd+GT\n' +
'+ECxkqI4/UYMgYfVMFja/e6+dQTWLblzuNaZh6wHASeNqpFmeQSBawBVV7qK3nC7\n' +
'CDY9r6Aq9JYMiJTE/TzyfBmBhnxtL1aKTu6EHy3siDlID7EjQx1Xyr/EtbJCmsVl\n' +
'E14StpggdK8=\n' +
'=enm3\n' +
'-----END PGP MESSAGE-----\n';

View File

@ -27,6 +27,7 @@ describe('Long running Encryption/Decryption', function () {
};
it('Successful encrypt 1 MB Uint8Array', function (done) {
//TODO: this succeeds, but result may be bogus (String with byte values as numbers)
let prm = Gpgmejs.init();
let data = bigUint8(1);
prm.then(function (context) {

View File

@ -0,0 +1,196 @@
/* gpgme.js - Javascript integration for gpgme
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
*
* This file is part of GPGME.
*
* GPGME is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* GPGME is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
* SPDX-License-Identifier: LGPL-2.1+
*/
describe('Encrypting-Decrypting in openpgp mode, using a Message object', function () {
it('Simple Encrypt-Decrypt', function (done) {
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
prm.then(function (context) {
context.encrypt({
data: openpgp.message.fromText(inputvalues.encrypt.good.data),
publicKeys: inputvalues.encrypt.good.fingerprint}
).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer).to.be.an("object");
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
let msg = openpgp.message.fromText(answer.data);
context.decrypt({message:msg}).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(inputvalues.encrypt.good.data);
context._GpgME.connection.disconnect();
done();
});
});
});
});
it('Encrypt-Decrypt, sending Uint8Array as data', function (done) {
//TODO! fails. Reason is that atob<->btoa destroys the uint8Array,
// resulting in a string of constituyent numbers
// (error already occurs in encryption)
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
prm.then(function (context) {
let input = bigUint8(0.3);
expect(input).to.be.an.instanceof(Uint8Array);
context.encrypt({
data: input,
publicKeys: inputvalues.encrypt.good.fingerprint}
).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.decrypt({message:answer.data}).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.an.instanceof(Uint8Array);
expect(result.data).to.equal(input);
context._GpgME.connection.disconnect();
done();
});
});
});
});
it('Keys as Fingerprints', function(done){
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
let input = inputvalues.encrypt.good.data_nonascii;
prm.then(function (context) {
context.encrypt({
data: input,
publicKeys: inputvalues.encrypt.good.fingerprint}
).then(function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.decrypt({message:answer.data}).then(function (result) {
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(input);
context._GpgME.connection.disconnect();
done();
});
});
});
});
it('Keys as openpgp Keys', function(){
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
let data = inputvalues.encrypt.good.data_nonascii;
let key = openpgp.key.readArmored(openpgpInputs.pubKeyArmored);
expect(key).to.be.an('object');
prm.then(function (context) {
context.encrypt({
data: data,
publicKeys: [key]}
).then( function (answer) {
expect(answer).to.not.be.empty;
expect(answer.data).to.be.a("string");
expect(answer.data).to.include('BEGIN PGP MESSAGE');
expect(answer.data).to.include('END PGP MESSAGE');
context.decrypt({message:answer.data}).then( function (result){
expect(result).to.not.be.empty;
expect(result.data).to.be.a('string');
expect(result.data).to.equal(data);
context._GpgME.connection.disconnect();
done();
});
});
});
});
it('Trying to send non-implemented parameters: passwords', function(done){
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
let data = 'Hello World';
let key = inputvalues.encrypt.good.fingerprint;
prm.then(function (context) {
context.encrypt({
data: data,
publicKeys: [key],
passwords: 'My secret password'}
).then( function(){},
function(error){
expect(error).to.be.an.instanceof(Error);
expect(error.code).equal('NOT_IMPLEMENTED');
done();
});
});
});
it('Trying to send non-implemented parameters: signature', function(done){
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
let data = 'Hello World';
let key = inputvalues.encrypt.good.fingerprint;
prm.then(function (context) {
context.encrypt({
data: data,
publicKeys: [key],
signature: {any: 'value'}
}).then(
function(){},
function(error){
expect(error).to.be.an.instanceof(Error);
expect(error.code).equal('NOT_IMPLEMENTED');
done();
});
});
});
});
describe('Keyring in openpgp mode', function(){
it('Check Existence and structure of Keyring after init', function(done){
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
prm.then(function (context) {
expect(context.Keyring).to.be.an('object');
expect(context.Keyring.getPublicKeys).to.be.a('function');
expect(context.Keyring.deleteKey).to.be.a('function');
expect(context.Keyring.getDefaultKey).to.be.a('function');
done();
});
});
// TODO: gpgme key interface not yet there
});
describe('Decrypting and verification in openpgp mode', function(){
it('Decrypt', function(){
let msg = openpgp.message.fromText(inputvalues.encryptedData);
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
prm.then(function (context) {
context.decrypt({message: msg})
.then(function(answer){
expect(answer.data).to.be.a('string');
expect(result.data).to.equal('¡Äußerste µ€ før ñoquis@hóme! Добрый день\n');
done();
});
});
});
it('Decryption attempt with bad data returns gnupg error', function(done){
let msg = openpgp.message.fromText(bigString(0.1));
let prm = Gpgmejs.init({api_style: 'gpgme_openpgpjs'});
prm.then(function (context) {
context.decrypt({message: msg})
.then( function(){},
function(error){
expect(error).to.be.an.instanceof(Error);
expect(error.code).to.equal('GNUPG_ERROR');
expect(error.message).to.be.a('string');
// TBD: Type of error
done();
});
});
}).timeout(4000);
});

View File

@ -181,7 +181,6 @@ class Answer{
if (!this._response.hasOwnProperty(key)){
this._response[key] = '';
}
// console.log(msg[key]);
this._response[key] += msg[key];
}
//params should not change through the message

View File

@ -80,7 +80,6 @@ export class GpgME {
let pubkeys = toKeyIdArray(publicKeys);
msg.setParameter('keys', pubkeys);
putData(msg, data);
if (wildcard === true){msg.setParameter('throw-keyids', true);
};
@ -171,19 +170,32 @@ function putData(message, data){
return gpgme_error('PARAM_WRONG');
} else if (data instanceof Uint8Array){
message.setParameter('base64', true);
// TODO: btoa turns the array into a string
// of comma separated of numbers
// atob(data).split(',') would result in a "normal" array of numbers
// atob(btoa(data)).split(',') would result in a "normal" array of numbers
// would result in a "normal" array of numbers
message.setParameter ('data', btoa(data));
} else if (typeof(data) === 'string') {
message.setParameter('base64', false);
message.setParameter('data', data);
} else if ( typeof(data) === 'object' && data.hasOwnProperty('getText')){
} else if (
typeof(data) === 'object' &&
typeof(data.getText) === 'function'
){
let txt = data.getText();
if (txt instanceof Uint8Array){
message.setParameter('base64', true);
message.setParameter ('data', btoa(txt));
}
else {
else if (typeof(txt) === 'string'){
message.setParameter('base64', false);
message.setParameter ('data', txt);
} else {
return gpgme_error('PARAM_WRONG');
}
} else {
return gpgme_error('PARAM_WRONG');
}

View File

@ -25,10 +25,10 @@
*/
import { GpgME } from "./gpgmejs";
import {GPGME_Keyring} from "./Keyring"
import {GPGME_Keyring} from "./Keyring";
import { GPGME_Key, createKey } from "./Key";
import { isFingerprint } from "./Helpers"
import { gpgme_error } from "./Errors"
import { isFingerprint } from "./Helpers";
import { gpgme_error } from "./Errors";
import { Connection } from "./Connection";
@ -60,8 +60,8 @@ import { Connection } from "./Connection";
/**
* Encrypt Message
* Supported:
* @param {String|Uint8Array} data
* //an openpgp Message also accepted here. TODO: is this wanted?
* @param {String|Message} data
* an openpgp Message is accepted here.
* @param {Key|Array<Key>} publicKeys
* //Strings of Fingerprints
* @param {Boolean} wildcard
@ -86,36 +86,39 @@ import { Connection } from "./Connection";
* @async
* @static
*/
encrypt({data = '', publicKeys = '', privateKeys, passwords=null,
sessionKey = null, filename, compression, armor=true, detached=false,
signature=null, returnSessionKey=null, wildcard=false, date=null}) {
if (passwords !== null
|| sessionKey !== null
|| signature !== null
|| returnSessionKey !== null
|| date !== null
encrypt(options) {
if (!options || typeof(options) !== 'object'){
return Promise.reject(gpgme_error('PARAM_WRONG'));
}
if (options.passwords
|| options.sessionKey
|| options.signature
|| options.returnSessionKey
|| (options.hasOwnProperty('date') && options.date !== null)
){
return Promise.reject(GPMGEJS_Error('NOT_IMPLEMENTED'));
return Promise.reject(gpgme_error('NOT_IMPLEMENTED'));
}
if ( privateKeys
|| compression
|| armor === false
|| detached == true){
return Promise.reject(gpgme_error('NOT_YET_IMPLEMENTED'));
if ( options.privateKeys
|| options.compression
|| (options.hasOwnProperty('armor') && options.armor === false)
|| (options.hasOwnProperty('detached') && options.detached == true)
){
return Promise.reject(gpgme_error('NOT_YET_IMPLEMENTED'));
}
if (filename){
if (options.filename){
if (this._config.unconsidered_params === 'warn'){
GPMGEJS_Error('PARAM_IGNORED');
gpgme_error('PARAM_IGNORED');
} else if (this._config.unconsidered_params === 'error'){
return Promise.reject(GPMGEJS_Error('NOT_IMPLEMENTED'));
return Promise.reject(gpgme_error('NOT_IMPLEMENTED'));
}
}
return this._GpgME.encrypt(data, translateKeys(publicKeys), wildcard);
return this._GpgME.encrypt(
options.data, options.publicKeys, options.wildcard);
}
/** Decrypt Message
* supported openpgpjs parameters:
* @param {Message|Uint8Array|String} message Message object from openpgpjs
* @param {Message|String} message Message object from openpgpjs
* Unsupported:
* @param {String|Array<String>} passwords
* @param {Key|Array<Key>} privateKeys
@ -128,26 +131,33 @@ import { Connection } from "./Connection";
* @param {Key|Array<Key>} publicKeys
*
* @returns {Promise<Object>} decrypted and verified message in the form:
* { data:Uint8Array|String, filename:String, signatures:[{ keyid:String, valid:Boolean }] }
* { data:String, filename:String, signatures:[{ keyid:String, valid:Boolean }] }
* @async
* @static
*/
decrypt({ message, privateKeys, passwords=null, sessionKeys,
publicKeys, format='utf8', signature=null, date= null}) {
if (passwords !== null || sessionKeys || privateKeys){
decrypt(options) {
if (options.passwords
|| options.sessionKeys
|| options.privateKeys
){
return Promise.reject(gpgme_error('NOT_IMPLEMENTED'));
}
if ( format !== 'utf8' || signature){
if ((options.hasOwnProperty('format') && options.format !== 'utf8')
|| options.signature
){
return Promise.reject(gpgme_error('NOT_YET_IMPLEMENTED'));
}
if (date !== null || publicKeys){
if ((options.hasOwnProperty('date') && options.date !== null)
|| options.publicKeys
){
if (this._config.unconsidered_params === 'warn'){
GPMGEJS_Error('PARAM_IGNORED');
} else if (this._config.unconsidered_params === 'reject'){
return Promise.reject(GPMGEJS_Error('NOT_IMPLEMENTED'));
}
}
return this._GpgME.decrypt(message);
return this._GpgME.decrypt(options.message);
// TODO: translate between:
// openpgp:
// { data:Uint8Array|String,
@ -276,14 +286,15 @@ class GPGME_Key_openpgpmode {
* @returns {Array<GPGME_Key_openpgpmode>}
*/
function translateKeys(input){
//TODO: does not check if inpout is okay!
if (!input){
return null;
}
if (!Array.isArray(input)){
input = [input];
}
let resultset;
for (let i=0; i< input.length; i++){
let resultset = [];
for (let i=0; i< input.length; i++) {
resultset.push(new GPGME_Key_openpgpmode(input[i]));
}
return resultset;