../cmd/epoint-client\
../cmd/epoint-server\
+fmt.dirs: $(addsuffix .fmt, $(DIRS))
clean.dirs: $(addsuffix .clean, $(DIRS))
install.dirs: $(addsuffix .install, $(DIRS))
nuke.dirs: $(addsuffix .nuke, $(DIRS))
test.dirs: $(addsuffix .test, $(DIRS))
testshort.dirs: $(addsuffix .testshort, $(DIRS))
+%.fmt:
+ gofmt -w $*/*.go
+
%.clean:
+$(MAKE) -C $* clean
+@echo test $*
+@$(MAKE) -C $* test.clean >$*/test.out 2>&1 || (echo TEST FAIL $*; cat $*/test.out; exit 1)
+fmt: fmt.dirs
+
clean: clean.dirs
install: install.dirs
type DebitCert struct {
Cert
- Beneficiary string
+ Beneficiary string
}
type CreditCert struct {
Cert
- Drawer string
- DebitCert string
+ Drawer string
+ DebitCert string
}
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) {
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 {
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 {
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)
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"
return
}
+// ParseStruct parses an epoint document and returns a struct representation
func ParseStruct(doc *Document) (iv interface{}, err error) {
switch doc.Type {
case "Draft":
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 {
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)
return New(DsaKey(r), 0, "Holder of "+issuer, denomination, "")
}
+// Key id (fingerprint)
+func Id(e *openpgp.Entity) string {
+ return fmt.Sprintf("%X", e.PrimaryKey.Fingerprint)
+}
+
// Check the issuer and denomination associated with the given pgp key
func Check(e *openpgp.Entity) (isIssuer bool, issuer, denomination string, err error) {
// allow multiple identities, use the first one that looks like an epoint uid
denomination = id.UserId.Comment
if id.UserId.Name == "Issuer" {
isIssuer = true
- issuer = fmt.Sprintf("%X", e.PrimaryKey.Fingerprint)
+ issuer = Id(e)
return
}
const prefix = "Holder of "
}
}
+func TestId(t *testing.T) {
+ idwant := "E51F405B809FA2DEA760603F9D33F730611CBCD9"
+ key, err := Issuer([]byte("rand"), "")
+ if err != nil {
+ t.Errorf("Issuer failed: %s", err)
+ return
+ }
+ id := Id(key)
+ if id != idwant {
+ t.Errorf("Id failed: expected %s, got %s", idwant, id)
+ }
+}
+
func TestIssuerHolder(t *testing.T) {
denomination := "1/100 EUR"
priv, err := Issuer([]byte("issuer-rand"), denomination)
if err != nil {
return
}
- return db.Set("key", fmt.Sprintf("%X", sk.PrimaryKey.Fingerprint), b.Bytes())
+ return db.Set("key", key.Id(sk), b.Bytes())
}
func GetKeys(fpr string) (es openpgp.EntityList, err error) {
if err != nil {
return
}
- fpr := fmt.Sprintf("%X", e.PrimaryKey.Fingerprint)
+ fpr := key.Id(e)
err = db.Set("key", fpr, b.Bytes())
if err != nil {
return
}
cert.LastDebitSerial = oldcert.LastDebitSerial
cert.LastCreditSerial = oldcert.LastCreditSerial
- if _,ok := iv.(*document.DebitCert); ok {
+ if _, ok := iv.(*document.DebitCert); ok {
cert.LastDebitSerial = oldcert.Serial
} else {
cert.LastCreditSerial = oldcert.Serial
}
cert.LastDebitSerial = oldcert.LastDebitSerial
cert.LastCreditSerial = oldcert.LastCreditSerial
- if _,ok := iv.(*document.DebitCert); ok {
+ if _, ok := iv.(*document.DebitCert); ok {
cert.LastDebitSerial = oldcert.Serial
} else {
cert.LastCreditSerial = oldcert.Serial
v, err = ioutil.ReadFile(filepath.Join(c.path, name, k))
if err != nil {
if p, ok := err.(*os.PathError); ok && p.Err == os.ENOENT {
- err = NotFoundError{name+"/"+k}
+ err = NotFoundError{name + "/" + k}
}
}
return