...

Source file src/github.com/sigstore/cosign/v2/pkg/oci/layout/signatures.go

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

     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 layout
    17  
    18  import (
    19  	v1 "github.com/google/go-containerregistry/pkg/v1"
    20  	"github.com/sigstore/cosign/v2/pkg/oci"
    21  	"github.com/sigstore/cosign/v2/pkg/oci/internal/signature"
    22  )
    23  
    24  const maxLayers = 1000
    25  
    26  type sigs struct {
    27  	v1.Image
    28  }
    29  
    30  var _ oci.Signatures = (*sigs)(nil)
    31  
    32  // Get implements oci.Signatures
    33  func (s *sigs) Get() ([]oci.Signature, error) {
    34  	manifest, err := s.Image.Manifest()
    35  	if err != nil {
    36  		return nil, err
    37  	}
    38  	numLayers := int64(len(manifest.Layers))
    39  	if numLayers > maxLayers {
    40  		return nil, oci.NewMaxLayersExceeded(numLayers, maxLayers)
    41  	}
    42  	signatures := make([]oci.Signature, 0, numLayers)
    43  	for _, desc := range manifest.Layers {
    44  		l, err := s.Image.LayerByDigest(desc.Digest)
    45  		if err != nil {
    46  			return nil, err
    47  		}
    48  		signatures = append(signatures, signature.New(l, desc))
    49  	}
    50  	return signatures, nil
    51  }
    52  

View as plain text