diff options
author | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-30 20:40:17 +0100 |
---|---|---|
committer | Rasmus Dahlberg <rasmus.dahlberg@kau.se> | 2020-10-30 20:40:17 +0100 |
commit | f367d220ff99eaee7debb234c3234de6c781359c (patch) | |
tree | 49fda266aaf121e725780d2b7e2d6eb70710c74c /reqres.go | |
parent | 5426f3bcd1a5ae4fc4b3b831b41c0d667a17e525 (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.go | 15 |
1 files changed, 6 insertions, 9 deletions
@@ -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)) |