From 90b0c664371e5c26560412ae004e0c5e01a77bca Mon Sep 17 00:00:00 2001 From: nsz Date: Wed, 23 Nov 2011 23:18:34 +0100 Subject: [PATCH] use keyring in verify, add beneficiary to debitcerts --- document/document.go | 16 ++++++++++++---- document/document_test.go | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/document/document.go b/document/document.go index 1b87bf6..e2a0859 100644 --- a/document/document.go +++ b/document/document.go @@ -38,6 +38,7 @@ import ( "crypto/openpgp" "crypto/openpgp/armor" "crypto/openpgp/packet" + "crypto/sha1" "encoding/hex" "fmt" "reflect" @@ -147,6 +148,7 @@ type DebitCert struct { Date int64 Difference int64 Draft string + Beneficiary string AuthorizedBy string Notes *string // optional LastDebitSerial int64 // 0 if none @@ -185,6 +187,13 @@ type BounceCert struct { References []string } +// sha1 sum of the (cleaned) document as uppercase hex string +func Id(d []byte) string { + h := sha1.New() + h.Write(d) + return fmt.Sprintf("%040X", h.Sum()) +} + // 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) @@ -217,7 +226,7 @@ func Format(iv interface{}, key *openpgp.Entity) (s []byte, err error) { } // verify an epoint document, return the cleaned version as well -func Verify(c *Signed, key *openpgp.Entity) (cleaned []byte, err error) { +func Verify(c *Signed, key openpgp.KeyRing) (cleaned []byte, err error) { err = CleanSigned(c) if err != nil { return @@ -230,11 +239,10 @@ func Verify(c *Signed, key *openpgp.Entity) (cleaned []byte, err error) { } // verify signature of body with given key -func VerifyCleaned(c *Signed, key *openpgp.Entity) (err error) { - kr := openpgp.EntityList{key} +func VerifyCleaned(c *Signed, key openpgp.KeyRing) (err error) { msg := bytes.NewBuffer(c.Body) sig := bytes.NewBuffer(c.Signature) - _, err = openpgp.CheckArmoredDetachedSignature(kr, msg, sig) + _, err = openpgp.CheckArmoredDetachedSignature(key, msg, sig) return } diff --git a/document/document_test.go b/document/document_test.go index 024b0bd..9bd2db1 100644 --- a/document/document_test.go +++ b/document/document_test.go @@ -187,6 +187,7 @@ Issuer: 000000000000000000000000000000000000000B Date: 2011-11-13T12:20:35Z Difference: 1 Draft: 000000000000000000000000000000000000000D +Beneficiary: 000000000000000000000000000000000000000E Authorized-By: 000000000000000000000000000000000000000A Notes: - Last-Debit-Serial: 0 -- 2.20.1