From 134f7e1cb59b7c1bd4f2eadfebe7f65da1264988 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Fri, 23 Oct 2020 18:37:37 +0200 Subject: added start on get-anchors code path --- reqres.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'reqres.go') diff --git a/reqres.go b/reqres.go index c384d02..a12892e 100644 --- a/reqres.go +++ b/reqres.go @@ -11,6 +11,7 @@ import ( "github.com/google/certificate-transparency-go/tls" "github.com/google/certificate-transparency-go/trillian/ctfe" + "github.com/google/certificate-transparency-go/x509" "github.com/google/trillian" ) @@ -50,6 +51,11 @@ type GetProofByHashResponse struct { InclusionProof string `json:"inclusion_proof"` // base64-encoded StItem } +// GetAnchorsResponse +type GetAnchorsResponse struct { + Certificates []string `json:"certificates"` +} + // 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). @@ -142,6 +148,14 @@ func NewGetProofByHashResponse(treeSize uint64, inclusionProof *trillian.Proof) }, nil } +func NewGetAnchorsResponse(anchors []*x509.Certificate) GetAnchorsResponse { + certificates := make([]string, 0, len(anchors)) + for _, certificate := range anchors { + certificates = append(certificates, base64.StdEncoding.EncodeToString(certificate.Raw)) + } + return GetAnchorsResponse{Certificates: certificates} +} + // VerifyAddEntryRequest determines whether a well-formed AddEntryRequest should // be inserted into the log. If so, the serialized leaf value is returned. func VerifyAddEntryRequest(a ctfe.CertValidationOpts, r AddEntryRequest) ([]byte, error) { -- cgit v1.2.3