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 descriptor: DecodedDescriptor<'a>,
14}
15
16impl<'a> FsVerityDescriptor<'a> {
17 pub fn from_bytes(data: &'a [u8]) -> Result<Self, Error> {
19 let descriptor = DecodedDescriptor::new(data, BLOCK_SIZE)?;
20
21 Ok(Self {
22 file_size: descriptor.file_size() as u64,
23 algorithm: descriptor.digest_algorithm(),
24 descriptor,
25 })
26 }
27
28 pub fn root(&self) -> &[u8] {
29 self.descriptor.root_digest()
30 }
31
32 pub fn salt(&self) -> &[u8] {
33 self.descriptor.salt()
34 }
35
36 pub fn fio_verification_options(&self) -> fio::VerificationOptions {
38 fio::VerificationOptions {
39 hash_algorithm: Some(self.algorithm),
40 salt: Some(self.descriptor.salt().to_vec()),
41 ..Default::default()
42 }
43 }
44}