async_git/plumbing/hash_object.rs
1use sha1::{Digest, Sha1};
2use tokio::io::{AsyncRead, AsyncReadExt};
3
4use crate::errors::Result;
5
6pub async fn hash_object<R: AsyncRead + Unpin>(mut r: R) -> Result<[u8; 20]> {
7 let mut hasher = Sha1::new();
8 let mut buffer = [0; 64];
9 loop {
10 let bytes = r.read(&mut buffer).await?;
11 if bytes == 0 {
12 break;
13 }
14 hasher.input(&buffer[..bytes]);
15 }
16 Ok(hasher.result().into())
17}