go-msgauth icon indicating copy to clipboard operation
go-msgauth copied to clipboard

New: `GenSignature()`

Open iredmail opened this issue 6 months ago • 2 comments

This PR introduces a new function with test:

// GenSignature reads message from r and return signature (without `DKIM-Signature:` header key).
GenSignature(r io.Reader, options *SignOptions) (signature string, err error)

Why we need this new function?

While developing a milter program with https://github.com/emersion/go-milter or its fork, we need to insert the DKIM-Signature: header, in this case we need go-msgauth library to return the generated dkim signature (header value) instead of a new email message with this header. This new function simplifies such task and saves some memory.

iredmail avatar Jun 16 '25 09:06 iredmail

How is this different from NewSigner followed by Signer.Signature?

emersion avatar Jun 26 '25 19:06 emersion

Hi @emersion

Sign() always generates a new (full) message with dkim header (w io.Writer), we just need the generated signature, not a new message. This GenSignature() avoids generating a new message, hence it saves memory. This is useful if we're developing a dkim signing plugin for a milter program.

// Sign signs a message. It reads it from r and writes the signed version to w.
func Sign(w io.Writer, r io.Reader, options *SignOptions) error {

https://github.com/emersion/go-msgauth/blob/master/dkim/sign.go#L309

iredmail avatar Jun 27 '25 00:06 iredmail

My suggestion was not to use Sign, but NewSigner + Signer.Signature.

emersion avatar Jun 29 '25 11:06 emersion

OK. Thanks for helping. :)

iredmail avatar Jun 30 '25 02:06 iredmail