async-git 0.0.0-squat-name

Pure-rust async implementation of git built on tokio
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use sha1::{Digest, Sha1};
use tokio::io::{AsyncRead, AsyncReadExt};

use crate::errors::Result;

pub async fn hash_object<R: AsyncRead + Unpin>(mut r: R) -> Result<[u8; 20]> {
    let mut hasher = Sha1::new();
    let mut buffer = [0; 64];
    loop {
        let bytes = r.read(&mut buffer).await?;
        if bytes == 0 {
            break;
        }
        hasher.input(&buffer[..bytes]);
    }
    Ok(hasher.result().into())
}