mirror of
https://github.com/astral-sh/uv.git
synced 2025-09-20 01:09:55 +00:00
Support MD5 hashes (#1556)
## Summary We can add other hashes if necessary, but I don't know that they're really used in practice. Closes https://github.com/astral-sh/uv/issues/1547.
This commit is contained in:
parent
9e0336c28a
commit
c1eb6130e1
4 changed files with 95 additions and 15 deletions
|
@ -136,16 +136,21 @@ impl Default for Yanked {
|
|||
#[archive(check_bytes)]
|
||||
#[archive_attr(derive(Debug))]
|
||||
pub struct Hashes {
|
||||
pub md5: Option<String>,
|
||||
pub sha256: Option<String>,
|
||||
}
|
||||
|
||||
impl Hashes {
|
||||
/// Format as `<algorithm>:<hash>`.
|
||||
///
|
||||
/// Currently limited to SHA256.
|
||||
pub fn to_string(&self) -> Option<String> {
|
||||
self.sha256
|
||||
.as_ref()
|
||||
.map(|sha256| format!("sha256:{sha256}"))
|
||||
.or_else(|| self.md5.as_ref().map(|md5| format!("md5:{md5}")))
|
||||
}
|
||||
|
||||
/// Return the hash digest.
|
||||
pub fn as_str(&self) -> Option<&str> {
|
||||
self.sha256.as_deref().or(self.md5.as_deref())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue