1 // 2 // Copyright 2021 The Sigstore Authors. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 package walk 17 18 import ( 19 "context" 20 21 "github.com/sigstore/cosign/v2/pkg/oci" 22 "github.com/sigstore/cosign/v2/pkg/oci/mutate" 23 ) 24 25 // Fn is the signature of the callback supplied to SignedEntity. 26 // The oci.SignedEntity is either an oci.SignedImageIndex or an oci.SignedImage. 27 // This callback is called on oci.SignedImageIndex *before* its children. 28 type Fn func(context.Context, oci.SignedEntity) error 29 30 // SignedEntity calls `fn` on the signed entity and each of its constituent entities 31 // (`SignedImageIndex` or `SignedImage`) transitively. 32 // Any errors returned by an `fn` are returned by `Walk`. 33 func SignedEntity(ctx context.Context, parent oci.SignedEntity, fn Fn) error { 34 _, err := mutate.Map(ctx, parent, func(ctx context.Context, se oci.SignedEntity) (oci.SignedEntity, error) { 35 if err := fn(ctx, se); err != nil { 36 return nil, err 37 } 38 return se, nil 39 }) 40 return err 41 } 42