-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpolicy.go
35 lines (29 loc) · 1.12 KB
/
policy.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
//go:generate mockgen -destination=mocks/mock_signature_policy.go -package=mocks github.com/edenzhong7/ifly/crypto SignaturePolicy
//go:generate mockgen -destination=mocks/mock_hash_policy.go -package=mocks github.com/edenzhong7/ifly/crypto HashPolicy
package iveil
import (
"math/big"
)
// SignaturePolicy defines the creation and validation of a cryptographic signature.
type SignaturePolicy interface {
GenerateKeys() ([]byte, []byte, error)
PrivateKeySize() int
PrivateToPublic(privateKey []byte) ([]byte, error)
PublicKeySize() int
Sign(privateKey []byte, message []byte) []byte
RandomKeyPair() *KeyPair
Verify(publicKey []byte, message []byte, signature []byte) bool
}
// HashPolicy defines how to create a cryptographic hash.
type HashPolicy interface {
HashBytes(b []byte) []byte
}
// Hash returns a hash of a big integer given a hash policy.
func Hash(hp HashPolicy, s *big.Int) *big.Int {
return s.SetBytes(hp.HashBytes(s.Bytes()))
}
//Encoder defines a encoder interface to encrypt and decrypt data
type EncoderPolicy interface {
Encrypt(data, key []byte) ([]byte, error)
Decrypt(data, key []byte) ([]byte, error)
}