...

Source file src/github.com/sigstore/cosign/v2/pkg/signature/annotations.go

Documentation: github.com/sigstore/cosign/v2/pkg/signature

     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 signature
    17  
    18  import (
    19  	_ "crypto/sha256" // for `crypto.SHA256`
    20  	"fmt"
    21  	"strings"
    22  )
    23  
    24  type AnnotationsMap struct {
    25  	Annotations map[string]interface{}
    26  }
    27  
    28  func (a *AnnotationsMap) Set(s string) error {
    29  	if a.Annotations == nil {
    30  		a.Annotations = map[string]interface{}{}
    31  	}
    32  	kvp := strings.SplitN(s, "=", 2)
    33  	if len(kvp) != 2 {
    34  		return fmt.Errorf("invalid flag: %s, expected key=value", s)
    35  	}
    36  
    37  	a.Annotations[kvp[0]] = kvp[1]
    38  	return nil
    39  }
    40  
    41  func (a *AnnotationsMap) String() string {
    42  	s := []string{}
    43  	for k, v := range a.Annotations {
    44  		s = append(s, fmt.Sprintf("%s=%s", k, v))
    45  	}
    46  	return strings.Join(s, ",")
    47  }
    48  

View as plain text