...

Source file src/github.com/sigstore/rekor/pkg/signer/signer.go

Documentation: github.com/sigstore/rekor/pkg/signer

     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  
    17  package signer
    18  
    19  import (
    20  	"context"
    21  	"crypto"
    22  	"strings"
    23  
    24  	"github.com/sigstore/sigstore/pkg/signature"
    25  	"github.com/sigstore/sigstore/pkg/signature/kms"
    26  	"golang.org/x/exp/slices"
    27  
    28  	// these are imported to load the providers via init() calls
    29  	_ "github.com/sigstore/sigstore/pkg/signature/kms/aws"
    30  	_ "github.com/sigstore/sigstore/pkg/signature/kms/azure"
    31  	_ "github.com/sigstore/sigstore/pkg/signature/kms/gcp"
    32  	_ "github.com/sigstore/sigstore/pkg/signature/kms/hashivault"
    33  )
    34  
    35  func New(ctx context.Context, signer string, pass string) (signature.Signer, error) {
    36  	switch {
    37  	case slices.ContainsFunc(kms.SupportedProviders(),
    38  		func(s string) bool {
    39  			return strings.HasPrefix(signer, s)
    40  		}):
    41  		return kms.Get(ctx, signer, crypto.SHA256)
    42  	case signer == MemoryScheme:
    43  		return NewMemory()
    44  	default:
    45  		return NewFile(signer, pass)
    46  	}
    47  }
    48  

View as plain text