Skip to main content

wolfssl_sys/
lib.rs

1mod bindings;
2
3pub use bindings::*;
4use std::ffi::CStr;
5
6/// Get WolfSSL version via `LIBWOLFSSL_VERSION_STRING` header defined in wolfssl/version.h
7pub fn get_wolfssl_version_string() -> &'static str {
8    CStr::from_bytes_until_nul(LIBWOLFSSL_VERSION_STRING)
9        .unwrap()
10        .to_str()
11        .unwrap()
12}
13
14/**
15 * Add more tests to gain more confidence in the bindings
16 */
17#[cfg(test)]
18mod tests {
19    use std::os::raw::c_int;
20
21    use test_case::test_case;
22    #[cfg(unix)]
23    type CurveGroupType = std::os::raw::c_uint;
24    #[cfg(windows)]
25    type CurveGroupType = std::os::raw::c_int;
26
27    use super::*;
28    #[test]
29    fn init_wolfssl() {
30        unsafe {
31            let res = wolfSSL_Init();
32            assert_eq!(res, WOLFSSL_SUCCESS as c_int);
33        }
34    }
35
36    #[cfg(feature = "postquantum")]
37    #[test_case(WOLFSSL_SECP521R1MLKEM1024)]
38    fn test_post_quantum_available(group: CurveGroupType) {
39        unsafe {
40            // Init WolfSSL
41            let res = wolfSSL_Init();
42            assert_eq!(res, WOLFSSL_SUCCESS as c_int);
43
44            // Set up client method
45            let method = wolfTLSv1_3_client_method();
46
47            // Create context
48            let context = wolfSSL_CTX_new(method);
49
50            // Create new SSL stream
51            let ssl = wolfSSL_new(context);
52
53            let res = wolfSSL_UseKeyShare(ssl, group.try_into().unwrap());
54
55            // Check that ML-KEM was enabled
56            assert_eq!(res, WOLFSSL_SUCCESS as c_int);
57        }
58    }
59
60    #[test]
61    fn test_wolfssl_version_is_not_empty() {
62        assert!(!get_wolfssl_version_string().is_empty())
63    }
64}