aboutsummaryrefslogtreecommitdiff
path: root/reqres.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-28 13:38:39 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2020-10-28 13:38:39 +0100
commitd752d967335e1418f27e03e0389b01178b28f232 (patch)
treeabc3b6f2e3b64af67f19ca50f6e5c3609d829fb9 /reqres.go
parente7801b268c97c6b72bfcd76549ce5fd50ab0b1b5 (diff)
added signed tree head and get-sth code path
Diffstat (limited to 'reqres.go')
-rw-r--r--reqres.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/reqres.go b/reqres.go
index fe79d51..e223fd9 100644
--- a/reqres.go
+++ b/reqres.go
@@ -55,11 +55,16 @@ type GetProofByHashResponse struct {
InclusionProof string `json:"inclusion_proof"` // base64-encoded StItem
}
-// GetAnchorsResponse
+// GetAnchorsResponse is an assembled get-anchor response
type GetAnchorsResponse struct {
Certificates []string `json:"certificates"`
}
+// GetSthResponse is an assembled get-sth response
+type GetSthResponse struct {
+ SignedTreeHead string `json:"sth"` // base64-encoded StItem
+}
+
// NewAddEntryRequest parses and sanitizes the JSON-encoded add-entry
// parameters from an incoming HTTP post. The resulting AddEntryRequest is
// well-formed, but not necessarily trusted (further sanitization is needed).
@@ -189,6 +194,16 @@ func NewGetAnchorsResponse(anchors []*x509.Certificate) GetAnchorsResponse {
return GetAnchorsResponse{Certificates: certificates}
}
+func NewGetSthResponse(sth StItem) (GetSthResponse, error) {
+ b, err := tls.Marshal(sth)
+ if err != nil {
+ return GetSthResponse{}, fmt.Errorf("tls marshal failed: %v", err)
+ }
+ return GetSthResponse{
+ SignedTreeHead: base64.StdEncoding.EncodeToString(b),
+ }, nil
+}
+
// VerifyAddEntryRequest determines whether a well-formed AddEntryRequest should
// be inserted into the log. The corresponding leaf and appendix is returned.
func VerifyAddEntryRequest(ld *LogParameters, r AddEntryRequest) ([]byte, []byte, error) {