OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
optiga_lib_logger.h
Go to the documentation of this file.
1 
38 #ifndef _OPTIGA_LIB_LOGGER_H_
39 #define _OPTIGA_LIB_LOGGER_H_
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #include "optiga_lib_types.h"
46 
47 //Logger levels
48 #define OPTIGA_UTIL_SERVICE "[optiga util] : "
49 #define OPTIGA_CRYPT_SERVICE "[optiga crypt] : "
50 #define OPTIGA_COMMAND_LAYER "[optiga cmd] : "
51 #define OPTIGA_COMMUNICATION_LAYER "[optiga comms] : "
52 
53 
54 // Logger colors options
55 #define OPTIGA_LIB_LOGGER_COLOR_RED "\x1b[31m"
56 #define OPTIGA_LIB_LOGGER_COLOR_GREEN "\x1b[32m"
57 #define OPTIGA_LIB_LOGGER_COLOR_YELLOW "\x1b[33m"
58 #define OPTIGA_LIB_LOGGER_COLOR_BLUE "\x1b[34m"
59 #define OPTIGA_LIB_LOGGER_COLOR_MAGENTA "\x1b[35m"
60 #define OPTIGA_LIB_LOGGER_COLOR_CYAN "\x1b[36m"
61 #define OPTIGA_LIB_LOGGER_COLOR_LIGHT_GREY "\x1b[90m"
62 #define OPTIGA_LIB_LOGGER_COLOR_LIGHT_RED "\x1b[91m"
63 #define OPTIGA_LIB_LOGGER_COLOR_LIGHT_GREEN "\x1b[92m"
64 #define OPTIGA_LIB_LOGGER_COLOR_LIGHT_YELLOW "\x1b[93m"
65 #define OPTIGA_LIB_LOGGER_COLOR_LIGHT_BLUE "\x1b[94m"
66 #define OPTIGA_LIB_LOGGER_COLOR_LIGHT_MAGENTA "\x1b[95m"
67 #define OPTIGA_LIB_LOGGER_COLOR_LIGHT_CYAN "\x1b[96m"
68 #define OPTIGA_LIB_LOGGER_COLOR_DEFAULT "\x1b[0m"
69 
70 // Logger color for different layers and data
71 #define OPTIGA_UTIL_SERVICE_COLOR OPTIGA_LIB_LOGGER_COLOR_DEFAULT
72 #define OPTIGA_CRYPT_SERVICE_COLOR OPTIGA_LIB_LOGGER_COLOR_DEFAULT
73 #define OPTIGA_COMMAND_LAYER_COLOR OPTIGA_LIB_LOGGER_COLOR_DEFAULT
74 #define OPTIGA_COMMUNICATION_LAYER_COLOR OPTIGA_LIB_LOGGER_COLOR_DEFAULT
75 #define OPTIGA_ERROR_COLOR OPTIGA_LIB_LOGGER_COLOR_RED
76 #define OPTIGA_UNPROTECTED_DATA_COLOR OPTIGA_LIB_LOGGER_COLOR_LIGHT_CYAN
77 #define OPTIGA_PROTECTED_DATA_COLOR OPTIGA_LIB_LOGGER_COLOR_YELLOW
78 
79 #define OPTIGA_HEX_BYTE_SEPERATOR ""
80 
96 void optiga_lib_print_string(const char_t *input_string);
97 
114 void optiga_lib_print_string_with_newline(const char_t * p_log_string);
115 
134 void optiga_lib_print_message(const char_t * p_log_string,
135  const char_t * p_log_layer,
136  const char_t * p_log_color);
137 
156 void optiga_lib_print_status(const char_t * p_log_layer,
157  const char_t * p_log_color,
158  uint16_t return_value);
177 void optiga_lib_print_array_hex_format(const uint8_t * p_log_string,
178  uint16_t length,
179  const char_t * p_log_color);
180 
197 #ifndef WIN32
198 #define OPTIGA_LIB_LOGGER_PRINT_ARRAY(p_output_buffer, p_temp_buffer, p_color) \
199 { \
200  sprintf((char_t *)p_output_buffer, \
201  "%25s%s%s", \
202  p_color, \
203  p_temp_buffer, \
204  OPTIGA_LIB_LOGGER_COLOR_DEFAULT); \
205 }
206 #else
207 #define OPTIGA_LIB_LOGGER_PRINT_ARRAY(p_output_buffer, p_temp_buffer, p_color) \
208 { \
209  sprintf_s((char_t *)p_output_buffer, \
210  sizeof(p_output_buffer), \
211  "%25s%s%s", \
212  p_color, \
213  p_temp_buffer, \
214  OPTIGA_LIB_LOGGER_COLOR_DEFAULT); \
215 }
216 #endif
217 
218 
236 #ifndef WIN32
237 #define OPTIGA_LIB_LOGGER_PRINT_INFO(p_output_buffer, p_temp_buffer, p_layer, p_color) \
238 { \
239  sprintf((char_t *)p_output_buffer, \
240  "%s%s%s%s", \
241  p_color, \
242  p_layer, \
243  p_temp_buffer, \
244  OPTIGA_LIB_LOGGER_COLOR_DEFAULT); \
245 }
246 #else
247 #define OPTIGA_LIB_LOGGER_PRINT_INFO(p_output_buffer, p_temp_buffer, p_layer, p_color) \
248 { \
249  sprintf_s((char_t *)p_output_buffer, \
250  sizeof(p_output_buffer), \
251  "%s%s%s%s", \
252  p_color, \
253  p_layer, \
254  p_temp_buffer, \
255  OPTIGA_LIB_LOGGER_COLOR_DEFAULT); \
256 }
257 #endif
258 
259 #ifdef __cplusplus
260 }
261 #endif
262 
263 #endif /*_OPTIGA_LIB_LOGGER_H_ */
264 
This file contains the type definitions for the fundamental data types.
void optiga_lib_print_string_with_newline(const char_t *p_log_string)
To log a string with a new line.
Definition: optiga_lib_logger.c:144
char char_t
Typedef for one byte integer.
Definition: optiga_lib_types.h:82
void optiga_lib_print_string(const char_t *input_string)
To log a string.
Definition: optiga_lib_logger.c:133
void optiga_lib_print_status(const char_t *p_log_layer, const char_t *p_log_color, uint16_t return_value)
To log a return value with a new line and layer information.
Definition: optiga_lib_logger.c:179
void optiga_lib_print_message(const char_t *p_log_string, const char_t *p_log_layer, const char_t *p_log_color)
To log a string with a new line and layer information.
Definition: optiga_lib_logger.c:160
void optiga_lib_print_array_hex_format(const uint8_t *p_log_string, uint16_t length, const char_t *p_log_color)
To log the byte array in hex format.
Definition: optiga_lib_logger.c:219