From d752d967335e1418f27e03e0389b01178b28f232 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Wed, 28 Oct 2020 13:38:39 +0100 Subject: added signed tree head and get-sth code path --- reqres.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'reqres.go') 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) { -- cgit v1.2.3