aboutsummaryrefslogtreecommitdiff
path: root/reqres.go
diff options
context:
space:
mode:
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) {