js: allow openpgp-like Message objects as Data

--

* src/gpgmejs.js: If a message offers a getText, consider it as the
  message's content
This commit is contained in:
Maximilian Krambach 2018-04-24 19:47:48 +02:00
parent e2aa8066a9
commit 30c47d80a2

View File

@ -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');
}