js: offer an always-trust parameter on encrypt

--

* src/gpgmejs.js: Setting the default to 'always trust' assumes that
  most api users will already have made their internal checks, but may
  not have the gnupg web-of-trust model implemented, thus trusting the
  key themselves, without gnupg having full or even any information.
  Still it should stay an option to have gnupg decide.
This commit is contained in:
Maximilian Krambach 2018-08-23 12:30:49 +02:00
parent 3fd6837fce
commit 352c53040d

View File

@ -128,6 +128,9 @@ export class GpgME {
* block. * block.
* @param {Boolean} options.wildcard (optional) If true, recipient * @param {Boolean} options.wildcard (optional) If true, recipient
* information will not be added to the message. * information will not be added to the message.
* @param {Boolean} always_trust (optional, default true) This assumes that
* used keys are fully trusted. If set to false, encryption to a key not
* fully trusted in gnupg will fail
* @param {Object} additional use additional valid gpg options as * @param {Object} additional use additional valid gpg options as
* defined in {@link permittedOperations} * defined in {@link permittedOperations}
* @returns {Promise<encrypt_result>} Object containing the encrypted * @returns {Promise<encrypt_result>} Object containing the encrypted
@ -135,7 +138,7 @@ export class GpgME {
* @async * @async
*/ */
encrypt ({ data, publicKeys, secretKeys, base64 = false, armor = true, encrypt ({ data, publicKeys, secretKeys, base64 = false, armor = true,
wildcard, additional = {} }){ wildcard, always_trust = true, additional = {} }){
if (!data || !publicKeys){ if (!data || !publicKeys){
return Promise.reject(gpgme_error('MSG_INCOMPLETE')); return Promise.reject(gpgme_error('MSG_INCOMPLETE'));
} }
@ -148,6 +151,9 @@ export class GpgME {
if (base64 === true) { if (base64 === true) {
msg.setParameter('base64', true); msg.setParameter('base64', true);
} }
if (always_trust === true) {
msg.setParameter('always-trust', true);
}
let pubkeys = toKeyIdArray(publicKeys); let pubkeys = toKeyIdArray(publicKeys);
if (!pubkeys.length) { if (!pubkeys.length) {
return Promise.reject(gpgme_error('MSG_NO_KEYS')); return Promise.reject(gpgme_error('MSG_NO_KEYS'));