Files
lix/src/libutil/references.hh
T
eldritch horrors df8851f286 libutil: rewrite RewritingSink as source
the rewriting sink was just broken. when given a rewrite set that
contained a key that is also a proper infix of another key it was
possible to produce an incorrectly rewritten result if the writer
used the wrong block size. fixing this duplicates rewriteStrings,
to avoid this we'll rewrite rewriteStrings to use RewritingSource
in a new mode that'll allow rewrites we had previously forbidden.

Change-Id: I57fa0a9a994e654e11d07172b8e31d15f0b7e8c0
2024-07-11 11:39:18 +00:00

49 lines
1.0 KiB
C++

#pragma once
///@file
#include "hash.hh"
namespace nix {
class RefScanSink : public Sink
{
StringSet hashes;
StringSet seen;
std::string tail;
public:
RefScanSink(StringSet && hashes) : hashes(hashes)
{ }
StringSet & getResult()
{ return seen; }
void operator () (std::string_view data) override;
};
struct RewritingSource : Source
{
const std::string::size_type maxRewriteSize;
const std::string initials;
const StringMap rewrites;
std::string rewritten, buffered;
std::string_view unreturned;
Source * inner;
static constexpr struct may_change_size_t {
explicit may_change_size_t() = default;
} may_change_size{};
RewritingSource(const std::string & from, const std::string & to, Source & inner);
RewritingSource(StringMap rewrites, Source & inner);
RewritingSource(may_change_size_t, StringMap rewrites, Source & inner);
size_t read(char * data, size_t len) override;
};
HashResult computeHashModulo(HashType ht, const std::string & modulus, Source & source);
}