Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cSSLDebug.h
Go to the documentation of this file.
1 //
3 //
4 #ifndef _INC_cSSLDebug_H
5 #define _INC_cSSLDebug_H
6 #ifndef NO_PRAGMA_ONCE
7 #pragma once
8 #endif
9 
10 #include "GraySSLInt.h"
13 
14 namespace GrayLib
15 {
16  class cBigUnsigned;
17  class cECPPoint;
18  class cKeyWrap;
19 }
20 
21 namespace GraySSL
22 {
23 
24 #ifdef USE_SSL_DEBUG
25  class GRAYSSL_LINK cSSLDebug : public cSingleton<cSSLDebug>
26  {
29 
30  public:
31  bool m_bUseLineNumbers; // true
32  LOGLEV_TYPE m_eThreshold; // LOGLEV_WARN; // LOGLEV_ANY; LOGLEV_TRACE
33 
34  static const char* k_pszPrefix; // Prefix
35 
36  private:
37  bool IsDebugThreshold(LOGLEV_TYPE eLevel) const
38  {
39  return eLevel >= m_eThreshold;
40  }
41 
42  void Prefix(StrBuilder& s, const cDebugSourceLine& src) const;
43 
44  public:
46 
47  static const char* debug_fmt(const char* format, ...);
48  void debug_print_msg(LOGLEV_TYPE level, cDebugSourceLine src, const char* text) const;
49  void debug_print_ret(LOGLEV_TYPE level, cDebugSourceLine src, const char* text, HRESULT hRes) const;
50  void debug_print_buf(LOGLEV_TYPE level, cDebugSourceLine src, const char* text, const BYTE* buf, size_t len) const;
51  void debug_print_mpi(LOGLEV_TYPE level, cDebugSourceLine src, const char* text, const cBigUnsigned& X) const;
52 
53 #if defined(USE_Key_EC)
54  void debug_print_ecp(LOGLEV_TYPE level, cDebugSourceLine src, const char* text, const cECPPoint* X) const;
55 #endif
56 #if defined(USE_SSL_X509_CRT_PARSE)
57  void debug_print_pk(LOGLEV_TYPE level, cDebugSourceLine src, const char* text, const cKeyWrap* pk) const;
58  void debug_print_crt(LOGLEV_TYPE level, cDebugSourceLine src, const char* text, const cX509Crt* crt) const;
59 #endif
60  };
61 
63  {
66  public:
69  const char* m_pszFuncName; //m_pszFuncName
70 
71  public:
72  cSSLDebugFunc(LOGLEV_TYPE level, const cDebugSourceLine& src, const char* pszFuncName)
73  : m_level(level), m_src(src), m_pszFuncName(pszFuncName)
74  {
75  if (m_pszFuncName == nullptr) m_pszFuncName = src.m_pszFunction;
76  cSSLDebug::I().debug_print_msg(m_level, m_src, cSSLDebug::debug_fmt("=> %s", m_pszFuncName));
77  }
79  {
80  // Func exit.
81  cSSLDebug::I().debug_print_msg(m_level, m_src, cSSLDebug::debug_fmt("<= %s", m_pszFuncName));
82  }
83  };
84 #endif
85 }
86 
87 #ifdef USE_SSL_DEBUG
88 #define SSL_DEBUG_FMT cSSLDebug::debug_fmt
89 
90 #define SSL_DEBUG_MSG( level, text ) cSSLDebug::I().debug_print_msg( level, DEBUGSOURCELINE, text );
91 #define SSL_DEBUG_MSGF( level, args ) cSSLDebug::I().debug_print_msg( level, DEBUGSOURCELINE, cSSLDebug::debug_fmt args );
92 #define SSL_DEBUG_RET( level, text, hRes ) cSSLDebug::I().debug_print_ret( level, DEBUGSOURCELINE, text, hRes );
93 #define SSL_DEBUG_BUF( level, text, buf, len ) cSSLDebug::I().debug_print_buf( level, DEBUGSOURCELINE, text, buf, len );
94 #define SSL_DEBUG_BIGINT( level, text, X ) cSSLDebug::I().debug_print_mpi( level, DEBUGSOURCELINE, text, X );
95 
96 #if defined(USE_Key_EC)
97 #define SSL_DEBUG_ECP( level, text, X ) cSSLDebug::I().debug_print_ecp( level, DEBUGSOURCELINE, text, X );
98 #endif
99 #if defined(USE_SSL_X509_CRT_PARSE)
100 #define SSL_DEBUG_CRT( level, text, crt ) cSSLDebug::I().debug_print_crt( level, DEBUGSOURCELINE, text, crt );
101 #endif
102 #define SSL_DEBUG_FUNC( level, text ) cSSLDebugFunc _debugfunc( level, DEBUGSOURCELINE, text ); // __FUNCTION__
103 
104 #else // USE_SSL_DEBUG
105 #define SSL_DEBUG_MSG( level, args ) __noop
106 #define SSL_DEBUG_MSGF( level, args ) __noop
107 #define SSL_DEBUG_RET( level, text, hRes ) __noop
108 #define SSL_DEBUG_BUF( level, text, buf, len ) __noop
109 #define SSL_DEBUG_BIGINT( level, text, X ) __noop
110 #define SSL_DEBUG_ECP( level, text, X ) __noop
111 #define SSL_DEBUG_CRT( level, text, crt ) __noop
112 #define SSL_DEBUG_FUNC( level, text ) __noop
113 #endif // USE_SSL_DEBUG
114 #endif
#define GRAYSSL_LINK
Definition: GraySSLInt.h:25
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cBigUnsigned.h:22
Definition: cECPGroupParams.h:41
Definition: cKeyWrap.h:25
Definition: cX509Crt.h:20
Definition: cSSLDebug.h:63
~cSSLDebugFunc()
Definition: cSSLDebug.h:78
cSSLDebugFunc(LOGLEV_TYPE level, const cDebugSourceLine &src, const char *pszFuncName)
Definition: cSSLDebug.h:72
const char * m_pszFuncName
Definition: cSSLDebug.h:69
const cDebugSourceLine & m_src
Definition: cSSLDebug.h:68
LOGLEV_TYPE m_level
Definition: cSSLDebug.h:67
Definition: cSSLDebug.h:26
void debug_print_mpi(LOGLEV_TYPE level, cDebugSourceLine src, const char *text, const cBigUnsigned &X) const
void debug_print_pk(LOGLEV_TYPE level, cDebugSourceLine src, const char *text, const cKeyWrap *pk) const
static const char * k_pszPrefix
Definition: cSSLDebug.h:34
static const char * debug_fmt(const char *format,...)
LOGLEV_TYPE m_eThreshold
Definition: cSSLDebug.h:32
void debug_print_msg(LOGLEV_TYPE level, cDebugSourceLine src, const char *text) const
void debug_print_ecp(LOGLEV_TYPE level, cDebugSourceLine src, const char *text, const cECPPoint *X) const
void debug_print_buf(LOGLEV_TYPE level, cDebugSourceLine src, const char *text, const BYTE *buf, size_t len) const
void debug_print_crt(LOGLEV_TYPE level, cDebugSourceLine src, const char *text, const cX509Crt *crt) const
void debug_print_ret(LOGLEV_TYPE level, cDebugSourceLine src, const char *text, HRESULT hRes) const
bool m_bUseLineNumbers
Definition: cSSLDebug.h:31
Definition: StrBuilder.h:18
Definition: cSingleton.h:127
static cSSLDebug &__stdcall I()
Definition: cSingleton.h:199
Definition: cMesh.h:22
Definition: GraySSL.cpp:11
LOGLEV_TYPE
Definition: cLogLevel.h:22
Definition: cDebugAssert.h:29
const char * m_pszFunction
Definition: cDebugAssert.h:35