-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
signing_algorithms.go
49 lines (40 loc) · 1.16 KB
/
signing_algorithms.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
package keyring
import (
"fmt"
"strings"
"github.com/cosmos/cosmos-sdk/crypto/hd"
)
// SignatureAlgo defines the interface for a keyring supported algorithm.
type SignatureAlgo interface {
Name() hd.PubKeyType
Derive() hd.DeriveFn
Generate() hd.GenerateFn
}
// NewSigningAlgoFromString creates a supported SignatureAlgo.
func NewSigningAlgoFromString(str string, algoList SigningAlgoList) (SignatureAlgo, error) {
for _, algo := range algoList {
if str == string(algo.Name()) {
return algo, nil
}
}
return nil, fmt.Errorf("provided algorithm %q is not supported", str)
}
// SigningAlgoList is a slice of signature algorithms
type SigningAlgoList []SignatureAlgo
// Contains returns true if the SigningAlgoList the given SignatureAlgo.
func (sal SigningAlgoList) Contains(algo SignatureAlgo) bool {
for _, cAlgo := range sal {
if cAlgo.Name() == algo.Name() {
return true
}
}
return false
}
// String returns a comma separated string of the signature algorithm names in the list.
func (sal SigningAlgoList) String() string {
names := make([]string, len(sal))
for i := range sal {
names[i] = string(sal[i].Name())
}
return strings.Join(names, ",")
}