@@ -4,6 +4,7 @@ use crate::{
44 ssl:: { Session , SessionConfig } ,
55 CurveGroup , Method , NewSessionError , RootCertificate , Secret , SslVerifyMode ,
66} ;
7+ use std:: os:: raw:: c_int;
78use std:: ptr:: NonNull ;
89use thiserror:: Error ;
910
@@ -97,7 +98,7 @@ impl ContextBuilder {
9798 self . ctx . as_ptr ( ) ,
9899 buf. as_ptr ( ) ,
99100 buf. len ( ) as std:: os:: raw:: c_long ,
100- WOLFSSL_FILETYPE_ASN1 ,
101+ WOLFSSL_FILETYPE_ASN1 as c_int ,
101102 )
102103 } ,
103104 // SAFETY: [`wolfSSL_CTX_load_verify_buffer`][0] ([also][1]) requires a valid `ctx` pointer from `wolfSSL_CTX_new()`.
@@ -111,16 +112,16 @@ impl ContextBuilder {
111112 self . ctx . as_ptr ( ) ,
112113 buf. as_ptr ( ) ,
113114 buf. len ( ) as std:: os:: raw:: c_long ,
114- WOLFSSL_FILETYPE_PEM ,
115+ WOLFSSL_FILETYPE_PEM as c_int ,
115116 )
116117 } ,
117118 RootCertificate :: PemFileOrDirectory ( path) => {
118119 let is_dir = path. is_dir ( ) ;
119- let path = path
120- . to_str ( )
121- . ok_or_else ( || Error :: fatal ( wolfssl_sys :: WOLFSSL_BAD_PATH ) ) ?;
120+ let path = path. to_str ( ) . ok_or_else ( || {
121+ Error :: fatal ( wolfssl_sys :: wolfSSL_ErrorCodes_WOLFSSL_BAD_PATH )
122+ } ) ?;
122123 let path = std:: ffi:: CString :: new ( path)
123- . map_err ( |_| Error :: fatal ( wolfssl_sys:: WOLFSSL_BAD_PATH ) ) ?;
124+ . map_err ( |_| Error :: fatal ( wolfssl_sys:: wolfSSL_ErrorCodes_WOLFSSL_BAD_PATH ) ) ?;
124125 if is_dir {
125126 // SAFETY: [`wolfSSL_CTX_load_verify_locations`][0] ([also][1]) requires a valid `ctx` pointer from `wolfSSL_CTX_new()`.
126127 // If not NULL, then the pointer passed as the path argument must be a valid NULL-terminated C-style string,
@@ -153,7 +154,7 @@ impl ContextBuilder {
153154 }
154155 } ;
155156
156- if result == wolfssl_sys:: WOLFSSL_SUCCESS {
157+ if result == wolfssl_sys:: WOLFSSL_SUCCESS as c_int {
157158 Ok ( self )
158159 } else {
159160 Err ( Error :: fatal ( result) )
@@ -165,7 +166,7 @@ impl ContextBuilder {
165166 /// [0]: https://www.wolfssl.com/documentation/manuals/wolfssl/ssl_8h.html#function-wolfssl_ctx_set_cipher_list
166167 pub fn with_cipher_list ( self , cipher_list : & str ) -> Result < Self > {
167168 let cipher_list = std:: ffi:: CString :: new ( cipher_list)
168- . map_err ( |_| Error :: fatal ( wolfssl_sys:: WOLFSSL_FAILURE ) ) ?;
169+ . map_err ( |_| Error :: fatal ( wolfssl_sys:: WOLFSSL_FAILURE as c_int ) ) ?;
169170
170171 // SAFETY: [`wolfSSL_CTX_set_cipher_list`][0] ([also][1]) requires a valid `ctx` pointer from `wolfSSL_CTX_new()` and
171172 // `list` parameter which should be a null terminated C string pointer which is guaranteed by
@@ -180,7 +181,7 @@ impl ContextBuilder {
180181 )
181182 } ;
182183
183- if result == wolfssl_sys:: WOLFSSL_SUCCESS {
184+ if result == wolfssl_sys:: WOLFSSL_SUCCESS as c_int {
184185 Ok ( self )
185186 } else {
186187 Err ( Error :: fatal ( result) )
@@ -209,7 +210,7 @@ impl ContextBuilder {
209210 )
210211 } ;
211212
212- if result == wolfssl_sys:: WOLFSSL_SUCCESS {
213+ if result == wolfssl_sys:: WOLFSSL_SUCCESS as c_int {
213214 Ok ( self )
214215 } else {
215216 Err ( Error :: fatal ( result) )
@@ -238,15 +239,15 @@ impl ContextBuilder {
238239 self . ctx . as_ptr ( ) ,
239240 buf. as_ptr ( ) ,
240241 buf. len ( ) as std:: os:: raw:: c_long ,
241- WOLFSSL_FILETYPE_ASN1 ,
242+ WOLFSSL_FILETYPE_ASN1 as c_int ,
242243 )
243244 } ,
244245 Secret :: Asn1File ( path) => {
245- let path = path
246- . to_str ( )
247- . ok_or_else ( || Error :: fatal ( wolfssl_sys :: BAD_PATH_ERROR ) ) ?;
246+ let path = path. to_str ( ) . ok_or_else ( || {
247+ Error :: fatal ( wolfssl_sys :: wolfCrypt_ErrorCodes_BAD_PATH_ERROR )
248+ } ) ?;
248249 let file = std:: ffi:: CString :: new ( path)
249- . map_err ( |_| Error :: fatal ( wolfssl_sys:: BAD_PATH_ERROR ) ) ?;
250+ . map_err ( |_| Error :: fatal ( wolfssl_sys:: wolfCrypt_ErrorCodes_BAD_PATH_ERROR ) ) ?;
250251 // SAFETY: [`wolfSSL_CTX_use_certificate_file`][0] ([also][1]) requires a valid `ctx` pointer from `wolfSSL_CTX_new()`.
251252 // The pointer passed as the path argument must be a valid NULL-terminated C-style string,
252253 // which is guaranteed by the use of `std::ffi::CString::as_c_str()` here.
@@ -257,7 +258,7 @@ impl ContextBuilder {
257258 wolfSSL_CTX_use_certificate_file (
258259 self . ctx . as_ptr ( ) ,
259260 file. as_c_str ( ) . as_ptr ( ) ,
260- WOLFSSL_FILETYPE_ASN1 ,
261+ WOLFSSL_FILETYPE_ASN1 as c_int ,
261262 )
262263 }
263264 }
@@ -272,15 +273,15 @@ impl ContextBuilder {
272273 self . ctx . as_ptr ( ) ,
273274 buf. as_ptr ( ) ,
274275 buf. len ( ) as std:: os:: raw:: c_long ,
275- WOLFSSL_FILETYPE_PEM ,
276+ WOLFSSL_FILETYPE_PEM as c_int ,
276277 )
277278 } ,
278279 Secret :: PemFile ( path) => {
279- let path = path
280- . to_str ( )
281- . ok_or_else ( || Error :: fatal ( wolfssl_sys :: BAD_PATH_ERROR ) ) ?;
280+ let path = path. to_str ( ) . ok_or_else ( || {
281+ Error :: fatal ( wolfssl_sys :: wolfCrypt_ErrorCodes_BAD_PATH_ERROR )
282+ } ) ?;
282283 let file = std:: ffi:: CString :: new ( path)
283- . map_err ( |_| Error :: fatal ( wolfssl_sys:: BAD_PATH_ERROR ) ) ?;
284+ . map_err ( |_| Error :: fatal ( wolfssl_sys:: wolfCrypt_ErrorCodes_BAD_PATH_ERROR ) ) ?;
284285 // SAFETY: [`wolfSSL_CTX_use_certificate_file`][0] ([also][1]) requires a valid `ctx` pointer from `wolfSSL_CTX_new()`.
285286 // The pointer passed as the path argument must be a valid NULL-terminated C-style string,
286287 // which is guaranteed by the use of `std::ffi::CString::as_c_str()` here.
@@ -291,13 +292,13 @@ impl ContextBuilder {
291292 wolfSSL_CTX_use_certificate_file (
292293 self . ctx . as_ptr ( ) ,
293294 file. as_c_str ( ) . as_ptr ( ) ,
294- WOLFSSL_FILETYPE_PEM ,
295+ WOLFSSL_FILETYPE_PEM as c_int ,
295296 )
296297 }
297298 }
298299 } ;
299300
300- if result == wolfssl_sys:: WOLFSSL_SUCCESS {
301+ if result == wolfssl_sys:: WOLFSSL_SUCCESS as c_int {
301302 Ok ( self )
302303 } else {
303304 Err ( Error :: fatal ( result) )
@@ -326,15 +327,15 @@ impl ContextBuilder {
326327 self . ctx . as_ptr ( ) ,
327328 buf. as_ptr ( ) ,
328329 buf. len ( ) as std:: os:: raw:: c_long ,
329- WOLFSSL_FILETYPE_ASN1 ,
330+ WOLFSSL_FILETYPE_ASN1 as c_int ,
330331 )
331332 } ,
332333 Secret :: Asn1File ( path) => {
333- let path = path
334- . to_str ( )
335- . ok_or_else ( || Error :: fatal ( wolfssl_sys :: BAD_PATH_ERROR ) ) ?;
334+ let path = path. to_str ( ) . ok_or_else ( || {
335+ Error :: fatal ( wolfssl_sys :: wolfCrypt_ErrorCodes_BAD_PATH_ERROR )
336+ } ) ?;
336337 let file = std:: ffi:: CString :: new ( path)
337- . map_err ( |_| Error :: fatal ( wolfssl_sys:: BAD_PATH_ERROR ) ) ?;
338+ . map_err ( |_| Error :: fatal ( wolfssl_sys:: wolfCrypt_ErrorCodes_BAD_PATH_ERROR ) ) ?;
338339 // SAFETY: [`wolfSSL_CTX_use_PrivateKey_file`][0] ([also][1]) requires a valid `ctx` pointer from `wolfSSL_CTX_new()`.
339340 // The pointer passed as the path argument must be a valid NULL-terminated C-style string,
340341 // which is guaranteed by the use of `std::ffi::CString::as_c_str()` here.
@@ -345,7 +346,7 @@ impl ContextBuilder {
345346 wolfSSL_CTX_use_PrivateKey_file (
346347 self . ctx . as_ptr ( ) ,
347348 file. as_c_str ( ) . as_ptr ( ) ,
348- WOLFSSL_FILETYPE_ASN1 ,
349+ WOLFSSL_FILETYPE_ASN1 as c_int ,
349350 )
350351 }
351352 }
@@ -360,15 +361,15 @@ impl ContextBuilder {
360361 self . ctx . as_ptr ( ) ,
361362 buf. as_ptr ( ) ,
362363 buf. len ( ) as std:: os:: raw:: c_long ,
363- WOLFSSL_FILETYPE_PEM ,
364+ WOLFSSL_FILETYPE_PEM as c_int ,
364365 )
365366 } ,
366367 Secret :: PemFile ( path) => {
367- let path = path
368- . to_str ( )
369- . ok_or_else ( || Error :: fatal ( wolfssl_sys :: BAD_PATH_ERROR ) ) ?;
368+ let path = path. to_str ( ) . ok_or_else ( || {
369+ Error :: fatal ( wolfssl_sys :: wolfCrypt_ErrorCodes_BAD_PATH_ERROR )
370+ } ) ?;
370371 let file = std:: ffi:: CString :: new ( path)
371- . map_err ( |_| Error :: fatal ( wolfssl_sys:: BAD_PATH_ERROR ) ) ?;
372+ . map_err ( |_| Error :: fatal ( wolfssl_sys:: wolfCrypt_ErrorCodes_BAD_PATH_ERROR ) ) ?;
372373 // SAFETY: [`wolfSSL_CTX_use_PrivateKey_file`][0] ([also][1]) requires a valid `ctx` pointer from `wolfSSL_CTX_new()`.
373374 // The pointer passed as the path argument must be a valid NULL-terminated C-style string,
374375 // which is guaranteed by the use of `std::ffi::CString::as_c_str()` here.
@@ -379,13 +380,13 @@ impl ContextBuilder {
379380 wolfSSL_CTX_use_PrivateKey_file (
380381 self . ctx . as_ptr ( ) ,
381382 file. as_c_str ( ) . as_ptr ( ) ,
382- WOLFSSL_FILETYPE_PEM ,
383+ WOLFSSL_FILETYPE_PEM as c_int ,
383384 )
384385 }
385386 }
386387 } ;
387388
388- if result == wolfssl_sys:: WOLFSSL_SUCCESS {
389+ if result == wolfssl_sys:: WOLFSSL_SUCCESS as c_int {
389390 Ok ( self )
390391 } else {
391392 Err ( Error :: fatal ( result) )
@@ -399,7 +400,7 @@ impl ContextBuilder {
399400 // SAFETY: [`wolfSSL_CTX_UseSecureRenegotiation`][1] does not have proper documentation.
400401 // Based on the implementation, the only requirement is the context which is passed to this api has to be a valid `WOLFSSL_CTX`
401402 let result = unsafe { wolfssl_sys:: wolfSSL_CTX_UseSecureRenegotiation ( self . ctx . as_ptr ( ) ) } ;
402- if result == wolfssl_sys:: WOLFSSL_SUCCESS {
403+ if result == wolfssl_sys:: WOLFSSL_SUCCESS as c_int {
403404 Ok ( self )
404405 } else {
405406 Err ( Error :: fatal ( result) )
@@ -580,7 +581,7 @@ mod tests {
580581 if ok {
581582 Ok ( b)
582583 } else {
583- Err ( Error :: fatal ( wolfssl_sys:: WOLFSSL_FAILURE ) )
584+ Err ( Error :: fatal ( wolfssl_sys:: WOLFSSL_FAILURE as c_int ) )
584585 }
585586 } )
586587 . unwrap ( ) ;
@@ -599,7 +600,7 @@ mod tests {
599600 if ok {
600601 Ok ( b)
601602 } else {
602- Err ( Error :: fatal ( wolfssl_sys:: WOLFSSL_FAILURE ) )
603+ Err ( Error :: fatal ( wolfssl_sys:: WOLFSSL_FAILURE as c_int ) )
603604 }
604605 } )
605606 . unwrap ( ) ;
0 commit comments