aboutsummaryrefslogtreecommitdiff
path: root/reqres.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-30 20:40:17 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-30 20:40:17 +0100
commitf367d220ff99eaee7debb234c3234de6c781359c (patch)
tree49fda266aaf121e725780d2b7e2d6eb70710c74c /reqres.go
parent5426f3bcd1a5ae4fc4b3b831b41c0d667a17e525 (diff)
refactor types and documentation
Structured files a bit better, added more documentation, switched to pointers as default (unless specifically motivated not to do so), and encapsulated TLS (un)marshaling for the respective types that use it.
Diffstat (limited to 'reqres.go')
-rw-r--r--reqres.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/reqres.go b/reqres.go
index a1e0d78..1cad933 100644
--- a/reqres.go
+++ b/reqres.go
@@ -59,8 +59,8 @@ func NewAddEntryRequest(lp *LogParameters, r *http.Request) ([]byte, []byte, err
return nil, nil, err
}
- item, err := StItemFromB64(entry.Item)
- if err != nil {
+ var item StItem
+ if err := item.UnmarshalB64(entry.Item); err != nil {
return nil, nil, fmt.Errorf("StItem(%s): %v", item.Format, err)
}
if item.Format != StFormatChecksumV1 {
@@ -84,9 +84,9 @@ func NewAddEntryRequest(lp *LogParameters, r *http.Request) ([]byte, []byte, err
return nil, nil, fmt.Errorf("invalid signature: %v", err)
}
- extra, err := tls.Marshal(NewAppendix(chain, signature, entry.SignatureScheme))
+ extra, err := NewAppendix(chain, signature, entry.SignatureScheme).Marshal()
if err != nil {
- return nil, nil, fmt.Errorf("failed tls marshaling appendix: %v", err)
+ return nil, nil, fmt.Errorf("failed marshaling appendix: %v", err)
}
return serialized, extra, nil
@@ -159,11 +159,8 @@ func NewGetConsistencyProofRequest(httpRequest *http.Request) (GetConsistencyPro
// NewGetEntryResponse assembles a log entry and its appendix
func NewGetEntryResponse(leaf, appendix []byte) (GetEntryResponse, error) {
var app Appendix
- extra, err := tls.Unmarshal(appendix, &app)
- if err != nil {
- return GetEntryResponse{}, fmt.Errorf("failed tls unmarshaling appendix: %v (%v)", err, extra)
- } else if len(extra) > 0 {
- return GetEntryResponse{}, fmt.Errorf("tls umarshal found extra data for appendix: %v", extra)
+ if err := app.Unmarshal(appendix); err != nil {
+ return GetEntryResponse{}, err
}
chain := make([]string, 0, len(app.Chain))