1 // Copyright 2015-2016 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 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef _SSL_METHODS_H_ 16 #define _SSL_METHODS_H_ 17 18 #include "ssl_types.h" 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 /** 25 * TLS method function implement 26 */ 27 #define IMPLEMENT_TLS_METHOD_FUNC(func_name, \ 28 new, free, \ 29 handshake, shutdown, clear, \ 30 read, send, pending, \ 31 set_fd, set_hostname, get_fd, \ 32 set_bufflen, \ 33 get_verify_result, \ 34 get_state) \ 35 static const SSL_METHOD_FUNC func_name LOCAL_ATRR = { \ 36 new, \ 37 free, \ 38 handshake, \ 39 shutdown, \ 40 clear, \ 41 read, \ 42 send, \ 43 pending, \ 44 set_fd, \ 45 set_hostname, \ 46 get_fd, \ 47 set_bufflen, \ 48 get_verify_result, \ 49 get_state \ 50 }; 51 52 #define IMPLEMENT_TLS_METHOD(ver, mode, fun, func_name) \ 53 const SSL_METHOD* func_name(void) { \ 54 static const SSL_METHOD func_name##_data LOCAL_ATRR = { \ 55 ver, \ 56 mode, \ 57 &(fun), \ 58 }; \ 59 return &func_name##_data; \ 60 } 61 62 #define IMPLEMENT_SSL_METHOD(ver, mode, fun, func_name) \ 63 const SSL_METHOD* func_name(void) { \ 64 static const SSL_METHOD func_name##_data LOCAL_ATRR = { \ 65 ver, \ 66 mode, \ 67 &(fun), \ 68 }; \ 69 return &func_name##_data; \ 70 } 71 72 #define IMPLEMENT_X509_METHOD(func_name, \ 73 new, \ 74 free, \ 75 load, \ 76 show_info) \ 77 const X509_METHOD* func_name(void) { \ 78 static const X509_METHOD func_name##_data LOCAL_ATRR = { \ 79 new, \ 80 free, \ 81 load, \ 82 show_info \ 83 }; \ 84 return &func_name##_data; \ 85 } 86 87 #define IMPLEMENT_PKEY_METHOD(func_name, \ 88 new, \ 89 free, \ 90 load) \ 91 const PKEY_METHOD* func_name(void) { \ 92 static const PKEY_METHOD func_name##_data LOCAL_ATRR = { \ 93 new, \ 94 free, \ 95 load \ 96 }; \ 97 return &func_name##_data; \ 98 } 99 100 /** 101 * @brief get X509 object method 102 * 103 * @param none 104 * 105 * @return X509 object method point 106 */ 107 const X509_METHOD* X509_method(void); 108 109 /** 110 * @brief get private key object method 111 * 112 * @param none 113 * 114 * @return private key object method point 115 */ 116 const PKEY_METHOD* EVP_PKEY_method(void); 117 118 #ifdef __cplusplus 119 } 120 #endif 121 122 #endif 123