Split canonicalization into a library of its own #1
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
canonical.zigis useful to things that are not DKIM, and today the only wayto reach it is to depend on a crypto library.
The case that turned this up is zig-mime,
which now interoperates with this library over raw bytes — it builds a message,
zig-dkim signs it, and
tests/dkim.zigover there checks that a message parsedand written out again still verifies. That pairing needs nothing from this
issue. What it cannot do is produce a canonical form on its own, and the
three ways out of that are all bad:
tree of everything that wants to read mail;
implementation of the same specification, and two implementations of one
thing drift apart the first time either is touched;
A library of its own fixes all three: one implementation, no crypto, and both
can use it.
What would move
src/canonical.zigentire —Canonicalization,Algorithms,body,header,headerParts,Collector,Limited— plus the parts ofsrc/message.zigit rests on:split,Line,LineIterator,Header,HeaderIterator,findFromBottom. That last group is arguably the morereusable half: "where do the headers stop, and where does each field begin and
end" is a question every mail program asks, and this answer is allocation-free
and has been fuzzed.
zig-dkim would gain a dependency and re-export both under their present names,
so nothing downstream changes.
Why it is worth writing once
The parts that make canonicalization annoying are exactly the parts you do not
want implemented twice:
"\r\n"undersimpleand""underrelaxed, so the two produce differentbh=for the same empty message;turns up after them;
l=interaction, where the limit applies to the canonicalized octetsand not the raw ones;
allocation-free.
Who else would want it
AAR,AMSandAS.bh=without signing — a milter deciding whether abody changed in transit, a test fixture generator, a debugging tool.
holding without taking on the crypto.
Not urgent
Nothing is blocked. zig-mime and zig-dkim compose over raw bytes today and
there is a test on the zig-mime side proving the round trip is good enough for
a signature to survive it. This is about making the canonical form reachable
without the crypto, and it can wait for a reason to exist.