summaryrefslogtreecommitdiff
path: root/src/openssl/globals.h
blob: 291a84e09cc31fdd037a99550cd69aa6fb1ddec0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * XML Security Library
 *
 * globals.h: internal header only used during the compilation
 *
 * This is free software; see Copyright file in the source
 * distribution for preciese wording.
 *
 * Copyright (C) 2002-2016 Aleksey Sanin <aleksey@aleksey.com>. All Rights Reserved.
 */
#ifndef __XMLSEC_GLOBALS_H__
#define __XMLSEC_GLOBALS_H__

/**
 * Use autoconf defines if present.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* HAVE_CONFIG_H */

#define IN_XMLSEC_CRYPTO
#define XMLSEC_PRIVATE

/* Include common error helper macros. */
#include "../errors_helpers.h"

/**************************************************************
 *
 * Error constants for OpenSSL
 *
 *************************************************************/
/**
 * XMLSEC_OPENSSL_ERRORS_LIB:
 *
 * Macro. The XMLSec library klass for OpenSSL errors reporting functions.
 */
#define XMLSEC_OPENSSL_ERRORS_LIB                       (ERR_LIB_USER + 57)

/**
 * XMLSEC_OPENSSL_ERRORS_FUNCTION:
 *
 * Macro. The XMLSec library functions OpenSSL errors reporting functions.
 */
#define XMLSEC_OPENSSL_ERRORS_FUNCTION                  0

/**
 * xmlSecOpenSSLError:
 * @errorFunction:      the failed function name.
 * @errorObject:        the error specific error object (e.g. transform, key data, etc).
 *
 * Macro. The XMLSec library macro for reporting OpenSSL crypro errors.
 */
#define xmlSecOpenSSLError(errorFunction, errorObject)      \
    {                                                       \
        unsigned long error_code = ERR_peek_error();        \
        const char* lib = ERR_lib_error_string(error_code);       \
        const char* func = ERR_func_error_string(error_code);     \
        const char* reason = ERR_reason_error_string(error_code); \
        xmlSecError(XMLSEC_ERRORS_HERE,                     \
                    (const char*)(errorObject),             \
                    (errorFunction),                        \
                    XMLSEC_ERRORS_R_CRYPTO_FAILED,          \
                    "openssl error: %lu: %s: %s %s",        \
                    error_code,                             \
                    xmlSecErrorsSafeString(lib),            \
                    xmlSecErrorsSafeString(func),           \
                    xmlSecErrorsSafeString(reason)          \
        );                                                  \
    }

/**
 * xmlSecOpenSSLError2:
 * @errorFunction:      the failed function name.
 * @errorObject:        the error specific error object (e.g. transform, key data, etc).
 * @msg:                the extra message.
 * @param:              the extra message param.
 *
 * Macro. The XMLSec library macro for reporting OpenSSL crypro errors.
 */
#define xmlSecOpenSSLError2(errorFunction, errorObject, msg, param) \
    {                                                       \
        unsigned long error_code = ERR_peek_error();        \
        const char* lib = ERR_lib_error_string(error_code);       \
        const char* func = ERR_func_error_string(error_code);     \
        const char* reason = ERR_reason_error_string(error_code); \
        xmlSecError(XMLSEC_ERRORS_HERE,                     \
                    (const char*)(errorObject),             \
                    (errorFunction),                        \
                    XMLSEC_ERRORS_R_CRYPTO_FAILED,          \
                    msg "; openssl error: %lu: %s: %s %s",  \
                    (param),                                \
                    error_code,                             \
                    xmlSecErrorsSafeString(lib),            \
                    xmlSecErrorsSafeString(func),           \
                    xmlSecErrorsSafeString(reason)          \
        );                                                  \
    }

#endif /* ! __XMLSEC_GLOBALS_H__ */