...

Source file src/github.com/sigstore/cosign/v2/pkg/oci/signed/index.go

Documentation: github.com/sigstore/cosign/v2/pkg/oci/signed

     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 signed
    17  
    18  import (
    19  	"errors"
    20  
    21  	v1 "github.com/google/go-containerregistry/pkg/v1"
    22  
    23  	"github.com/sigstore/cosign/v2/pkg/oci"
    24  	"github.com/sigstore/cosign/v2/pkg/oci/empty"
    25  )
    26  
    27  // ImageIndex returns an oci.SignedImageIndex form of the v1.ImageIndex with
    28  // no signatures.
    29  func ImageIndex(i v1.ImageIndex) oci.SignedImageIndex {
    30  	return &index{
    31  		v1Index: i,
    32  	}
    33  }
    34  
    35  type v1Index v1.ImageIndex
    36  
    37  type index struct {
    38  	v1Index
    39  }
    40  
    41  var _ oci.SignedImageIndex = (*index)(nil)
    42  
    43  // SignedImage implements oci.SignedImageIndex
    44  func (ii *index) SignedImage(h v1.Hash) (oci.SignedImage, error) {
    45  	i, err := ii.Image(h)
    46  	if err != nil {
    47  		return nil, err
    48  	}
    49  	return Image(i), nil
    50  }
    51  
    52  // SignedImageIndex implements oci.SignedImageIndex
    53  func (ii *index) SignedImageIndex(h v1.Hash) (oci.SignedImageIndex, error) {
    54  	i, err := ii.ImageIndex(h)
    55  	if err != nil {
    56  		return nil, err
    57  	}
    58  	return ImageIndex(i), nil
    59  }
    60  
    61  // Signatures implements oci.SignedImageIndex
    62  func (*index) Signatures() (oci.Signatures, error) {
    63  	return empty.Signatures(), nil
    64  }
    65  
    66  // Attestations implements oci.SignedImageIndex
    67  func (*index) Attestations() (oci.Signatures, error) {
    68  	return empty.Signatures(), nil
    69  }
    70  
    71  // Attestations implements oci.SignedImage
    72  func (*index) Attachment(name string) (oci.File, error) { //nolint: revive
    73  	return nil, errors.New("unimplemented")
    74  }
    75  

View as plain text