-
Notifications
You must be signed in to change notification settings - Fork 765
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a --verify-hashes hash-checking mode
- Loading branch information
1 parent
e271d1f
commit 088b164
Showing
14 changed files
with
478 additions
and
81 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
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,35 @@ | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum HashCheckingMode { | ||
/// Hashes should be validated against a pre-defined list of hashes. Every requirement must | ||
/// itself be hashable (e.g., Git dependencies are forbidden) _and_ have a hash in the lockfile. | ||
Require, | ||
/// Hashes should be validated, if present, but ignored if absent. | ||
Verify, | ||
} | ||
|
||
impl HashCheckingMode { | ||
/// Return the [`HashCheckingMode`] from the command-line arguments, if any. | ||
pub fn from_args(require_hashes: bool, verify_hashes: bool) -> Option<Self> { | ||
if require_hashes { | ||
Some(Self::Require) | ||
} else if verify_hashes { | ||
Some(Self::Verify) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
/// Returns `true` if the hash checking mode is `Require`. | ||
pub fn is_require(&self) -> bool { | ||
matches!(self, Self::Require) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for HashCheckingMode { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Require => write!(f, "--require-hashes"), | ||
Self::Verify => write!(f, "--verify-hashes"), | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.