feat: Support data verification in Download (#1248)

By accepting `&mut dyn DataVerifier` for users to pass any callback that
uses `digest::Digest`/`digest::Mac`, `sigstore` or whatever they want.

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
Jiahao XU 2023-08-06 15:56:02 +10:00 committed by GitHub
parent 3181e16e36
commit e4c776f403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 92 additions and 61 deletions

View file

@ -21,7 +21,7 @@ use crate::utils::{extract_with_blocking_task, StreamReadable};
pub async fn extract_bin<S>(stream: S, path: &Path) -> Result<ExtractedFiles, DownloadError>
where
S: Stream<Item = Result<Bytes, DownloadError>> + Send + Sync + Unpin + 'static,
S: Stream<Item = Result<Bytes, DownloadError>> + Send + Sync + Unpin,
{
debug!("Writing to `{}`", path.display());
@ -45,7 +45,7 @@ where
pub async fn extract_zip<S>(stream: S, path: &Path) -> Result<ExtractedFiles, DownloadError>
where
S: Stream<Item = Result<Bytes, DownloadError>> + Unpin + Send + Sync + 'static,
S: Stream<Item = Result<Bytes, DownloadError>> + Unpin + Send + Sync,
{
debug!("Decompressing from zip archive to `{}`", path.display());
@ -79,7 +79,7 @@ pub async fn extract_tar_based_stream<S>(
fmt: TarBasedFmt,
) -> Result<ExtractedFiles, DownloadError>
where
S: Stream<Item = Result<Bytes, DownloadError>> + Send + Sync + Unpin + 'static,
S: Stream<Item = Result<Bytes, DownloadError>> + Send + Sync + Unpin,
{
debug!("Extracting from {fmt} archive to {}", dst.display());
@ -162,7 +162,7 @@ fn extract_with_blocking_decoder<S, F, T>(
f: F,
) -> impl Future<Output = Result<T, DownloadError>>
where
S: Stream<Item = Result<Bytes, DownloadError>> + Send + Sync + Unpin + 'static,
S: Stream<Item = Result<Bytes, DownloadError>> + Send + Sync + Unpin,
F: FnOnce(mpsc::Receiver<Bytes>, &Path) -> io::Result<T> + Send + Sync + 'static,
T: Send + 'static,
{