Skip to content

Commit

Permalink
rust: Bind lcfs_fd_measure_fsverity
Browse files Browse the repository at this point in the history
This is a reasonable thing to want to do.

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Nov 6, 2024
1 parent d0dd0f1 commit 955a594
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion rust/composefs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 15 additions & 0 deletions rust/composefs-sys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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] {
Expand Down

0 comments on commit 955a594

Please sign in to comment.