diff --git a/rust/composefs-sys/Cargo.toml b/rust/composefs-sys/Cargo.toml index d3ce70f..790d24d 100644 --- a/rust/composefs-sys/Cargo.toml +++ b/rust/composefs-sys/Cargo.toml @@ -19,8 +19,9 @@ name = "composefs" version = "1" [features] -# Depend on 1.0.4 APIs +# Require functions from the C library corresponding to the provided version. v1_0_4 = [] +v1_0_7 = ["v1_0_4"] [build-dependencies] system-deps = "6" diff --git a/rust/composefs-sys/src/lib.rs b/rust/composefs-sys/src/lib.rs index 4ade072..f624290 100644 --- a/rust/composefs-sys/src/lib.rs +++ b/rust/composefs-sys/src/lib.rs @@ -11,6 +11,8 @@ extern "C" { pub fn lcfs_fd_get_fsverity(digest: *mut u8, fd: std::os::raw::c_int) -> std::os::raw::c_int; #[cfg(feature = "v1_0_4")] pub fn lcfs_fd_enable_fsverity(fd: std::os::raw::c_int) -> std::os::raw::c_int; + #[cfg(feature = "v1_0_7")] + pub fn lcfs_fd_measure_fsverity(digest: *mut u8, fd: std::os::raw::c_int) -> std::os::raw::c_int; } /// Convert an integer return value into a `Result`. @@ -41,6 +43,19 @@ mod tests { Ok(()) } + #[test] + #[cfg(feature = "v1_0_7")] + fn test_fd_measure_fsverity() -> Result<()> { + let mut tf = tempfile::NamedTempFile::new()?; + tf.write_all(b"hello")?; + let tf = std::fs::File::open(tf.path())?; + // This fd can't have fsverity enabled + let mut buf = [0u8; LCFS_SHA256_DIGEST_LEN]; + let r = unsafe { lcfs_fd_measure_fsverity(buf.as_mut_ptr(), tf.as_raw_fd()) }; + assert_ne!(r, 0); + Ok(()) + } + #[test] fn test_digest() -> Result<()> { for f in [lcfs_compute_fsverity_from_fd, lcfs_fd_get_fsverity] {