diff --git a/pkg/client/rekor_client.go b/pkg/client/rekor_client.go index fd7ca4813..2ed00c0e4 100644 --- a/pkg/client/rekor_client.go +++ b/pkg/client/rekor_client.go @@ -65,7 +65,7 @@ func GetRekorClient(rekorServerURL string, opts ...Option) (*client.Rekor, error rt := httptransport.NewWithClient(url.Host, url.Path, []string{url.Scheme}, httpClient) rt.Consumers["application/json"] = runtime.JSONConsumer() rt.Consumers["application/x-pem-file"] = runtime.TextConsumer() - rt.Consumers[tle.TLEMediaType] = &tle.TLEConsumer{} + rt.Consumers[tle.TLEMediaType] = &tle.Consumer{} rt.Producers["application/json"] = runtime.JSONProducer() rt.DefaultMediaType = "application/json" diff --git a/pkg/generated/restapi/configure_rekor_server.go b/pkg/generated/restapi/configure_rekor_server.go index 833d266cb..2d119656b 100644 --- a/pkg/generated/restapi/configure_rekor_server.go +++ b/pkg/generated/restapi/configure_rekor_server.go @@ -89,7 +89,7 @@ func configureAPI(api *operations.RekorServerAPI) http.Handler { api.JSONProducer = runtime.JSONProducer() api.ApplicationXPemFileProducer = runtime.TextProducer() - api.ApplicationXSigstoreTleProducer = tle.TLEProducer{} + api.ApplicationXSigstoreTleProducer = &tle.Producer{} // disable all endpoints to start api.IndexSearchIndexHandler = index.SearchIndexHandlerFunc(pkgapi.SearchIndexNotImplementedHandler) diff --git a/pkg/tle/tle.go b/pkg/tle/tle.go index abaea20bc..e0a20639d 100644 --- a/pkg/tle/tle.go +++ b/pkg/tle/tle.go @@ -112,7 +112,7 @@ func MarshalTLEToJSON(tle *rekor_pb.TransparencyLogEntry) ([]byte, error) { return protojson.Marshal(tle) } -func GenerateLogEntry(tle *rekor_pb.TransparencyLogEntry) *models.LogEntry { +func GenerateLogEntry(tle *rekor_pb.TransparencyLogEntry) models.LogEntry { if tle == nil { return nil } @@ -120,9 +120,9 @@ func GenerateLogEntry(tle *rekor_pb.TransparencyLogEntry) *models.LogEntry { entryUUID := hex.EncodeToString(rfc6962.DefaultHasher.HashLeaf(tle.CanonicalizedBody)) inclusionProofHashes := []string{} for _, hash := range tle.InclusionProof.Hashes { - inclusionProofHashes = append(inclusionProofHashes, hex.EncodeToString(hash)) + inclusionProofHashes = append(inclusionProofHashes, base64.StdEncoding.EncodeToString(hash)) } - return &models.LogEntry{ + return models.LogEntry{ entryUUID: models.LogEntryAnon{ Body: tle.CanonicalizedBody, IntegratedTime: swag.Int64(tle.IntegratedTime), @@ -142,9 +142,9 @@ func GenerateLogEntry(tle *rekor_pb.TransparencyLogEntry) *models.LogEntry { } } -type TLEProducer struct{} +type Producer struct{} -func (t TLEProducer) Produce(w io.Writer, input interface{}) error { +func (t Producer) Produce(w io.Writer, input interface{}) error { switch i := input.(type) { case models.LogEntry: var entry models.LogEntryAnon @@ -189,9 +189,9 @@ func (t TLEProducer) Produce(w io.Writer, input interface{}) error { return nil } -type TLEConsumer struct{} +type Consumer struct{} -func (t TLEConsumer) Consume(r io.Reader, output interface{}) error { +func (t Consumer) Consume(r io.Reader, output interface{}) error { tleBytes, err := io.ReadAll(r) if err != nil { return err @@ -215,11 +215,11 @@ func (t TLEConsumer) Consume(r io.Reader, output interface{}) error { if err := protojson.Unmarshal(element, msg); err != nil { return fmt.Errorf("parsing element: %w", err) } - if result, ok := output.([]models.LogEntry); ok { + if result, ok := output.(*[]models.LogEntry); ok { logEntry := GenerateLogEntry(msg) - result = append(result, *logEntry) - } else if result, ok := output.([]*rekor_pb.TransparencyLogEntry); ok { - result = append(result, msg) + *result = append(*result, logEntry) + } else if result, ok := output.(*[]*rekor_pb.TransparencyLogEntry); ok { + *result = append(*result, msg) } else { return errors.New("unsupported conversion") } @@ -231,11 +231,11 @@ func (t TLEConsumer) Consume(r io.Reader, output interface{}) error { if err := protojson.Unmarshal(tleBytes, tle); err != nil { return fmt.Errorf("parsing element: %w", err) } - if _, ok := output.(*rekor_pb.TransparencyLogEntry); ok { - output = tle + if result, ok := output.(**rekor_pb.TransparencyLogEntry); ok { + *result = tle return nil - } else if _, ok := output.(*models.LogEntry); ok { - output = GenerateLogEntry(tle) + } else if result, ok := output.(*models.LogEntry); ok { + *result = GenerateLogEntry(tle) return nil } else { return errors.New("unsupported conversion")