"Fossies" - the Fresh Open Source Software Archive

Member "knot-2.8.2/src/libdnssec/error.c" (5 Jun 2019, 2845 Bytes) of package /linux/misc/dns/knot-2.8.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "error.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.7.6_vs_2.8.0.

    1 /*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
    2 
    3     This program is free software: you can redistribute it and/or modify
    4     it under the terms of the GNU General Public License as published by
    5     the Free Software Foundation, either version 3 of the License, or
    6     (at your option) any later version.
    7 
    8     This program is distributed in the hope that it will be useful,
    9     but WITHOUT ANY WARRANTY; without even the implied warranty of
   10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   11     GNU General Public License for more details.
   12 
   13     You should have received a copy of the GNU General Public License
   14     along with this program.  If not, see <https://www.gnu.org/licenses/>.
   15 */
   16 
   17 #include <string.h>
   18 
   19 #include "libdnssec/error.h"
   20 #include "libdnssec/shared/shared.h"
   21 
   22 typedef struct error_message_t {
   23     int code;
   24     const char *text;
   25 } error_message_t;
   26 
   27 static const error_message_t ERROR_MESSAGES[] = {
   28     { DNSSEC_EOK,           "no error" },
   29 
   30     { DNSSEC_ENOMEM,        "not enough memory" },
   31     { DNSSEC_EINVAL,        "invalid argument" },
   32     { DNSSEC_ENOENT,        "no such file or directory" },
   33 
   34     { DNSSEC_ERROR,         "unspecified error" },
   35     { DNSSEC_NOT_IMPLEMENTED_ERROR, "not implemented" },
   36     { DNSSEC_MALFORMED_DATA,    "malformed data" },
   37     { DNSSEC_NOT_FOUND,     "not found" },
   38 
   39     { DNSSEC_PKCS8_IMPORT_ERROR,    "PKCS #8 import error" },
   40     { DNSSEC_KEY_EXPORT_ERROR,  "key export error" },
   41     { DNSSEC_KEY_IMPORT_ERROR,  "key import error" },
   42     { DNSSEC_KEY_GENERATE_ERROR,    "key generation error" },
   43 
   44     { DNSSEC_INVALID_PUBLIC_KEY,    "invalid public key" },
   45     { DNSSEC_INVALID_PRIVATE_KEY,   "invalid private key" },
   46     { DNSSEC_INVALID_KEY_ALGORITHM, "invalid key algorithm" },
   47     { DNSSEC_INVALID_KEY_SIZE,  "invalid key size" },
   48     { DNSSEC_INVALID_KEY_ID,    "invalid key ID" },
   49     { DNSSEC_INVALID_KEY_NAME,  "invalid key name" },
   50 
   51     { DNSSEC_NO_PUBLIC_KEY,     "no public key" },
   52     { DNSSEC_NO_PRIVATE_KEY,    "no private key" },
   53     { DNSSEC_KEY_ALREADY_PRESENT,   "key already present" },
   54 
   55     { DNSSEC_SIGN_INIT_ERROR,   "signing initialization error" },
   56     { DNSSEC_SIGN_ERROR,        "signing error" },
   57     { DNSSEC_INVALID_SIGNATURE, "invalid signature" },
   58 
   59     { DNSSEC_INVALID_NSEC3_ALGORITHM, "invalid NSEC3 algorithm" },
   60     { DNSSEC_NSEC3_HASHING_ERROR,   "NSEC3 hashing error" },
   61 
   62     { DNSSEC_INVALID_DS_ALGORITHM,  "invalid DS algorithm" },
   63     { DNSSEC_DS_HASHING_ERROR,  "DS hashing error" },
   64 
   65     { DNSSEC_KEYSTORE_INVALID_CONFIG,  "invalid KASP keystore configuration" },
   66 
   67     { DNSSEC_P11_FAILED_TO_LOAD_MODULE, "failed to load PKCS #11 module" },
   68     { DNSSEC_P11_TOO_MANY_MODULES,      "too many PKCS #11 modules loaded" },
   69     { DNSSEC_P11_TOKEN_NOT_AVAILABLE,   "PKCS #11 token not available" },
   70 
   71     { 0 }
   72 };
   73 
   74 _public_
   75 const char *dnssec_strerror(int error)
   76 {
   77     for (const error_message_t *m = ERROR_MESSAGES; m->text; m++) {
   78         if (m->code == error) {
   79             return m->text;
   80         }
   81     }
   82 
   83     return NULL;
   84 }