Merge pull request #9455 from holtrop/rust-wc-init-cleanup

Rust wrapper: wrap wolfCrypt_Init() and wolfCrypt_Cleanup()
This commit is contained in:
Sean Parkinson
2025-11-25 09:17:23 +10:00
committed by GitHub
2 changed files with 55 additions and 0 deletions

View File

@@ -31,3 +31,47 @@ pub mod prf;
pub mod random;
pub mod rsa;
pub mod sha;
use crate::sys;
/// Initialize resources used by wolfCrypt.
///
/// # Returns
///
/// Returns either Ok(()) on success or Err(e) containing the wolfSSL
/// library error code value.
///
/// # Example
///
/// ```rust
/// use wolfssl::wolfcrypt::*;
/// wolfcrypt_init().expect("Error with wolfcrypt_init()");
/// ```
pub fn wolfcrypt_init() -> Result<(), i32> {
let rc = unsafe { sys::wolfCrypt_Init() };
if rc != 0 {
return Err(rc);
}
Ok(())
}
/// Clean up resources used by wolfCrypt.
///
/// # Returns
///
/// Returns either Ok(()) on success or Err(e) containing the wolfSSL
/// library error code value.
///
/// # Example
///
/// ```rust
/// use wolfssl::wolfcrypt::*;
/// wolfcrypt_cleanup().expect("Error with wolfcrypt_cleanup()");
/// ```
pub fn wolfcrypt_cleanup() -> Result<(), i32> {
let rc = unsafe { sys::wolfCrypt_Cleanup() };
if rc != 0 {
return Err(rc);
}
Ok(())
}

View File

@@ -0,0 +1,11 @@
use wolfssl::wolfcrypt::*;
#[test]
fn test_wolfcrypt_init() {
wolfcrypt_init().expect("Error with wolfcrypt_init()");
}
#[test]
fn test_wolfcrypt_cleanup() {
wolfcrypt_cleanup().expect("Error with wolfcrypt_cleanup()");
}