|
Packit Service |
30b792 |
/* gpgme.js - Javascript integration for gpgme
|
|
Packit Service |
30b792 |
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* This file is part of GPGME.
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* GPGME is free software; you can redistribute it and/or modify it
|
|
Packit Service |
30b792 |
* under the terms of the GNU Lesser General Public License as
|
|
Packit Service |
30b792 |
* published by the Free Software Foundation; either version 2.1 of
|
|
Packit Service |
30b792 |
* the License, or (at your option) any later version.
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* GPGME is distributed in the hope that it will be useful, but
|
|
Packit Service |
30b792 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
30b792 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit Service |
30b792 |
* Lesser General Public License for more details.
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit Service |
30b792 |
* License along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit Service |
30b792 |
* SPDX-License-Identifier: LGPL-2.1+
|
|
Packit Service |
30b792 |
*
|
|
Packit Service |
30b792 |
* Author(s):
|
|
Packit Service |
30b792 |
* Maximilian Krambach <mkrambach@intevation.de>
|
|
Packit Service |
30b792 |
*/
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
import { GpgME } from './gpgmejs';
|
|
Packit Service |
30b792 |
import { gpgme_error } from './Errors';
|
|
Packit Service |
30b792 |
import { Connection } from './Connection';
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
/**
|
|
Packit Service |
30b792 |
* Main entry point for gpgme.js. It initializes by testing the nativeMessaging
|
|
Packit Service |
30b792 |
* connection once, and then offers the available functions as method of the
|
|
Packit Service |
30b792 |
* response object.
|
|
Packit Service |
30b792 |
* An unsuccessful attempt will reject as a GPGME_Error.
|
|
Packit Service |
30b792 |
* @param {Object} config (optional) configuration options
|
|
Packit Service |
30b792 |
* @param {Number} config.timeout set the timeout for the initial connection
|
|
Packit Service |
30b792 |
* check. On some machines and operating systems a default timeout of 500 ms is
|
|
Packit Service |
30b792 |
* too low, so a higher number might be attempted.
|
|
Packit Service |
30b792 |
* @returns {Promise<GpgME>}
|
|
Packit Service |
30b792 |
* @async
|
|
Packit Service |
30b792 |
*/
|
|
Packit Service |
30b792 |
function init ({ timeout = 1000 } = {}){
|
|
Packit Service |
30b792 |
return new Promise(function (resolve, reject){
|
|
Packit Service |
30b792 |
const connection = new Connection;
|
|
Packit Service |
30b792 |
connection.checkConnection(false, timeout).then(
|
|
Packit Service |
30b792 |
function (result){
|
|
Packit Service |
30b792 |
if (result === true) {
|
|
Packit Service |
30b792 |
resolve(new GpgME());
|
|
Packit Service |
30b792 |
} else {
|
|
Packit Service |
30b792 |
reject(gpgme_error('CONN_NO_CONNECT'));
|
|
Packit Service |
30b792 |
}
|
|
Packit Service |
30b792 |
}, function (){ // unspecific connection error. Should not happen
|
|
Packit Service |
30b792 |
reject(gpgme_error('CONN_NO_CONNECT'));
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
});
|
|
Packit Service |
30b792 |
}
|
|
Packit Service |
30b792 |
|
|
Packit Service |
30b792 |
const exportvalue = { init:init };
|
|
Packit Service |
30b792 |
export default exportvalue;
|