From 11dabddd0bb1fce854b001a70694cb9b6be4ff26 Mon Sep 17 00:00:00 2001 From: nsz Date: Mon, 28 Nov 2011 20:11:00 +0100 Subject: [PATCH] clean body in document.Sign --- document/document.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/document/document.go b/document/document.go index 0ac99b6..1e26d28 100644 --- a/document/document.go +++ b/document/document.go @@ -32,7 +32,7 @@ package document // TODO: fields of notice (last notice, serial, failure notice,..) // TODO: limits and cert type specific input validation // TODO: fix Cert mess -// TODO: nonce is id, id is even number of hex digits +// TODO: nonce is id, id is even number of hex digits (require only draftid.nonce to be uniq) // TODO: denom, issuer from key (key representation: armor?) import ( @@ -258,6 +258,15 @@ func ToCert(v interface{}) (cert *Cert, err error) { return } +func cleanBody(s []byte) []byte { + nl := []byte{'\n'} + a := bytes.Split(s, nl) + for i := range a { + a[i] = bytes.TrimRight(a[i], " \t") + } + return bytes.Join(a, nl) +} + // sha1 sum of the (cleaned) document body as uppercase hex string func Id(c *Signed) string { h := sha1.New() @@ -311,7 +320,7 @@ func Verify(c *Signed, key openpgp.KeyRing) (err error) { func Sign(body []byte, key *openpgp.Entity) (c *Signed, err error) { c = new(Signed) c.Hash = "SHA256" - c.Body = body + c.Body = cleanBody(body) w := new(bytes.Buffer) err = openpgp.ArmoredDetachSignText(w, key, bytes.NewBuffer(c.Body)) if err != nil { -- 2.20.1