-
Notifications
You must be signed in to change notification settings - Fork 18
/
types.go
64 lines (53 loc) · 1.67 KB
/
types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Open Component Model contributors.
//
// SPDX-License-Identifier: Apache-2.0
package signing
import (
"crypto"
"encoding/json"
"hash"
"github.com/sirupsen/logrus"
"github.com/open-component-model/ocm/v2/pkg/contexts/credentials"
)
type Signature struct {
Value string
MediaType string
Algorithm string
Issuer string
}
func (s *Signature) String() string {
data, err := json.Marshal(s)
if err != nil {
logrus.Error(err)
}
return string(data)
}
// Signer interface is used to implement different signing algorithms.
// Each Signer should have a matching Verifier.
type Signer interface {
// Sign returns the signature for the given digest
Sign(cctx credentials.Context, digest string, hash crypto.Hash, issuer string, privatekey interface{}) (*Signature, error)
// Algorithm is the name of the finally used signature algorithm.
// A signer might be registered using a logical name, so there might
// be multiple signer registration providing the same signature algorithm
Algorithm() string
}
// Verifier interface is used to implement different verification algorithms.
// Each Verifier should have a matching Signer.
type Verifier interface {
// Verify checks the signature, returns an error on verification failure
Verify(digest string, hash crypto.Hash, sig *Signature, publickey interface{}) error
Algorithm() string
}
// SignatureHandler can create and verify signature of a dedicated type.
type SignatureHandler interface {
Algorithm() string
Signer
Verifier
}
// Hasher creates a new hash.Hash interface.
type Hasher interface {
Algorithm() string
Create() hash.Hash
Crypto() crypto.Hash
}