@@ -87,46 +87,6 @@ STATIC void mbedtls_debug(void *ctx, int level, const char *file, int line, cons
87
87
}
88
88
#endif
89
89
90
- STATIC NORETURN void mbedtls_raise_error (int err ) {
91
- // _mbedtls_ssl_send and _mbedtls_ssl_recv (below) turn positive error codes from the
92
- // underlying socket into negative codes to pass them through mbedtls. Here we turn them
93
- // positive again so they get interpreted as the OSError they really are. The
94
- // cut-off of -256 is a bit hacky, sigh.
95
- if (err < 0 && err > -256 ) {
96
- mp_raise_OSError (- err );
97
- }
98
-
99
- #if defined(MBEDTLS_ERROR_C )
100
- // Including mbedtls_strerror takes about 1.5KB due to the error strings.
101
- // MBEDTLS_ERROR_C is the define used by mbedtls to conditionally include mbedtls_strerror.
102
- // It is set/unset in the MBEDTLS_CONFIG_FILE which is defined in the Makefile.
103
-
104
- // Try to allocate memory for the message
105
- #define ERR_STR_MAX 80 // mbedtls_strerror truncates if it doesn't fit
106
- mp_obj_str_t * o_str = m_new_obj_maybe (mp_obj_str_t );
107
- byte * o_str_buf = m_new_maybe (byte , ERR_STR_MAX );
108
- if (o_str == NULL || o_str_buf == NULL ) {
109
- mp_raise_OSError (err );
110
- }
111
-
112
- // print the error message into the allocated buffer
113
- mbedtls_strerror (err , (char * )o_str_buf , ERR_STR_MAX );
114
- size_t len = strlen ((char * )o_str_buf );
115
-
116
- // Put the exception object together
117
- o_str -> base .type = & mp_type_str ;
118
- o_str -> data = o_str_buf ;
119
- o_str -> len = len ;
120
- o_str -> hash = qstr_compute_hash (o_str -> data , o_str -> len );
121
- // raise
122
- mp_obj_t args [2 ] = { MP_OBJ_NEW_SMALL_INT (err ), MP_OBJ_FROM_PTR (o_str )};
123
- nlr_raise (mp_obj_exception_make_new (& mp_type_OSError , 2 , 0 , args ));
124
- #else
125
- // mbedtls is compiled without error strings so we simply return the err number
126
- mp_raise_OSError (err ); // err is typically a large negative number
127
- #endif
128
- }
129
-
130
90
// mod_ssl_errstr returns the error string corresponding to the error code found in an OSError,
131
91
// such as returned by read/write.
132
92
STATIC mp_obj_t mod_ssl_errstr (mp_obj_t err_in ) {
@@ -299,7 +259,7 @@ STATIC mp_obj_ssl_socket_t *socket_new(mp_obj_t sock, struct ssl_args *args) {
299
259
} else if (ret == MBEDTLS_ERR_X509_BAD_INPUT_DATA ) {
300
260
mp_raise_ValueError (MP_ERROR_TEXT ("invalid cert" ));
301
261
} else {
302
- mbedtls_raise_error ( ret );
262
+ mp_raise_OSError ( - ret );
303
263
}
304
264
}
305
265
0 commit comments