key.Id +fmt fixes
[epoint] / pkg / document / document.go
index 22065fc..eecd68a 100644 (file)
@@ -160,13 +160,13 @@ type Cert struct {
 
 type DebitCert struct {
        Cert
-       Beneficiary      string
+       Beneficiary string
 }
 
 type CreditCert struct {
        Cert
-       Drawer           string
-       DebitCert        string
+       Drawer    string
+       DebitCert string
 }
 
 type BounceCert struct {
@@ -180,6 +180,7 @@ type BounceCert struct {
        References   []string
 }
 
+// Common cert part of a debit or credit cert
 func ToCert(v interface{}) (cert *Cert, err error) {
        cert = new(Cert)
        switch x := v.(type) {
@@ -209,7 +210,7 @@ func Id(c *Signed) string {
        return fmt.Sprintf("%040X", h.Sum())
 }
 
-// parse an epoint document without checking the signature and format details
+// Parse an epoint document without checking the signature and format details
 func Parse(s []byte) (iv interface{}, c *Signed, err error) {
        c, err = ParseSigned(s)
        if err != nil {
@@ -223,7 +224,7 @@ func Parse(s []byte) (iv interface{}, c *Signed, err error) {
        return
 }
 
-// format and sign an epoint document
+// Format and sign an epoint document
 func Format(iv interface{}, key *openpgp.Entity) (s []byte, c *Signed, err error) {
        doc, err := FormatStruct(iv)
        if err != nil {
@@ -241,7 +242,7 @@ func Format(iv interface{}, key *openpgp.Entity) (s []byte, c *Signed, err error
        return
 }
 
-// verify an epoint document, return the cleaned version as well
+// Verify an epoint document, return the cleaned version as well
 func Verify(c *Signed, key openpgp.KeyRing) (err error) {
        msg := bytes.NewBuffer(c.Body)
        sig := bytes.NewBuffer(c.Signature)
@@ -251,7 +252,7 @@ func Verify(c *Signed, key openpgp.KeyRing) (err error) {
        return
 }
 
-// sign body with given secret key
+// Sign body with given secret key
 func Sign(body []byte, key *openpgp.Entity) (c *Signed, err error) {
        c = new(Signed)
        c.Hash = "SHA256"
@@ -494,6 +495,7 @@ func parseStruct(v reflect.Value, fields map[string]string, seen map[string]bool
        return
 }
 
+// ParseStruct parses an epoint document and returns a struct representation
 func ParseStruct(doc *Document) (iv interface{}, err error) {
        switch doc.Type {
        case "Draft":
@@ -580,7 +582,7 @@ func formatStruct(v reflect.Value, doc *Document) (err error) {
        return
 }
 
-// turn a struct into a document
+// FormatStruct turns a struct into a document
 func FormatStruct(iv interface{}) (doc *Document, err error) {
        v := reflect.ValueOf(iv)
        if v.Kind() != reflect.Ptr || v.IsNil() || v.Elem().Kind() != reflect.Struct {
@@ -593,6 +595,7 @@ func FormatStruct(iv interface{}) (doc *Document, err error) {
        return
 }
 
+// ParseFields parses a key value sequence into a fields map
 func ParseFields(s []byte) (fields map[string]string, rest []byte, err error) {
        rest = s
        fields = make(map[string]string)