"Fossies" - the Fresh Open Source Software Archive

Member "cri-o-1.25.1/vendor/github.com/sigstore/sigstore/pkg/signature/dsse/adapters.go" (7 Oct 2022, 2319 Bytes) of package /linux/misc/cri-o-1.25.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Go source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 dsse
   17 
   18 import (
   19     "bytes"
   20     "crypto"
   21     "errors"
   22 
   23     "github.com/sigstore/sigstore/pkg/signature"
   24 )
   25 
   26 // SignerAdapter wraps a `sigstore/signature.Signer`, making it compatible with `go-securesystemslib/dsse.Signer`.
   27 type SignerAdapter struct {
   28     SignatureSigner signature.Signer
   29     Pub             crypto.PublicKey
   30     Opts            []signature.SignOption
   31     PubKeyID        string
   32 }
   33 
   34 // Sign implements `go-securesystemslib/dsse.Signer`
   35 func (a *SignerAdapter) Sign(data []byte) ([]byte, error) {
   36     return a.SignatureSigner.SignMessage(bytes.NewReader(data), a.Opts...)
   37 }
   38 
   39 // Verify disabled `go-securesystemslib/dsse.Verifier`
   40 func (a *SignerAdapter) Verify(data []byte, sig []byte) error {
   41     return errors.New("Verify disabled")
   42 }
   43 
   44 // Public implements `go-securesystemslib/dsse.Verifier`
   45 func (a *SignerAdapter) Public() crypto.PublicKey {
   46     return a.Pub
   47 }
   48 
   49 // KeyID implements `go-securesystemslib/dsse.Verifier`
   50 func (a SignerAdapter) KeyID() (string, error) {
   51     return a.PubKeyID, nil
   52 }
   53 
   54 // VerifierAdapter wraps a `sigstore/signature.Verifier`, making it compatible with `go-securesystemslib/dsse.Verifier`.
   55 type VerifierAdapter struct {
   56     SignatureVerifier signature.Verifier
   57     Pub               crypto.PublicKey
   58     PubKeyID          string
   59 }
   60 
   61 // Verify implements `go-securesystemslib/dsse.Verifier`
   62 func (a *VerifierAdapter) Verify(data []byte, sig []byte) error {
   63     return a.SignatureVerifier.VerifySignature(bytes.NewReader(sig), bytes.NewReader(data))
   64 }
   65 
   66 // Public implements `go-securesystemslib/dsse.Verifier`
   67 func (a *VerifierAdapter) Public() crypto.PublicKey {
   68     return a.Pub
   69 }
   70 
   71 // KeyID implements `go-securesystemslib/dsse.Verifier`
   72 func (a *VerifierAdapter) KeyID() (string, error) {
   73     return a.PubKeyID, nil
   74 }