1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 08:11:47 +02:00

nix hash convert: Support SRI hashes that lack trailing '=' characters

Fixes #11996.

(cherry picked from commit 52f1cd0595)
This commit is contained in:
Eelco Dolstra 2024-12-05 16:02:35 +01:00 committed by Mergify
parent fc11659148
commit 00d0e63c61
3 changed files with 16 additions and 10 deletions

View file

@ -134,7 +134,8 @@ std::string Hash::to_string(HashFormat hashFormat, bool includeAlgo) const
Hash Hash::dummy(HashAlgorithm::SHA256);
Hash Hash::parseSRI(std::string_view original) {
Hash Hash::parseSRI(std::string_view original)
{
auto rest = original;
// Parse the has type before the separater, if there was one.

View file

@ -222,9 +222,12 @@ struct CmdHashConvert : Command
Category category() override { return catUtility; }
void run() override {
for (const auto& s: hashStrings) {
Hash h = Hash::parseAny(s, algo);
if (from && h.to_string(*from, from == HashFormat::SRI) != s) {
for (const auto & s: hashStrings) {
Hash h =
from == HashFormat::SRI
? Hash::parseSRI(s)
: Hash::parseAny(s, algo);
if (from && from != HashFormat::SRI && h.to_string(*from, false) != s) {
auto from_as_string = printHashFormat(*from);
throw BadHash("input hash '%s' does not have the expected format '--from %s'", s, from_as_string);
}