1 /* gpgme.js - Javascript integration for gpgme
2 * Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
4 * This file is part of GPGME.
6 * GPGME is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as
8 * published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * GPGME is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * SPDX-License-Identifier: LGPL-2.1+
21 * Maximilian Krambach <mkrambach@intevation.de>
25 import { GpgME } from './gpgmejs';
26 import { gpgme_error } from './Errors';
27 import { Connection } from './Connection';
30 * Main entry point for gpgme.js. It initializes by testing the nativeMessaging
31 * connection once, and then offers the available functions as method of the
33 * An unsuccessful attempt will reject as a GPGME_Error.
34 * @param {Object} config (optional) configuration options
35 * @param {Number} config.timeout set the timeout for the initial connection
36 * check. On some machines and operating systems a default timeout of 500 ms is
37 * too low, so a higher number might be attempted.
38 * @returns {Promise<GpgME>}
41 function init ({ timeout = 500 } = {}){
42 return new Promise(function (resolve, reject){
43 const connection = new Connection;
44 connection.checkConnection(false, timeout).then(
46 if (result === true) {
49 reject(gpgme_error('CONN_NO_CONNECT'));
51 }, function (){ // unspecific connection error. Should not happen
52 reject(gpgme_error('CONN_NO_CONNECT'));
57 const exportvalue = { init:init };
58 export default exportvalue;