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 <https://www.gnu.org/licenses/>.
18 * SPDX-License-Identifier: LGPL-2.1+
21 * Maximilian Krambach <mkrambach@intevation.de>
25 * Listing of all possible error codes and messages of a {@link GPGME_Error}.
27 export const err_list = {
30 msg:'Connection with the nativeMessaging host could not be'
34 'CONN_EMPTY_GPG_ANSWER':{
35 msg: 'The nativeMessaging answer was empty.',
39 msg: 'A connection timeout was exceeded.',
42 'CONN_UNEXPECTED_ANSWER': {
43 msg: 'The answer from gnupg was not as expected.',
46 'CONN_ALREADY_CONNECTED':{
47 msg: 'A connection was already established.',
52 msg: 'The Message did not match the minimum requirements for'
53 + ' the interaction.',
57 msg: 'The Message is empty.',
61 msg: 'The operation requested could not be found',
65 msg: 'There were no valid keys provided.',
69 msg: 'The String is not an accepted fingerprint',
73 msg:'Key object is invalid',
77 msg:'This key does not exist in GPG',
81 msg:'This property has not been retrieved yet from GPG',
85 msg: 'This property cannot be used in synchronous calls',
89 msg:'A default key could not be established. Please check yout gpg ' +
94 msg:'A malformed signature was created',
98 msg:'There were no signatures found',
103 msg: 'Invalid parameter was found',
107 msg: 'Decoding failed due to unexpected data',
111 msg: 'An parameter was set that has no effect in gpgmejs',
115 msg: 'Unspecified error',
121 * Checks the given error code and returns an {@link GPGME_Error} error object
122 * with some information about meaning and origin
123 * @param {String} code Error code as defined in {@link err_list}.
124 * @param {String} info Possible additional error message to pass through.
125 * Currently used for errors sent as answer by gnupg via a native Message port
126 * @returns {GPGME_Error}
128 export function gpgme_error (code = 'GENERIC_ERROR', info){
129 if (err_list.hasOwnProperty(code)){
130 if (err_list[code].type === 'error'){
131 return new GPGME_Error(code);
133 if (err_list[code].type === 'warning'){
134 // eslint-disable-next-line no-console
135 // console.warn(code + ': ' + err_list[code].msg);
138 } else if (code === 'GNUPG_ERROR'){
139 return new GPGME_Error(code, info);
142 return new GPGME_Error('GENERIC_ERROR');
147 * An error class with additional info about the origin of the error, as string
148 * It is created by {@link gpgme_error}, and its' codes are defined in
151 * @property {String} code Short description of origin and type of the error
152 * @property {String} msg Additional info
157 class GPGME_Error extends Error{
158 constructor (code = 'GENERIC_ERROR', msg=''){
160 if (code === 'GNUPG_ERROR' && typeof (msg) === 'string'){
162 } else if (err_list.hasOwnProperty(code)){
164 super(err_list[code].msg + '--' + msg);
166 super(err_list[code].msg);
169 super(err_list['GENERIC_ERROR'].msg);