diff options
author | Kasper Gałkowski <kpg@posteo.net> | 2022-04-08 19:38:43 +0200 |
---|---|---|
committer | Kasper Gałkowski <kpg@posteo.net> | 2022-04-12 21:13:14 +0200 |
commit | 2769e43f61d827e1b8fe46257450986d76319243 (patch) | |
tree | 204ee0a1ac88f41e03cbff14d9e50c4f43e69a4a /src | |
parent | 2c2fd4946f96e6839ecbfb4cf61318d8910e7e8f (diff) |
assert hash types for Git and Mercurial
Diffstat (limited to 'src')
-rw-r--r-- | src/libfetchers/git.cc | 8 | ||||
-rw-r--r-- | src/libfetchers/mercurial.cc | 9 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index d75c5d3ae..220442479 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -189,8 +189,16 @@ struct GitInputScheme : InputScheme if (submodules) cacheType += "-submodules"; if (allRefs) cacheType += "-all-refs"; + auto checkHashType = [&](const std::optional<Hash> & hash) + { + if (hash.has_value() && !(hash->type == htSHA1 || hash->type == htSHA256)) + throw Error("Hash '%s' is not supported by Git. Supported types are sha1 and sha256.", hash->to_string(Base16, true)); + }; + auto getLockedAttrs = [&]() { + checkHashType(input.getRev()); + return Attrs({ {"type", cacheType}, {"name", name}, diff --git a/src/libfetchers/mercurial.cc b/src/libfetchers/mercurial.cc index 8b82e9daa..19ff98030 100644 --- a/src/libfetchers/mercurial.cc +++ b/src/libfetchers/mercurial.cc @@ -201,8 +201,17 @@ struct MercurialInputScheme : InputScheme if (!input.getRef()) input.attrs.insert_or_assign("ref", "default"); + auto checkHashType = [&](const std::optional<Hash> & hash) + { + if (hash.has_value() && hash->type != htSHA1) + throw Error("Hash '%s' is not supported by Mercurial. Only sha1 is supported.", hash->to_string(Base16, true)); + }; + + auto getLockedAttrs = [&]() { + checkHashType(input.getRev()); + return Attrs({ {"type", "hg"}, {"name", name}, |