diff options
Diffstat (limited to 'reqres.go')
-rw-r--r-- | reqres.go | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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) { |