projects
/
epoint
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c951b07
)
key.Id +fmt fixes
author
nsz
<nsz@port70.net>
Tue, 13 Dec 2011 20:01:20 +0000
(21:01 +0100)
committer
nsz
<nsz@port70.net>
Tue, 13 Dec 2011 20:01:20 +0000
(21:01 +0100)
pkg/Makefile
patch
|
blob
|
history
pkg/document/document.go
patch
|
blob
|
history
pkg/key/key.go
patch
|
blob
|
history
pkg/key/key_test.go
patch
|
blob
|
history
pkg/server/server.go
patch
|
blob
|
history
pkg/store/store.go
patch
|
blob
|
history
diff --git
a/pkg/Makefile
b/pkg/Makefile
index
4917a98
..
896c219
100644
(file)
--- a/
pkg/Makefile
+++ b/
pkg/Makefile
@@
-11,12
+11,16
@@
DIRS=\
../cmd/epoint-client\
../cmd/epoint-server\
../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))
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
%.clean:
+$(MAKE) -C $* clean
@@
-31,6
+35,8
@@
testshort.dirs: $(addsuffix .testshort, $(DIRS))
+@echo test $*
+@$(MAKE) -C $* test.clean >$*/test.out 2>&1 || (echo TEST FAIL $*; cat $*/test.out; exit 1)
+@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
clean: clean.dirs
install: install.dirs
diff --git
a/pkg/document/document.go
b/pkg/document/document.go
index
22065fc
..
eecd68a
100644
(file)
--- a/
pkg/document/document.go
+++ b/
pkg/document/document.go
@@
-160,13
+160,13
@@
type Cert struct {
type DebitCert struct {
Cert
type DebitCert struct {
Cert
- Beneficiary
string
+ Beneficiary string
}
type CreditCert struct {
Cert
}
type CreditCert struct {
Cert
- Drawer
string
- DebitCert
string
+ Drawer string
+ DebitCert string
}
type BounceCert struct {
}
type BounceCert struct {
@@
-180,6
+180,7
@@
type BounceCert struct {
References []string
}
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) {
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())
}
return fmt.Sprintf("%040X", h.Sum())
}
-//
p
arse an epoint document without checking the signature and format details
+//
P
arse 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 {
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
}
return
}
-//
f
ormat and sign an epoint document
+//
F
ormat 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 {
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
}
return
}
-//
v
erify an epoint document, return the cleaned version as well
+//
V
erify 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)
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
}
return
}
-//
s
ign body with given secret key
+//
S
ign body with given secret key
func Sign(body []byte, key *openpgp.Entity) (c *Signed, err error) {
c = new(Signed)
c.Hash = "SHA256"
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
}
return
}
+// ParseStruct parses an epoint document and returns a struct representation
func ParseStruct(doc *Document) (iv interface{}, err error) {
switch doc.Type {
case "Draft":
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
}
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 {
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
}
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)
func ParseFields(s []byte) (fields map[string]string, rest []byte, err error) {
rest = s
fields = make(map[string]string)
diff --git
a/pkg/key/key.go
b/pkg/key/key.go
index
f5f9143
..
29e92bd
100644
(file)
--- a/
pkg/key/key.go
+++ b/
pkg/key/key.go
@@
-109,6
+109,11
@@
func Holder(r []byte, issuer, denomination string) (e *openpgp.Entity, err error
return New(DsaKey(r), 0, "Holder of "+issuer, denomination, "")
}
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
// 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
@@
-116,7
+121,7
@@
func Check(e *openpgp.Entity) (isIssuer bool, issuer, denomination string, err e
denomination = id.UserId.Comment
if id.UserId.Name == "Issuer" {
isIssuer = true
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 "
return
}
const prefix = "Holder of "
diff --git
a/pkg/key/key_test.go
b/pkg/key/key_test.go
index
1e594fe
..
0226d12
100644
(file)
--- a/
pkg/key/key_test.go
+++ b/
pkg/key/key_test.go
@@
-37,6
+37,19
@@
func TestKey(t *testing.T) {
}
}
}
}
+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)
func TestIssuerHolder(t *testing.T) {
denomination := "1/100 EUR"
priv, err := Issuer([]byte("issuer-rand"), denomination)
diff --git
a/pkg/server/server.go
b/pkg/server/server.go
index
71bd3fc
..
614c256
100644
(file)
--- a/
pkg/server/server.go
+++ b/
pkg/server/server.go
@@
-24,7
+24,7
@@
func StoreSk(sk *openpgp.Entity) (err error) {
if err != nil {
return
}
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) {
}
func GetKeys(fpr string) (es openpgp.EntityList, err error) {
@@
-75,7
+75,7
@@
func AddKeys(d []byte) (err error) {
if err != nil {
return
}
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
err = db.Set("key", fpr, b.Bytes())
if err != nil {
return
@@
-259,7
+259,7
@@
func NewDebitCert(draftid string, draft *document.Draft) (*document.DebitCert, e
}
cert.LastDebitSerial = oldcert.LastDebitSerial
cert.LastCreditSerial = oldcert.LastCreditSerial
}
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.Serial
} else {
cert.LastCreditSerial = oldcert.Serial
@@
-315,7
+315,7
@@
func NewCreditCert(draftid string, draft *document.Draft, dcertid string, dcert
}
cert.LastDebitSerial = oldcert.LastDebitSerial
cert.LastCreditSerial = oldcert.LastCreditSerial
}
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.Serial
} else {
cert.LastCreditSerial = oldcert.Serial
diff --git
a/pkg/store/store.go
b/pkg/store/store.go
index
2a6d2f8
..
a27935c
100644
(file)
--- a/
pkg/store/store.go
+++ b/
pkg/store/store.go
@@
-42,7
+42,7
@@
func (c *Conn) Get(name, k string) (v []byte, err error) {
v, err = ioutil.ReadFile(filepath.Join(c.path, name, k))
if err != nil {
if p, ok := err.(*os.PathError); ok && p.Err == os.ENOENT {
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
}
}
return