Add support for SHA256 source file hashing for LLVM 11+.

This commit is contained in:
Arlo Siemsen 2020-10-13 08:41:06 -07:00
parent 5565241f65
commit 3296d5ca7b
10 changed files with 59 additions and 10 deletions

View file

@ -59,6 +59,7 @@ use std::str::FromStr;
use md5::Md5;
use sha1::Digest;
use sha1::Sha1;
use sha2::Sha256;
use tracing::debug;
@ -1040,6 +1041,7 @@ pub struct OffsetOverflowError;
pub enum SourceFileHashAlgorithm {
Md5,
Sha1,
Sha256,
}
impl FromStr for SourceFileHashAlgorithm {
@ -1049,6 +1051,7 @@ impl FromStr for SourceFileHashAlgorithm {
match s {
"md5" => Ok(SourceFileHashAlgorithm::Md5),
"sha1" => Ok(SourceFileHashAlgorithm::Sha1),
"sha256" => Ok(SourceFileHashAlgorithm::Sha256),
_ => Err(()),
}
}
@ -1061,7 +1064,7 @@ rustc_data_structures::impl_stable_hash_via_hash!(SourceFileHashAlgorithm);
#[derive(HashStable_Generic, Encodable, Decodable)]
pub struct SourceFileHash {
pub kind: SourceFileHashAlgorithm,
value: [u8; 20],
value: [u8; 32],
}
impl SourceFileHash {
@ -1077,6 +1080,9 @@ impl SourceFileHash {
SourceFileHashAlgorithm::Sha1 => {
value.copy_from_slice(&Sha1::digest(data));
}
SourceFileHashAlgorithm::Sha256 => {
value.copy_from_slice(&Sha256::digest(data));
}
}
hash
}
@ -1096,6 +1102,7 @@ impl SourceFileHash {
match self.kind {
SourceFileHashAlgorithm::Md5 => 16,
SourceFileHashAlgorithm::Sha1 => 20,
SourceFileHashAlgorithm::Sha256 => 32,
}
}
}