use ic_host_artifacts::artifact::{ArtifactError, ArtifactIdentity, hash_reader};
use std::{
io::{self, Read},
os::fd::AsFd,
};
pub fn hash_descriptor(
descriptor: &impl AsFd,
max_bytes: u64,
) -> Result<ArtifactIdentity, ArtifactError> {
hash_reader(DescriptorReader(descriptor), max_bytes)
}
struct DescriptorReader<'a, F>(&'a F);
impl<F: AsFd> Read for DescriptorReader<'_, F> {
fn read(&mut self, buffer: &mut [u8]) -> io::Result<usize> {
rustix::io::read(self.0, buffer).map_err(Into::into)
}
}
#[cfg(test)]
mod tests;