forked from lix-project/lix
Validate text version instead, throw Errors
This commit is contained in:
parent
a5cdf1867e
commit
78f137e931
1 changed files with 9 additions and 9 deletions
|
@ -45,26 +45,26 @@ ContentAddress parseContentAddress(std::string_view rawCa) {
|
||||||
auto prefix = string(rawCa, 0, prefixSeparator);
|
auto prefix = string(rawCa, 0, prefixSeparator);
|
||||||
if (prefix == "text") {
|
if (prefix == "text") {
|
||||||
auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos);
|
auto hashTypeAndHash = rawCa.substr(prefixSeparator+1, string::npos);
|
||||||
return TextHash { Hash(string(hashTypeAndHash)) };
|
Hash hash = Hash(string(hashTypeAndHash));
|
||||||
|
if (hash.type != HashType::SHA256) {
|
||||||
|
throw Error("parseContentAddress: the text hash should have type SHA256");
|
||||||
|
}
|
||||||
|
return TextHash { hash };
|
||||||
} else if (prefix == "fixed") {
|
} else if (prefix == "fixed") {
|
||||||
// This has to be an inverse to makeFixedOutputCA
|
// This has to be an inverse to makeFixedOutputCA
|
||||||
auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos);
|
auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos);
|
||||||
if (methodAndHash.substr(0,2) == "r:") {
|
if (methodAndHash.substr(0,2) == "r:") {
|
||||||
std::string_view hashRaw = methodAndHash.substr(2,string::npos);
|
std::string_view hashRaw = methodAndHash.substr(2,string::npos);
|
||||||
Hash hash = Hash(string(hashRaw));
|
return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) };
|
||||||
assert(hash.type == HashType::SHA256);
|
|
||||||
return FileSystemHash { FileIngestionMethod::Recursive, hash };
|
|
||||||
} else {
|
} else {
|
||||||
std::string_view hashRaw = methodAndHash;
|
std::string_view hashRaw = methodAndHash;
|
||||||
Hash hash = Hash(string(hashRaw));
|
return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) };
|
||||||
assert(hash.type == HashType::SHA256);
|
|
||||||
return FileSystemHash { FileIngestionMethod::Flat, hash };
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw "parseContentAddress: format not recognized; has to be text or fixed";
|
throw Error("parseContentAddress: format not recognized; has to be text or fixed");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
throw "Not a content address because it lacks an appropriate prefix";
|
throw Error("Not a content address because it lacks an appropriate prefix");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue