1use crate::superblock::BLOCK_SIZE;
5use anyhow::Error;
6use fidl_fuchsia_io as fio;
7use fsverity_merkle::FsVerityDescriptor as DecodedDescriptor;
8
9pub struct FsVerityDescriptor<'a> {
11 pub file_size: u64,
12 pub algorithm: fio::HashAlgorithm,
13 pub root: &'a [u8],
14 pub salt: &'a [u8],
15}
16
17impl<'a> FsVerityDescriptor<'a> {
18 pub fn from_bytes(data: &'a [u8]) -> Result<Self, Error> {
20 let descriptor = DecodedDescriptor::from_bytes(data, BLOCK_SIZE)?;
21
22 Ok(Self {
23 file_size: descriptor.file_size() as u64,
24 algorithm: descriptor.digest_algorithm(),
25 root: descriptor.root_digest(),
26 salt: descriptor.salt(),
27 })
28 }
29
30 pub fn fio_verification_options(&self) -> fio::VerificationOptions {
32 fio::VerificationOptions {
33 hash_algorithm: Some(self.algorithm),
34 salt: Some(self.salt.to_vec()),
35 ..Default::default()
36 }
37 }
38}