err.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. // Copyright 2020 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #ifndef _OPENSSL_ERR_H
  14. #define _OPENSSL_ERR_H
  15. #include <stdint.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * @note This file contains a very simple implementation of error stack
  21. * for ESP APIs stubs to OpenSSL
  22. */
  23. #define OPENSSL_PUT_SYSTEM_ERROR() \
  24. ERR_put_error(ERR_LIB_SYS, 0, 0, __FILE__, __LINE__);
  25. #define OPENSSL_PUT_LIB_ERROR(lib, code) \
  26. ERR_put_error(lib, 0, code, __FILE__, __LINE__);
  27. #define ERR_GET_LIB(packed_error) ((int)(((packed_error) >> 24) & 0xff))
  28. #define ERR_GET_REASON(packed_error) ((int)((packed_error) & 0xffff))
  29. #define ERR_R_PEM_LIB ERR_LIB_PEM
  30. /* inherent openssl errors */
  31. # define ERR_R_FATAL 64
  32. # define ERR_R_MALLOC_FAILURE (1|ERR_R_FATAL)
  33. # define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
  34. # define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
  35. # define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL)
  36. # define ERR_R_DISABLED (5|ERR_R_FATAL)
  37. # define ERR_R_INIT_FAIL (6|ERR_R_FATAL)
  38. # define ERR_R_PASSED_INVALID_ARGUMENT (7)
  39. # define ERR_R_OPERATION_FAIL (8|ERR_R_FATAL)
  40. # define ERR_R_INVALID_PROVIDER_FUNCTIONS (9|ERR_R_FATAL)
  41. # define ERR_R_INTERRUPTED_OR_CANCELLED (10)
  42. enum {
  43. ERR_LIB_NONE = 1,
  44. ERR_LIB_SYS,
  45. ERR_LIB_BN,
  46. ERR_LIB_RSA,
  47. ERR_LIB_DH,
  48. ERR_LIB_EVP,
  49. ERR_LIB_BUF,
  50. ERR_LIB_OBJ,
  51. ERR_LIB_PEM,
  52. ERR_LIB_DSA,
  53. ERR_LIB_X509,
  54. ERR_LIB_ASN1,
  55. ERR_LIB_CONF,
  56. ERR_LIB_CRYPTO,
  57. ERR_LIB_EC,
  58. ERR_LIB_SSL,
  59. ERR_LIB_BIO,
  60. ERR_LIB_PKCS7,
  61. ERR_LIB_PKCS8,
  62. ERR_LIB_X509V3,
  63. ERR_LIB_RAND,
  64. ERR_LIB_ENGINE,
  65. ERR_LIB_OCSP,
  66. ERR_LIB_UI,
  67. ERR_LIB_COMP,
  68. ERR_LIB_ECDSA,
  69. ERR_LIB_ECDH,
  70. ERR_LIB_HMAC,
  71. ERR_LIB_DIGEST,
  72. ERR_LIB_CIPHER,
  73. ERR_LIB_HKDF,
  74. ERR_LIB_USER,
  75. ERR_NUM_LIBS
  76. };
  77. /**
  78. * @brief clear the SSL error code
  79. *
  80. * @param none
  81. *
  82. * @return none
  83. */
  84. void ERR_clear_error(void);
  85. /**
  86. * @brief get the current SSL error code
  87. *
  88. * @param none
  89. *
  90. * @return current SSL error number
  91. */
  92. uint32_t ERR_get_error(void);
  93. /**
  94. * @brief peek the current SSL error code, not clearing it
  95. *
  96. * @param none
  97. *
  98. * @return current SSL error number
  99. */
  100. uint32_t ERR_peek_error(void);
  101. /**
  102. * @brief peek the last SSL error code, not clearing it
  103. *
  104. * @param none
  105. *
  106. * @return current SSL error number
  107. */
  108. uint32_t ERR_peek_last_error(void);
  109. /**
  110. * @brief register the SSL error strings
  111. *
  112. * @param none
  113. *
  114. * @return none
  115. */
  116. void ERR_load_SSL_strings(void);
  117. /**
  118. * @brief clear the SSL error code
  119. *
  120. * @param none
  121. *
  122. * @return none
  123. */
  124. void ERR_clear_error(void);
  125. /**
  126. * @brief peek the current SSL error code, not clearing it
  127. *
  128. * @param none
  129. *
  130. * @return current SSL error number
  131. */
  132. uint32_t ERR_peek_error(void);
  133. /**
  134. * @brief peek the last SSL error code, not clearing it
  135. *
  136. * @param none
  137. *
  138. * @return current SSL error number
  139. */
  140. uint32_t ERR_peek_last_error(void);
  141. /**
  142. * @brief capture the current error to the error structure
  143. *
  144. * @param library Related library
  145. * @param unused Not used (used for compliant function prototype)
  146. * @param reason The actual error code
  147. * @param file File name of the error report
  148. * @param line Line number of the error report
  149. *
  150. */
  151. void ERR_put_error(int library, int unused, int reason, const char *file, unsigned line);
  152. /**
  153. * @brief Peek the current SSL error, not clearing it
  154. *
  155. * @param file file name of the reported error
  156. * @param line line number of the reported error
  157. * @param data Associated data to the reported error
  158. * @param flags Flags associated to the error
  159. *
  160. * @return current SSL error number
  161. */
  162. uint32_t ERR_peek_error_line_data(const char **file, int *line,
  163. const char **data, int *flags);
  164. /**
  165. * @brief Get the current SSL error
  166. *
  167. * @param file file name of the reported error
  168. * @param line line number of the reported error
  169. * @param data Associated data to the reported error
  170. * @param flags Flags associated to the error
  171. *
  172. * @return current SSL error number
  173. */
  174. uint32_t ERR_get_error_line_data(const char **file, int *line,
  175. const char **data, int *flags);
  176. /**
  177. * @brief API provided as a declaration only
  178. *
  179. */
  180. void SSL_load_error_strings(void);
  181. /**
  182. * @brief API provided as a declaration only
  183. *
  184. */
  185. void ERR_free_strings(void);
  186. /**
  187. * @brief API provided as a declaration only
  188. *
  189. */
  190. void ERR_remove_state(unsigned long pid);
  191. /**
  192. * @brief Returns error string -- Not implemented
  193. *
  194. * @param packed_error Packed error code
  195. *
  196. * @return NULL
  197. */
  198. const char *ERR_reason_error_string(uint32_t packed_error);
  199. #ifdef __cplusplus
  200. }
  201. #endif
  202. #endif // _OPENSSL_ERR_H