From 30c47d80a27054aa340cbd6dc39d1b8a5dc5cf22 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 24 Apr 2018 19:47:48 +0200 Subject: [PATCH] js: allow openpgp-like Message objects as Data -- * src/gpgmejs.js: If a message offers a getText, consider it as the message's content --- lang/js/src/gpgmejs.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lang/js/src/gpgmejs.js b/lang/js/src/gpgmejs.js index 4b2a03a4..03ed5cb6 100644 --- a/lang/js/src/gpgmejs.js +++ b/lang/js/src/gpgmejs.js @@ -159,6 +159,13 @@ function putData(message, data){ } else if (typeof(data) === 'string') { message.setParameter('base64', false); message.setParameter('data', data); + } else if ( typeof(data) === 'object' && data.hasOwnProperty(getText)){ + let txt = data.getText(); + if (txt instanceof Uint8Array){ + let decoder = new TextDecoder('utf8'); + message.setParameter('base64', true); + message.setParameter ('data', decoder.decode(txt)); + } } else { return new GPGMEJS_Error('WRONGPARAM'); }