-
Notifications
You must be signed in to change notification settings - Fork 197
/
keyMock.go
110 lines (88 loc) · 2.14 KB
/
keyMock.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package mock
import (
"crypto/rand"
"github.com/ElrondNetwork/elrond-go-core/hashing/sha256"
"github.com/ElrondNetwork/elrond-go-crypto"
)
// PublicKeyMock -
type PublicKeyMock struct {
pubKey []byte
}
// PrivateKeyMock -
type PrivateKeyMock struct {
privKey []byte
}
// KeyGenMock -
type KeyGenMock struct {
}
// ToByteArray -
func (sspk *PublicKeyMock) ToByteArray() ([]byte, error) {
return sspk.pubKey, nil
}
// Suite -
func (sspk *PublicKeyMock) Suite() crypto.Suite {
return nil
}
// Point -
func (sspk *PublicKeyMock) Point() crypto.Point {
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (sspk *PublicKeyMock) IsInterfaceNil() bool {
return sspk == nil
}
// ToByteArray -
func (sk *PrivateKeyMock) ToByteArray() ([]byte, error) {
return sk.privKey, nil
}
// GeneratePublic -
func (sk *PrivateKeyMock) GeneratePublic() crypto.PublicKey {
return &PublicKeyMock{
pubKey: sha256.NewSha256().Compute(string(sk.privKey)),
}
}
// Suite -
func (sk *PrivateKeyMock) Suite() crypto.Suite {
return nil
}
// Scalar -
func (sk *PrivateKeyMock) Scalar() crypto.Scalar {
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (sk *PrivateKeyMock) IsInterfaceNil() bool {
return sk == nil
}
// GeneratePair -
func (keyGen *KeyGenMock) GeneratePair() (crypto.PrivateKey, crypto.PublicKey) {
buff := make([]byte, 32)
_, _ = rand.Read(buff)
sk := &PrivateKeyMock{
privKey: buff,
}
return sk, sk.GeneratePublic()
}
// PrivateKeyFromByteArray -
func (keyGen *KeyGenMock) PrivateKeyFromByteArray(buff []byte) (crypto.PrivateKey, error) {
return &PrivateKeyMock{
privKey: buff,
}, nil
}
// PublicKeyFromByteArray -
func (keyGen *KeyGenMock) PublicKeyFromByteArray(buff []byte) (crypto.PublicKey, error) {
return &PublicKeyMock{
pubKey: buff,
}, nil
}
// CheckPublicKeyValid -
func (keyGen *KeyGenMock) CheckPublicKeyValid(_ []byte) error {
return nil
}
// Suite -
func (keyGen *KeyGenMock) Suite() crypto.Suite {
return nil
}
// IsInterfaceNil returns true if there is no value under the interface
func (keyGen *KeyGenMock) IsInterfaceNil() bool {
return keyGen == nil
}