/src/error.c
C | 66 lines | 50 code | 8 blank | 8 comment | 1 complexity | 3a7a6e8fe378630e42dcdd0adec3aa17 MD5 | raw file
Possible License(s): Apache-2.0
- /*
- * error.c
- * simplepgp
- *
- * Created by Trevor Bentley on 11/26/11.
- * Copyright 2011 Trevor Bentley. All rights reserved.
- *
- */
- #include "simplepgp.h"
- #include "packet_private.h"
- #include "error.h"
- uint32_t _spgp_err;
- jmp_buf exception;
- #ifdef DEBUG_LOG_ENABLED
- uint8_t debug_log_enabled = 1;
- #else
- uint8_t debug_log_enabled = 0;
- #endif
- uint32_t spgp_err(void) {
- return _spgp_err;
- }
- const char *spgp_err_str(uint32_t err) {
- switch (err) {
- case INVALID_ARGS:
- return "Invalid arguments given to function.";
- case OUT_OF_MEMORY:
- return "Not enough memory to continue parsing.";
- case INVALID_HEADER:
- return "Invalid header format. Corrupted or invalid data.";
- case FORMAT_UNSUPPORTED:
- return "Message format is valid, but not currently supported.";
- case BUFFER_OVERFLOW:
- return "Index into buffer exceeded the maximum "
- "bound of the buffer.";
- case INCOMPLETE_PACKET:
- return "OpenPGP packet seemed to end unexpectedly.";
- case DECRYPT_FAILED:
- return "Decryption of a necessary element failed.";
- case GCRY_ERROR:
- return "There was an error in the libgcrypt library.";
- case KEYCHAIN_ERROR:
- return "There was a problem with the global keychain.";
- case ZLIB_ERROR:
- return "zlib had a problem uncompressing the packet.";
- case SIGNATURE_ERROR:
- return "There was a problem validating a signature.";
- default:
- return "Unknown/undocumented error.";
- }
- }
- uint8_t spgp_debug_log_enabled(void) {
- return debug_log_enabled;
- }
- void spgp_debug_log_set(uint8_t enable) {
- pthread_mutex_lock(&spgp_mtx);
- debug_log_enabled = enable;
- pthread_mutex_unlock(&spgp_mtx);
- }