-
Notifications
You must be signed in to change notification settings - Fork 1
/
default.go
84 lines (74 loc) · 2.58 KB
/
default.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package crypto
import (
libp2pcrypto "github.com/libp2p/go-libp2p-core/crypto"
pb "github.com/libp2p/go-libp2p-core/crypto/pb"
)
type SecurityContext struct {
Protocol string `json:",omitempty"`
KeyFactoryAlgorithm string `json:",omitempty"`
KeyStoreType string `json:",omitempty"`
KeyPairAlgorithm string `json:",omitempty"`
KeyPairType string `json:",omitempty"`
KeyPairLength uint `json:",omitempty"`
SecretKeyAlgorithm string `json:",omitempty"`
SecretKeySize uint `json:",omitempty"`
HashKeySize uint `json:",omitempty"`
AsymmetricalAlgorithm string `json:",omitempty"`
SymmetricalAlgorithm string `json:",omitempty"`
SignatureAlgorithm string `json:",omitempty"`
MessageDigestAlgorithm string `json:",omitempty"`
KeyGeneratorAlgorithm string `json:",omitempty"`
HmacAlgorithm string `json:",omitempty"`
Username string `json:",omitempty"`
Password string `json:",omitempty"`
}
const (
KeyPairType_RSA string = "RSA"
KeyPairType_ECDSA string = "ECDSA"
KeyPairType_Secp256k1 string = "Secp256k1"
KeyPairType_Ed25519 string = "Ed25519"
)
const (
Protocol_openpgp string = "OpenPGP"
Protocol_libp2p string = "libp2p"
Protocol_standard string = "standard"
)
func GetPbKeyType(keyPairType string) pb.KeyType {
var pbKeyType = pb.KeyType_Ed25519
if keyPairType == KeyPairType_Ed25519 {
pbKeyType = pb.KeyType_Ed25519
} else if keyPairType == KeyPairType_RSA {
pbKeyType = pb.KeyType_RSA
} else if keyPairType == KeyPairType_Secp256k1 {
pbKeyType = pb.KeyType_Secp256k1
} else if keyPairType == KeyPairType_ECDSA {
pbKeyType = pb.KeyType_ECDSA
}
return pbKeyType
}
func GetLibp2pKeyType(keyPairType string) int {
var libp2pKeyType = libp2pcrypto.Ed25519
if keyPairType == KeyPairType_Ed25519 {
libp2pKeyType = libp2pcrypto.Ed25519
} else if keyPairType == KeyPairType_RSA {
libp2pKeyType = libp2pcrypto.RSA
} else if keyPairType == KeyPairType_Secp256k1 {
libp2pKeyType = libp2pcrypto.Secp256k1
} else if keyPairType == KeyPairType_ECDSA {
libp2pKeyType = libp2pcrypto.ECDSA
}
return libp2pKeyType
}
func GetKeyType(keyPairType int) string {
var openKeyType = KeyPairType_Ed25519
if keyPairType == libp2pcrypto.Ed25519 {
openKeyType = KeyPairType_Ed25519
} else if keyPairType == libp2pcrypto.RSA {
openKeyType = KeyPairType_RSA
} else if keyPairType == libp2pcrypto.Secp256k1 {
openKeyType = KeyPairType_Secp256k1
} else if keyPairType == libp2pcrypto.ECDSA {
openKeyType = KeyPairType_ECDSA
}
return openKeyType
}