Merge pull request #9455 from holtrop/rust-wc-init-cleanup
Rust wrapper: wrap wolfCrypt_Init() and wolfCrypt_Cleanup()
This commit is contained in:
@@ -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(())
|
||||
}
|
||||
|
||||
11
wrapper/rust/wolfssl/tests/test_wolfcrypt.rs
Normal file
11
wrapper/rust/wolfssl/tests/test_wolfcrypt.rs
Normal 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()");
|
||||
}
|
||||
Reference in New Issue
Block a user