mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 23:36:16 +02:00
HashType: Rename to HashAlgorithm
To be consistent with CLI, nix API and many other references. As part of this, we also converted it to a scoped enum. https://github.com/NixOS/nix/issues/8876
This commit is contained in:
parent
0c2d5f7673
commit
5334c9c792
64 changed files with 450 additions and 450 deletions
|
@ -205,7 +205,7 @@ void importPaths(int fd, int dontCheckSigs)
|
||||||
SV * hashPath(char * algo, int base32, char * path)
|
SV * hashPath(char * algo, int base32, char * path)
|
||||||
PPCODE:
|
PPCODE:
|
||||||
try {
|
try {
|
||||||
Hash h = hashPath(parseHashType(algo), path).first;
|
Hash h = hashPath(parseHashAlgo(algo), path).first;
|
||||||
auto s = h.to_string(base32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
auto s = h.to_string(base32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
||||||
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
@ -216,7 +216,7 @@ SV * hashPath(char * algo, int base32, char * path)
|
||||||
SV * hashFile(char * algo, int base32, char * path)
|
SV * hashFile(char * algo, int base32, char * path)
|
||||||
PPCODE:
|
PPCODE:
|
||||||
try {
|
try {
|
||||||
Hash h = hashFile(parseHashType(algo), path);
|
Hash h = hashFile(parseHashAlgo(algo), path);
|
||||||
auto s = h.to_string(base32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
auto s = h.to_string(base32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
||||||
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
@ -227,7 +227,7 @@ SV * hashFile(char * algo, int base32, char * path)
|
||||||
SV * hashString(char * algo, int base32, char * s)
|
SV * hashString(char * algo, int base32, char * s)
|
||||||
PPCODE:
|
PPCODE:
|
||||||
try {
|
try {
|
||||||
Hash h = hashString(parseHashType(algo), s);
|
Hash h = hashString(parseHashAlgo(algo), s);
|
||||||
auto s = h.to_string(base32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
auto s = h.to_string(base32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
||||||
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
@ -238,7 +238,7 @@ SV * hashString(char * algo, int base32, char * s)
|
||||||
SV * convertHash(char * algo, char * s, int toBase32)
|
SV * convertHash(char * algo, char * s, int toBase32)
|
||||||
PPCODE:
|
PPCODE:
|
||||||
try {
|
try {
|
||||||
auto h = Hash::parseAny(s, parseHashType(algo));
|
auto h = Hash::parseAny(s, parseHashAlgo(algo));
|
||||||
auto s = h.to_string(toBase32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
auto s = h.to_string(toBase32 ? HashFormat::Base32 : HashFormat::Base16, false);
|
||||||
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
XPUSHs(sv_2mortal(newSVpv(s.c_str(), 0)));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
|
@ -281,7 +281,7 @@ SV * addToStore(char * srcPath, int recursive, char * algo)
|
||||||
PPCODE:
|
PPCODE:
|
||||||
try {
|
try {
|
||||||
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
||||||
auto path = store()->addToStore(std::string(baseNameOf(srcPath)), srcPath, method, parseHashType(algo));
|
auto path = store()->addToStore(std::string(baseNameOf(srcPath)), srcPath, method, parseHashAlgo(algo));
|
||||||
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(path).c_str(), 0)));
|
XPUSHs(sv_2mortal(newSVpv(store()->printStorePath(path).c_str(), 0)));
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
croak("%s", e.what());
|
croak("%s", e.what());
|
||||||
|
@ -291,7 +291,7 @@ SV * addToStore(char * srcPath, int recursive, char * algo)
|
||||||
SV * makeFixedOutputPath(int recursive, char * algo, char * hash, char * name)
|
SV * makeFixedOutputPath(int recursive, char * algo, char * hash, char * name)
|
||||||
PPCODE:
|
PPCODE:
|
||||||
try {
|
try {
|
||||||
auto h = Hash::parseAny(hash, parseHashType(algo));
|
auto h = Hash::parseAny(hash, parseHashAlgo(algo));
|
||||||
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
auto method = recursive ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
||||||
auto path = store()->makeFixedOutputPath(name, FixedOutputInfo {
|
auto path = store()->makeFixedOutputPath(name, FixedOutputInfo {
|
||||||
.method = method,
|
.method = method,
|
||||||
|
|
|
@ -904,7 +904,7 @@ Fingerprint LockedFlake::getFingerprint() const
|
||||||
// FIXME: as an optimization, if the flake contains a lock file
|
// FIXME: as an optimization, if the flake contains a lock file
|
||||||
// and we haven't changed it, then it's sufficient to use
|
// and we haven't changed it, then it's sufficient to use
|
||||||
// flake.sourceInfo.storePath for the fingerprint.
|
// flake.sourceInfo.storePath for the fingerprint.
|
||||||
return hashString(htSHA256,
|
return hashString(HashAlgorithm::SHA256,
|
||||||
fmt("%s;%s;%d;%d;%s",
|
fmt("%s;%s;%d;%d;%s",
|
||||||
flake.storePath.to_string(),
|
flake.storePath.to_string(),
|
||||||
flake.lockedRef.subdir,
|
flake.lockedRef.subdir,
|
||||||
|
|
|
@ -1317,7 +1317,7 @@ drvName, Bindings * attrs, Value & v)
|
||||||
.errPos = state.positions[noPos]
|
.errPos = state.positions[noPos]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
auto h = newHashAllowEmpty(*outputHash, parseHashTypeOpt(outputHashAlgo));
|
auto h = newHashAllowEmpty(*outputHash, parseHashAlgoOpt(outputHashAlgo));
|
||||||
|
|
||||||
auto method = ingestionMethod.value_or(FileIngestionMethod::Flat);
|
auto method = ingestionMethod.value_or(FileIngestionMethod::Flat);
|
||||||
|
|
||||||
|
@ -1339,7 +1339,7 @@ drvName, Bindings * attrs, Value & v)
|
||||||
.errPos = state.positions[noPos]
|
.errPos = state.positions[noPos]
|
||||||
});
|
});
|
||||||
|
|
||||||
auto ht = parseHashTypeOpt(outputHashAlgo).value_or(htSHA256);
|
auto ht = parseHashAlgoOpt(outputHashAlgo).value_or(HashAlgorithm::SHA256);
|
||||||
auto method = ingestionMethod.value_or(FileIngestionMethod::Recursive);
|
auto method = ingestionMethod.value_or(FileIngestionMethod::Recursive);
|
||||||
|
|
||||||
for (auto & i : outputs) {
|
for (auto & i : outputs) {
|
||||||
|
@ -1348,13 +1348,13 @@ drvName, Bindings * attrs, Value & v)
|
||||||
drv.outputs.insert_or_assign(i,
|
drv.outputs.insert_or_assign(i,
|
||||||
DerivationOutput::Impure {
|
DerivationOutput::Impure {
|
||||||
.method = method,
|
.method = method,
|
||||||
.hashType = ht,
|
.hashAlgo = ht,
|
||||||
});
|
});
|
||||||
else
|
else
|
||||||
drv.outputs.insert_or_assign(i,
|
drv.outputs.insert_or_assign(i,
|
||||||
DerivationOutput::CAFloating {
|
DerivationOutput::CAFloating {
|
||||||
.method = method,
|
.method = method,
|
||||||
.hashType = ht,
|
.hashAlgo = ht,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1754,17 +1754,17 @@ static RegisterPrimOp primop_findFile(PrimOp {
|
||||||
/* Return the cryptographic hash of a file in base-16. */
|
/* Return the cryptographic hash of a file in base-16. */
|
||||||
static void prim_hashFile(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_hashFile(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
auto type = state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.hashFile");
|
auto algo = state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.hashFile");
|
||||||
std::optional<HashType> ht = parseHashType(type);
|
std::optional<HashAlgorithm> ha = parseHashAlgo(algo);
|
||||||
if (!ht)
|
if (!ha)
|
||||||
state.debugThrowLastTrace(Error({
|
state.debugThrowLastTrace(Error({
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash algo '%1%'", algo),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
auto path = realisePath(state, pos, *args[1]);
|
auto path = realisePath(state, pos, *args[1]);
|
||||||
|
|
||||||
v.mkString(hashString(*ht, path.readFile()).to_string(HashFormat::Base16, false));
|
v.mkString(hashString(*ha, path.readFile()).to_string(HashFormat::Base16, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_hashFile({
|
static RegisterPrimOp primop_hashFile({
|
||||||
|
@ -2341,7 +2341,7 @@ static void prim_path(EvalState & state, const PosIdx pos, Value * * args, Value
|
||||||
else if (n == "recursive")
|
else if (n == "recursive")
|
||||||
method = FileIngestionMethod { state.forceBool(*attr.value, attr.pos, "while evaluating the `recursive` attribute passed to builtins.path") };
|
method = FileIngestionMethod { state.forceBool(*attr.value, attr.pos, "while evaluating the `recursive` attribute passed to builtins.path") };
|
||||||
else if (n == "sha256")
|
else if (n == "sha256")
|
||||||
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the `sha256` attribute passed to builtins.path"), htSHA256);
|
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the `sha256` attribute passed to builtins.path"), HashAlgorithm::SHA256);
|
||||||
else
|
else
|
||||||
state.debugThrowLastTrace(EvalError({
|
state.debugThrowLastTrace(EvalError({
|
||||||
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", state.symbols[attr.name]),
|
.msg = hintfmt("unsupported argument '%1%' to 'addPath'", state.symbols[attr.name]),
|
||||||
|
@ -3766,18 +3766,18 @@ static RegisterPrimOp primop_stringLength({
|
||||||
/* Return the cryptographic hash of a string in base-16. */
|
/* Return the cryptographic hash of a string in base-16. */
|
||||||
static void prim_hashString(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
static void prim_hashString(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
auto type = state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.hashString");
|
auto algo = state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.hashString");
|
||||||
std::optional<HashType> ht = parseHashType(type);
|
std::optional<HashAlgorithm> ha = parseHashAlgo(algo);
|
||||||
if (!ht)
|
if (!ha)
|
||||||
state.debugThrowLastTrace(Error({
|
state.debugThrowLastTrace(Error({
|
||||||
.msg = hintfmt("unknown hash type '%1%'", type),
|
.msg = hintfmt("unknown hash algo '%1%'", algo),
|
||||||
.errPos = state.positions[pos]
|
.errPos = state.positions[pos]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
NixStringContext context; // discarded
|
NixStringContext context; // discarded
|
||||||
auto s = state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.hashString");
|
auto s = state.forceString(*args[1], context, pos, "while evaluating the second argument passed to builtins.hashString");
|
||||||
|
|
||||||
v.mkString(hashString(*ht, s).to_string(HashFormat::Base16, false));
|
v.mkString(hashString(*ha, s).to_string(HashFormat::Base16, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_hashString({
|
static RegisterPrimOp primop_hashString({
|
||||||
|
@ -3800,15 +3800,15 @@ static void prim_convertHash(EvalState & state, const PosIdx pos, Value * * args
|
||||||
auto hash = state.forceStringNoCtx(*iteratorHash->value, pos, "while evaluating the attribute 'hash'");
|
auto hash = state.forceStringNoCtx(*iteratorHash->value, pos, "while evaluating the attribute 'hash'");
|
||||||
|
|
||||||
Bindings::iterator iteratorHashAlgo = inputAttrs->find(state.symbols.create("hashAlgo"));
|
Bindings::iterator iteratorHashAlgo = inputAttrs->find(state.symbols.create("hashAlgo"));
|
||||||
std::optional<HashType> ht = std::nullopt;
|
std::optional<HashAlgorithm> ha = std::nullopt;
|
||||||
if (iteratorHashAlgo != inputAttrs->end()) {
|
if (iteratorHashAlgo != inputAttrs->end()) {
|
||||||
ht = parseHashType(state.forceStringNoCtx(*iteratorHashAlgo->value, pos, "while evaluating the attribute 'hashAlgo'"));
|
ha = parseHashAlgo(state.forceStringNoCtx(*iteratorHashAlgo->value, pos, "while evaluating the attribute 'hashAlgo'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Bindings::iterator iteratorToHashFormat = getAttr(state, state.symbols.create("toHashFormat"), args[0]->attrs, "while locating the attribute 'toHashFormat'");
|
Bindings::iterator iteratorToHashFormat = getAttr(state, state.symbols.create("toHashFormat"), args[0]->attrs, "while locating the attribute 'toHashFormat'");
|
||||||
HashFormat hf = parseHashFormat(state.forceStringNoCtx(*iteratorToHashFormat->value, pos, "while evaluating the attribute 'toHashFormat'"));
|
HashFormat hf = parseHashFormat(state.forceStringNoCtx(*iteratorToHashFormat->value, pos, "while evaluating the attribute 'toHashFormat'"));
|
||||||
|
|
||||||
v.mkString(Hash::parseAny(hash, ht).to_string(hf, hf == HashFormat::SRI));
|
v.mkString(Hash::parseAny(hash, ha).to_string(hf, hf == HashFormat::SRI));
|
||||||
}
|
}
|
||||||
|
|
||||||
static RegisterPrimOp primop_convertHash({
|
static RegisterPrimOp primop_convertHash({
|
||||||
|
|
|
@ -31,7 +31,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a
|
||||||
// be both a revision or a branch/tag name.
|
// be both a revision or a branch/tag name.
|
||||||
auto value = state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the `rev` attribute passed to builtins.fetchMercurial");
|
auto value = state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the `rev` attribute passed to builtins.fetchMercurial");
|
||||||
if (std::regex_match(value.begin(), value.end(), revRegex))
|
if (std::regex_match(value.begin(), value.end(), revRegex))
|
||||||
rev = Hash::parseAny(value, htSHA1);
|
rev = Hash::parseAny(value, HashAlgorithm::SHA1);
|
||||||
else
|
else
|
||||||
ref = value;
|
ref = value;
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ static void prim_fetchMercurial(EvalState & state, const PosIdx pos, Value * * a
|
||||||
attrs2.alloc("branch").mkString(*input2.getRef());
|
attrs2.alloc("branch").mkString(*input2.getRef());
|
||||||
// Backward compatibility: set 'rev' to
|
// Backward compatibility: set 'rev' to
|
||||||
// 0000000000000000000000000000000000000000 for a dirty tree.
|
// 0000000000000000000000000000000000000000 for a dirty tree.
|
||||||
auto rev2 = input2.getRev().value_or(Hash(htSHA1));
|
auto rev2 = input2.getRev().value_or(Hash(HashAlgorithm::SHA1));
|
||||||
attrs2.alloc("rev").mkString(rev2.gitRev());
|
attrs2.alloc("rev").mkString(rev2.gitRev());
|
||||||
attrs2.alloc("shortRev").mkString(rev2.gitRev().substr(0, 12));
|
attrs2.alloc("shortRev").mkString(rev2.gitRev().substr(0, 12));
|
||||||
if (auto revCount = input2.getRevCount())
|
if (auto revCount = input2.getRevCount())
|
||||||
|
|
|
@ -46,7 +46,7 @@ void emitTreeAttrs(
|
||||||
attrs.alloc("shortRev").mkString(rev->gitShortRev());
|
attrs.alloc("shortRev").mkString(rev->gitShortRev());
|
||||||
} else if (emptyRevFallback) {
|
} else if (emptyRevFallback) {
|
||||||
// Backwards compat for `builtins.fetchGit`: dirty repos return an empty sha1 as rev
|
// Backwards compat for `builtins.fetchGit`: dirty repos return an empty sha1 as rev
|
||||||
auto emptyHash = Hash(htSHA1);
|
auto emptyHash = Hash(HashAlgorithm::SHA1);
|
||||||
attrs.alloc("rev").mkString(emptyHash.gitRev());
|
attrs.alloc("rev").mkString(emptyHash.gitRev());
|
||||||
attrs.alloc("shortRev").mkString(emptyHash.gitShortRev());
|
attrs.alloc("shortRev").mkString(emptyHash.gitShortRev());
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
if (n == "url")
|
if (n == "url")
|
||||||
url = state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the url we should fetch");
|
url = state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the url we should fetch");
|
||||||
else if (n == "sha256")
|
else if (n == "sha256")
|
||||||
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the sha256 of the content we should fetch"), htSHA256);
|
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the sha256 of the content we should fetch"), HashAlgorithm::SHA256);
|
||||||
else if (n == "name")
|
else if (n == "name")
|
||||||
name = state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the name of the content we should fetch");
|
name = state.forceStringNoCtx(*attr.value, attr.pos, "while evaluating the name of the content we should fetch");
|
||||||
else
|
else
|
||||||
|
@ -276,7 +276,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
state.debugThrowLastTrace(EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who));
|
state.debugThrowLastTrace(EvalError("in pure evaluation mode, '%s' requires a 'sha256' argument", who));
|
||||||
|
|
||||||
// early exit if pinned and already in the store
|
// early exit if pinned and already in the store
|
||||||
if (expectedHash && expectedHash->type == htSHA256) {
|
if (expectedHash && expectedHash->algo == HashAlgorithm::SHA256) {
|
||||||
auto expectedPath = state.store->makeFixedOutputPath(
|
auto expectedPath = state.store->makeFixedOutputPath(
|
||||||
name,
|
name,
|
||||||
FixedOutputInfo {
|
FixedOutputInfo {
|
||||||
|
@ -301,7 +301,7 @@ static void fetch(EvalState & state, const PosIdx pos, Value * * args, Value & v
|
||||||
if (expectedHash) {
|
if (expectedHash) {
|
||||||
auto hash = unpack
|
auto hash = unpack
|
||||||
? state.store->queryPathInfo(storePath)->narHash
|
? state.store->queryPathInfo(storePath)->narHash
|
||||||
: hashFile(htSHA256, state.store->toRealPath(storePath));
|
: hashFile(HashAlgorithm::SHA256, state.store->toRealPath(storePath));
|
||||||
if (hash != *expectedHash)
|
if (hash != *expectedHash)
|
||||||
state.debugThrowLastTrace(EvalError((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
|
state.debugThrowLastTrace(EvalError((unsigned int) 102, "hash mismatch in file downloaded from '%s':\n specified: %s\n got: %s",
|
||||||
*url, expectedHash->to_string(HashFormat::Base32, true), hash.to_string(HashFormat::Base32, true)));
|
*url, expectedHash->to_string(HashFormat::Base32, true), hash.to_string(HashFormat::Base32, true)));
|
||||||
|
|
|
@ -289,8 +289,8 @@ std::string Input::getType() const
|
||||||
std::optional<Hash> Input::getNarHash() const
|
std::optional<Hash> Input::getNarHash() const
|
||||||
{
|
{
|
||||||
if (auto s = maybeGetStrAttr(attrs, "narHash")) {
|
if (auto s = maybeGetStrAttr(attrs, "narHash")) {
|
||||||
auto hash = s->empty() ? Hash(htSHA256) : Hash::parseSRI(*s);
|
auto hash = s->empty() ? Hash(HashAlgorithm::SHA256) : Hash::parseSRI(*s);
|
||||||
if (hash.type != htSHA256)
|
if (hash.algo != HashAlgorithm::SHA256)
|
||||||
throw UsageError("narHash must use SHA-256");
|
throw UsageError("narHash must use SHA-256");
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +314,7 @@ std::optional<Hash> Input::getRev() const
|
||||||
} catch (BadHash &e) {
|
} catch (BadHash &e) {
|
||||||
// Default to sha1 for backwards compatibility with existing
|
// Default to sha1 for backwards compatibility with existing
|
||||||
// usages (e.g. `builtins.fetchTree` calls or flake inputs).
|
// usages (e.g. `builtins.fetchTree` calls or flake inputs).
|
||||||
hash = Hash::parseAny(*s, htSHA1);
|
hash = Hash::parseAny(*s, HashAlgorithm::SHA1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ Hash toHash(const git_oid & oid)
|
||||||
#ifdef GIT_EXPERIMENTAL_SHA256
|
#ifdef GIT_EXPERIMENTAL_SHA256
|
||||||
assert(oid.type == GIT_OID_SHA1);
|
assert(oid.type == GIT_OID_SHA1);
|
||||||
#endif
|
#endif
|
||||||
Hash hash(htSHA1);
|
Hash hash(HashAlgorithm::SHA1);
|
||||||
memcpy(hash.hash, oid.id, hash.hashSize);
|
memcpy(hash.hash, oid.id, hash.hashSize);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +439,7 @@ struct GitRepoImpl : GitRepo, std::enable_shared_from_this<GitRepoImpl>
|
||||||
std::string re = R"(Good "git" signature for \* with .* key SHA256:[)";
|
std::string re = R"(Good "git" signature for \* with .* key SHA256:[)";
|
||||||
for (const fetchers::PublicKey & k : publicKeys){
|
for (const fetchers::PublicKey & k : publicKeys){
|
||||||
// Calculate sha256 fingerprint from public key and escape the regex symbol '+' to match the key literally
|
// Calculate sha256 fingerprint from public key and escape the regex symbol '+' to match the key literally
|
||||||
auto fingerprint = trim(hashString(htSHA256, base64Decode(k.key)).to_string(nix::HashFormat::Base64, false), "=");
|
auto fingerprint = trim(hashString(HashAlgorithm::SHA256, base64Decode(k.key)).to_string(nix::HashFormat::Base64, false), "=");
|
||||||
auto escaped_fingerprint = std::regex_replace(fingerprint, std::regex("\\+"), "\\+" );
|
auto escaped_fingerprint = std::regex_replace(fingerprint, std::regex("\\+"), "\\+" );
|
||||||
re += "(" + escaped_fingerprint + ")";
|
re += "(" + escaped_fingerprint + ")";
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,7 @@ bool touchCacheFile(const Path & path, time_t touch_time)
|
||||||
Path getCachePath(std::string_view key)
|
Path getCachePath(std::string_view key)
|
||||||
{
|
{
|
||||||
return getCacheDir() + "/nix/gitv3/" +
|
return getCacheDir() + "/nix/gitv3/" +
|
||||||
hashString(htSHA256, key).to_string(HashFormat::Base32, false);
|
hashString(HashAlgorithm::SHA256, key).to_string(HashFormat::Base32, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the name of the HEAD branch.
|
// Returns the name of the HEAD branch.
|
||||||
|
@ -369,7 +369,7 @@ struct GitInputScheme : InputScheme
|
||||||
{
|
{
|
||||||
auto checkHashType = [&](const std::optional<Hash> & hash)
|
auto checkHashType = [&](const std::optional<Hash> & hash)
|
||||||
{
|
{
|
||||||
if (hash.has_value() && !(hash->type == htSHA1 || hash->type == htSHA256))
|
if (hash.has_value() && !(hash->algo == HashAlgorithm::SHA1 || hash->algo == HashAlgorithm::SHA256))
|
||||||
throw Error("Hash '%s' is not supported by Git. Supported types are sha1 and sha256.", hash->to_string(HashFormat::Base16, true));
|
throw Error("Hash '%s' is not supported by Git. Supported types are sha1 and sha256.", hash->to_string(HashFormat::Base16, true));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -559,7 +559,7 @@ struct GitInputScheme : InputScheme
|
||||||
repoInfo.url
|
repoInfo.url
|
||||||
);
|
);
|
||||||
} else
|
} else
|
||||||
input.attrs.insert_or_assign("rev", Hash::parseAny(chomp(readFile(localRefFile)), htSHA1).gitRev());
|
input.attrs.insert_or_assign("rev", Hash::parseAny(chomp(readFile(localRefFile)), HashAlgorithm::SHA1).gitRev());
|
||||||
|
|
||||||
// cache dir lock is removed at scope end; we will only use read-only operations on specific revisions in the remainder
|
// cache dir lock is removed at scope end; we will only use read-only operations on specific revisions in the remainder
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct GitArchiveInputScheme : InputScheme
|
||||||
auto size = path.size();
|
auto size = path.size();
|
||||||
if (size == 3) {
|
if (size == 3) {
|
||||||
if (std::regex_match(path[2], revRegex))
|
if (std::regex_match(path[2], revRegex))
|
||||||
rev = Hash::parseAny(path[2], htSHA1);
|
rev = Hash::parseAny(path[2], HashAlgorithm::SHA1);
|
||||||
else if (std::regex_match(path[2], refRegex))
|
else if (std::regex_match(path[2], refRegex))
|
||||||
ref = path[2];
|
ref = path[2];
|
||||||
else
|
else
|
||||||
|
@ -68,7 +68,7 @@ struct GitArchiveInputScheme : InputScheme
|
||||||
if (name == "rev") {
|
if (name == "rev") {
|
||||||
if (rev)
|
if (rev)
|
||||||
throw BadURL("URL '%s' contains multiple commit hashes", url.url);
|
throw BadURL("URL '%s' contains multiple commit hashes", url.url);
|
||||||
rev = Hash::parseAny(value, htSHA1);
|
rev = Hash::parseAny(value, HashAlgorithm::SHA1);
|
||||||
}
|
}
|
||||||
else if (name == "ref") {
|
else if (name == "ref") {
|
||||||
if (!std::regex_match(value, refRegex))
|
if (!std::regex_match(value, refRegex))
|
||||||
|
@ -284,7 +284,7 @@ struct GitHubInputScheme : GitArchiveInputScheme
|
||||||
readFile(
|
readFile(
|
||||||
store->toRealPath(
|
store->toRealPath(
|
||||||
downloadFile(store, url, "source", false, headers).storePath)));
|
downloadFile(store, url, "source", false, headers).storePath)));
|
||||||
auto rev = Hash::parseAny(std::string { json["sha"] }, htSHA1);
|
auto rev = Hash::parseAny(std::string { json["sha"] }, HashAlgorithm::SHA1);
|
||||||
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
|
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +356,7 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
||||||
readFile(
|
readFile(
|
||||||
store->toRealPath(
|
store->toRealPath(
|
||||||
downloadFile(store, url, "source", false, headers).storePath)));
|
downloadFile(store, url, "source", false, headers).storePath)));
|
||||||
auto rev = Hash::parseAny(std::string(json[0]["id"]), htSHA1);
|
auto rev = Hash::parseAny(std::string(json[0]["id"]), HashAlgorithm::SHA1);
|
||||||
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
|
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ struct SourceHutInputScheme : GitArchiveInputScheme
|
||||||
if(!id)
|
if(!id)
|
||||||
throw BadURL("in '%d', couldn't find ref '%d'", input.to_string(), ref);
|
throw BadURL("in '%d', couldn't find ref '%d'", input.to_string(), ref);
|
||||||
|
|
||||||
auto rev = Hash::parseAny(*id, htSHA1);
|
auto rev = Hash::parseAny(*id, HashAlgorithm::SHA1);
|
||||||
debug("HEAD revision for '%s' is %s", fmt("%s/%s", base_url, ref), rev.gitRev());
|
debug("HEAD revision for '%s' is %s", fmt("%s/%s", base_url, ref), rev.gitRev());
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ struct IndirectInputScheme : InputScheme
|
||||||
if (path.size() == 1) {
|
if (path.size() == 1) {
|
||||||
} else if (path.size() == 2) {
|
} else if (path.size() == 2) {
|
||||||
if (std::regex_match(path[1], revRegex))
|
if (std::regex_match(path[1], revRegex))
|
||||||
rev = Hash::parseAny(path[1], htSHA1);
|
rev = Hash::parseAny(path[1], HashAlgorithm::SHA1);
|
||||||
else if (std::regex_match(path[1], refRegex))
|
else if (std::regex_match(path[1], refRegex))
|
||||||
ref = path[1];
|
ref = path[1];
|
||||||
else
|
else
|
||||||
|
@ -31,7 +31,7 @@ struct IndirectInputScheme : InputScheme
|
||||||
ref = path[1];
|
ref = path[1];
|
||||||
if (!std::regex_match(path[2], revRegex))
|
if (!std::regex_match(path[2], revRegex))
|
||||||
throw BadURL("in flake URL '%s', '%s' is not a commit hash", url.url, path[2]);
|
throw BadURL("in flake URL '%s', '%s' is not a commit hash", url.url, path[2]);
|
||||||
rev = Hash::parseAny(path[2], htSHA1);
|
rev = Hash::parseAny(path[2], HashAlgorithm::SHA1);
|
||||||
} else
|
} else
|
||||||
throw BadURL("GitHub URL '%s' is invalid", url.url);
|
throw BadURL("GitHub URL '%s' is invalid", url.url);
|
||||||
|
|
||||||
|
|
|
@ -44,8 +44,8 @@ StorePath InputAccessor::fetchToStore(
|
||||||
|
|
||||||
auto storePath =
|
auto storePath =
|
||||||
settings.readOnlyMode
|
settings.readOnlyMode
|
||||||
? store->computeStorePathFromDump(*source, name, method, htSHA256).first
|
? store->computeStorePathFromDump(*source, name, method, HashAlgorithm::SHA256).first
|
||||||
: store->addToStoreFromDump(*source, name, method, htSHA256, repair);
|
: store->addToStoreFromDump(*source, name, method, HashAlgorithm::SHA256, repair);
|
||||||
|
|
||||||
if (cacheKey)
|
if (cacheKey)
|
||||||
fetchers::getCache()->add(store, *cacheKey, {}, storePath, true);
|
fetchers::getCache()->add(store, *cacheKey, {}, storePath, true);
|
||||||
|
|
|
@ -210,7 +210,7 @@ struct MercurialInputScheme : InputScheme
|
||||||
return files.count(file);
|
return files.count(file);
|
||||||
};
|
};
|
||||||
|
|
||||||
auto storePath = store->addToStore(input.getName(), actualPath, FileIngestionMethod::Recursive, htSHA256, filter);
|
auto storePath = store->addToStore(input.getName(), actualPath, FileIngestionMethod::Recursive, HashAlgorithm::SHA256, filter);
|
||||||
|
|
||||||
return {std::move(storePath), input};
|
return {std::move(storePath), input};
|
||||||
}
|
}
|
||||||
|
@ -220,7 +220,7 @@ struct MercurialInputScheme : InputScheme
|
||||||
|
|
||||||
auto checkHashType = [&](const std::optional<Hash> & hash)
|
auto checkHashType = [&](const std::optional<Hash> & hash)
|
||||||
{
|
{
|
||||||
if (hash.has_value() && hash->type != htSHA1)
|
if (hash.has_value() && hash->algo != HashAlgorithm::SHA1)
|
||||||
throw Error("Hash '%s' is not supported by Mercurial. Only sha1 is supported.", hash->to_string(HashFormat::Base16, true));
|
throw Error("Hash '%s' is not supported by Mercurial. Only sha1 is supported.", hash->to_string(HashFormat::Base16, true));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -260,14 +260,14 @@ struct MercurialInputScheme : InputScheme
|
||||||
});
|
});
|
||||||
|
|
||||||
if (auto res = getCache()->lookup(store, unlockedAttrs)) {
|
if (auto res = getCache()->lookup(store, unlockedAttrs)) {
|
||||||
auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), htSHA1);
|
auto rev2 = Hash::parseAny(getStrAttr(res->first, "rev"), HashAlgorithm::SHA1);
|
||||||
if (!input.getRev() || input.getRev() == rev2) {
|
if (!input.getRev() || input.getRev() == rev2) {
|
||||||
input.attrs.insert_or_assign("rev", rev2.gitRev());
|
input.attrs.insert_or_assign("rev", rev2.gitRev());
|
||||||
return makeResult(res->first, std::move(res->second));
|
return makeResult(res->first, std::move(res->second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(htSHA256, actualUrl).to_string(HashFormat::Base32, false));
|
Path cacheDir = fmt("%s/nix/hg/%s", getCacheDir(), hashString(HashAlgorithm::SHA256, actualUrl).to_string(HashFormat::Base32, false));
|
||||||
|
|
||||||
/* If this is a commit hash that we already have, we don't
|
/* If this is a commit hash that we already have, we don't
|
||||||
have to pull again. */
|
have to pull again. */
|
||||||
|
@ -301,7 +301,7 @@ struct MercurialInputScheme : InputScheme
|
||||||
runHg({ "log", "-R", cacheDir, "-r", revOrRef, "--template", "{node} {rev} {branch}" }));
|
runHg({ "log", "-R", cacheDir, "-r", revOrRef, "--template", "{node} {rev} {branch}" }));
|
||||||
assert(tokens.size() == 3);
|
assert(tokens.size() == 3);
|
||||||
|
|
||||||
input.attrs.insert_or_assign("rev", Hash::parseAny(tokens[0], htSHA1).gitRev());
|
input.attrs.insert_or_assign("rev", Hash::parseAny(tokens[0], HashAlgorithm::SHA1).gitRev());
|
||||||
auto revCount = std::stoull(tokens[1]);
|
auto revCount = std::stoull(tokens[1]);
|
||||||
input.attrs.insert_or_assign("ref", tokens[2]);
|
input.attrs.insert_or_assign("ref", tokens[2]);
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ DownloadFileResult downloadFile(
|
||||||
} else {
|
} else {
|
||||||
StringSink sink;
|
StringSink sink;
|
||||||
dumpString(res.data, sink);
|
dumpString(res.data, sink);
|
||||||
auto hash = hashString(htSHA256, res.data);
|
auto hash = hashString(HashAlgorithm::SHA256, res.data);
|
||||||
ValidPathInfo info {
|
ValidPathInfo info {
|
||||||
*store,
|
*store,
|
||||||
name,
|
name,
|
||||||
|
@ -82,7 +82,7 @@ DownloadFileResult downloadFile(
|
||||||
.hash = hash,
|
.hash = hash,
|
||||||
.references = {},
|
.references = {},
|
||||||
},
|
},
|
||||||
hashString(htSHA256, sink.s),
|
hashString(HashAlgorithm::SHA256, sink.s),
|
||||||
};
|
};
|
||||||
info.narSize = sink.s.size();
|
info.narSize = sink.s.size();
|
||||||
auto source = StringSource { sink.s };
|
auto source = StringSource { sink.s };
|
||||||
|
@ -156,7 +156,7 @@ DownloadTarballResult downloadTarball(
|
||||||
throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url);
|
throw nix::Error("tarball '%s' contains an unexpected number of top-level files", url);
|
||||||
auto topDir = tmpDir + "/" + members.begin()->name;
|
auto topDir = tmpDir + "/" + members.begin()->name;
|
||||||
lastModified = lstat(topDir).st_mtime;
|
lastModified = lstat(topDir).st_mtime;
|
||||||
unpackedStorePath = store->addToStore(name, topDir, FileIngestionMethod::Recursive, htSHA256, defaultPathFilter, NoRepair);
|
unpackedStorePath = store->addToStore(name, topDir, FileIngestionMethod::Recursive, HashAlgorithm::SHA256, defaultPathFilter, NoRepair);
|
||||||
}
|
}
|
||||||
|
|
||||||
Attrs infoAttrs({
|
Attrs infoAttrs({
|
||||||
|
|
|
@ -143,9 +143,9 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
|
||||||
/* Read the NAR simultaneously into a CompressionSink+FileSink (to
|
/* Read the NAR simultaneously into a CompressionSink+FileSink (to
|
||||||
write the compressed NAR to disk), into a HashSink (to get the
|
write the compressed NAR to disk), into a HashSink (to get the
|
||||||
NAR hash), and into a NarAccessor (to get the NAR listing). */
|
NAR hash), and into a NarAccessor (to get the NAR listing). */
|
||||||
HashSink fileHashSink { htSHA256 };
|
HashSink fileHashSink { HashAlgorithm::SHA256 };
|
||||||
std::shared_ptr<SourceAccessor> narAccessor;
|
std::shared_ptr<SourceAccessor> narAccessor;
|
||||||
HashSink narHashSink { htSHA256 };
|
HashSink narHashSink { HashAlgorithm::SHA256 };
|
||||||
{
|
{
|
||||||
FdSink fileSink(fdTemp.get());
|
FdSink fileSink(fdTemp.get());
|
||||||
TeeSink teeSinkCompressed { fileSink, fileHashSink };
|
TeeSink teeSinkCompressed { fileSink, fileHashSink };
|
||||||
|
@ -301,9 +301,9 @@ void BinaryCacheStore::addToStore(const ValidPathInfo & info, Source & narSource
|
||||||
}
|
}
|
||||||
|
|
||||||
StorePath BinaryCacheStore::addToStoreFromDump(Source & dump, std::string_view name,
|
StorePath BinaryCacheStore::addToStoreFromDump(Source & dump, std::string_view name,
|
||||||
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references)
|
FileIngestionMethod method, HashAlgorithm hashAlgo, RepairFlag repair, const StorePathSet & references)
|
||||||
{
|
{
|
||||||
if (method != FileIngestionMethod::Recursive || hashAlgo != htSHA256)
|
if (method != FileIngestionMethod::Recursive || hashAlgo != HashAlgorithm::SHA256)
|
||||||
unsupported("addToStoreFromDump");
|
unsupported("addToStoreFromDump");
|
||||||
return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) {
|
return addToStoreCommon(dump, repair, CheckSigs, [&](HashResult nar) {
|
||||||
ValidPathInfo info {
|
ValidPathInfo info {
|
||||||
|
@ -399,13 +399,13 @@ void BinaryCacheStore::queryPathInfoUncached(const StorePath & storePath,
|
||||||
}
|
}
|
||||||
|
|
||||||
StorePath BinaryCacheStore::addToStore(
|
StorePath BinaryCacheStore::addToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
const Path & srcPath,
|
const Path & srcPath,
|
||||||
FileIngestionMethod method,
|
FileIngestionMethod method,
|
||||||
HashType hashAlgo,
|
HashAlgorithm hashAlgo,
|
||||||
PathFilter & filter,
|
PathFilter & filter,
|
||||||
RepairFlag repair,
|
RepairFlag repair,
|
||||||
const StorePathSet & references)
|
const StorePathSet & references)
|
||||||
{
|
{
|
||||||
/* FIXME: Make BinaryCacheStore::addToStoreCommon support
|
/* FIXME: Make BinaryCacheStore::addToStoreCommon support
|
||||||
non-recursive+sha256 so we can just use the default
|
non-recursive+sha256 so we can just use the default
|
||||||
|
@ -448,7 +448,7 @@ StorePath BinaryCacheStore::addTextToStore(
|
||||||
const StorePathSet & references,
|
const StorePathSet & references,
|
||||||
RepairFlag repair)
|
RepairFlag repair)
|
||||||
{
|
{
|
||||||
auto textHash = hashString(htSHA256, s);
|
auto textHash = hashString(HashAlgorithm::SHA256, s);
|
||||||
auto path = makeTextPath(name, TextInfo { { textHash }, references });
|
auto path = makeTextPath(name, TextInfo { { textHash }, references });
|
||||||
|
|
||||||
if (!repair && isValidPath(path))
|
if (!repair && isValidPath(path))
|
||||||
|
|
|
@ -124,16 +124,16 @@ public:
|
||||||
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
||||||
|
|
||||||
StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
||||||
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) override;
|
FileIngestionMethod method, HashAlgorithm hashAlgo, RepairFlag repair, const StorePathSet & references) override;
|
||||||
|
|
||||||
StorePath addToStore(
|
StorePath addToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
const Path & srcPath,
|
const Path & srcPath,
|
||||||
FileIngestionMethod method,
|
FileIngestionMethod method,
|
||||||
HashType hashAlgo,
|
HashAlgorithm hashAlgo,
|
||||||
PathFilter & filter,
|
PathFilter & filter,
|
||||||
RepairFlag repair,
|
RepairFlag repair,
|
||||||
const StorePathSet & references) override;
|
const StorePathSet & references) override;
|
||||||
|
|
||||||
StorePath addTextToStore(
|
StorePath addTextToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
|
|
|
@ -1066,7 +1066,7 @@ void LocalDerivationGoal::initTmpDir() {
|
||||||
if (passAsFile.find(i.first) == passAsFile.end()) {
|
if (passAsFile.find(i.first) == passAsFile.end()) {
|
||||||
env[i.first] = i.second;
|
env[i.first] = i.second;
|
||||||
} else {
|
} else {
|
||||||
auto hash = hashString(htSHA256, i.first);
|
auto hash = hashString(HashAlgorithm::SHA256, i.first);
|
||||||
std::string fn = ".attr-" + hash.to_string(HashFormat::Base32, false);
|
std::string fn = ".attr-" + hash.to_string(HashFormat::Base32, false);
|
||||||
Path p = tmpDir + "/" + fn;
|
Path p = tmpDir + "/" + fn;
|
||||||
writeFile(p, rewriteStrings(i.second, inputRewrites));
|
writeFile(p, rewriteStrings(i.second, inputRewrites));
|
||||||
|
@ -1290,13 +1290,13 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual In
|
||||||
{ throw Error("queryPathFromHashPart"); }
|
{ throw Error("queryPathFromHashPart"); }
|
||||||
|
|
||||||
StorePath addToStore(
|
StorePath addToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
const Path & srcPath,
|
const Path & srcPath,
|
||||||
FileIngestionMethod method,
|
FileIngestionMethod method,
|
||||||
HashType hashAlgo,
|
HashAlgorithm hashAlgo,
|
||||||
PathFilter & filter,
|
PathFilter & filter,
|
||||||
RepairFlag repair,
|
RepairFlag repair,
|
||||||
const StorePathSet & references) override
|
const StorePathSet & references) override
|
||||||
{ throw Error("addToStore"); }
|
{ throw Error("addToStore"); }
|
||||||
|
|
||||||
void addToStore(const ValidPathInfo & info, Source & narSource,
|
void addToStore(const ValidPathInfo & info, Source & narSource,
|
||||||
|
@ -1318,12 +1318,12 @@ struct RestrictedStore : public virtual RestrictedStoreConfig, public virtual In
|
||||||
}
|
}
|
||||||
|
|
||||||
StorePath addToStoreFromDump(
|
StorePath addToStoreFromDump(
|
||||||
Source & dump,
|
Source & dump,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
FileIngestionMethod method,
|
FileIngestionMethod method,
|
||||||
HashType hashAlgo,
|
HashAlgorithm hashAlgo,
|
||||||
RepairFlag repair,
|
RepairFlag repair,
|
||||||
const StorePathSet & references) override
|
const StorePathSet & references) override
|
||||||
{
|
{
|
||||||
auto path = next->addToStoreFromDump(dump, name, method, hashAlgo, repair, references);
|
auto path = next->addToStoreFromDump(dump, name, method, hashAlgo, repair, references);
|
||||||
goal.addDependency(path);
|
goal.addDependency(path);
|
||||||
|
@ -2466,7 +2466,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
rewriteOutput(outputRewrites);
|
rewriteOutput(outputRewrites);
|
||||||
/* FIXME optimize and deduplicate with addToStore */
|
/* FIXME optimize and deduplicate with addToStore */
|
||||||
std::string oldHashPart { scratchPath->hashPart() };
|
std::string oldHashPart { scratchPath->hashPart() };
|
||||||
HashModuloSink caSink { outputHash.hashType, oldHashPart };
|
HashModuloSink caSink {outputHash.hashAlgo, oldHashPart };
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](const TextIngestionMethod &) {
|
[&](const TextIngestionMethod &) {
|
||||||
readFile(actualPath, caSink);
|
readFile(actualPath, caSink);
|
||||||
|
@ -2511,7 +2511,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
std::string(newInfo0.path.hashPart())}});
|
std::string(newInfo0.path.hashPart())}});
|
||||||
}
|
}
|
||||||
|
|
||||||
HashResult narHashAndSize = hashPath(htSHA256, actualPath);
|
HashResult narHashAndSize = hashPath(HashAlgorithm::SHA256, actualPath);
|
||||||
newInfo0.narHash = narHashAndSize.first;
|
newInfo0.narHash = narHashAndSize.first;
|
||||||
newInfo0.narSize = narHashAndSize.second;
|
newInfo0.narSize = narHashAndSize.second;
|
||||||
|
|
||||||
|
@ -2531,7 +2531,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
std::string { scratchPath->hashPart() },
|
std::string { scratchPath->hashPart() },
|
||||||
std::string { requiredFinalPath.hashPart() });
|
std::string { requiredFinalPath.hashPart() });
|
||||||
rewriteOutput(outputRewrites);
|
rewriteOutput(outputRewrites);
|
||||||
auto narHashAndSize = hashPath(htSHA256, actualPath);
|
auto narHashAndSize = hashPath(HashAlgorithm::SHA256, actualPath);
|
||||||
ValidPathInfo newInfo0 { requiredFinalPath, narHashAndSize.first };
|
ValidPathInfo newInfo0 { requiredFinalPath, narHashAndSize.first };
|
||||||
newInfo0.narSize = narHashAndSize.second;
|
newInfo0.narSize = narHashAndSize.second;
|
||||||
auto refs = rewriteRefs();
|
auto refs = rewriteRefs();
|
||||||
|
@ -2546,7 +2546,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
|
|
||||||
auto newInfo0 = newInfoFromCA(DerivationOutput::CAFloating {
|
auto newInfo0 = newInfoFromCA(DerivationOutput::CAFloating {
|
||||||
.method = dof.ca.method,
|
.method = dof.ca.method,
|
||||||
.hashType = wanted.type,
|
.hashAlgo = wanted.algo,
|
||||||
});
|
});
|
||||||
|
|
||||||
/* Check wanted hash */
|
/* Check wanted hash */
|
||||||
|
@ -2583,7 +2583,7 @@ SingleDrvOutputs LocalDerivationGoal::registerOutputs()
|
||||||
[&](const DerivationOutput::Impure & doi) {
|
[&](const DerivationOutput::Impure & doi) {
|
||||||
return newInfoFromCA(DerivationOutput::CAFloating {
|
return newInfoFromCA(DerivationOutput::CAFloating {
|
||||||
.method = doi.method,
|
.method = doi.method,
|
||||||
.hashType = doi.hashType,
|
.hashAlgo = doi.hashAlgo,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -2945,7 +2945,7 @@ StorePath LocalDerivationGoal::makeFallbackPath(OutputNameView outputName)
|
||||||
{
|
{
|
||||||
return worker.store.makeStorePath(
|
return worker.store.makeStorePath(
|
||||||
"rewrite:" + std::string(drvPath.to_string()) + ":name:" + std::string(outputName),
|
"rewrite:" + std::string(drvPath.to_string()) + ":name:" + std::string(outputName),
|
||||||
Hash(htSHA256), outputPathName(drv->name, outputName));
|
Hash(HashAlgorithm::SHA256), outputPathName(drv->name, outputName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2953,7 +2953,7 @@ StorePath LocalDerivationGoal::makeFallbackPath(const StorePath & path)
|
||||||
{
|
{
|
||||||
return worker.store.makeStorePath(
|
return worker.store.makeStorePath(
|
||||||
"rewrite:" + std::string(drvPath.to_string()) + ":" + std::string(path.to_string()),
|
"rewrite:" + std::string(drvPath.to_string()) + ":" + std::string(path.to_string()),
|
||||||
Hash(htSHA256), path.name());
|
Hash(HashAlgorithm::SHA256), path.name());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -519,8 +519,8 @@ bool Worker::pathContentsGood(const StorePath & path)
|
||||||
if (!pathExists(store.printStorePath(path)))
|
if (!pathExists(store.printStorePath(path)))
|
||||||
res = false;
|
res = false;
|
||||||
else {
|
else {
|
||||||
HashResult current = hashPath(info->narHash.type, store.printStorePath(path));
|
HashResult current = hashPath(info->narHash.algo, store.printStorePath(path));
|
||||||
Hash nullHash(htSHA256);
|
Hash nullHash(HashAlgorithm::SHA256);
|
||||||
res = info->narHash == nullHash || info->narHash == current.first;
|
res = info->narHash == nullHash || info->narHash == current.first;
|
||||||
}
|
}
|
||||||
pathContentsGoodCache.insert_or_assign(path, res);
|
pathContentsGoodCache.insert_or_assign(path, res);
|
||||||
|
|
|
@ -63,9 +63,9 @@ void builtinFetchurl(const BasicDerivation & drv, const std::string & netrcData)
|
||||||
for (auto hashedMirror : settings.hashedMirrors.get())
|
for (auto hashedMirror : settings.hashedMirrors.get())
|
||||||
try {
|
try {
|
||||||
if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/';
|
if (!hasSuffix(hashedMirror, "/")) hashedMirror += '/';
|
||||||
std::optional<HashType> ht = parseHashTypeOpt(getAttr("outputHashAlgo"));
|
std::optional<HashAlgorithm> ht = parseHashAlgoOpt(getAttr("outputHashAlgo"));
|
||||||
Hash h = newHashAllowEmpty(getAttr("outputHash"), ht);
|
Hash h = newHashAllowEmpty(getAttr("outputHash"), ht);
|
||||||
fetch(hashedMirror + printHashType(h.type) + "/" + h.to_string(HashFormat::Base16, false));
|
fetch(hashedMirror + printHashAlgo(h.algo) + "/" + h.to_string(HashFormat::Base16, false));
|
||||||
return;
|
return;
|
||||||
} catch (Error & e) {
|
} catch (Error & e) {
|
||||||
debug(e.what());
|
debug(e.what());
|
||||||
|
|
|
@ -38,14 +38,14 @@ ContentAddressMethod ContentAddressMethod::parsePrefix(std::string_view & m)
|
||||||
return FileIngestionMethod::Flat;
|
return FileIngestionMethod::Flat;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string ContentAddressMethod::render(HashType ht) const
|
std::string ContentAddressMethod::render(HashAlgorithm ha) const
|
||||||
{
|
{
|
||||||
return std::visit(overloaded {
|
return std::visit(overloaded {
|
||||||
[&](const TextIngestionMethod & th) {
|
[&](const TextIngestionMethod & th) {
|
||||||
return std::string{"text:"} + printHashType(ht);
|
return std::string{"text:"} + printHashAlgo(ha);
|
||||||
},
|
},
|
||||||
[&](const FileIngestionMethod & fim) {
|
[&](const FileIngestionMethod & fim) {
|
||||||
return "fixed:" + makeFileIngestionPrefix(fim) + printHashType(ht);
|
return "fixed:" + makeFileIngestionPrefix(fim) + printHashAlgo(ha);
|
||||||
}
|
}
|
||||||
}, raw);
|
}, raw);
|
||||||
}
|
}
|
||||||
|
@ -67,7 +67,7 @@ std::string ContentAddress::render() const
|
||||||
/**
|
/**
|
||||||
* Parses content address strings up to the hash.
|
* Parses content address strings up to the hash.
|
||||||
*/
|
*/
|
||||||
static std::pair<ContentAddressMethod, HashType> parseContentAddressMethodPrefix(std::string_view & rest)
|
static std::pair<ContentAddressMethod, HashAlgorithm> parseContentAddressMethodPrefix(std::string_view & rest)
|
||||||
{
|
{
|
||||||
std::string_view wholeInput { rest };
|
std::string_view wholeInput { rest };
|
||||||
|
|
||||||
|
@ -83,27 +83,27 @@ static std::pair<ContentAddressMethod, HashType> parseContentAddressMethodPrefix
|
||||||
auto hashTypeRaw = splitPrefixTo(rest, ':');
|
auto hashTypeRaw = splitPrefixTo(rest, ':');
|
||||||
if (!hashTypeRaw)
|
if (!hashTypeRaw)
|
||||||
throw UsageError("content address hash must be in form '<algo>:<hash>', but found: %s", wholeInput);
|
throw UsageError("content address hash must be in form '<algo>:<hash>', but found: %s", wholeInput);
|
||||||
HashType hashType = parseHashType(*hashTypeRaw);
|
HashAlgorithm hashAlgo = parseHashAlgo(*hashTypeRaw);
|
||||||
return hashType;
|
return hashAlgo;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Switch on prefix
|
// Switch on prefix
|
||||||
if (prefix == "text") {
|
if (prefix == "text") {
|
||||||
// No parsing of the ingestion method, "text" only support flat.
|
// No parsing of the ingestion method, "text" only support flat.
|
||||||
HashType hashType = parseHashType_();
|
HashAlgorithm hashAlgo = parseHashType_();
|
||||||
return {
|
return {
|
||||||
TextIngestionMethod {},
|
TextIngestionMethod {},
|
||||||
std::move(hashType),
|
std::move(hashAlgo),
|
||||||
};
|
};
|
||||||
} else if (prefix == "fixed") {
|
} else if (prefix == "fixed") {
|
||||||
// Parse method
|
// Parse method
|
||||||
auto method = FileIngestionMethod::Flat;
|
auto method = FileIngestionMethod::Flat;
|
||||||
if (splitPrefix(rest, "r:"))
|
if (splitPrefix(rest, "r:"))
|
||||||
method = FileIngestionMethod::Recursive;
|
method = FileIngestionMethod::Recursive;
|
||||||
HashType hashType = parseHashType_();
|
HashAlgorithm hashAlgo = parseHashType_();
|
||||||
return {
|
return {
|
||||||
std::move(method),
|
std::move(method),
|
||||||
std::move(hashType),
|
std::move(hashAlgo),
|
||||||
};
|
};
|
||||||
} else
|
} else
|
||||||
throw UsageError("content address prefix '%s' is unrecognized. Recogonized prefixes are 'text' or 'fixed'", prefix);
|
throw UsageError("content address prefix '%s' is unrecognized. Recogonized prefixes are 'text' or 'fixed'", prefix);
|
||||||
|
@ -113,15 +113,15 @@ ContentAddress ContentAddress::parse(std::string_view rawCa)
|
||||||
{
|
{
|
||||||
auto rest = rawCa;
|
auto rest = rawCa;
|
||||||
|
|
||||||
auto [caMethod, hashType] = parseContentAddressMethodPrefix(rest);
|
auto [caMethod, hashAlgo] = parseContentAddressMethodPrefix(rest);
|
||||||
|
|
||||||
return ContentAddress {
|
return ContentAddress {
|
||||||
.method = std::move(caMethod),
|
.method = std::move(caMethod),
|
||||||
.hash = Hash::parseNonSRIUnprefixed(rest, hashType),
|
.hash = Hash::parseNonSRIUnprefixed(rest, hashAlgo),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<ContentAddressMethod, HashType> ContentAddressMethod::parse(std::string_view caMethod)
|
std::pair<ContentAddressMethod, HashAlgorithm> ContentAddressMethod::parse(std::string_view caMethod)
|
||||||
{
|
{
|
||||||
std::string asPrefix = std::string{caMethod} + ":";
|
std::string asPrefix = std::string{caMethod} + ":";
|
||||||
// parseContentAddressMethodPrefix takes its argument by reference
|
// parseContentAddressMethodPrefix takes its argument by reference
|
||||||
|
@ -144,7 +144,7 @@ std::string renderContentAddress(std::optional<ContentAddress> ca)
|
||||||
std::string ContentAddress::printMethodAlgo() const
|
std::string ContentAddress::printMethodAlgo() const
|
||||||
{
|
{
|
||||||
return method.renderPrefix()
|
return method.renderPrefix()
|
||||||
+ printHashType(hash.type);
|
+ printHashAlgo(hash.algo);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StoreReferences::empty() const
|
bool StoreReferences::empty() const
|
||||||
|
|
|
@ -94,7 +94,7 @@ struct ContentAddressMethod
|
||||||
/**
|
/**
|
||||||
* Parse a content addressing method and hash type.
|
* Parse a content addressing method and hash type.
|
||||||
*/
|
*/
|
||||||
static std::pair<ContentAddressMethod, HashType> parse(std::string_view rawCaMethod);
|
static std::pair<ContentAddressMethod, HashAlgorithm> parse(std::string_view rawCaMethod);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render a content addressing method and hash type in a
|
* Render a content addressing method and hash type in a
|
||||||
|
@ -102,7 +102,7 @@ struct ContentAddressMethod
|
||||||
*
|
*
|
||||||
* The rough inverse of `parse()`.
|
* The rough inverse of `parse()`.
|
||||||
*/
|
*/
|
||||||
std::string render(HashType ht) const;
|
std::string render(HashAlgorithm ha) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -400,22 +400,22 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
||||||
logger->startWork();
|
logger->startWork();
|
||||||
auto pathInfo = [&]() {
|
auto pathInfo = [&]() {
|
||||||
// NB: FramedSource must be out of scope before logger->stopWork();
|
// NB: FramedSource must be out of scope before logger->stopWork();
|
||||||
auto [contentAddressMethod, hashType_] = ContentAddressMethod::parse(camStr);
|
auto [contentAddressMethod, hashAlgo_] = ContentAddressMethod::parse(camStr);
|
||||||
auto hashType = hashType_; // work around clang bug
|
auto hashAlgo = hashAlgo_; // work around clang bug
|
||||||
FramedSource source(from);
|
FramedSource source(from);
|
||||||
// TODO this is essentially RemoteStore::addCAToStore. Move it up to Store.
|
// TODO this is essentially RemoteStore::addCAToStore. Move it up to Store.
|
||||||
return std::visit(overloaded {
|
return std::visit(overloaded {
|
||||||
[&](const TextIngestionMethod &) {
|
[&](const TextIngestionMethod &) {
|
||||||
if (hashType != htSHA256)
|
if (hashAlgo != HashAlgorithm::SHA256)
|
||||||
throw UnimplementedError("When adding text-hashed data called '%s', only SHA-256 is supported but '%s' was given",
|
throw UnimplementedError("When adding text-hashed data called '%s', only SHA-256 is supported but '%s' was given",
|
||||||
name, printHashType(hashType));
|
name, printHashAlgo(hashAlgo));
|
||||||
// We could stream this by changing Store
|
// We could stream this by changing Store
|
||||||
std::string contents = source.drain();
|
std::string contents = source.drain();
|
||||||
auto path = store->addTextToStore(name, contents, refs, repair);
|
auto path = store->addTextToStore(name, contents, refs, repair);
|
||||||
return store->queryPathInfo(path);
|
return store->queryPathInfo(path);
|
||||||
},
|
},
|
||||||
[&](const FileIngestionMethod & fim) {
|
[&](const FileIngestionMethod & fim) {
|
||||||
auto path = store->addToStoreFromDump(source, name, fim, hashType, repair, refs);
|
auto path = store->addToStoreFromDump(source, name, fim, hashAlgo, repair, refs);
|
||||||
return store->queryPathInfo(path);
|
return store->queryPathInfo(path);
|
||||||
},
|
},
|
||||||
}, contentAddressMethod.raw);
|
}, contentAddressMethod.raw);
|
||||||
|
@ -424,7 +424,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
||||||
|
|
||||||
WorkerProto::Serialise<ValidPathInfo>::write(*store, wconn, *pathInfo);
|
WorkerProto::Serialise<ValidPathInfo>::write(*store, wconn, *pathInfo);
|
||||||
} else {
|
} else {
|
||||||
HashType hashAlgo;
|
HashAlgorithm hashAlgo;
|
||||||
std::string baseName;
|
std::string baseName;
|
||||||
FileIngestionMethod method;
|
FileIngestionMethod method;
|
||||||
{
|
{
|
||||||
|
@ -440,7 +440,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
||||||
hashAlgoRaw = "sha256";
|
hashAlgoRaw = "sha256";
|
||||||
method = FileIngestionMethod::Recursive;
|
method = FileIngestionMethod::Recursive;
|
||||||
}
|
}
|
||||||
hashAlgo = parseHashType(hashAlgoRaw);
|
hashAlgo = parseHashAlgo(hashAlgoRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dumpSource = sinkToSource([&](Sink & saved) {
|
auto dumpSource = sinkToSource([&](Sink & saved) {
|
||||||
|
@ -883,7 +883,7 @@ static void performOp(TunnelLogger * logger, ref<Store> store,
|
||||||
bool repair, dontCheckSigs;
|
bool repair, dontCheckSigs;
|
||||||
auto path = store->parseStorePath(readString(from));
|
auto path = store->parseStorePath(readString(from));
|
||||||
auto deriver = readString(from);
|
auto deriver = readString(from);
|
||||||
auto narHash = Hash::parseAny(readString(from), htSHA256);
|
auto narHash = Hash::parseAny(readString(from), HashAlgorithm::SHA256);
|
||||||
ValidPathInfo info { path, narHash };
|
ValidPathInfo info { path, narHash };
|
||||||
if (deriver != "")
|
if (deriver != "")
|
||||||
info.deriver = store->parseStorePath(deriver);
|
info.deriver = store->parseStorePath(deriver);
|
||||||
|
|
|
@ -215,25 +215,25 @@ static StringSet parseStrings(std::istream & str, bool arePaths)
|
||||||
|
|
||||||
static DerivationOutput parseDerivationOutput(
|
static DerivationOutput parseDerivationOutput(
|
||||||
const StoreDirConfig & store,
|
const StoreDirConfig & store,
|
||||||
std::string_view pathS, std::string_view hashAlgo, std::string_view hashS,
|
std::string_view pathS, std::string_view hashAlgoStr, std::string_view hashS,
|
||||||
const ExperimentalFeatureSettings & xpSettings)
|
const ExperimentalFeatureSettings & xpSettings)
|
||||||
{
|
{
|
||||||
if (hashAlgo != "") {
|
if (hashAlgoStr != "") {
|
||||||
ContentAddressMethod method = ContentAddressMethod::parsePrefix(hashAlgo);
|
ContentAddressMethod method = ContentAddressMethod::parsePrefix(hashAlgoStr);
|
||||||
if (method == TextIngestionMethod {})
|
if (method == TextIngestionMethod {})
|
||||||
xpSettings.require(Xp::DynamicDerivations);
|
xpSettings.require(Xp::DynamicDerivations);
|
||||||
const auto hashType = parseHashType(hashAlgo);
|
const auto hashAlgo = parseHashAlgo(hashAlgoStr);
|
||||||
if (hashS == "impure") {
|
if (hashS == "impure") {
|
||||||
xpSettings.require(Xp::ImpureDerivations);
|
xpSettings.require(Xp::ImpureDerivations);
|
||||||
if (pathS != "")
|
if (pathS != "")
|
||||||
throw FormatError("impure derivation output should not specify output path");
|
throw FormatError("impure derivation output should not specify output path");
|
||||||
return DerivationOutput::Impure {
|
return DerivationOutput::Impure {
|
||||||
.method = std::move(method),
|
.method = std::move(method),
|
||||||
.hashType = std::move(hashType),
|
.hashAlgo = std::move(hashAlgo),
|
||||||
};
|
};
|
||||||
} else if (hashS != "") {
|
} else if (hashS != "") {
|
||||||
validatePath(pathS);
|
validatePath(pathS);
|
||||||
auto hash = Hash::parseNonSRIUnprefixed(hashS, hashType);
|
auto hash = Hash::parseNonSRIUnprefixed(hashS, hashAlgo);
|
||||||
return DerivationOutput::CAFixed {
|
return DerivationOutput::CAFixed {
|
||||||
.ca = ContentAddress {
|
.ca = ContentAddress {
|
||||||
.method = std::move(method),
|
.method = std::move(method),
|
||||||
|
@ -246,7 +246,7 @@ static DerivationOutput parseDerivationOutput(
|
||||||
throw FormatError("content-addressed derivation output should not specify output path");
|
throw FormatError("content-addressed derivation output should not specify output path");
|
||||||
return DerivationOutput::CAFloating {
|
return DerivationOutput::CAFloating {
|
||||||
.method = std::move(method),
|
.method = std::move(method),
|
||||||
.hashType = std::move(hashType),
|
.hashAlgo = std::move(hashAlgo),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -547,7 +547,7 @@ std::string Derivation::unparse(const StoreDirConfig & store, bool maskOutputs,
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::CAFloating & dof) {
|
[&](const DerivationOutput::CAFloating & dof) {
|
||||||
s += ','; printUnquotedString(s, "");
|
s += ','; printUnquotedString(s, "");
|
||||||
s += ','; printUnquotedString(s, dof.method.renderPrefix() + printHashType(dof.hashType));
|
s += ','; printUnquotedString(s, dof.method.renderPrefix() + printHashAlgo(dof.hashAlgo));
|
||||||
s += ','; printUnquotedString(s, "");
|
s += ','; printUnquotedString(s, "");
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::Deferred &) {
|
[&](const DerivationOutput::Deferred &) {
|
||||||
|
@ -558,7 +558,7 @@ std::string Derivation::unparse(const StoreDirConfig & store, bool maskOutputs,
|
||||||
[&](const DerivationOutput::Impure & doi) {
|
[&](const DerivationOutput::Impure & doi) {
|
||||||
// FIXME
|
// FIXME
|
||||||
s += ','; printUnquotedString(s, "");
|
s += ','; printUnquotedString(s, "");
|
||||||
s += ','; printUnquotedString(s, doi.method.renderPrefix() + printHashType(doi.hashType));
|
s += ','; printUnquotedString(s, doi.method.renderPrefix() + printHashAlgo(doi.hashAlgo));
|
||||||
s += ','; printUnquotedString(s, "impure");
|
s += ','; printUnquotedString(s, "impure");
|
||||||
}
|
}
|
||||||
}, i.second.raw);
|
}, i.second.raw);
|
||||||
|
@ -631,7 +631,7 @@ DerivationType BasicDerivation::type() const
|
||||||
floatingCAOutputs,
|
floatingCAOutputs,
|
||||||
deferredIAOutputs,
|
deferredIAOutputs,
|
||||||
impureOutputs;
|
impureOutputs;
|
||||||
std::optional<HashType> floatingHashType;
|
std::optional<HashAlgorithm> floatingHashAlgo;
|
||||||
|
|
||||||
for (auto & i : outputs) {
|
for (auto & i : outputs) {
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
|
@ -643,10 +643,10 @@ DerivationType BasicDerivation::type() const
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::CAFloating & dof) {
|
[&](const DerivationOutput::CAFloating & dof) {
|
||||||
floatingCAOutputs.insert(i.first);
|
floatingCAOutputs.insert(i.first);
|
||||||
if (!floatingHashType) {
|
if (!floatingHashAlgo) {
|
||||||
floatingHashType = dof.hashType;
|
floatingHashAlgo = dof.hashAlgo;
|
||||||
} else {
|
} else {
|
||||||
if (*floatingHashType != dof.hashType)
|
if (*floatingHashAlgo != dof.hashAlgo)
|
||||||
throw Error("all floating outputs must use the same hash type");
|
throw Error("all floating outputs must use the same hash type");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -774,7 +774,7 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut
|
||||||
std::map<std::string, Hash> outputHashes;
|
std::map<std::string, Hash> outputHashes;
|
||||||
for (const auto & i : drv.outputs) {
|
for (const auto & i : drv.outputs) {
|
||||||
auto & dof = std::get<DerivationOutput::CAFixed>(i.second.raw);
|
auto & dof = std::get<DerivationOutput::CAFixed>(i.second.raw);
|
||||||
auto hash = hashString(htSHA256, "fixed:out:"
|
auto hash = hashString(HashAlgorithm::SHA256, "fixed:out:"
|
||||||
+ dof.ca.printMethodAlgo() + ":"
|
+ dof.ca.printMethodAlgo() + ":"
|
||||||
+ dof.ca.hash.to_string(HashFormat::Base16, false) + ":"
|
+ dof.ca.hash.to_string(HashFormat::Base16, false) + ":"
|
||||||
+ store.printStorePath(dof.path(store, drv.name, i.first)));
|
+ store.printStorePath(dof.path(store, drv.name, i.first)));
|
||||||
|
@ -825,7 +825,7 @@ DrvHash hashDerivationModulo(Store & store, const Derivation & drv, bool maskOut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hash = hashString(htSHA256, drv.unparse(store, maskOutputs, &inputs2));
|
auto hash = hashString(HashAlgorithm::SHA256, drv.unparse(store, maskOutputs, &inputs2));
|
||||||
|
|
||||||
std::map<std::string, Hash> outputHashes;
|
std::map<std::string, Hash> outputHashes;
|
||||||
for (const auto & [outputName, _] : drv.outputs) {
|
for (const auto & [outputName, _] : drv.outputs) {
|
||||||
|
@ -930,7 +930,7 @@ void writeDerivation(Sink & out, const StoreDirConfig & store, const BasicDeriva
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::CAFloating & dof) {
|
[&](const DerivationOutput::CAFloating & dof) {
|
||||||
out << ""
|
out << ""
|
||||||
<< (dof.method.renderPrefix() + printHashType(dof.hashType))
|
<< (dof.method.renderPrefix() + printHashAlgo(dof.hashAlgo))
|
||||||
<< "";
|
<< "";
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::Deferred &) {
|
[&](const DerivationOutput::Deferred &) {
|
||||||
|
@ -940,7 +940,7 @@ void writeDerivation(Sink & out, const StoreDirConfig & store, const BasicDeriva
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::Impure & doi) {
|
[&](const DerivationOutput::Impure & doi) {
|
||||||
out << ""
|
out << ""
|
||||||
<< (doi.method.renderPrefix() + printHashType(doi.hashType))
|
<< (doi.method.renderPrefix() + printHashAlgo(doi.hashAlgo))
|
||||||
<< "impure";
|
<< "impure";
|
||||||
},
|
},
|
||||||
}, i.second.raw);
|
}, i.second.raw);
|
||||||
|
@ -958,7 +958,7 @@ void writeDerivation(Sink & out, const StoreDirConfig & store, const BasicDeriva
|
||||||
std::string hashPlaceholder(const OutputNameView outputName)
|
std::string hashPlaceholder(const OutputNameView outputName)
|
||||||
{
|
{
|
||||||
// FIXME: memoize?
|
// FIXME: memoize?
|
||||||
return "/" + hashString(htSHA256, concatStrings("nix-output:", outputName)).to_string(HashFormat::Base32, false);
|
return "/" + hashString(HashAlgorithm::SHA256, concatStrings("nix-output:", outputName)).to_string(HashFormat::Base32, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1150,7 +1150,7 @@ void Derivation::checkInvariants(Store & store, const StorePath & drvPath) const
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Hash impureOutputHash = hashString(htSHA256, "impure");
|
const Hash impureOutputHash = hashString(HashAlgorithm::SHA256, "impure");
|
||||||
|
|
||||||
nlohmann::json DerivationOutput::toJSON(
|
nlohmann::json DerivationOutput::toJSON(
|
||||||
const StoreDirConfig & store, std::string_view drvName, OutputNameView outputName) const
|
const StoreDirConfig & store, std::string_view drvName, OutputNameView outputName) const
|
||||||
|
@ -1167,11 +1167,11 @@ nlohmann::json DerivationOutput::toJSON(
|
||||||
// FIXME print refs?
|
// FIXME print refs?
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::CAFloating & dof) {
|
[&](const DerivationOutput::CAFloating & dof) {
|
||||||
res["hashAlgo"] = dof.method.renderPrefix() + printHashType(dof.hashType);
|
res["hashAlgo"] = dof.method.renderPrefix() + printHashAlgo(dof.hashAlgo);
|
||||||
},
|
},
|
||||||
[&](const DerivationOutput::Deferred &) {},
|
[&](const DerivationOutput::Deferred &) {},
|
||||||
[&](const DerivationOutput::Impure & doi) {
|
[&](const DerivationOutput::Impure & doi) {
|
||||||
res["hashAlgo"] = doi.method.renderPrefix() + printHashType(doi.hashType);
|
res["hashAlgo"] = doi.method.renderPrefix() + printHashAlgo(doi.hashAlgo);
|
||||||
res["impure"] = true;
|
res["impure"] = true;
|
||||||
},
|
},
|
||||||
}, raw);
|
}, raw);
|
||||||
|
@ -1191,15 +1191,15 @@ DerivationOutput DerivationOutput::fromJSON(
|
||||||
for (const auto & [key, _] : json)
|
for (const auto & [key, _] : json)
|
||||||
keys.insert(key);
|
keys.insert(key);
|
||||||
|
|
||||||
auto methodAlgo = [&]() -> std::pair<ContentAddressMethod, HashType> {
|
auto methodAlgo = [&]() -> std::pair<ContentAddressMethod, HashAlgorithm> {
|
||||||
std::string hashAlgo = json["hashAlgo"];
|
std::string hashAlgoStr = json["hashAlgo"];
|
||||||
// remaining to parse, will be mutated by parsers
|
// remaining to parse, will be mutated by parsers
|
||||||
std::string_view s = hashAlgo;
|
std::string_view s = hashAlgoStr;
|
||||||
ContentAddressMethod method = ContentAddressMethod::parsePrefix(s);
|
ContentAddressMethod method = ContentAddressMethod::parsePrefix(s);
|
||||||
if (method == TextIngestionMethod {})
|
if (method == TextIngestionMethod {})
|
||||||
xpSettings.require(Xp::DynamicDerivations);
|
xpSettings.require(Xp::DynamicDerivations);
|
||||||
auto hashType = parseHashType(s);
|
auto hashAlgo = parseHashAlgo(s);
|
||||||
return { std::move(method), std::move(hashType) };
|
return { std::move(method), std::move(hashAlgo) };
|
||||||
};
|
};
|
||||||
|
|
||||||
if (keys == (std::set<std::string_view> { "path" })) {
|
if (keys == (std::set<std::string_view> { "path" })) {
|
||||||
|
@ -1209,11 +1209,11 @@ DerivationOutput DerivationOutput::fromJSON(
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (keys == (std::set<std::string_view> { "path", "hashAlgo", "hash" })) {
|
else if (keys == (std::set<std::string_view> { "path", "hashAlgo", "hash" })) {
|
||||||
auto [method, hashType] = methodAlgo();
|
auto [method, hashAlgo] = methodAlgo();
|
||||||
auto dof = DerivationOutput::CAFixed {
|
auto dof = DerivationOutput::CAFixed {
|
||||||
.ca = ContentAddress {
|
.ca = ContentAddress {
|
||||||
.method = std::move(method),
|
.method = std::move(method),
|
||||||
.hash = Hash::parseNonSRIUnprefixed((std::string) json["hash"], hashType),
|
.hash = Hash::parseNonSRIUnprefixed((std::string) json["hash"], hashAlgo),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if (dof.path(store, drvName, outputName) != store.parseStorePath((std::string) json["path"]))
|
if (dof.path(store, drvName, outputName) != store.parseStorePath((std::string) json["path"]))
|
||||||
|
@ -1223,10 +1223,10 @@ DerivationOutput DerivationOutput::fromJSON(
|
||||||
|
|
||||||
else if (keys == (std::set<std::string_view> { "hashAlgo" })) {
|
else if (keys == (std::set<std::string_view> { "hashAlgo" })) {
|
||||||
xpSettings.require(Xp::CaDerivations);
|
xpSettings.require(Xp::CaDerivations);
|
||||||
auto [method, hashType] = methodAlgo();
|
auto [method, hashAlgo] = methodAlgo();
|
||||||
return DerivationOutput::CAFloating {
|
return DerivationOutput::CAFloating {
|
||||||
.method = std::move(method),
|
.method = std::move(method),
|
||||||
.hashType = std::move(hashType),
|
.hashAlgo = std::move(hashAlgo),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1236,10 +1236,10 @@ DerivationOutput DerivationOutput::fromJSON(
|
||||||
|
|
||||||
else if (keys == (std::set<std::string_view> { "hashAlgo", "impure" })) {
|
else if (keys == (std::set<std::string_view> { "hashAlgo", "impure" })) {
|
||||||
xpSettings.require(Xp::ImpureDerivations);
|
xpSettings.require(Xp::ImpureDerivations);
|
||||||
auto [method, hashType] = methodAlgo();
|
auto [method, hashAlgo] = methodAlgo();
|
||||||
return DerivationOutput::Impure {
|
return DerivationOutput::Impure {
|
||||||
.method = std::move(method),
|
.method = std::move(method),
|
||||||
.hashType = hashType,
|
.hashAlgo = hashAlgo,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,9 +75,9 @@ struct DerivationOutput
|
||||||
/**
|
/**
|
||||||
* How the serialization will be hashed
|
* How the serialization will be hashed
|
||||||
*/
|
*/
|
||||||
HashType hashType;
|
HashAlgorithm hashAlgo;
|
||||||
|
|
||||||
GENERATE_CMP(CAFloating, me->method, me->hashType);
|
GENERATE_CMP(CAFloating, me->method, me->hashAlgo);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,9 +102,9 @@ struct DerivationOutput
|
||||||
/**
|
/**
|
||||||
* How the serialization will be hashed
|
* How the serialization will be hashed
|
||||||
*/
|
*/
|
||||||
HashType hashType;
|
HashAlgorithm hashAlgo;
|
||||||
|
|
||||||
GENERATE_CMP(Impure, me->method, me->hashType);
|
GENERATE_CMP(Impure, me->method, me->hashAlgo);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::variant<
|
typedef std::variant<
|
||||||
|
|
|
@ -19,7 +19,7 @@ DownstreamPlaceholder DownstreamPlaceholder::unknownCaOutput(
|
||||||
auto drvName = drvNameWithExtension.substr(0, drvNameWithExtension.size() - 4);
|
auto drvName = drvNameWithExtension.substr(0, drvNameWithExtension.size() - 4);
|
||||||
auto clearText = "nix-upstream-output:" + std::string { drvPath.hashPart() } + ":" + outputPathName(drvName, outputName);
|
auto clearText = "nix-upstream-output:" + std::string { drvPath.hashPart() } + ":" + outputPathName(drvName, outputName);
|
||||||
return DownstreamPlaceholder {
|
return DownstreamPlaceholder {
|
||||||
hashString(htSHA256, clearText)
|
hashString(HashAlgorithm::SHA256, clearText)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ DownstreamPlaceholder DownstreamPlaceholder::unknownDerivation(
|
||||||
+ compressed.to_string(HashFormat::Base32, false)
|
+ compressed.to_string(HashFormat::Base32, false)
|
||||||
+ ":" + std::string { outputName };
|
+ ":" + std::string { outputName };
|
||||||
return DownstreamPlaceholder {
|
return DownstreamPlaceholder {
|
||||||
hashString(htSHA256, clearText)
|
hashString(HashAlgorithm::SHA256, clearText)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ void Store::exportPath(const StorePath & path, Sink & sink)
|
||||||
{
|
{
|
||||||
auto info = queryPathInfo(path);
|
auto info = queryPathInfo(path);
|
||||||
|
|
||||||
HashSink hashSink(htSHA256);
|
HashSink hashSink(HashAlgorithm::SHA256);
|
||||||
TeeSink teeSink(sink, hashSink);
|
TeeSink teeSink(sink, hashSink);
|
||||||
|
|
||||||
narFromPath(path, teeSink);
|
narFromPath(path, teeSink);
|
||||||
|
@ -39,7 +39,7 @@ void Store::exportPath(const StorePath & path, Sink & sink)
|
||||||
filesystem corruption from spreading to other machines.
|
filesystem corruption from spreading to other machines.
|
||||||
Don't complain if the stored hash is zero (unknown). */
|
Don't complain if the stored hash is zero (unknown). */
|
||||||
Hash hash = hashSink.currentHash().first;
|
Hash hash = hashSink.currentHash().first;
|
||||||
if (hash != info->narHash && info->narHash != Hash(info->narHash.type))
|
if (hash != info->narHash && info->narHash != Hash(info->narHash.algo))
|
||||||
throw Error("hash of path '%s' has changed from '%s' to '%s'!",
|
throw Error("hash of path '%s' has changed from '%s' to '%s'!",
|
||||||
printStorePath(path), info->narHash.to_string(HashFormat::Base32, true), hash.to_string(HashFormat::Base32, true));
|
printStorePath(path), info->narHash.to_string(HashFormat::Base32, true), hash.to_string(HashFormat::Base32, true));
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ StorePaths Store::importPaths(Source & source, CheckSigsFlag checkSigs)
|
||||||
auto references = CommonProto::Serialise<StorePathSet>::read(*this,
|
auto references = CommonProto::Serialise<StorePathSet>::read(*this,
|
||||||
CommonProto::ReadConn { .from = source });
|
CommonProto::ReadConn { .from = source });
|
||||||
auto deriver = readString(source);
|
auto deriver = readString(source);
|
||||||
auto narHash = hashString(htSHA256, saved.s);
|
auto narHash = hashString(HashAlgorithm::SHA256, saved.s);
|
||||||
|
|
||||||
ValidPathInfo info { path, narHash };
|
ValidPathInfo info { path, narHash };
|
||||||
if (deriver != "")
|
if (deriver != "")
|
||||||
|
|
|
@ -50,7 +50,7 @@ static void makeSymlink(const Path & link, const Path & target)
|
||||||
|
|
||||||
void LocalStore::addIndirectRoot(const Path & path)
|
void LocalStore::addIndirectRoot(const Path & path)
|
||||||
{
|
{
|
||||||
std::string hash = hashString(htSHA1, path).to_string(HashFormat::Base32, false);
|
std::string hash = hashString(HashAlgorithm::SHA1, path).to_string(HashFormat::Base32, false);
|
||||||
Path realRoot = canonPath(fmt("%1%/%2%/auto/%3%", stateDir, gcRootsDir, hash));
|
Path realRoot = canonPath(fmt("%1%/%2%/auto/%3%", stateDir, gcRootsDir, hash));
|
||||||
makeSymlink(realRoot, path);
|
makeSymlink(realRoot, path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -267,13 +267,13 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor
|
||||||
{ unsupported("queryPathFromHashPart"); }
|
{ unsupported("queryPathFromHashPart"); }
|
||||||
|
|
||||||
StorePath addToStore(
|
StorePath addToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
const Path & srcPath,
|
const Path & srcPath,
|
||||||
FileIngestionMethod method,
|
FileIngestionMethod method,
|
||||||
HashType hashAlgo,
|
HashAlgorithm hashAlgo,
|
||||||
PathFilter & filter,
|
PathFilter & filter,
|
||||||
RepairFlag repair,
|
RepairFlag repair,
|
||||||
const StorePathSet & references) override
|
const StorePathSet & references) override
|
||||||
{ unsupported("addToStore"); }
|
{ unsupported("addToStore"); }
|
||||||
|
|
||||||
StorePath addTextToStore(
|
StorePath addTextToStore(
|
||||||
|
|
|
@ -955,7 +955,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
|
||||||
StorePathSet paths;
|
StorePathSet paths;
|
||||||
|
|
||||||
for (auto & [_, i] : infos) {
|
for (auto & [_, i] : infos) {
|
||||||
assert(i.narHash.type == htSHA256);
|
assert(i.narHash.algo == HashAlgorithm::SHA256);
|
||||||
if (isValidPath_(*state, i.path))
|
if (isValidPath_(*state, i.path))
|
||||||
updatePathInfo(*state, i);
|
updatePathInfo(*state, i);
|
||||||
else
|
else
|
||||||
|
@ -1069,7 +1069,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
|
|
||||||
/* While restoring the path from the NAR, compute the hash
|
/* While restoring the path from the NAR, compute the hash
|
||||||
of the NAR. */
|
of the NAR. */
|
||||||
HashSink hashSink(htSHA256);
|
HashSink hashSink(HashAlgorithm::SHA256);
|
||||||
|
|
||||||
TeeSource wrapperSource { source, hashSink };
|
TeeSource wrapperSource { source, hashSink };
|
||||||
|
|
||||||
|
@ -1090,7 +1090,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
auto & specified = *info.ca;
|
auto & specified = *info.ca;
|
||||||
auto actualHash = hashCAPath(
|
auto actualHash = hashCAPath(
|
||||||
specified.method,
|
specified.method,
|
||||||
specified.hash.type,
|
specified.hash.algo,
|
||||||
info.path
|
info.path
|
||||||
);
|
);
|
||||||
if (specified.hash != actualHash.hash) {
|
if (specified.hash != actualHash.hash) {
|
||||||
|
@ -1116,7 +1116,7 @@ void LocalStore::addToStore(const ValidPathInfo & info, Source & source,
|
||||||
|
|
||||||
|
|
||||||
StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name,
|
StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name,
|
||||||
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references)
|
FileIngestionMethod method, HashAlgorithm hashAlgo, RepairFlag repair, const StorePathSet & references)
|
||||||
{
|
{
|
||||||
/* For computing the store path. */
|
/* For computing the store path. */
|
||||||
auto hashSink = std::make_unique<HashSink>(hashAlgo);
|
auto hashSink = std::make_unique<HashSink>(hashAlgo);
|
||||||
|
@ -1220,8 +1220,8 @@ StorePath LocalStore::addToStoreFromDump(Source & source0, std::string_view name
|
||||||
/* For computing the nar hash. In recursive SHA-256 mode, this
|
/* For computing the nar hash. In recursive SHA-256 mode, this
|
||||||
is the same as the store hash, so no need to do it again. */
|
is the same as the store hash, so no need to do it again. */
|
||||||
auto narHash = std::pair { hash, size };
|
auto narHash = std::pair { hash, size };
|
||||||
if (method != FileIngestionMethod::Recursive || hashAlgo != htSHA256) {
|
if (method != FileIngestionMethod::Recursive || hashAlgo != HashAlgorithm::SHA256) {
|
||||||
HashSink narSink { htSHA256 };
|
HashSink narSink { HashAlgorithm::SHA256 };
|
||||||
dumpPath(realPath, narSink);
|
dumpPath(realPath, narSink);
|
||||||
narHash = narSink.finish();
|
narHash = narSink.finish();
|
||||||
}
|
}
|
||||||
|
@ -1252,7 +1252,7 @@ StorePath LocalStore::addTextToStore(
|
||||||
std::string_view s,
|
std::string_view s,
|
||||||
const StorePathSet & references, RepairFlag repair)
|
const StorePathSet & references, RepairFlag repair)
|
||||||
{
|
{
|
||||||
auto hash = hashString(htSHA256, s);
|
auto hash = hashString(HashAlgorithm::SHA256, s);
|
||||||
auto dstPath = makeTextPath(name, TextInfo {
|
auto dstPath = makeTextPath(name, TextInfo {
|
||||||
.hash = hash,
|
.hash = hash,
|
||||||
.references = references,
|
.references = references,
|
||||||
|
@ -1278,7 +1278,7 @@ StorePath LocalStore::addTextToStore(
|
||||||
|
|
||||||
StringSink sink;
|
StringSink sink;
|
||||||
dumpString(s, sink);
|
dumpString(s, sink);
|
||||||
auto narHash = hashString(htSHA256, sink.s);
|
auto narHash = hashString(HashAlgorithm::SHA256, sink.s);
|
||||||
|
|
||||||
optimisePath(realPath, repair);
|
optimisePath(realPath, repair);
|
||||||
|
|
||||||
|
@ -1389,7 +1389,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
|
||||||
for (auto & link : readDirectory(linksDir)) {
|
for (auto & link : readDirectory(linksDir)) {
|
||||||
printMsg(lvlTalkative, "checking contents of '%s'", link.name);
|
printMsg(lvlTalkative, "checking contents of '%s'", link.name);
|
||||||
Path linkPath = linksDir + "/" + link.name;
|
Path linkPath = linksDir + "/" + link.name;
|
||||||
std::string hash = hashPath(htSHA256, linkPath).first.to_string(HashFormat::Base32, false);
|
std::string hash = hashPath(HashAlgorithm::SHA256, linkPath).first.to_string(HashFormat::Base32, false);
|
||||||
if (hash != link.name) {
|
if (hash != link.name) {
|
||||||
printError("link '%s' was modified! expected hash '%s', got '%s'",
|
printError("link '%s' was modified! expected hash '%s', got '%s'",
|
||||||
linkPath, link.name, hash);
|
linkPath, link.name, hash);
|
||||||
|
@ -1406,7 +1406,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
|
||||||
|
|
||||||
printInfo("checking store hashes...");
|
printInfo("checking store hashes...");
|
||||||
|
|
||||||
Hash nullHash(htSHA256);
|
Hash nullHash(HashAlgorithm::SHA256);
|
||||||
|
|
||||||
for (auto & i : validPaths) {
|
for (auto & i : validPaths) {
|
||||||
try {
|
try {
|
||||||
|
@ -1415,7 +1415,7 @@ bool LocalStore::verifyStore(bool checkContents, RepairFlag repair)
|
||||||
/* Check the content hash (optionally - slow). */
|
/* Check the content hash (optionally - slow). */
|
||||||
printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i));
|
printMsg(lvlTalkative, "checking contents of '%s'", printStorePath(i));
|
||||||
|
|
||||||
auto hashSink = HashSink(info->narHash.type);
|
auto hashSink = HashSink(info->narHash.algo);
|
||||||
|
|
||||||
dumpPath(Store::toRealPath(i), hashSink);
|
dumpPath(Store::toRealPath(i), hashSink);
|
||||||
auto current = hashSink.finish();
|
auto current = hashSink.finish();
|
||||||
|
@ -1697,20 +1697,20 @@ void LocalStore::queryRealisationUncached(const DrvOutput & id,
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentAddress LocalStore::hashCAPath(
|
ContentAddress LocalStore::hashCAPath(
|
||||||
const ContentAddressMethod & method, const HashType & hashType,
|
const ContentAddressMethod & method, const HashAlgorithm & hashAlgo,
|
||||||
const StorePath & path)
|
const StorePath & path)
|
||||||
{
|
{
|
||||||
return hashCAPath(method, hashType, Store::toRealPath(path), path.hashPart());
|
return hashCAPath(method, hashAlgo, Store::toRealPath(path), path.hashPart());
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentAddress LocalStore::hashCAPath(
|
ContentAddress LocalStore::hashCAPath(
|
||||||
const ContentAddressMethod & method,
|
const ContentAddressMethod & method,
|
||||||
const HashType & hashType,
|
const HashAlgorithm & hashAlgo,
|
||||||
const Path & path,
|
const Path & path,
|
||||||
const std::string_view pathHash
|
const std::string_view pathHash
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
HashModuloSink caSink ( hashType, std::string(pathHash) );
|
HashModuloSink caSink ( hashAlgo, std::string(pathHash) );
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](const TextIngestionMethod &) {
|
[&](const TextIngestionMethod &) {
|
||||||
readFile(path, caSink);
|
readFile(path, caSink);
|
||||||
|
|
|
@ -178,7 +178,7 @@ public:
|
||||||
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
||||||
|
|
||||||
StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
||||||
FileIngestionMethod method, HashType hashAlgo, RepairFlag repair, const StorePathSet & references) override;
|
FileIngestionMethod method, HashAlgorithm hashAlgo, RepairFlag repair, const StorePathSet & references) override;
|
||||||
|
|
||||||
StorePath addTextToStore(
|
StorePath addTextToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
|
@ -353,12 +353,12 @@ private:
|
||||||
// XXX: Make a generic `Store` method
|
// XXX: Make a generic `Store` method
|
||||||
ContentAddress hashCAPath(
|
ContentAddress hashCAPath(
|
||||||
const ContentAddressMethod & method,
|
const ContentAddressMethod & method,
|
||||||
const HashType & hashType,
|
const HashAlgorithm & hashAlgo,
|
||||||
const StorePath & path);
|
const StorePath & path);
|
||||||
|
|
||||||
ContentAddress hashCAPath(
|
ContentAddress hashCAPath(
|
||||||
const ContentAddressMethod & method,
|
const ContentAddressMethod & method,
|
||||||
const HashType & hashType,
|
const HashAlgorithm & hashAlgo,
|
||||||
const Path & path,
|
const Path & path,
|
||||||
const std::string_view pathHash
|
const std::string_view pathHash
|
||||||
);
|
);
|
||||||
|
|
|
@ -43,7 +43,7 @@ std::map<StorePath, StorePath> makeContentAddressed(
|
||||||
|
|
||||||
sink.s = rewriteStrings(sink.s, rewrites);
|
sink.s = rewriteStrings(sink.s, rewrites);
|
||||||
|
|
||||||
HashModuloSink hashModuloSink(htSHA256, oldHashPart);
|
HashModuloSink hashModuloSink(HashAlgorithm::SHA256, oldHashPart);
|
||||||
hashModuloSink(sink.s);
|
hashModuloSink(sink.s);
|
||||||
|
|
||||||
auto narModuloHash = hashModuloSink.finish().first;
|
auto narModuloHash = hashModuloSink.finish().first;
|
||||||
|
@ -66,7 +66,7 @@ std::map<StorePath, StorePath> makeContentAddressed(
|
||||||
rsink2(sink.s);
|
rsink2(sink.s);
|
||||||
rsink2.flush();
|
rsink2.flush();
|
||||||
|
|
||||||
info.narHash = hashString(htSHA256, sink2.s);
|
info.narHash = hashString(HashAlgorithm::SHA256, sink2.s);
|
||||||
info.narSize = sink.s.size();
|
info.narSize = sink.s.size();
|
||||||
|
|
||||||
StringSource source(sink2.s);
|
StringSource source(sink2.s);
|
||||||
|
|
|
@ -113,10 +113,10 @@ std::string NarInfo::to_string(const Store & store) const
|
||||||
res += "URL: " + url + "\n";
|
res += "URL: " + url + "\n";
|
||||||
assert(compression != "");
|
assert(compression != "");
|
||||||
res += "Compression: " + compression + "\n";
|
res += "Compression: " + compression + "\n";
|
||||||
assert(fileHash && fileHash->type == htSHA256);
|
assert(fileHash && fileHash->algo == HashAlgorithm::SHA256);
|
||||||
res += "FileHash: " + fileHash->to_string(HashFormat::Base32, true) + "\n";
|
res += "FileHash: " + fileHash->to_string(HashFormat::Base32, true) + "\n";
|
||||||
res += "FileSize: " + std::to_string(fileSize) + "\n";
|
res += "FileSize: " + std::to_string(fileSize) + "\n";
|
||||||
assert(narHash.type == htSHA256);
|
assert(narHash.algo == HashAlgorithm::SHA256);
|
||||||
res += "NarHash: " + narHash.to_string(HashFormat::Base32, true) + "\n";
|
res += "NarHash: " + narHash.to_string(HashFormat::Base32, true) + "\n";
|
||||||
res += "NarSize: " + std::to_string(narSize) + "\n";
|
res += "NarSize: " + std::to_string(narSize) + "\n";
|
||||||
|
|
||||||
|
|
|
@ -146,7 +146,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
|
||||||
Also note that if `path' is a symlink, then we're hashing the
|
Also note that if `path' is a symlink, then we're hashing the
|
||||||
contents of the symlink (i.e. the result of readlink()), not
|
contents of the symlink (i.e. the result of readlink()), not
|
||||||
the contents of the target (which may not even exist). */
|
the contents of the target (which may not even exist). */
|
||||||
Hash hash = hashPath(htSHA256, path).first;
|
Hash hash = hashPath(HashAlgorithm::SHA256, path).first;
|
||||||
debug("'%1%' has hash '%2%'", path, hash.to_string(HashFormat::Base32, true));
|
debug("'%1%' has hash '%2%'", path, hash.to_string(HashFormat::Base32, true));
|
||||||
|
|
||||||
/* Check if this is a known hash. */
|
/* Check if this is a known hash. */
|
||||||
|
@ -156,7 +156,7 @@ void LocalStore::optimisePath_(Activity * act, OptimiseStats & stats,
|
||||||
if (pathExists(linkPath)) {
|
if (pathExists(linkPath)) {
|
||||||
auto stLink = lstat(linkPath);
|
auto stLink = lstat(linkPath);
|
||||||
if (st.st_size != stLink.st_size
|
if (st.st_size != stLink.st_size
|
||||||
|| (repair && hash != hashPath(htSHA256, linkPath).first))
|
|| (repair && hash != hashPath(HashAlgorithm::SHA256, linkPath).first))
|
||||||
{
|
{
|
||||||
// XXX: Consider overwriting linkPath with our valid version.
|
// XXX: Consider overwriting linkPath with our valid version.
|
||||||
warn("removing corrupted link '%s'", linkPath);
|
warn("removing corrupted link '%s'", linkPath);
|
||||||
|
|
|
@ -49,7 +49,7 @@ std::pair<StorePathSet, HashResult> scanForReferences(
|
||||||
const std::string & path,
|
const std::string & path,
|
||||||
const StorePathSet & refs)
|
const StorePathSet & refs)
|
||||||
{
|
{
|
||||||
HashSink hashSink { htSHA256 };
|
HashSink hashSink { HashAlgorithm::SHA256 };
|
||||||
auto found = scanForReferences(hashSink, path, refs);
|
auto found = scanForReferences(hashSink, path, refs);
|
||||||
auto hash = hashSink.finish();
|
auto hash = hashSink.finish();
|
||||||
return std::pair<StorePathSet, HashResult>(found, hash);
|
return std::pair<StorePathSet, HashResult>(found, hash);
|
||||||
|
|
|
@ -49,7 +49,7 @@ StorePath StorePath::dummy("ffffffffffffffffffffffffffffffff-x");
|
||||||
|
|
||||||
StorePath StorePath::random(std::string_view name)
|
StorePath StorePath::random(std::string_view name)
|
||||||
{
|
{
|
||||||
Hash hash(htSHA1);
|
Hash hash(HashAlgorithm::SHA1);
|
||||||
randombytes_buf(hash.hash, hash.hashSize);
|
randombytes_buf(hash.hash, hash.hashSize);
|
||||||
return StorePath(hash, name);
|
return StorePath(hash, name);
|
||||||
}
|
}
|
||||||
|
|
|
@ -417,12 +417,12 @@ std::optional<StorePath> RemoteStore::queryPathFromHashPart(const std::string &
|
||||||
|
|
||||||
|
|
||||||
ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
||||||
Source & dump,
|
Source & dump,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
ContentAddressMethod caMethod,
|
ContentAddressMethod caMethod,
|
||||||
HashType hashType,
|
HashAlgorithm hashAlgo,
|
||||||
const StorePathSet & references,
|
const StorePathSet & references,
|
||||||
RepairFlag repair)
|
RepairFlag repair)
|
||||||
{
|
{
|
||||||
std::optional<ConnectionHandle> conn_(getConnection());
|
std::optional<ConnectionHandle> conn_(getConnection());
|
||||||
auto & conn = *conn_;
|
auto & conn = *conn_;
|
||||||
|
@ -432,7 +432,7 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
||||||
conn->to
|
conn->to
|
||||||
<< WorkerProto::Op::AddToStore
|
<< WorkerProto::Op::AddToStore
|
||||||
<< name
|
<< name
|
||||||
<< caMethod.render(hashType);
|
<< caMethod.render(hashAlgo);
|
||||||
WorkerProto::write(*this, *conn, references);
|
WorkerProto::write(*this, *conn, references);
|
||||||
conn->to << repair;
|
conn->to << repair;
|
||||||
|
|
||||||
|
@ -453,9 +453,9 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
||||||
|
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](const TextIngestionMethod & thm) -> void {
|
[&](const TextIngestionMethod & thm) -> void {
|
||||||
if (hashType != htSHA256)
|
if (hashAlgo != HashAlgorithm::SHA256)
|
||||||
throw UnimplementedError("When adding text-hashed data called '%s', only SHA-256 is supported but '%s' was given",
|
throw UnimplementedError("When adding text-hashed data called '%s', only SHA-256 is supported but '%s' was given",
|
||||||
name, printHashType(hashType));
|
name, printHashAlgo(hashAlgo));
|
||||||
std::string s = dump.drain();
|
std::string s = dump.drain();
|
||||||
conn->to << WorkerProto::Op::AddTextToStore << name << s;
|
conn->to << WorkerProto::Op::AddTextToStore << name << s;
|
||||||
WorkerProto::write(*this, *conn, references);
|
WorkerProto::write(*this, *conn, references);
|
||||||
|
@ -465,9 +465,9 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
||||||
conn->to
|
conn->to
|
||||||
<< WorkerProto::Op::AddToStore
|
<< WorkerProto::Op::AddToStore
|
||||||
<< name
|
<< name
|
||||||
<< ((hashType == htSHA256 && fim == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */
|
<< ((hashAlgo == HashAlgorithm::SHA256 && fim == FileIngestionMethod::Recursive) ? 0 : 1) /* backwards compatibility hack */
|
||||||
<< (fim == FileIngestionMethod::Recursive ? 1 : 0)
|
<< (fim == FileIngestionMethod::Recursive ? 1 : 0)
|
||||||
<< printHashType(hashType);
|
<< printHashAlgo(hashAlgo);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn->to.written = 0;
|
conn->to.written = 0;
|
||||||
|
@ -503,9 +503,9 @@ ref<const ValidPathInfo> RemoteStore::addCAToStore(
|
||||||
|
|
||||||
|
|
||||||
StorePath RemoteStore::addToStoreFromDump(Source & dump, std::string_view name,
|
StorePath RemoteStore::addToStoreFromDump(Source & dump, std::string_view name,
|
||||||
FileIngestionMethod method, HashType hashType, RepairFlag repair, const StorePathSet & references)
|
FileIngestionMethod method, HashAlgorithm hashAlgo, RepairFlag repair, const StorePathSet & references)
|
||||||
{
|
{
|
||||||
return addCAToStore(dump, name, method, hashType, references, repair)->path;
|
return addCAToStore(dump, name, method, hashAlgo, references, repair)->path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ StorePath RemoteStore::addTextToStore(
|
||||||
RepairFlag repair)
|
RepairFlag repair)
|
||||||
{
|
{
|
||||||
StringSource source(s);
|
StringSource source(s);
|
||||||
return addCAToStore(source, name, TextIngestionMethod {}, htSHA256, references, repair)->path;
|
return addCAToStore(source, name, TextIngestionMethod {}, HashAlgorithm::SHA256, references, repair)->path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteStore::registerDrvOutput(const Realisation & info)
|
void RemoteStore::registerDrvOutput(const Realisation & info)
|
||||||
|
|
|
@ -74,18 +74,18 @@ public:
|
||||||
* Add a content-addressable store path. `dump` will be drained.
|
* Add a content-addressable store path. `dump` will be drained.
|
||||||
*/
|
*/
|
||||||
ref<const ValidPathInfo> addCAToStore(
|
ref<const ValidPathInfo> addCAToStore(
|
||||||
Source & dump,
|
Source & dump,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
ContentAddressMethod caMethod,
|
ContentAddressMethod caMethod,
|
||||||
HashType hashType,
|
HashAlgorithm hashAlgo,
|
||||||
const StorePathSet & references,
|
const StorePathSet & references,
|
||||||
RepairFlag repair);
|
RepairFlag repair);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a content-addressable store path. Does not support references. `dump` will be drained.
|
* Add a content-addressable store path. Does not support references. `dump` will be drained.
|
||||||
*/
|
*/
|
||||||
StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
||||||
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair, const StorePathSet & references = StorePathSet()) override;
|
FileIngestionMethod method = FileIngestionMethod::Recursive, HashAlgorithm hashAlgo = HashAlgorithm::SHA256, RepairFlag repair = NoRepair, const StorePathSet & references = StorePathSet()) override;
|
||||||
|
|
||||||
void addToStore(const ValidPathInfo & info, Source & nar,
|
void addToStore(const ValidPathInfo & info, Source & nar,
|
||||||
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
RepairFlag repair, CheckSigsFlag checkSigs) override;
|
||||||
|
|
|
@ -153,7 +153,7 @@ StorePath StoreDirConfig::makeStorePath(std::string_view type,
|
||||||
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
|
/* e.g., "source:sha256:1abc...:/nix/store:foo.tar.gz" */
|
||||||
auto s = std::string(type) + ":" + std::string(hash)
|
auto s = std::string(type) + ":" + std::string(hash)
|
||||||
+ ":" + storeDir + ":" + std::string(name);
|
+ ":" + storeDir + ":" + std::string(name);
|
||||||
auto h = compressHash(hashString(htSHA256, s), 20);
|
auto h = compressHash(hashString(HashAlgorithm::SHA256, s), 20);
|
||||||
return StorePath(h, name);
|
return StorePath(h, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,12 +191,12 @@ static std::string makeType(
|
||||||
|
|
||||||
StorePath StoreDirConfig::makeFixedOutputPath(std::string_view name, const FixedOutputInfo & info) const
|
StorePath StoreDirConfig::makeFixedOutputPath(std::string_view name, const FixedOutputInfo & info) const
|
||||||
{
|
{
|
||||||
if (info.hash.type == htSHA256 && info.method == FileIngestionMethod::Recursive) {
|
if (info.hash.algo == HashAlgorithm::SHA256 && info.method == FileIngestionMethod::Recursive) {
|
||||||
return makeStorePath(makeType(*this, "source", info.references), info.hash, name);
|
return makeStorePath(makeType(*this, "source", info.references), info.hash, name);
|
||||||
} else {
|
} else {
|
||||||
assert(info.references.size() == 0);
|
assert(info.references.size() == 0);
|
||||||
return makeStorePath("output:out",
|
return makeStorePath("output:out",
|
||||||
hashString(htSHA256,
|
hashString(HashAlgorithm::SHA256,
|
||||||
"fixed:out:"
|
"fixed:out:"
|
||||||
+ makeFileIngestionPrefix(info.method)
|
+ makeFileIngestionPrefix(info.method)
|
||||||
+ info.hash.to_string(HashFormat::Base16, true) + ":"),
|
+ info.hash.to_string(HashFormat::Base16, true) + ":"),
|
||||||
|
@ -207,7 +207,7 @@ StorePath StoreDirConfig::makeFixedOutputPath(std::string_view name, const Fixed
|
||||||
|
|
||||||
StorePath StoreDirConfig::makeTextPath(std::string_view name, const TextInfo & info) const
|
StorePath StoreDirConfig::makeTextPath(std::string_view name, const TextInfo & info) const
|
||||||
{
|
{
|
||||||
assert(info.hash.type == htSHA256);
|
assert(info.hash.algo == HashAlgorithm::SHA256);
|
||||||
return makeStorePath(
|
return makeStorePath(
|
||||||
makeType(*this, "text", StoreReferences {
|
makeType(*this, "text", StoreReferences {
|
||||||
.others = info.references,
|
.others = info.references,
|
||||||
|
@ -233,11 +233,11 @@ StorePath StoreDirConfig::makeFixedOutputPathFromCA(std::string_view name, const
|
||||||
|
|
||||||
|
|
||||||
std::pair<StorePath, Hash> StoreDirConfig::computeStorePathFromDump(
|
std::pair<StorePath, Hash> StoreDirConfig::computeStorePathFromDump(
|
||||||
Source & dump,
|
Source & dump,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
FileIngestionMethod method,
|
FileIngestionMethod method,
|
||||||
HashType hashAlgo,
|
HashAlgorithm hashAlgo,
|
||||||
const StorePathSet & references) const
|
const StorePathSet & references) const
|
||||||
{
|
{
|
||||||
HashSink sink(hashAlgo);
|
HashSink sink(hashAlgo);
|
||||||
dump.drainInto(sink);
|
dump.drainInto(sink);
|
||||||
|
@ -257,20 +257,20 @@ StorePath StoreDirConfig::computeStorePathForText(
|
||||||
const StorePathSet & references) const
|
const StorePathSet & references) const
|
||||||
{
|
{
|
||||||
return makeTextPath(name, TextInfo {
|
return makeTextPath(name, TextInfo {
|
||||||
.hash = hashString(htSHA256, s),
|
.hash = hashString(HashAlgorithm::SHA256, s),
|
||||||
.references = references,
|
.references = references,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
StorePath Store::addToStore(
|
StorePath Store::addToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
const Path & _srcPath,
|
const Path & _srcPath,
|
||||||
FileIngestionMethod method,
|
FileIngestionMethod method,
|
||||||
HashType hashAlgo,
|
HashAlgorithm hashAlgo,
|
||||||
PathFilter & filter,
|
PathFilter & filter,
|
||||||
RepairFlag repair,
|
RepairFlag repair,
|
||||||
const StorePathSet & references)
|
const StorePathSet & references)
|
||||||
{
|
{
|
||||||
Path srcPath(absPath(_srcPath));
|
Path srcPath(absPath(_srcPath));
|
||||||
auto source = sinkToSource([&](Sink & sink) {
|
auto source = sinkToSource([&](Sink & sink) {
|
||||||
|
@ -405,10 +405,10 @@ digraph graphname {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
ValidPathInfo Store::addToStoreSlow(std::string_view name, const Path & srcPath,
|
ValidPathInfo Store::addToStoreSlow(std::string_view name, const Path & srcPath,
|
||||||
FileIngestionMethod method, HashType hashAlgo,
|
FileIngestionMethod method, HashAlgorithm hashAlgo,
|
||||||
std::optional<Hash> expectedCAHash)
|
std::optional<Hash> expectedCAHash)
|
||||||
{
|
{
|
||||||
HashSink narHashSink { htSHA256 };
|
HashSink narHashSink { HashAlgorithm::SHA256 };
|
||||||
HashSink caHashSink { hashAlgo };
|
HashSink caHashSink { hashAlgo };
|
||||||
|
|
||||||
/* Note that fileSink and unusualHashTee must be mutually exclusive, since
|
/* Note that fileSink and unusualHashTee must be mutually exclusive, since
|
||||||
|
@ -417,7 +417,7 @@ ValidPathInfo Store::addToStoreSlow(std::string_view name, const Path & srcPath,
|
||||||
RegularFileSink fileSink { caHashSink };
|
RegularFileSink fileSink { caHashSink };
|
||||||
TeeSink unusualHashTee { narHashSink, caHashSink };
|
TeeSink unusualHashTee { narHashSink, caHashSink };
|
||||||
|
|
||||||
auto & narSink = method == FileIngestionMethod::Recursive && hashAlgo != htSHA256
|
auto & narSink = method == FileIngestionMethod::Recursive && hashAlgo != HashAlgorithm::SHA256
|
||||||
? static_cast<Sink &>(unusualHashTee)
|
? static_cast<Sink &>(unusualHashTee)
|
||||||
: narHashSink;
|
: narHashSink;
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ ValidPathInfo Store::addToStoreSlow(std::string_view name, const Path & srcPath,
|
||||||
finish. */
|
finish. */
|
||||||
auto [narHash, narSize] = narHashSink.finish();
|
auto [narHash, narSize] = narHashSink.finish();
|
||||||
|
|
||||||
auto hash = method == FileIngestionMethod::Recursive && hashAlgo == htSHA256
|
auto hash = method == FileIngestionMethod::Recursive && hashAlgo == HashAlgorithm::SHA256
|
||||||
? narHash
|
? narHash
|
||||||
: caHashSink.finish().first;
|
: caHashSink.finish().first;
|
||||||
|
|
||||||
|
@ -1205,7 +1205,7 @@ std::optional<ValidPathInfo> decodeValidPathInfo(const Store & store, std::istre
|
||||||
if (!hashGiven) {
|
if (!hashGiven) {
|
||||||
std::string s;
|
std::string s;
|
||||||
getline(str, s);
|
getline(str, s);
|
||||||
auto narHash = Hash::parseAny(s, htSHA256);
|
auto narHash = Hash::parseAny(s, HashAlgorithm::SHA256);
|
||||||
getline(str, s);
|
getline(str, s);
|
||||||
auto narSize = string2Int<uint64_t>(s);
|
auto narSize = string2Int<uint64_t>(s);
|
||||||
if (!narSize) throw Error("number expected");
|
if (!narSize) throw Error("number expected");
|
||||||
|
|
|
@ -427,13 +427,13 @@ public:
|
||||||
* libutil/archive.hh).
|
* libutil/archive.hh).
|
||||||
*/
|
*/
|
||||||
virtual StorePath addToStore(
|
virtual StorePath addToStore(
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
const Path & srcPath,
|
const Path & srcPath,
|
||||||
FileIngestionMethod method = FileIngestionMethod::Recursive,
|
FileIngestionMethod method = FileIngestionMethod::Recursive,
|
||||||
HashType hashAlgo = htSHA256,
|
HashAlgorithm hashAlgo = HashAlgorithm::SHA256,
|
||||||
PathFilter & filter = defaultPathFilter,
|
PathFilter & filter = defaultPathFilter,
|
||||||
RepairFlag repair = NoRepair,
|
RepairFlag repair = NoRepair,
|
||||||
const StorePathSet & references = StorePathSet());
|
const StorePathSet & references = StorePathSet());
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy the contents of a path to the store and register the
|
* Copy the contents of a path to the store and register the
|
||||||
|
@ -441,8 +441,8 @@ public:
|
||||||
* memory.
|
* memory.
|
||||||
*/
|
*/
|
||||||
ValidPathInfo addToStoreSlow(std::string_view name, const Path & srcPath,
|
ValidPathInfo addToStoreSlow(std::string_view name, const Path & srcPath,
|
||||||
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256,
|
FileIngestionMethod method = FileIngestionMethod::Recursive, HashAlgorithm hashAlgo = HashAlgorithm::SHA256,
|
||||||
std::optional<Hash> expectedCAHash = {});
|
std::optional<Hash> expectedCAHash = {});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like addToStore(), but the contents of the path are contained
|
* Like addToStore(), but the contents of the path are contained
|
||||||
|
@ -454,8 +454,8 @@ public:
|
||||||
* \todo remove?
|
* \todo remove?
|
||||||
*/
|
*/
|
||||||
virtual StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
virtual StorePath addToStoreFromDump(Source & dump, std::string_view name,
|
||||||
FileIngestionMethod method = FileIngestionMethod::Recursive, HashType hashAlgo = htSHA256, RepairFlag repair = NoRepair,
|
FileIngestionMethod method = FileIngestionMethod::Recursive, HashAlgorithm hashAlgo = HashAlgorithm::SHA256, RepairFlag repair = NoRepair,
|
||||||
const StorePathSet & references = StorePathSet())
|
const StorePathSet & references = StorePathSet())
|
||||||
{ unsupported("addToStoreFromDump"); }
|
{ unsupported("addToStoreFromDump"); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -98,7 +98,7 @@ struct StoreDirConfig : public Config
|
||||||
Source & dump,
|
Source & dump,
|
||||||
std::string_view name,
|
std::string_view name,
|
||||||
FileIngestionMethod method = FileIngestionMethod::Recursive,
|
FileIngestionMethod method = FileIngestionMethod::Recursive,
|
||||||
HashType hashAlgo = htSHA256,
|
HashAlgorithm hashAlgo = HashAlgorithm::SHA256,
|
||||||
const StorePathSet & references = {}) const;
|
const StorePathSet & references = {}) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -160,7 +160,7 @@ void WorkerProto::Serialise<ValidPathInfo>::write(const StoreDirConfig & store,
|
||||||
UnkeyedValidPathInfo WorkerProto::Serialise<UnkeyedValidPathInfo>::read(const StoreDirConfig & store, ReadConn conn)
|
UnkeyedValidPathInfo WorkerProto::Serialise<UnkeyedValidPathInfo>::read(const StoreDirConfig & store, ReadConn conn)
|
||||||
{
|
{
|
||||||
auto deriver = readString(conn.from);
|
auto deriver = readString(conn.from);
|
||||||
auto narHash = Hash::parseAny(readString(conn.from), htSHA256);
|
auto narHash = Hash::parseAny(readString(conn.from), HashAlgorithm::SHA256);
|
||||||
UnkeyedValidPathInfo info(narHash);
|
UnkeyedValidPathInfo info(narHash);
|
||||||
if (deriver != "") info.deriver = store.parseStorePath(deriver);
|
if (deriver != "") info.deriver = store.parseStorePath(deriver);
|
||||||
info.references = WorkerProto::Serialise<StorePathSet>::read(store, conn);
|
info.references = WorkerProto::Serialise<StorePathSet>::read(store, conn);
|
||||||
|
|
|
@ -546,32 +546,32 @@ nlohmann::json Args::toJSON()
|
||||||
|
|
||||||
static void hashTypeCompleter(AddCompletions & completions, size_t index, std::string_view prefix)
|
static void hashTypeCompleter(AddCompletions & completions, size_t index, std::string_view prefix)
|
||||||
{
|
{
|
||||||
for (auto & type : hashTypes)
|
for (auto & type : hashAlgorithms)
|
||||||
if (hasPrefix(type, prefix))
|
if (hasPrefix(type, prefix))
|
||||||
completions.add(type);
|
completions.add(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
Args::Flag Args::Flag::mkHashTypeFlag(std::string && longName, HashType * ht)
|
Args::Flag Args::Flag::mkHashTypeFlag(std::string && longName, HashAlgorithm * ha)
|
||||||
{
|
{
|
||||||
return Flag {
|
return Flag {
|
||||||
.longName = std::move(longName),
|
.longName = std::move(longName),
|
||||||
.description = "hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')",
|
.description = "hash algorithm ('md5', 'sha1', 'sha256', or 'sha512')",
|
||||||
.labels = {"hash-algo"},
|
.labels = {"hash-algo"},
|
||||||
.handler = {[ht](std::string s) {
|
.handler = {[ha](std::string s) {
|
||||||
*ht = parseHashType(s);
|
*ha = parseHashAlgo(s);
|
||||||
}},
|
}},
|
||||||
.completer = hashTypeCompleter,
|
.completer = hashTypeCompleter,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Args::Flag Args::Flag::mkHashTypeOptFlag(std::string && longName, std::optional<HashType> * oht)
|
Args::Flag Args::Flag::mkHashTypeOptFlag(std::string && longName, std::optional<HashAlgorithm> * oha)
|
||||||
{
|
{
|
||||||
return Flag {
|
return Flag {
|
||||||
.longName = std::move(longName),
|
.longName = std::move(longName),
|
||||||
.description = "hash algorithm ('md5', 'sha1', 'sha256', or 'sha512'). Optional as can also be gotten from SRI hash itself.",
|
.description = "hash algorithm ('md5', 'sha1', 'sha256', or 'sha512'). Optional as can also be gotten from SRI hash itself.",
|
||||||
.labels = {"hash-algo"},
|
.labels = {"hash-algo"},
|
||||||
.handler = {[oht](std::string s) {
|
.handler = {[oha](std::string s) {
|
||||||
*oht = std::optional<HashType> { parseHashType(s) };
|
*oha = std::optional<HashAlgorithm> {parseHashAlgo(s) };
|
||||||
}},
|
}},
|
||||||
.completer = hashTypeCompleter,
|
.completer = hashTypeCompleter,
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
enum HashType : char;
|
enum struct HashAlgorithm : char;
|
||||||
|
|
||||||
class MultiCommand;
|
class MultiCommand;
|
||||||
|
|
||||||
|
@ -175,8 +175,8 @@ protected:
|
||||||
|
|
||||||
std::optional<ExperimentalFeature> experimentalFeature;
|
std::optional<ExperimentalFeature> experimentalFeature;
|
||||||
|
|
||||||
static Flag mkHashTypeFlag(std::string && longName, HashType * ht);
|
static Flag mkHashTypeFlag(std::string && longName, HashAlgorithm * ha);
|
||||||
static Flag mkHashTypeOptFlag(std::string && longName, std::optional<HashType> * oht);
|
static Flag mkHashTypeOptFlag(std::string && longName, std::optional<HashAlgorithm> * oha);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -106,7 +106,7 @@ void parse(
|
||||||
std::string hashs = getString(source, 20);
|
std::string hashs = getString(source, 20);
|
||||||
left -= 20;
|
left -= 20;
|
||||||
|
|
||||||
Hash hash(htSHA1);
|
Hash hash(HashAlgorithm::SHA1);
|
||||||
std::copy(hashs.begin(), hashs.end(), hash.hash);
|
std::copy(hashs.begin(), hashs.end(), hash.hash);
|
||||||
|
|
||||||
hook(name, TreeEntry {
|
hook(name, TreeEntry {
|
||||||
|
@ -241,12 +241,12 @@ Mode dump(
|
||||||
|
|
||||||
|
|
||||||
TreeEntry dumpHash(
|
TreeEntry dumpHash(
|
||||||
HashType ht,
|
HashAlgorithm ha,
|
||||||
SourceAccessor & accessor, const CanonPath & path, PathFilter & filter)
|
SourceAccessor & accessor, const CanonPath & path, PathFilter & filter)
|
||||||
{
|
{
|
||||||
std::function<DumpHook> hook;
|
std::function<DumpHook> hook;
|
||||||
hook = [&](const CanonPath & path) -> TreeEntry {
|
hook = [&](const CanonPath & path) -> TreeEntry {
|
||||||
auto hashSink = HashSink(ht);
|
auto hashSink = HashSink(ha);
|
||||||
auto mode = dump(accessor, path, hashSink, hook, filter);
|
auto mode = dump(accessor, path, hashSink, hook, filter);
|
||||||
auto hash = hashSink.finish().first;
|
auto hash = hashSink.finish().first;
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -123,9 +123,9 @@ Mode dump(
|
||||||
* A smaller wrapper around `dump`.
|
* A smaller wrapper around `dump`.
|
||||||
*/
|
*/
|
||||||
TreeEntry dumpHash(
|
TreeEntry dumpHash(
|
||||||
HashType ht,
|
HashAlgorithm ha,
|
||||||
SourceAccessor & accessor, const CanonPath & path,
|
SourceAccessor & accessor, const CanonPath & path,
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A line from the output of `git ls-remote --symref`.
|
* A line from the output of `git ls-remote --symref`.
|
||||||
|
|
|
@ -16,23 +16,23 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
static size_t regularHashSize(HashType type) {
|
static size_t regularHashSize(HashAlgorithm type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case htMD5: return md5HashSize;
|
case HashAlgorithm::MD5: return md5HashSize;
|
||||||
case htSHA1: return sha1HashSize;
|
case HashAlgorithm::SHA1: return sha1HashSize;
|
||||||
case htSHA256: return sha256HashSize;
|
case HashAlgorithm::SHA256: return sha256HashSize;
|
||||||
case htSHA512: return sha512HashSize;
|
case HashAlgorithm::SHA512: return sha512HashSize;
|
||||||
}
|
}
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::set<std::string> hashTypes = { "md5", "sha1", "sha256", "sha512" };
|
std::set<std::string> hashAlgorithms = {"md5", "sha1", "sha256", "sha512" };
|
||||||
|
|
||||||
|
|
||||||
Hash::Hash(HashType type) : type(type)
|
Hash::Hash(HashAlgorithm algo) : algo(algo)
|
||||||
{
|
{
|
||||||
hashSize = regularHashSize(type);
|
hashSize = regularHashSize(algo);
|
||||||
assert(hashSize <= maxHashSize);
|
assert(hashSize <= maxHashSize);
|
||||||
memset(hash, 0, maxHashSize);
|
memset(hash, 0, maxHashSize);
|
||||||
}
|
}
|
||||||
|
@ -109,16 +109,16 @@ static std::string printHash32(const Hash & hash)
|
||||||
|
|
||||||
std::string printHash16or32(const Hash & hash)
|
std::string printHash16or32(const Hash & hash)
|
||||||
{
|
{
|
||||||
assert(hash.type);
|
assert(static_cast<char>(hash.algo));
|
||||||
return hash.to_string(hash.type == htMD5 ? HashFormat::Base16 : HashFormat::Base32, false);
|
return hash.to_string(hash.algo == HashAlgorithm::MD5 ? HashFormat::Base16 : HashFormat::Base32, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Hash::to_string(HashFormat hashFormat, bool includeType) const
|
std::string Hash::to_string(HashFormat hashFormat, bool includeAlgo) const
|
||||||
{
|
{
|
||||||
std::string s;
|
std::string s;
|
||||||
if (hashFormat == HashFormat::SRI || includeType) {
|
if (hashFormat == HashFormat::SRI || includeAlgo) {
|
||||||
s += printHashType(type);
|
s += printHashAlgo(algo);
|
||||||
s += hashFormat == HashFormat::SRI ? '-' : ':';
|
s += hashFormat == HashFormat::SRI ? '-' : ':';
|
||||||
}
|
}
|
||||||
switch (hashFormat) {
|
switch (hashFormat) {
|
||||||
|
@ -136,7 +136,7 @@ std::string Hash::to_string(HashFormat hashFormat, bool includeType) const
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
Hash Hash::dummy(htSHA256);
|
Hash Hash::dummy(HashAlgorithm::SHA256);
|
||||||
|
|
||||||
Hash Hash::parseSRI(std::string_view original) {
|
Hash Hash::parseSRI(std::string_view original) {
|
||||||
auto rest = original;
|
auto rest = original;
|
||||||
|
@ -145,18 +145,18 @@ Hash Hash::parseSRI(std::string_view original) {
|
||||||
auto hashRaw = splitPrefixTo(rest, '-');
|
auto hashRaw = splitPrefixTo(rest, '-');
|
||||||
if (!hashRaw)
|
if (!hashRaw)
|
||||||
throw BadHash("hash '%s' is not SRI", original);
|
throw BadHash("hash '%s' is not SRI", original);
|
||||||
HashType parsedType = parseHashType(*hashRaw);
|
HashAlgorithm parsedType = parseHashAlgo(*hashRaw);
|
||||||
|
|
||||||
return Hash(rest, parsedType, true);
|
return Hash(rest, parsedType, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mutates the string to eliminate the prefixes when found
|
// Mutates the string to eliminate the prefixes when found
|
||||||
static std::pair<std::optional<HashType>, bool> getParsedTypeAndSRI(std::string_view & rest)
|
static std::pair<std::optional<HashAlgorithm>, bool> getParsedTypeAndSRI(std::string_view & rest)
|
||||||
{
|
{
|
||||||
bool isSRI = false;
|
bool isSRI = false;
|
||||||
|
|
||||||
// Parse the hash type before the separator, if there was one.
|
// Parse the hash type before the separator, if there was one.
|
||||||
std::optional<HashType> optParsedType;
|
std::optional<HashAlgorithm> optParsedType;
|
||||||
{
|
{
|
||||||
auto hashRaw = splitPrefixTo(rest, ':');
|
auto hashRaw = splitPrefixTo(rest, ':');
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ static std::pair<std::optional<HashType>, bool> getParsedTypeAndSRI(std::string_
|
||||||
isSRI = true;
|
isSRI = true;
|
||||||
}
|
}
|
||||||
if (hashRaw)
|
if (hashRaw)
|
||||||
optParsedType = parseHashType(*hashRaw);
|
optParsedType = parseHashAlgo(*hashRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {optParsedType, isSRI};
|
return {optParsedType, isSRI};
|
||||||
|
@ -185,29 +185,29 @@ Hash Hash::parseAnyPrefixed(std::string_view original)
|
||||||
return Hash(rest, *optParsedType, isSRI);
|
return Hash(rest, *optParsedType, isSRI);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hash Hash::parseAny(std::string_view original, std::optional<HashType> optType)
|
Hash Hash::parseAny(std::string_view original, std::optional<HashAlgorithm> optAlgo)
|
||||||
{
|
{
|
||||||
auto rest = original;
|
auto rest = original;
|
||||||
auto [optParsedType, isSRI] = getParsedTypeAndSRI(rest);
|
auto [optParsedType, isSRI] = getParsedTypeAndSRI(rest);
|
||||||
|
|
||||||
// Either the string or user must provide the type, if they both do they
|
// Either the string or user must provide the type, if they both do they
|
||||||
// must agree.
|
// must agree.
|
||||||
if (!optParsedType && !optType)
|
if (!optParsedType && !optAlgo)
|
||||||
throw BadHash("hash '%s' does not include a type, nor is the type otherwise known from context", rest);
|
throw BadHash("hash '%s' does not include a type, nor is the type otherwise known from context", rest);
|
||||||
else if (optParsedType && optType && *optParsedType != *optType)
|
else if (optParsedType && optAlgo && *optParsedType != *optAlgo)
|
||||||
throw BadHash("hash '%s' should have type '%s'", original, printHashType(*optType));
|
throw BadHash("hash '%s' should have type '%s'", original, printHashAlgo(*optAlgo));
|
||||||
|
|
||||||
HashType hashType = optParsedType ? *optParsedType : *optType;
|
HashAlgorithm hashAlgo = optParsedType ? *optParsedType : *optAlgo;
|
||||||
return Hash(rest, hashType, isSRI);
|
return Hash(rest, hashAlgo, isSRI);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hash Hash::parseNonSRIUnprefixed(std::string_view s, HashType type)
|
Hash Hash::parseNonSRIUnprefixed(std::string_view s, HashAlgorithm algo)
|
||||||
{
|
{
|
||||||
return Hash(s, type, false);
|
return Hash(s, algo, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Hash::Hash(std::string_view rest, HashType type, bool isSRI)
|
Hash::Hash(std::string_view rest, HashAlgorithm algo, bool isSRI)
|
||||||
: Hash(type)
|
: Hash(algo)
|
||||||
{
|
{
|
||||||
if (!isSRI && rest.size() == base16Len()) {
|
if (!isSRI && rest.size() == base16Len()) {
|
||||||
|
|
||||||
|
@ -257,19 +257,19 @@ Hash::Hash(std::string_view rest, HashType type, bool isSRI)
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
throw BadHash("hash '%s' has wrong length for hash type '%s'", rest, printHashType(this->type));
|
throw BadHash("hash '%s' has wrong length for hash algorithm '%s'", rest, printHashAlgo(this->algo));
|
||||||
}
|
}
|
||||||
|
|
||||||
Hash newHashAllowEmpty(std::string_view hashStr, std::optional<HashType> ht)
|
Hash newHashAllowEmpty(std::string_view hashStr, std::optional<HashAlgorithm> ha)
|
||||||
{
|
{
|
||||||
if (hashStr.empty()) {
|
if (hashStr.empty()) {
|
||||||
if (!ht)
|
if (!ha)
|
||||||
throw BadHash("empty hash requires explicit hash type");
|
throw BadHash("empty hash requires explicit hash type");
|
||||||
Hash h(*ht);
|
Hash h(*ha);
|
||||||
warn("found empty hash, assuming '%s'", h.to_string(HashFormat::SRI, true));
|
warn("found empty hash, assuming '%s'", h.to_string(HashFormat::SRI, true));
|
||||||
return h;
|
return h;
|
||||||
} else
|
} else
|
||||||
return Hash::parseAny(hashStr, ht);
|
return Hash::parseAny(hashStr, ha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -282,58 +282,58 @@ union Ctx
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static void start(HashType ht, Ctx & ctx)
|
static void start(HashAlgorithm ha, Ctx & ctx)
|
||||||
{
|
{
|
||||||
if (ht == htMD5) MD5_Init(&ctx.md5);
|
if (ha == HashAlgorithm::MD5) MD5_Init(&ctx.md5);
|
||||||
else if (ht == htSHA1) SHA1_Init(&ctx.sha1);
|
else if (ha == HashAlgorithm::SHA1) SHA1_Init(&ctx.sha1);
|
||||||
else if (ht == htSHA256) SHA256_Init(&ctx.sha256);
|
else if (ha == HashAlgorithm::SHA256) SHA256_Init(&ctx.sha256);
|
||||||
else if (ht == htSHA512) SHA512_Init(&ctx.sha512);
|
else if (ha == HashAlgorithm::SHA512) SHA512_Init(&ctx.sha512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void update(HashType ht, Ctx & ctx,
|
static void update(HashAlgorithm ha, Ctx & ctx,
|
||||||
std::string_view data)
|
std::string_view data)
|
||||||
{
|
{
|
||||||
if (ht == htMD5) MD5_Update(&ctx.md5, data.data(), data.size());
|
if (ha == HashAlgorithm::MD5) MD5_Update(&ctx.md5, data.data(), data.size());
|
||||||
else if (ht == htSHA1) SHA1_Update(&ctx.sha1, data.data(), data.size());
|
else if (ha == HashAlgorithm::SHA1) SHA1_Update(&ctx.sha1, data.data(), data.size());
|
||||||
else if (ht == htSHA256) SHA256_Update(&ctx.sha256, data.data(), data.size());
|
else if (ha == HashAlgorithm::SHA256) SHA256_Update(&ctx.sha256, data.data(), data.size());
|
||||||
else if (ht == htSHA512) SHA512_Update(&ctx.sha512, data.data(), data.size());
|
else if (ha == HashAlgorithm::SHA512) SHA512_Update(&ctx.sha512, data.data(), data.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void finish(HashType ht, Ctx & ctx, unsigned char * hash)
|
static void finish(HashAlgorithm ha, Ctx & ctx, unsigned char * hash)
|
||||||
{
|
{
|
||||||
if (ht == htMD5) MD5_Final(hash, &ctx.md5);
|
if (ha == HashAlgorithm::MD5) MD5_Final(hash, &ctx.md5);
|
||||||
else if (ht == htSHA1) SHA1_Final(hash, &ctx.sha1);
|
else if (ha == HashAlgorithm::SHA1) SHA1_Final(hash, &ctx.sha1);
|
||||||
else if (ht == htSHA256) SHA256_Final(hash, &ctx.sha256);
|
else if (ha == HashAlgorithm::SHA256) SHA256_Final(hash, &ctx.sha256);
|
||||||
else if (ht == htSHA512) SHA512_Final(hash, &ctx.sha512);
|
else if (ha == HashAlgorithm::SHA512) SHA512_Final(hash, &ctx.sha512);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Hash hashString(HashType ht, std::string_view s)
|
Hash hashString(HashAlgorithm ha, std::string_view s)
|
||||||
{
|
{
|
||||||
Ctx ctx;
|
Ctx ctx;
|
||||||
Hash hash(ht);
|
Hash hash(ha);
|
||||||
start(ht, ctx);
|
start(ha, ctx);
|
||||||
update(ht, ctx, s);
|
update(ha, ctx, s);
|
||||||
finish(ht, ctx, hash.hash);
|
finish(ha, ctx, hash.hash);
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Hash hashFile(HashType ht, const Path & path)
|
Hash hashFile(HashAlgorithm ha, const Path & path)
|
||||||
{
|
{
|
||||||
HashSink sink(ht);
|
HashSink sink(ha);
|
||||||
readFile(path, sink);
|
readFile(path, sink);
|
||||||
return sink.finish().first;
|
return sink.finish().first;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HashSink::HashSink(HashType ht) : ht(ht)
|
HashSink::HashSink(HashAlgorithm ha) : ha(ha)
|
||||||
{
|
{
|
||||||
ctx = new Ctx;
|
ctx = new Ctx;
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
start(ht, *ctx);
|
start(ha, *ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
HashSink::~HashSink()
|
HashSink::~HashSink()
|
||||||
|
@ -345,14 +345,14 @@ HashSink::~HashSink()
|
||||||
void HashSink::writeUnbuffered(std::string_view data)
|
void HashSink::writeUnbuffered(std::string_view data)
|
||||||
{
|
{
|
||||||
bytes += data.size();
|
bytes += data.size();
|
||||||
update(ht, *ctx, data);
|
update(ha, *ctx, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
HashResult HashSink::finish()
|
HashResult HashSink::finish()
|
||||||
{
|
{
|
||||||
flush();
|
flush();
|
||||||
Hash hash(ht);
|
Hash hash(ha);
|
||||||
nix::finish(ht, *ctx, hash.hash);
|
nix::finish(ha, *ctx, hash.hash);
|
||||||
return HashResult(hash, bytes);
|
return HashResult(hash, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -360,16 +360,16 @@ HashResult HashSink::currentHash()
|
||||||
{
|
{
|
||||||
flush();
|
flush();
|
||||||
Ctx ctx2 = *ctx;
|
Ctx ctx2 = *ctx;
|
||||||
Hash hash(ht);
|
Hash hash(ha);
|
||||||
nix::finish(ht, ctx2, hash.hash);
|
nix::finish(ha, ctx2, hash.hash);
|
||||||
return HashResult(hash, bytes);
|
return HashResult(hash, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
HashResult hashPath(
|
HashResult hashPath(
|
||||||
HashType ht, const Path & path, PathFilter & filter)
|
HashAlgorithm ha, const Path & path, PathFilter & filter)
|
||||||
{
|
{
|
||||||
HashSink sink(ht);
|
HashSink sink(ha);
|
||||||
dumpPath(path, sink, filter);
|
dumpPath(path, sink, filter);
|
||||||
return sink.finish();
|
return sink.finish();
|
||||||
}
|
}
|
||||||
|
@ -377,7 +377,7 @@ HashResult hashPath(
|
||||||
|
|
||||||
Hash compressHash(const Hash & hash, unsigned int newSize)
|
Hash compressHash(const Hash & hash, unsigned int newSize)
|
||||||
{
|
{
|
||||||
Hash h(hash.type);
|
Hash h(hash.algo);
|
||||||
h.hashSize = newSize;
|
h.hashSize = newSize;
|
||||||
for (unsigned int i = 0; i < hash.hashSize; ++i)
|
for (unsigned int i = 0; i < hash.hashSize; ++i)
|
||||||
h.hash[i % newSize] ^= hash.hash[i];
|
h.hash[i % newSize] ^= hash.hash[i];
|
||||||
|
@ -420,31 +420,31 @@ std::string_view printHashFormat(HashFormat HashFormat)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<HashType> parseHashTypeOpt(std::string_view s)
|
std::optional<HashAlgorithm> parseHashAlgoOpt(std::string_view s)
|
||||||
{
|
{
|
||||||
if (s == "md5") return htMD5;
|
if (s == "md5") return HashAlgorithm::MD5;
|
||||||
if (s == "sha1") return htSHA1;
|
if (s == "sha1") return HashAlgorithm::SHA1;
|
||||||
if (s == "sha256") return htSHA256;
|
if (s == "sha256") return HashAlgorithm::SHA256;
|
||||||
if (s == "sha512") return htSHA512;
|
if (s == "sha512") return HashAlgorithm::SHA512;
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
HashType parseHashType(std::string_view s)
|
HashAlgorithm parseHashAlgo(std::string_view s)
|
||||||
{
|
{
|
||||||
auto opt_h = parseHashTypeOpt(s);
|
auto opt_h = parseHashAlgoOpt(s);
|
||||||
if (opt_h)
|
if (opt_h)
|
||||||
return *opt_h;
|
return *opt_h;
|
||||||
else
|
else
|
||||||
throw UsageError("unknown hash algorithm '%1%', expect 'md5', 'sha1', 'sha256', or 'sha512'", s);
|
throw UsageError("unknown hash algorithm '%1%', expect 'md5', 'sha1', 'sha256', or 'sha512'", s);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string_view printHashType(HashType ht)
|
std::string_view printHashAlgo(HashAlgorithm ha)
|
||||||
{
|
{
|
||||||
switch (ht) {
|
switch (ha) {
|
||||||
case htMD5: return "md5";
|
case HashAlgorithm::MD5: return "md5";
|
||||||
case htSHA1: return "sha1";
|
case HashAlgorithm::SHA1: return "sha1";
|
||||||
case htSHA256: return "sha256";
|
case HashAlgorithm::SHA256: return "sha256";
|
||||||
case htSHA512: return "sha512";
|
case HashAlgorithm::SHA512: return "sha512";
|
||||||
default:
|
default:
|
||||||
// illegal hash type enum value internally, as opposed to external input
|
// illegal hash type enum value internally, as opposed to external input
|
||||||
// which should be validated with nice error message.
|
// which should be validated with nice error message.
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace nix {
|
||||||
MakeError(BadHash, Error);
|
MakeError(BadHash, Error);
|
||||||
|
|
||||||
|
|
||||||
enum HashType : char { htMD5 = 42, htSHA1, htSHA256, htSHA512 };
|
enum struct HashAlgorithm : char { MD5 = 42, SHA1, SHA256, SHA512 };
|
||||||
|
|
||||||
|
|
||||||
const int md5HashSize = 16;
|
const int md5HashSize = 16;
|
||||||
|
@ -20,7 +20,7 @@ const int sha1HashSize = 20;
|
||||||
const int sha256HashSize = 32;
|
const int sha256HashSize = 32;
|
||||||
const int sha512HashSize = 64;
|
const int sha512HashSize = 64;
|
||||||
|
|
||||||
extern std::set<std::string> hashTypes;
|
extern std::set<std::string> hashAlgorithms;
|
||||||
|
|
||||||
extern const std::string base32Chars;
|
extern const std::string base32Chars;
|
||||||
|
|
||||||
|
@ -46,12 +46,12 @@ struct Hash
|
||||||
size_t hashSize = 0;
|
size_t hashSize = 0;
|
||||||
uint8_t hash[maxHashSize] = {};
|
uint8_t hash[maxHashSize] = {};
|
||||||
|
|
||||||
HashType type;
|
HashAlgorithm algo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a zero-filled hash object.
|
* Create a zero-filled hash object.
|
||||||
*/
|
*/
|
||||||
explicit Hash(HashType type);
|
explicit Hash(HashAlgorithm algo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse the hash from a string representation in the format
|
* Parse the hash from a string representation in the format
|
||||||
|
@ -60,7 +60,7 @@ struct Hash
|
||||||
* is not present, then the hash type must be specified in the
|
* is not present, then the hash type must be specified in the
|
||||||
* string.
|
* string.
|
||||||
*/
|
*/
|
||||||
static Hash parseAny(std::string_view s, std::optional<HashType> type);
|
static Hash parseAny(std::string_view s, std::optional<HashAlgorithm> optAlgo);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a hash from a string representation like the above, except the
|
* Parse a hash from a string representation like the above, except the
|
||||||
|
@ -72,7 +72,7 @@ struct Hash
|
||||||
* Parse a plain hash that musst not have any prefix indicating the type.
|
* Parse a plain hash that musst not have any prefix indicating the type.
|
||||||
* The type is passed in to disambiguate.
|
* The type is passed in to disambiguate.
|
||||||
*/
|
*/
|
||||||
static Hash parseNonSRIUnprefixed(std::string_view s, HashType type);
|
static Hash parseNonSRIUnprefixed(std::string_view s, HashAlgorithm algo);
|
||||||
|
|
||||||
static Hash parseSRI(std::string_view original);
|
static Hash parseSRI(std::string_view original);
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ private:
|
||||||
* The type must be provided, the string view must not include <type>
|
* The type must be provided, the string view must not include <type>
|
||||||
* prefix. `isSRI` helps disambigate the various base-* encodings.
|
* prefix. `isSRI` helps disambigate the various base-* encodings.
|
||||||
*/
|
*/
|
||||||
Hash(std::string_view s, HashType type, bool isSRI);
|
Hash(std::string_view s, HashAlgorithm algo, bool isSRI);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
|
@ -125,10 +125,10 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a string representation of the hash, in base-16, base-32
|
* Return a string representation of the hash, in base-16, base-32
|
||||||
* or base-64. By default, this is prefixed by the hash type
|
* or base-64. By default, this is prefixed by the hash algo
|
||||||
* (e.g. "sha256:").
|
* (e.g. "sha256:").
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::string to_string(HashFormat hashFormat, bool includeType) const;
|
[[nodiscard]] std::string to_string(HashFormat hashFormat, bool includeAlgo) const;
|
||||||
|
|
||||||
[[nodiscard]] std::string gitRev() const
|
[[nodiscard]] std::string gitRev() const
|
||||||
{
|
{
|
||||||
|
@ -146,7 +146,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Helper that defaults empty hashes to the 0 hash.
|
* Helper that defaults empty hashes to the 0 hash.
|
||||||
*/
|
*/
|
||||||
Hash newHashAllowEmpty(std::string_view hashStr, std::optional<HashType> ht);
|
Hash newHashAllowEmpty(std::string_view hashStr, std::optional<HashAlgorithm> ha);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Print a hash in base-16 if it's MD5, or base-32 otherwise.
|
* Print a hash in base-16 if it's MD5, or base-32 otherwise.
|
||||||
|
@ -156,14 +156,14 @@ std::string printHash16or32(const Hash & hash);
|
||||||
/**
|
/**
|
||||||
* Compute the hash of the given string.
|
* Compute the hash of the given string.
|
||||||
*/
|
*/
|
||||||
Hash hashString(HashType ht, std::string_view s);
|
Hash hashString(HashAlgorithm ha, std::string_view s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the hash of the given file, hashing its contents directly.
|
* Compute the hash of the given file, hashing its contents directly.
|
||||||
*
|
*
|
||||||
* (Metadata, such as the executable permission bit, is ignored.)
|
* (Metadata, such as the executable permission bit, is ignored.)
|
||||||
*/
|
*/
|
||||||
Hash hashFile(HashType ht, const Path & path);
|
Hash hashFile(HashAlgorithm ha, const Path & path);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compute the hash of the given path, serializing as a Nix Archive and
|
* Compute the hash of the given path, serializing as a Nix Archive and
|
||||||
|
@ -172,8 +172,8 @@ Hash hashFile(HashType ht, const Path & path);
|
||||||
* The hash is defined as (essentially) hashString(ht, dumpPath(path)).
|
* The hash is defined as (essentially) hashString(ht, dumpPath(path)).
|
||||||
*/
|
*/
|
||||||
typedef std::pair<Hash, uint64_t> HashResult;
|
typedef std::pair<Hash, uint64_t> HashResult;
|
||||||
HashResult hashPath(HashType ht, const Path & path,
|
HashResult hashPath(HashAlgorithm ha, const Path & path,
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compress a hash to the specified number of bytes by cyclically
|
* Compress a hash to the specified number of bytes by cyclically
|
||||||
|
@ -199,17 +199,17 @@ std::string_view printHashFormat(HashFormat hashFormat);
|
||||||
/**
|
/**
|
||||||
* Parse a string representing a hash type.
|
* Parse a string representing a hash type.
|
||||||
*/
|
*/
|
||||||
HashType parseHashType(std::string_view s);
|
HashAlgorithm parseHashAlgo(std::string_view s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will return nothing on parse error
|
* Will return nothing on parse error
|
||||||
*/
|
*/
|
||||||
std::optional<HashType> parseHashTypeOpt(std::string_view s);
|
std::optional<HashAlgorithm> parseHashAlgoOpt(std::string_view s);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* And the reverse.
|
* And the reverse.
|
||||||
*/
|
*/
|
||||||
std::string_view printHashType(HashType ht);
|
std::string_view printHashAlgo(HashAlgorithm ha);
|
||||||
|
|
||||||
|
|
||||||
union Ctx;
|
union Ctx;
|
||||||
|
@ -222,12 +222,12 @@ struct AbstractHashSink : virtual Sink
|
||||||
class HashSink : public BufferedSink, public AbstractHashSink
|
class HashSink : public BufferedSink, public AbstractHashSink
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
HashType ht;
|
HashAlgorithm ha;
|
||||||
Ctx * ctx;
|
Ctx * ctx;
|
||||||
uint64_t bytes;
|
uint64_t bytes;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HashSink(HashType ht);
|
HashSink(HashAlgorithm ha);
|
||||||
HashSink(const HashSink & h);
|
HashSink(const HashSink & h);
|
||||||
~HashSink();
|
~HashSink();
|
||||||
void writeUnbuffered(std::string_view data) override;
|
void writeUnbuffered(std::string_view data) override;
|
||||||
|
|
|
@ -110,8 +110,8 @@ void RewritingSink::flush()
|
||||||
prev.clear();
|
prev.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
HashModuloSink::HashModuloSink(HashType ht, const std::string & modulus)
|
HashModuloSink::HashModuloSink(HashAlgorithm ha, const std::string & modulus)
|
||||||
: hashSink(ht)
|
: hashSink(ha)
|
||||||
, rewritingSink(modulus, std::string(modulus.size(), 0), hashSink)
|
, rewritingSink(modulus, std::string(modulus.size(), 0), hashSink)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ struct HashModuloSink : AbstractHashSink
|
||||||
HashSink hashSink;
|
HashSink hashSink;
|
||||||
RewritingSink rewritingSink;
|
RewritingSink rewritingSink;
|
||||||
|
|
||||||
HashModuloSink(HashType ht, const std::string & modulus);
|
HashModuloSink(HashAlgorithm ha, const std::string & modulus);
|
||||||
|
|
||||||
void operator () (std::string_view data) override;
|
void operator () (std::string_view data) override;
|
||||||
|
|
||||||
|
|
|
@ -39,11 +39,11 @@ void SourceAccessor::readFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
Hash SourceAccessor::hashPath(
|
Hash SourceAccessor::hashPath(
|
||||||
const CanonPath & path,
|
const CanonPath & path,
|
||||||
PathFilter & filter,
|
PathFilter & filter,
|
||||||
HashType ht)
|
HashAlgorithm ha)
|
||||||
{
|
{
|
||||||
HashSink sink(ht);
|
HashSink sink(ha);
|
||||||
dumpPath(path, sink, filter);
|
dumpPath(path, sink, filter);
|
||||||
return sink.finish().first;
|
return sink.finish().first;
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,9 @@ struct SourceAccessor
|
||||||
PathFilter & filter = defaultPathFilter);
|
PathFilter & filter = defaultPathFilter);
|
||||||
|
|
||||||
Hash hashPath(
|
Hash hashPath(
|
||||||
const CanonPath & path,
|
const CanonPath & path,
|
||||||
PathFilter & filter = defaultPathFilter,
|
PathFilter & filter = defaultPathFilter,
|
||||||
HashType ht = htSHA256);
|
HashAlgorithm ha = HashAlgorithm::SHA256);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a corresponding path in the root filesystem, if
|
* Return a corresponding path in the root filesystem, if
|
||||||
|
|
|
@ -193,7 +193,7 @@ static void opAddFixed(Strings opFlags, Strings opArgs)
|
||||||
if (opArgs.empty())
|
if (opArgs.empty())
|
||||||
throw UsageError("first argument must be hash algorithm");
|
throw UsageError("first argument must be hash algorithm");
|
||||||
|
|
||||||
HashType hashAlgo = parseHashType(opArgs.front());
|
HashAlgorithm hashAlgo = parseHashAlgo(opArgs.front());
|
||||||
opArgs.pop_front();
|
opArgs.pop_front();
|
||||||
|
|
||||||
for (auto & i : opArgs)
|
for (auto & i : opArgs)
|
||||||
|
@ -214,7 +214,7 @@ static void opPrintFixedPath(Strings opFlags, Strings opArgs)
|
||||||
throw UsageError("'--print-fixed-path' requires three arguments");
|
throw UsageError("'--print-fixed-path' requires three arguments");
|
||||||
|
|
||||||
Strings::iterator i = opArgs.begin();
|
Strings::iterator i = opArgs.begin();
|
||||||
HashType hashAlgo = parseHashType(*i++);
|
HashAlgorithm hashAlgo = parseHashAlgo(*i++);
|
||||||
std::string hash = *i++;
|
std::string hash = *i++;
|
||||||
std::string name = *i++;
|
std::string name = *i++;
|
||||||
|
|
||||||
|
@ -405,7 +405,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise)) {
|
for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise)) {
|
||||||
auto info = store->queryPathInfo(j);
|
auto info = store->queryPathInfo(j);
|
||||||
if (query == qHash) {
|
if (query == qHash) {
|
||||||
assert(info->narHash.type == htSHA256);
|
assert(info->narHash.algo == HashAlgorithm::SHA256);
|
||||||
cout << fmt("%s\n", info->narHash.to_string(HashFormat::Base32, true));
|
cout << fmt("%s\n", info->narHash.to_string(HashFormat::Base32, true));
|
||||||
} else if (query == qSize)
|
} else if (query == qSize)
|
||||||
cout << fmt("%d\n", info->narSize);
|
cout << fmt("%d\n", info->narSize);
|
||||||
|
@ -541,7 +541,7 @@ static void registerValidity(bool reregister, bool hashGiven, bool canonicalise)
|
||||||
if (canonicalise)
|
if (canonicalise)
|
||||||
canonicalisePathMetaData(store->printStorePath(info->path), {});
|
canonicalisePathMetaData(store->printStorePath(info->path), {});
|
||||||
if (!hashGiven) {
|
if (!hashGiven) {
|
||||||
HashResult hash = hashPath(htSHA256, store->printStorePath(info->path));
|
HashResult hash = hashPath(HashAlgorithm::SHA256, store->printStorePath(info->path));
|
||||||
info->narHash = hash.first;
|
info->narHash = hash.first;
|
||||||
info->narSize = hash.second;
|
info->narSize = hash.second;
|
||||||
}
|
}
|
||||||
|
@ -763,7 +763,7 @@ static void opVerifyPath(Strings opFlags, Strings opArgs)
|
||||||
auto path = store->followLinksToStorePath(i);
|
auto path = store->followLinksToStorePath(i);
|
||||||
printMsg(lvlTalkative, "checking path '%s'...", store->printStorePath(path));
|
printMsg(lvlTalkative, "checking path '%s'...", store->printStorePath(path));
|
||||||
auto info = store->queryPathInfo(path);
|
auto info = store->queryPathInfo(path);
|
||||||
HashSink sink(info->narHash.type);
|
HashSink sink(info->narHash.algo);
|
||||||
store->narFromPath(path, sink);
|
store->narFromPath(path, sink);
|
||||||
auto current = sink.finish();
|
auto current = sink.finish();
|
||||||
if (current.first != info->narHash) {
|
if (current.first != info->narHash) {
|
||||||
|
@ -979,7 +979,7 @@ static void opServe(Strings opFlags, Strings opArgs)
|
||||||
auto deriver = readString(in);
|
auto deriver = readString(in);
|
||||||
ValidPathInfo info {
|
ValidPathInfo info {
|
||||||
store->parseStorePath(path),
|
store->parseStorePath(path),
|
||||||
Hash::parseAny(readString(in), htSHA256),
|
Hash::parseAny(readString(in), HashAlgorithm::SHA256),
|
||||||
};
|
};
|
||||||
if (deriver != "")
|
if (deriver != "")
|
||||||
info.deriver = store->parseStorePath(deriver);
|
info.deriver = store->parseStorePath(deriver);
|
||||||
|
|
|
@ -60,11 +60,11 @@ struct CmdAddToStore : MixDryRun, StoreCommand
|
||||||
StringSink sink;
|
StringSink sink;
|
||||||
dumpPath(path, sink);
|
dumpPath(path, sink);
|
||||||
|
|
||||||
auto narHash = hashString(htSHA256, sink.s);
|
auto narHash = hashString(HashAlgorithm::SHA256, sink.s);
|
||||||
|
|
||||||
Hash hash = narHash;
|
Hash hash = narHash;
|
||||||
if (ingestionMethod == FileIngestionMethod::Flat) {
|
if (ingestionMethod == FileIngestionMethod::Flat) {
|
||||||
HashSink hsink(htSHA256);
|
HashSink hsink(HashAlgorithm::SHA256);
|
||||||
readFile(path, hsink);
|
readFile(path, hsink);
|
||||||
hash = hsink.finish().first;
|
hash = hsink.finish().first;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ struct CmdHashBase : Command
|
||||||
FileIngestionMethod mode;
|
FileIngestionMethod mode;
|
||||||
HashFormat hashFormat = HashFormat::SRI;
|
HashFormat hashFormat = HashFormat::SRI;
|
||||||
bool truncate = false;
|
bool truncate = false;
|
||||||
HashType ht = htSHA256;
|
HashAlgorithm ha = HashAlgorithm::SHA256;
|
||||||
std::vector<std::string> paths;
|
std::vector<std::string> paths;
|
||||||
std::optional<std::string> modulus;
|
std::optional<std::string> modulus;
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ struct CmdHashBase : Command
|
||||||
.handler = {&hashFormat, HashFormat::Base16},
|
.handler = {&hashFormat, HashFormat::Base16},
|
||||||
});
|
});
|
||||||
|
|
||||||
addFlag(Flag::mkHashTypeFlag("type", &ht));
|
addFlag(Flag::mkHashTypeFlag("type", &ha));
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
addFlag({
|
addFlag({
|
||||||
|
@ -84,9 +84,9 @@ struct CmdHashBase : Command
|
||||||
|
|
||||||
std::unique_ptr<AbstractHashSink> hashSink;
|
std::unique_ptr<AbstractHashSink> hashSink;
|
||||||
if (modulus)
|
if (modulus)
|
||||||
hashSink = std::make_unique<HashModuloSink>(ht, *modulus);
|
hashSink = std::make_unique<HashModuloSink>(ha, *modulus);
|
||||||
else
|
else
|
||||||
hashSink = std::make_unique<HashSink>(ht);
|
hashSink = std::make_unique<HashSink>(ha);
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case FileIngestionMethod::Flat:
|
case FileIngestionMethod::Flat:
|
||||||
|
@ -107,7 +107,7 @@ struct CmdHashBase : Command
|
||||||
struct CmdToBase : Command
|
struct CmdToBase : Command
|
||||||
{
|
{
|
||||||
HashFormat hashFormat;
|
HashFormat hashFormat;
|
||||||
std::optional<HashType> ht;
|
std::optional<HashAlgorithm> ht;
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
|
|
||||||
CmdToBase(HashFormat hashFormat) : hashFormat(hashFormat)
|
CmdToBase(HashFormat hashFormat) : hashFormat(hashFormat)
|
||||||
|
@ -139,7 +139,7 @@ struct CmdHashConvert : Command
|
||||||
{
|
{
|
||||||
std::optional<HashFormat> from;
|
std::optional<HashFormat> from;
|
||||||
HashFormat to;
|
HashFormat to;
|
||||||
std::optional<HashType> type;
|
std::optional<HashAlgorithm> type;
|
||||||
std::vector<std::string> hashStrings;
|
std::vector<std::string> hashStrings;
|
||||||
|
|
||||||
CmdHashConvert(): to(HashFormat::SRI) {
|
CmdHashConvert(): to(HashFormat::SRI) {
|
||||||
|
@ -166,7 +166,7 @@ struct CmdHashConvert : Command
|
||||||
.description = "Specify the algorithm if it can't be auto-detected.",
|
.description = "Specify the algorithm if it can't be auto-detected.",
|
||||||
.labels = {"hash algorithm"},
|
.labels = {"hash algorithm"},
|
||||||
.handler = {[this](std::string str) {
|
.handler = {[this](std::string str) {
|
||||||
type = parseHashType(str);
|
type = parseHashAlgo(str);
|
||||||
}},
|
}},
|
||||||
});
|
});
|
||||||
expectArgs({
|
expectArgs({
|
||||||
|
@ -223,7 +223,7 @@ static auto rCmdHash = registerCommand<CmdHash>("hash");
|
||||||
/* Legacy nix-hash command. */
|
/* Legacy nix-hash command. */
|
||||||
static int compatNixHash(int argc, char * * argv)
|
static int compatNixHash(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
std::optional<HashType> ht;
|
std::optional<HashAlgorithm> ha;
|
||||||
bool flat = false;
|
bool flat = false;
|
||||||
HashFormat hashFormat = HashFormat::Base16;
|
HashFormat hashFormat = HashFormat::Base16;
|
||||||
bool truncate = false;
|
bool truncate = false;
|
||||||
|
@ -243,7 +243,7 @@ static int compatNixHash(int argc, char * * argv)
|
||||||
else if (*arg == "--truncate") truncate = true;
|
else if (*arg == "--truncate") truncate = true;
|
||||||
else if (*arg == "--type") {
|
else if (*arg == "--type") {
|
||||||
std::string s = getArg(*arg, arg, end);
|
std::string s = getArg(*arg, arg, end);
|
||||||
ht = parseHashType(s);
|
ha = parseHashAlgo(s);
|
||||||
}
|
}
|
||||||
else if (*arg == "--to-base16") {
|
else if (*arg == "--to-base16") {
|
||||||
op = opTo;
|
op = opTo;
|
||||||
|
@ -270,8 +270,8 @@ static int compatNixHash(int argc, char * * argv)
|
||||||
|
|
||||||
if (op == opHash) {
|
if (op == opHash) {
|
||||||
CmdHashBase cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive);
|
CmdHashBase cmd(flat ? FileIngestionMethod::Flat : FileIngestionMethod::Recursive);
|
||||||
if (!ht.has_value()) ht = htMD5;
|
if (!ha.has_value()) ha = HashAlgorithm::MD5;
|
||||||
cmd.ht = ht.value();
|
cmd.ha = ha.value();
|
||||||
cmd.hashFormat = hashFormat;
|
cmd.hashFormat = hashFormat;
|
||||||
cmd.truncate = truncate;
|
cmd.truncate = truncate;
|
||||||
cmd.paths = ss;
|
cmd.paths = ss;
|
||||||
|
@ -281,7 +281,7 @@ static int compatNixHash(int argc, char * * argv)
|
||||||
else {
|
else {
|
||||||
CmdToBase cmd(hashFormat);
|
CmdToBase cmd(hashFormat);
|
||||||
cmd.args = ss;
|
cmd.args = ss;
|
||||||
if (ht.has_value()) cmd.ht = ht;
|
if (ha.has_value()) cmd.ht = ha;
|
||||||
cmd.run();
|
cmd.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,13 @@ std::string resolveMirrorUrl(EvalState & state, const std::string & url)
|
||||||
}
|
}
|
||||||
|
|
||||||
std::tuple<StorePath, Hash> prefetchFile(
|
std::tuple<StorePath, Hash> prefetchFile(
|
||||||
ref<Store> store,
|
ref<Store> store,
|
||||||
std::string_view url,
|
std::string_view url,
|
||||||
std::optional<std::string> name,
|
std::optional<std::string> name,
|
||||||
HashType hashType,
|
HashAlgorithm hashAlgo,
|
||||||
std::optional<Hash> expectedHash,
|
std::optional<Hash> expectedHash,
|
||||||
bool unpack,
|
bool unpack,
|
||||||
bool executable)
|
bool executable)
|
||||||
{
|
{
|
||||||
auto ingestionMethod = unpack || executable ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
auto ingestionMethod = unpack || executable ? FileIngestionMethod::Recursive : FileIngestionMethod::Flat;
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ std::tuple<StorePath, Hash> prefetchFile(
|
||||||
/* If an expected hash is given, the file may already exist in
|
/* If an expected hash is given, the file may already exist in
|
||||||
the store. */
|
the store. */
|
||||||
if (expectedHash) {
|
if (expectedHash) {
|
||||||
hashType = expectedHash->type;
|
hashAlgo = expectedHash->algo;
|
||||||
storePath = store->makeFixedOutputPath(*name, FixedOutputInfo {
|
storePath = store->makeFixedOutputPath(*name, FixedOutputInfo {
|
||||||
.method = ingestionMethod,
|
.method = ingestionMethod,
|
||||||
.hash = *expectedHash,
|
.hash = *expectedHash,
|
||||||
|
@ -122,7 +122,7 @@ std::tuple<StorePath, Hash> prefetchFile(
|
||||||
Activity act(*logger, lvlChatty, actUnknown,
|
Activity act(*logger, lvlChatty, actUnknown,
|
||||||
fmt("adding '%s' to the store", url));
|
fmt("adding '%s' to the store", url));
|
||||||
|
|
||||||
auto info = store->addToStoreSlow(*name, tmpFile, ingestionMethod, hashType, expectedHash);
|
auto info = store->addToStoreSlow(*name, tmpFile, ingestionMethod, hashAlgo, expectedHash);
|
||||||
storePath = info.path;
|
storePath = info.path;
|
||||||
assert(info.ca);
|
assert(info.ca);
|
||||||
hash = info.ca->hash;
|
hash = info.ca->hash;
|
||||||
|
@ -134,7 +134,7 @@ std::tuple<StorePath, Hash> prefetchFile(
|
||||||
static int main_nix_prefetch_url(int argc, char * * argv)
|
static int main_nix_prefetch_url(int argc, char * * argv)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
HashType ht = htSHA256;
|
HashAlgorithm ha = HashAlgorithm::SHA256;
|
||||||
std::vector<std::string> args;
|
std::vector<std::string> args;
|
||||||
bool printPath = getEnv("PRINT_PATH") == "1";
|
bool printPath = getEnv("PRINT_PATH") == "1";
|
||||||
bool fromExpr = false;
|
bool fromExpr = false;
|
||||||
|
@ -155,7 +155,7 @@ static int main_nix_prefetch_url(int argc, char * * argv)
|
||||||
printVersion("nix-prefetch-url");
|
printVersion("nix-prefetch-url");
|
||||||
else if (*arg == "--type") {
|
else if (*arg == "--type") {
|
||||||
auto s = getArg(*arg, arg, end);
|
auto s = getArg(*arg, arg, end);
|
||||||
ht = parseHashType(s);
|
ha = parseHashAlgo(s);
|
||||||
}
|
}
|
||||||
else if (*arg == "--print-path")
|
else if (*arg == "--print-path")
|
||||||
printPath = true;
|
printPath = true;
|
||||||
|
@ -233,10 +233,10 @@ static int main_nix_prefetch_url(int argc, char * * argv)
|
||||||
|
|
||||||
std::optional<Hash> expectedHash;
|
std::optional<Hash> expectedHash;
|
||||||
if (args.size() == 2)
|
if (args.size() == 2)
|
||||||
expectedHash = Hash::parseAny(args[1], ht);
|
expectedHash = Hash::parseAny(args[1], ha);
|
||||||
|
|
||||||
auto [storePath, hash] = prefetchFile(
|
auto [storePath, hash] = prefetchFile(
|
||||||
store, resolveMirrorUrl(*state, url), name, ht, expectedHash, unpack, executable);
|
store, resolveMirrorUrl(*state, url), name, ha, expectedHash, unpack, executable);
|
||||||
|
|
||||||
stopProgressBar();
|
stopProgressBar();
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON
|
||||||
std::string url;
|
std::string url;
|
||||||
bool executable = false;
|
bool executable = false;
|
||||||
std::optional<std::string> name;
|
std::optional<std::string> name;
|
||||||
HashType hashType = htSHA256;
|
HashAlgorithm hashAlgo = HashAlgorithm::SHA256;
|
||||||
std::optional<Hash> expectedHash;
|
std::optional<Hash> expectedHash;
|
||||||
|
|
||||||
CmdStorePrefetchFile()
|
CmdStorePrefetchFile()
|
||||||
|
@ -275,11 +275,11 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON
|
||||||
.description = "The expected hash of the file.",
|
.description = "The expected hash of the file.",
|
||||||
.labels = {"hash"},
|
.labels = {"hash"},
|
||||||
.handler = {[&](std::string s) {
|
.handler = {[&](std::string s) {
|
||||||
expectedHash = Hash::parseAny(s, hashType);
|
expectedHash = Hash::parseAny(s, hashAlgo);
|
||||||
}}
|
}}
|
||||||
});
|
});
|
||||||
|
|
||||||
addFlag(Flag::mkHashTypeFlag("hash-type", &hashType));
|
addFlag(Flag::mkHashTypeFlag("hash-type", &hashAlgo));
|
||||||
|
|
||||||
addFlag({
|
addFlag({
|
||||||
.longName = "executable",
|
.longName = "executable",
|
||||||
|
@ -305,7 +305,7 @@ struct CmdStorePrefetchFile : StoreCommand, MixJSON
|
||||||
}
|
}
|
||||||
void run(ref<Store> store) override
|
void run(ref<Store> store) override
|
||||||
{
|
{
|
||||||
auto [storePath, hash] = prefetchFile(store, url, name, hashType, expectedHash, false, executable);
|
auto [storePath, hash] = prefetchFile(store, url, name, hashAlgo, expectedHash, false, executable);
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
auto res = nlohmann::json::object();
|
auto res = nlohmann::json::object();
|
||||||
|
|
|
@ -216,7 +216,7 @@ struct ProfileManifest
|
||||||
StringSink sink;
|
StringSink sink;
|
||||||
dumpPath(tempDir, sink);
|
dumpPath(tempDir, sink);
|
||||||
|
|
||||||
auto narHash = hashString(htSHA256, sink.s);
|
auto narHash = hashString(HashAlgorithm::SHA256, sink.s);
|
||||||
|
|
||||||
ValidPathInfo info {
|
ValidPathInfo info {
|
||||||
*store,
|
*store,
|
||||||
|
|
|
@ -98,7 +98,7 @@ struct CmdVerify : StorePathsCommand
|
||||||
|
|
||||||
if (!noContents) {
|
if (!noContents) {
|
||||||
|
|
||||||
auto hashSink = HashSink(info->narHash.type);
|
auto hashSink = HashSink(info->narHash.algo);
|
||||||
|
|
||||||
store->narFromPath(info->path, hashSink);
|
store->narFromPath(info->path, hashSink);
|
||||||
|
|
||||||
|
|
|
@ -84,15 +84,15 @@ CHARACTERIZATION_TEST(
|
||||||
(std::tuple<ContentAddress, ContentAddress, ContentAddress> {
|
(std::tuple<ContentAddress, ContentAddress, ContentAddress> {
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = TextIngestionMethod {},
|
.method = TextIngestionMethod {},
|
||||||
.hash = hashString(HashType::htSHA256, "Derive(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "Derive(...)"),
|
||||||
},
|
},
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Flat,
|
.method = FileIngestionMethod::Flat,
|
||||||
.hash = hashString(HashType::htSHA1, "blob blob..."),
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
||||||
},
|
},
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hash = hashString(HashType::htSHA256, "(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ CHARACTERIZATION_TEST(
|
||||||
std::optional {
|
std::optional {
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Flat,
|
.method = FileIngestionMethod::Flat,
|
||||||
.hash = hashString(HashType::htSHA1, "blob blob..."),
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -134,7 +134,7 @@ TEST_JSON(DynDerivationTest, caFixedText,
|
||||||
TEST_JSON(CaDerivationTest, caFloating,
|
TEST_JSON(CaDerivationTest, caFloating,
|
||||||
(DerivationOutput::CAFloating {
|
(DerivationOutput::CAFloating {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hashType = htSHA256,
|
.hashAlgo = HashAlgorithm::SHA256,
|
||||||
}),
|
}),
|
||||||
"drv-name", "output-name")
|
"drv-name", "output-name")
|
||||||
|
|
||||||
|
@ -145,7 +145,7 @@ TEST_JSON(DerivationTest, deferred,
|
||||||
TEST_JSON(ImpureDerivationTest, impure,
|
TEST_JSON(ImpureDerivationTest, impure,
|
||||||
(DerivationOutput::Impure {
|
(DerivationOutput::Impure {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hashType = htSHA256,
|
.hashAlgo = HashAlgorithm::SHA256,
|
||||||
}),
|
}),
|
||||||
"drv-name", "output-name")
|
"drv-name", "output-name")
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ static NarInfo makeNarInfo(const Store & store, bool includeImpureInfo) {
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo {
|
FixedOutputInfo {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hash = hashString(HashType::htSHA256, "(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
||||||
|
|
||||||
.references = {
|
.references = {
|
||||||
.others = {
|
.others = {
|
||||||
|
|
|
@ -25,7 +25,7 @@ static UnkeyedValidPathInfo makePathInfo(const Store & store, bool includeImpure
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo {
|
FixedOutputInfo {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hash = hashString(HashType::htSHA256, "(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
||||||
|
|
||||||
.references = {
|
.references = {
|
||||||
.others = {
|
.others = {
|
||||||
|
|
|
@ -53,15 +53,15 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
(std::tuple<ContentAddress, ContentAddress, ContentAddress> {
|
(std::tuple<ContentAddress, ContentAddress, ContentAddress> {
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = TextIngestionMethod {},
|
.method = TextIngestionMethod {},
|
||||||
.hash = hashString(HashType::htSHA256, "Derive(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "Derive(...)"),
|
||||||
},
|
},
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Flat,
|
.method = FileIngestionMethod::Flat,
|
||||||
.hash = hashString(HashType::htSHA1, "blob blob..."),
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
||||||
},
|
},
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hash = hashString(HashType::htSHA256, "(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
std::optional {
|
std::optional {
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Flat,
|
.method = FileIngestionMethod::Flat,
|
||||||
.hash = hashString(HashType::htSHA1, "blob blob..."),
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -55,15 +55,15 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
(std::tuple<ContentAddress, ContentAddress, ContentAddress> {
|
(std::tuple<ContentAddress, ContentAddress, ContentAddress> {
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = TextIngestionMethod {},
|
.method = TextIngestionMethod {},
|
||||||
.hash = hashString(HashType::htSHA256, "Derive(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "Derive(...)"),
|
||||||
},
|
},
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Flat,
|
.method = FileIngestionMethod::Flat,
|
||||||
.hash = hashString(HashType::htSHA1, "blob blob..."),
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
||||||
},
|
},
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hash = hashString(HashType::htSHA256, "(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -464,7 +464,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
"foo",
|
"foo",
|
||||||
FixedOutputInfo {
|
FixedOutputInfo {
|
||||||
.method = FileIngestionMethod::Recursive,
|
.method = FileIngestionMethod::Recursive,
|
||||||
.hash = hashString(HashType::htSHA256, "(...)"),
|
.hash = hashString(HashAlgorithm::SHA256, "(...)"),
|
||||||
.references = {
|
.references = {
|
||||||
.others = {
|
.others = {
|
||||||
StorePath {
|
StorePath {
|
||||||
|
@ -539,7 +539,7 @@ VERSIONED_CHARACTERIZATION_TEST(
|
||||||
std::optional {
|
std::optional {
|
||||||
ContentAddress {
|
ContentAddress {
|
||||||
.method = FileIngestionMethod::Flat,
|
.method = FileIngestionMethod::Flat,
|
||||||
.hash = hashString(HashType::htSHA1, "blob blob..."),
|
.hash = hashString(HashAlgorithm::SHA1, "blob blob..."),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -95,7 +95,7 @@ const static Tree tree = {
|
||||||
{
|
{
|
||||||
.mode = Mode::Regular,
|
.mode = Mode::Regular,
|
||||||
// hello world with special chars from above
|
// hello world with special chars from above
|
||||||
.hash = Hash::parseAny("63ddb340119baf8492d2da53af47e8c7cfcd5eb2", htSHA1),
|
.hash = Hash::parseAny("63ddb340119baf8492d2da53af47e8c7cfcd5eb2", HashAlgorithm::SHA1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -103,7 +103,7 @@ const static Tree tree = {
|
||||||
{
|
{
|
||||||
.mode = Mode::Executable,
|
.mode = Mode::Executable,
|
||||||
// ditto
|
// ditto
|
||||||
.hash = Hash::parseAny("63ddb340119baf8492d2da53af47e8c7cfcd5eb2", htSHA1),
|
.hash = Hash::parseAny("63ddb340119baf8492d2da53af47e8c7cfcd5eb2", HashAlgorithm::SHA1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -111,7 +111,7 @@ const static Tree tree = {
|
||||||
{
|
{
|
||||||
.mode = Mode::Directory,
|
.mode = Mode::Directory,
|
||||||
// Empty directory hash
|
// Empty directory hash
|
||||||
.hash = Hash::parseAny("4b825dc642cb6eb9a060e54bf8d69288fbee4904", htSHA1),
|
.hash = Hash::parseAny("4b825dc642cb6eb9a060e54bf8d69288fbee4904", HashAlgorithm::SHA1),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -174,7 +174,7 @@ TEST_F(GitTest, both_roundrip) {
|
||||||
std::function<DumpHook> dumpHook;
|
std::function<DumpHook> dumpHook;
|
||||||
dumpHook = [&](const CanonPath & path) {
|
dumpHook = [&](const CanonPath & path) {
|
||||||
StringSink s;
|
StringSink s;
|
||||||
HashSink hashSink { htSHA1 };
|
HashSink hashSink { HashAlgorithm::SHA1 };
|
||||||
TeeSink s2 { s, hashSink };
|
TeeSink s2 { s, hashSink };
|
||||||
auto mode = dump(
|
auto mode = dump(
|
||||||
files, path, s2, dumpHook,
|
files, path, s2, dumpHook,
|
||||||
|
|
|
@ -13,28 +13,28 @@ namespace nix {
|
||||||
TEST(hashString, testKnownMD5Hashes1) {
|
TEST(hashString, testKnownMD5Hashes1) {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc1321
|
// values taken from: https://tools.ietf.org/html/rfc1321
|
||||||
auto s1 = "";
|
auto s1 = "";
|
||||||
auto hash = hashString(HashType::htMD5, s1);
|
auto hash = hashString(HashAlgorithm::MD5, s1);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true), "md5:d41d8cd98f00b204e9800998ecf8427e");
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true), "md5:d41d8cd98f00b204e9800998ecf8427e");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(hashString, testKnownMD5Hashes2) {
|
TEST(hashString, testKnownMD5Hashes2) {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc1321
|
// values taken from: https://tools.ietf.org/html/rfc1321
|
||||||
auto s2 = "abc";
|
auto s2 = "abc";
|
||||||
auto hash = hashString(HashType::htMD5, s2);
|
auto hash = hashString(HashAlgorithm::MD5, s2);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true), "md5:900150983cd24fb0d6963f7d28e17f72");
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true), "md5:900150983cd24fb0d6963f7d28e17f72");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(hashString, testKnownSHA1Hashes1) {
|
TEST(hashString, testKnownSHA1Hashes1) {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc3174
|
// values taken from: https://tools.ietf.org/html/rfc3174
|
||||||
auto s = "abc";
|
auto s = "abc";
|
||||||
auto hash = hashString(HashType::htSHA1, s);
|
auto hash = hashString(HashAlgorithm::SHA1, s);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),"sha1:a9993e364706816aba3e25717850c26c9cd0d89d");
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),"sha1:a9993e364706816aba3e25717850c26c9cd0d89d");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(hashString, testKnownSHA1Hashes2) {
|
TEST(hashString, testKnownSHA1Hashes2) {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc3174
|
// values taken from: https://tools.ietf.org/html/rfc3174
|
||||||
auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||||
auto hash = hashString(HashType::htSHA1, s);
|
auto hash = hashString(HashAlgorithm::SHA1, s);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),"sha1:84983e441c3bd26ebaae4aa1f95129e5e54670f1");
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),"sha1:84983e441c3bd26ebaae4aa1f95129e5e54670f1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ namespace nix {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc4634
|
// values taken from: https://tools.ietf.org/html/rfc4634
|
||||||
auto s = "abc";
|
auto s = "abc";
|
||||||
|
|
||||||
auto hash = hashString(HashType::htSHA256, s);
|
auto hash = hashString(HashAlgorithm::SHA256, s);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
||||||
"sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
"sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ namespace nix {
|
||||||
TEST(hashString, testKnownSHA256Hashes2) {
|
TEST(hashString, testKnownSHA256Hashes2) {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc4634
|
// values taken from: https://tools.ietf.org/html/rfc4634
|
||||||
auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
auto s = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
|
||||||
auto hash = hashString(HashType::htSHA256, s);
|
auto hash = hashString(HashAlgorithm::SHA256, s);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
||||||
"sha256:248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
|
"sha256:248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1");
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ namespace nix {
|
||||||
TEST(hashString, testKnownSHA512Hashes1) {
|
TEST(hashString, testKnownSHA512Hashes1) {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc4634
|
// values taken from: https://tools.ietf.org/html/rfc4634
|
||||||
auto s = "abc";
|
auto s = "abc";
|
||||||
auto hash = hashString(HashType::htSHA512, s);
|
auto hash = hashString(HashAlgorithm::SHA512, s);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
||||||
"sha512:ddaf35a193617abacc417349ae20413112e6fa4e89a9"
|
"sha512:ddaf35a193617abacc417349ae20413112e6fa4e89a9"
|
||||||
"7ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd"
|
"7ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd"
|
||||||
|
@ -68,7 +68,7 @@ namespace nix {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc4634
|
// values taken from: https://tools.ietf.org/html/rfc4634
|
||||||
auto s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
auto s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
||||||
|
|
||||||
auto hash = hashString(HashType::htSHA512, s);
|
auto hash = hashString(HashAlgorithm::SHA512, s);
|
||||||
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
ASSERT_EQ(hash.to_string(HashFormat::Base16, true),
|
||||||
"sha512:8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa1"
|
"sha512:8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa1"
|
||||||
"7299aeadb6889018501d289e4900f7e4331b99dec4b5433a"
|
"7299aeadb6889018501d289e4900f7e4331b99dec4b5433a"
|
||||||
|
|
Loading…
Reference in a new issue