aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/references.hh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-05-02 01:25:46 +0200
committereldritch horrors <pennae@lix.systems>2024-07-11 11:39:18 +0000
commitdf8851f286a407c46ea9107ca403888291f1afbe (patch)
tree568fbfaac2d35b968498fa3eb267c862e28c0b71 /src/libutil/references.hh
parent014410cbf0bda9c0fcdaf5f894120883cdc805ce (diff)
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
Diffstat (limited to 'src/libutil/references.hh')
-rw-r--r--src/libutil/references.hh21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/libutil/references.hh b/src/libutil/references.hh
index 3fefd824b..f0f467190 100644
--- a/src/libutil/references.hh
+++ b/src/libutil/references.hh
@@ -23,19 +23,24 @@ public:
void operator () (std::string_view data) override;
};
-struct RewritingSink : Sink
+struct RewritingSource : Source
{
+ const std::string::size_type maxRewriteSize;
+ const std::string initials;
const StringMap rewrites;
- std::string::size_type maxRewriteSize;
- std::string prev;
- Sink & nextSink;
+ std::string rewritten, buffered;
+ std::string_view unreturned;
+ Source * inner;
- RewritingSink(const std::string & from, const std::string & to, Sink & nextSink);
- RewritingSink(const StringMap & rewrites, Sink & nextSink);
+ static constexpr struct may_change_size_t {
+ explicit may_change_size_t() = default;
+ } may_change_size{};
- void operator () (std::string_view data) override;
+ 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);
- void flush();
+ size_t read(char * data, size_t len) override;
};
HashResult computeHashModulo(HashType ht, const std::string & modulus, Source & source);