X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=document%2Fdocument.go;h=1e26d28cf59669dc32435e9f08520680d08da983;hb=11dabddd0bb1fce854b001a70694cb9b6be4ff26;hp=695bc8625784e87e28eb23d22da504f01b2621ea;hpb=8c18ef4b933521326f7b352829305dcaaeb8e7c4;p=epoint diff --git a/document/document.go b/document/document.go index 695bc86..1e26d28 100644 --- a/document/document.go +++ b/document/document.go @@ -32,6 +32,8 @@ 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 (require only draftid.nonce to be uniq) +// TODO: denom, issuer from key (key representation: armor?) import ( "bytes" @@ -104,7 +106,7 @@ var fieldtype = map[string]string{ "Last-Credit-Serial": "int", "Last-Debit-Serial": "int", "Maturity-Date": "date", - "Nonce": "text", + "Nonce": "id", "Notes": "text", "References": "ids", "Serial": "int", @@ -127,9 +129,9 @@ type Draft struct { Denomination string Issuer string AuthorizedBy string - MaturityDate *int64 // optional - ExpiryDate *int64 // optional - Nonce *string // optional + MaturityDate *int64 // optional + ExpiryDate *int64 // optional + Nonce string Notes *string // optional } @@ -256,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() @@ -299,9 +310,9 @@ func Format(iv interface{}, key *openpgp.Entity) (s []byte, c *Signed, err error func Verify(c *Signed, key openpgp.KeyRing) (err error) { msg := bytes.NewBuffer(c.Body) sig := bytes.NewBuffer(c.Signature) -// TODO: verify signature - _,_ = msg,sig -// _, err = openpgp.CheckArmoredDetachedSignature(key, msg, sig) + // TODO: verify signature + _, _ = msg, sig + // _, err = openpgp.CheckArmoredDetachedSignature(key, msg, sig) return } @@ -309,10 +320,14 @@ 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) - w.Write([]byte("\n-----BEGIN PGP SIGNATURE-----\n\nTODO: signature\n")) -// err = openpgp.ArmoredDetachSignText(w, key, bytes.NewBuffer(c.Body)) + err = openpgp.ArmoredDetachSignText(w, key, bytes.NewBuffer(c.Body)) + if err != nil { + return + } + // close armored document with a \n + _, _ = w.Write([]byte{'\n'}) c.Signature = w.Bytes() return }