Rollup merge of #77950 - arlosi:sha256, r=eddyb

Add support for SHA256 source file hashing

Adds support for `-Z src-hash-algorithm sha256`, which became available in LLVM 11.

Using an older version of LLVM will cause an error `invalid checksum kind` if the hash algorithm is set to sha256.

r? `@eddyb`
cc #70401 `@est31`
This commit is contained in:
Mara Bos 2020-11-03 19:32:26 +01:00 committed by GitHub
commit 52405f7c0c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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;
@ -1034,6 +1035,7 @@ pub struct OffsetOverflowError;
pub enum SourceFileHashAlgorithm {
Md5,
Sha1,
Sha256,
}
impl FromStr for SourceFileHashAlgorithm {
@ -1043,6 +1045,7 @@ impl FromStr for SourceFileHashAlgorithm {
match s {
"md5" => Ok(SourceFileHashAlgorithm::Md5),
"sha1" => Ok(SourceFileHashAlgorithm::Sha1),
"sha256" => Ok(SourceFileHashAlgorithm::Sha256),
_ => Err(()),
}
}
@ -1055,7 +1058,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 {
@ -1071,6 +1074,9 @@ impl SourceFileHash {
SourceFileHashAlgorithm::Sha1 => {
value.copy_from_slice(&Sha1::digest(data));
}
SourceFileHashAlgorithm::Sha256 => {
value.copy_from_slice(&Sha256::digest(data));
}
}
hash
}
@ -1090,6 +1096,7 @@ impl SourceFileHash {
match self.kind {
SourceFileHashAlgorithm::Md5 => 16,
SourceFileHashAlgorithm::Sha1 => 20,
SourceFileHashAlgorithm::Sha256 => 32,
}
}
}