2018-04-18 14:38:06 +00:00
|
|
|
/* gpgme.js - Javascript integration for gpgme
|
|
|
|
* Copyright (C) 2018 Bundesamt für Sicherheit in der Informationstechnik
|
|
|
|
*
|
|
|
|
* This file is part of GPGME.
|
|
|
|
*
|
|
|
|
* GPGME is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU Lesser General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2.1 of
|
|
|
|
* the License, or (at your option) any later version.
|
2018-04-10 09:33:14 +00:00
|
|
|
*
|
2018-04-18 14:38:06 +00:00
|
|
|
* GPGME is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1+
|
2018-06-06 11:05:53 +00:00
|
|
|
*
|
|
|
|
* Author(s):
|
|
|
|
* Maximilian Krambach <mkrambach@intevation.de>
|
2018-04-10 09:33:14 +00:00
|
|
|
*/
|
2018-04-18 14:38:06 +00:00
|
|
|
|
2018-06-06 11:05:53 +00:00
|
|
|
|
|
|
|
import { GpgME } from './gpgmejs';
|
|
|
|
import { gpgme_error } from './Errors';
|
|
|
|
import { Connection } from './Connection';
|
2018-04-24 16:44:30 +00:00
|
|
|
|
|
|
|
/**
|
2018-07-10 12:32:26 +00:00
|
|
|
* Initializes gpgme.js by testing the nativeMessaging connection once.
|
|
|
|
* @returns {Promise<GpgME> | GPGME_Error}
|
2018-06-11 13:10:43 +00:00
|
|
|
*
|
|
|
|
* @async
|
2018-04-24 16:44:30 +00:00
|
|
|
*/
|
2018-06-11 13:10:43 +00:00
|
|
|
function init(){
|
2018-04-26 15:13:34 +00:00
|
|
|
return new Promise(function(resolve, reject){
|
2018-07-30 10:31:27 +00:00
|
|
|
let connection = Object.freeze(new Connection);
|
2018-05-25 09:53:24 +00:00
|
|
|
connection.checkConnection(false).then(
|
|
|
|
function(result){
|
|
|
|
if (result === true) {
|
2018-07-30 10:31:27 +00:00
|
|
|
resolve(Object.freeze(new GpgME()));
|
2018-05-25 09:53:24 +00:00
|
|
|
} else {
|
|
|
|
reject(gpgme_error('CONN_NO_CONNECT'));
|
|
|
|
}
|
2018-06-06 11:05:53 +00:00
|
|
|
}, function(){ //unspecific connection error. Should not happen
|
2018-05-03 12:12:10 +00:00
|
|
|
reject(gpgme_error('CONN_NO_CONNECT'));
|
2018-06-06 11:05:53 +00:00
|
|
|
});
|
2018-04-24 16:44:30 +00:00
|
|
|
});
|
2018-04-26 15:13:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-24 16:44:30 +00:00
|
|
|
export default {
|
|
|
|
init: init
|
2018-06-06 11:05:53 +00:00
|
|
|
};
|