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+
24 msg:'Connection with the nativeMessaging host could not be'
28 'CONN_EMPTY_GPG_ANSWER':{
29 msg: 'The nativeMessaging answer was empty.',
33 msg: 'A connection timeout was exceeded.',
36 'CONN_UNEXPECTED_ANSWER': {
37 msg: 'The answer from gnupg was not as expected.',
40 'CONN_ALREADY_CONNECTED':{
41 msg: 'A connection was already established.',
46 msg: 'The Message did not match the minimum requirements for'
47 + ' the interaction.',
51 msg: 'The Message is empty.',
55 msg: 'The operation requested could not be found',
59 msg: 'There were no valid keys provided.',
63 msg: 'The String is not an accepted fingerprint',
67 msg:'Key object is invalid',
71 msg:'This key does not exist in GPG',
75 msg:'This property has not been retrieved yet from GPG',
80 msg: 'Invalid parameter was found',
84 msg: 'An parameter was set that has no effect in gpgmejs',
88 msg: 'Unspecified error',
94 * Checks the given error code and returns an error object with some
95 * information about meaning and origin
96 * @param {*} code Error code. Should be in err_list or 'GNUPG_ERROR'
97 * @param {*} info Error message passed through if code is 'GNUPG_ERROR'
99 export function gpgme_error(code = 'GENERIC_ERROR', info){
100 if (err_list.hasOwnProperty(code)){
101 if (err_list[code].type === 'error'){
102 return new GPGME_Error(code);
104 if (err_list[code].type === 'warning'){
105 console.warn(code + ': ' + err_list[code].msg);
108 } else if (code === 'GNUPG_ERROR'){
109 return new GPGME_Error(code, info);
112 return new GPGME_Error('GENERIC_ERROR');
116 class GPGME_Error extends Error{
117 constructor(code, msg=''){
118 if (code === 'GNUPG_ERROR' && typeof(msg) === 'string'){
120 } else if (err_list.hasOwnProperty(code)){
122 super(err_list[code].msg + "--" + msg);
124 super(err_list[code].msg);
127 super(err_list['GENERIC_ERROR'].msg);
129 this.code = code || 'GENERIC_ERROR';