clean body in document.Sign
authornsz <nsz@port70.net>
Mon, 28 Nov 2011 19:11:00 +0000 (20:11 +0100)
committernsz <nsz@port70.net>
Mon, 28 Nov 2011 19:11:00 +0000 (20:11 +0100)
document/document.go

index 0ac99b6..1e26d28 100644 (file)
@@ -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 {