aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorCarlo Nucera <carlo.nucera@protonmail.com>2020-06-02 16:20:22 -0400
committerCarlo Nucera <carlo.nucera@protonmail.com>2020-06-02 16:20:22 -0400
commit78f137e931eff3c5133fe0a58f5d469f50959556 (patch)
tree6d220e4099612b3d9c222b426045e5fc5ed5fc2b /src/libstore
parenta5cdf1867efdf50f8cef324bbc36d1b840e13f8c (diff)
Validate text version instead, throw Errors
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/content-address.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libstore/content-address.cc b/src/libstore/content-address.cc
index 4c3af18fd..8a8112fd0 100644
--- a/src/libstore/content-address.cc
+++ b/src/libstore/content-address.cc
@@ -45,26 +45,26 @@ ContentAddress parseContentAddress(std::string_view rawCa) {
auto prefix = string(rawCa, 0, prefixSeparator);
if (prefix == "text") {
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") {
// This has to be an inverse to makeFixedOutputCA
auto methodAndHash = rawCa.substr(prefixSeparator+1, string::npos);
if (methodAndHash.substr(0,2) == "r:") {
std::string_view hashRaw = methodAndHash.substr(2,string::npos);
- Hash hash = Hash(string(hashRaw));
- assert(hash.type == HashType::SHA256);
- return FileSystemHash { FileIngestionMethod::Recursive, hash };
+ return FileSystemHash { FileIngestionMethod::Recursive, Hash(string(hashRaw)) };
} else {
std::string_view hashRaw = methodAndHash;
- Hash hash = Hash(string(hashRaw));
- assert(hash.type == HashType::SHA256);
- return FileSystemHash { FileIngestionMethod::Flat, hash };
+ return FileSystemHash { FileIngestionMethod::Flat, Hash(string(hashRaw)) };
}
} 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 {
- throw "Not a content address because it lacks an appropriate prefix";
+ throw Error("Not a content address because it lacks an appropriate prefix");
}
};