error.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the License); you may
  5. * not use this file except in compliance with the License.
  6. *
  7. * http://www.apache.org/licenses/LICENSE-2.0
  8. */
  9. #ifndef GMSSL_ERROR_H
  10. #define GMSSL_ERROR_H
  11. #include <stdio.h>
  12. #include <stdarg.h>
  13. #include <string.h>
  14. #include <stdint.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #define GMSSL_FMT_BIN 1
  19. #define GMSSL_FMT_HEX 2
  20. #define GMSSL_FMT_DER 4
  21. #define GMSSL_FMT_PEM 8
  22. #define DEBUG 1
  23. #define warning_print() \
  24. do { if (DEBUG) fprintf(stderr, "%s:%d:%s():\n",__FILE__, __LINE__, __func__); } while (0)
  25. #define error_print() \
  26. do { if (DEBUG) fprintf(stderr, "%s:%d:%s():\n",__FILE__, __LINE__, __func__); } while (0)
  27. #define error_print_msg(fmt, ...) \
  28. do { if (DEBUG) fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, __LINE__, __func__, __VA_ARGS__); } while (0)
  29. #define error_puts(str) \
  30. do { if (DEBUG) fprintf(stderr, "%s: %d: %s: %s", __FILE__, __LINE__, __func__, str); } while (0)
  31. void print_der(const uint8_t *in, size_t inlen);
  32. void print_bytes(const uint8_t *in, size_t inlen);
  33. void print_nodes(const uint32_t *in, size_t inlen);
  34. #define FMT_CARRAY 0x80
  35. int format_print(FILE *fp, int format, int indent, const char *str, ...);
  36. int format_bytes(FILE *fp, int format, int indent, const char *str, const uint8_t *data, size_t datalen);
  37. int format_string(FILE *fp, int format, int indent, const char *str, const uint8_t *data, size_t datalen);
  38. //int tls_trace(int format, int indent, const char *str, ...);
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. #endif