cleanups
[epoint] / document / document.go
index 695bc86..0ac99b6 100644 (file)
@@ -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
+// 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
 }
 
@@ -299,9 +301,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
 }
 
@@ -311,8 +313,12 @@ func Sign(body []byte, key *openpgp.Entity) (c *Signed, err error) {
        c.Hash = "SHA256"
        c.Body = 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
 }