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_P521_KYBER_LEVEL5)]
38    #[cfg_attr(not(feature = "kyber_only"), test_case(WOLFSSL_SECP521R1MLKEM1024))]
39    fn test_post_quantum_available(group: CurveGroupType) {
40        unsafe {
41            // Init WolfSSL
42            let res = wolfSSL_Init();
43            assert_eq!(res, WOLFSSL_SUCCESS as c_int);
44
45            // Set up client method
46            let method = wolfTLSv1_3_client_method();
47
48            // Create context
49            let context = wolfSSL_CTX_new(method);
50
51            // Create new SSL stream
52            let ssl = wolfSSL_new(context);
53
54            let res = wolfSSL_UseKeyShare(ssl, group.try_into().unwrap());
55
56            // Check that Kyber/ML-KEM was enabled
57            assert_eq!(res, WOLFSSL_SUCCESS as c_int);
58        }
59    }
60
61    #[test]
62    fn test_wolfssl_version_is_not_empty() {
63        assert!(!get_wolfssl_version_string().is_empty())
64    }
65}