-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: downloaded layer integrity checks (#6)
* fix: downloaded layer integrity checks - checking that file has already been downloaded - check file integrity after download - change directory where layers are downloaded to no include registry like `docker` subdir * chore: disabling nightly checks because clippy nightly is buggy - see rust-lang/rust-clippy#13458
- Loading branch information
Showing
8 changed files
with
166 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use std::path::Path; | ||
|
||
use oci_spec::image::DigestAlgorithm; | ||
use sha2::{Digest, Sha256, Sha384, Sha512}; | ||
use tokio::{fs::File, io::AsyncReadExt}; | ||
|
||
use crate::{MonocoreError, MonocoreResult}; | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
// Functions | ||
//-------------------------------------------------------------------------------------------------- | ||
|
||
/// Gets the hash of a file. | ||
pub async fn get_file_hash(path: &Path, algorithm: &DigestAlgorithm) -> MonocoreResult<Vec<u8>> { | ||
let mut file = File::open(path).await?; | ||
let mut buffer = Vec::new(); | ||
file.read_to_end(&mut buffer).await?; | ||
|
||
let hash = match algorithm { | ||
DigestAlgorithm::Sha256 => Sha256::digest(&buffer).to_vec(), | ||
DigestAlgorithm::Sha384 => Sha384::digest(&buffer).to_vec(), | ||
DigestAlgorithm::Sha512 => Sha512::digest(&buffer).to_vec(), | ||
_ => { | ||
return Err(MonocoreError::UnsupportedImageHashAlgorithm(format!( | ||
"Unsupported algorithm: {}", | ||
algorithm | ||
))); | ||
} | ||
}; | ||
|
||
Ok(hash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
//! Utility functions and types. | ||
mod conversion; | ||
mod file; | ||
mod path; | ||
|
||
//-------------------------------------------------------------------------------------------------- | ||
// Exports | ||
//-------------------------------------------------------------------------------------------------- | ||
|
||
pub use conversion::*; | ||
pub use file::*; | ||
pub use path::*; |
Oops, something went wrong.