mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 23:18:15 -05:00
Refactor Exported Names to Follow Golang Best Practices (#13075)
* Fix exported names that start with a package name * A few more renames * Fix exported names that start with a package name * A few more renames * Radek's feedback * Fix conflict * fix keymanager test * Fix comments --------- Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
// Initialize herumi temporarily while we transition to blst for ethdo.
|
||||
func init() {
|
||||
herumi.HerumiInit()
|
||||
herumi.Init()
|
||||
}
|
||||
|
||||
// SecretKeyFromBytes creates a BLS private key from a BigEndian byte slice.
|
||||
|
||||
138
crypto/bls/common/mock/interface_mock.go
generated
138
crypto/bls/common/mock/interface_mock.go
generated
@@ -12,30 +12,30 @@ import (
|
||||
)
|
||||
|
||||
// MockSecretKey is a mock of SecretKey interface.
|
||||
type MockSecretKey struct {
|
||||
type SecretKey struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockSecretKeyMockRecorder
|
||||
recorder *SecretKeyMockRecorder
|
||||
}
|
||||
|
||||
// MockSecretKeyMockRecorder is the mock recorder for MockSecretKey.
|
||||
type MockSecretKeyMockRecorder struct {
|
||||
mock *MockSecretKey
|
||||
type SecretKeyMockRecorder struct {
|
||||
mock *SecretKey
|
||||
}
|
||||
|
||||
// NewMockSecretKey creates a new mock instance.
|
||||
func NewMockSecretKey(ctrl *gomock.Controller) *MockSecretKey {
|
||||
mock := &MockSecretKey{ctrl: ctrl}
|
||||
mock.recorder = &MockSecretKeyMockRecorder{mock}
|
||||
// NewSecretKey creates a new mock instance.
|
||||
func NewSecretKey(ctrl *gomock.Controller) *SecretKey {
|
||||
mock := &SecretKey{ctrl: ctrl}
|
||||
mock.recorder = &SecretKeyMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockSecretKey) EXPECT() *MockSecretKeyMockRecorder {
|
||||
func (m *SecretKey) EXPECT() *SecretKeyMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Marshal mocks base method.
|
||||
func (m *MockSecretKey) Marshal() []byte {
|
||||
func (m *SecretKey) Marshal() []byte {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Marshal")
|
||||
ret0, _ := ret[0].([]byte)
|
||||
@@ -43,13 +43,13 @@ func (m *MockSecretKey) Marshal() []byte {
|
||||
}
|
||||
|
||||
// Marshal indicates an expected call of Marshal.
|
||||
func (mr *MockSecretKeyMockRecorder) Marshal() *gomock.Call {
|
||||
func (mr *SecretKeyMockRecorder) Marshal() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Marshal", reflect.TypeOf((*MockSecretKey)(nil).Marshal))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Marshal", reflect.TypeOf((*SecretKey)(nil).Marshal))
|
||||
}
|
||||
|
||||
// PublicKey mocks base method.
|
||||
func (m *MockSecretKey) PublicKey() common.PublicKey {
|
||||
func (m *SecretKey) PublicKey() common.PublicKey {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "PublicKey")
|
||||
ret0, _ := ret[0].(common.PublicKey)
|
||||
@@ -57,13 +57,13 @@ func (m *MockSecretKey) PublicKey() common.PublicKey {
|
||||
}
|
||||
|
||||
// PublicKey indicates an expected call of PublicKey.
|
||||
func (mr *MockSecretKeyMockRecorder) PublicKey() *gomock.Call {
|
||||
func (mr *SecretKeyMockRecorder) PublicKey() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublicKey", reflect.TypeOf((*MockSecretKey)(nil).PublicKey))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PublicKey", reflect.TypeOf((*SecretKey)(nil).PublicKey))
|
||||
}
|
||||
|
||||
// Sign mocks base method.
|
||||
func (m *MockSecretKey) Sign(msg []byte) common.Signature {
|
||||
func (m *SecretKey) Sign(msg []byte) common.Signature {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Sign", msg)
|
||||
ret0, _ := ret[0].(common.Signature)
|
||||
@@ -71,36 +71,36 @@ func (m *MockSecretKey) Sign(msg []byte) common.Signature {
|
||||
}
|
||||
|
||||
// Sign indicates an expected call of Sign.
|
||||
func (mr *MockSecretKeyMockRecorder) Sign(msg interface{}) *gomock.Call {
|
||||
func (mr *SecretKeyMockRecorder) Sign(msg interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sign", reflect.TypeOf((*MockSecretKey)(nil).Sign), msg)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Sign", reflect.TypeOf((*SecretKey)(nil).Sign), msg)
|
||||
}
|
||||
|
||||
// MockPublicKey is a mock of PublicKey interface.
|
||||
type MockPublicKey struct {
|
||||
type PublicKey struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockPublicKeyMockRecorder
|
||||
recorder *PublicKeyMockRecorder
|
||||
}
|
||||
|
||||
// MockPublicKeyMockRecorder is the mock recorder for MockPublicKey.
|
||||
type MockPublicKeyMockRecorder struct {
|
||||
mock *MockPublicKey
|
||||
type PublicKeyMockRecorder struct {
|
||||
mock *PublicKey
|
||||
}
|
||||
|
||||
// NewMockPublicKey creates a new mock instance.
|
||||
func NewMockPublicKey(ctrl *gomock.Controller) *MockPublicKey {
|
||||
mock := &MockPublicKey{ctrl: ctrl}
|
||||
mock.recorder = &MockPublicKeyMockRecorder{mock}
|
||||
// NewPublicKey creates a new mock instance.
|
||||
func NewPublicKey(ctrl *gomock.Controller) *PublicKey {
|
||||
mock := &PublicKey{ctrl: ctrl}
|
||||
mock.recorder = &PublicKeyMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockPublicKey) EXPECT() *MockPublicKeyMockRecorder {
|
||||
func (m *PublicKey) EXPECT() *PublicKeyMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// Aggregate mocks base method.
|
||||
func (m *MockPublicKey) Aggregate(p2 common.PublicKey) common.PublicKey {
|
||||
func (m *PublicKey) Aggregate(p2 common.PublicKey) common.PublicKey {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Aggregate", p2)
|
||||
ret0, _ := ret[0].(common.PublicKey)
|
||||
@@ -108,13 +108,13 @@ func (m *MockPublicKey) Aggregate(p2 common.PublicKey) common.PublicKey {
|
||||
}
|
||||
|
||||
// Aggregate indicates an expected call of Aggregate.
|
||||
func (mr *MockPublicKeyMockRecorder) Aggregate(p2 interface{}) *gomock.Call {
|
||||
func (mr *PublicKeyMockRecorder) Aggregate(p2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Aggregate", reflect.TypeOf((*MockPublicKey)(nil).Aggregate), p2)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Aggregate", reflect.TypeOf((*PublicKey)(nil).Aggregate), p2)
|
||||
}
|
||||
|
||||
// Copy mocks base method.
|
||||
func (m *MockPublicKey) Copy() common.PublicKey {
|
||||
func (m *PublicKey) Copy() common.PublicKey {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Copy")
|
||||
ret0, _ := ret[0].(common.PublicKey)
|
||||
@@ -122,13 +122,13 @@ func (m *MockPublicKey) Copy() common.PublicKey {
|
||||
}
|
||||
|
||||
// Copy indicates an expected call of Copy.
|
||||
func (mr *MockPublicKeyMockRecorder) Copy() *gomock.Call {
|
||||
func (mr *PublicKeyMockRecorder) Copy() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Copy", reflect.TypeOf((*MockPublicKey)(nil).Copy))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Copy", reflect.TypeOf((*PublicKey)(nil).Copy))
|
||||
}
|
||||
|
||||
// Equals mocks base method.
|
||||
func (m *MockPublicKey) Equals(p2 common.PublicKey) bool {
|
||||
func (m *PublicKey) Equals(p2 common.PublicKey) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Equals", p2)
|
||||
ret0, _ := ret[0].(bool)
|
||||
@@ -136,13 +136,13 @@ func (m *MockPublicKey) Equals(p2 common.PublicKey) bool {
|
||||
}
|
||||
|
||||
// Equals indicates an expected call of Equals.
|
||||
func (mr *MockPublicKeyMockRecorder) Equals(p2 interface{}) *gomock.Call {
|
||||
func (mr *PublicKeyMockRecorder) Equals(p2 interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Equals", reflect.TypeOf((*MockPublicKey)(nil).Equals), p2)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Equals", reflect.TypeOf((*PublicKey)(nil).Equals), p2)
|
||||
}
|
||||
|
||||
// IsInfinite mocks base method.
|
||||
func (m *MockPublicKey) IsInfinite() bool {
|
||||
func (m *PublicKey) IsInfinite() bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "IsInfinite")
|
||||
ret0, _ := ret[0].(bool)
|
||||
@@ -150,13 +150,13 @@ func (m *MockPublicKey) IsInfinite() bool {
|
||||
}
|
||||
|
||||
// IsInfinite indicates an expected call of IsInfinite.
|
||||
func (mr *MockPublicKeyMockRecorder) IsInfinite() *gomock.Call {
|
||||
func (mr *PublicKeyMockRecorder) IsInfinite() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsInfinite", reflect.TypeOf((*MockPublicKey)(nil).IsInfinite))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsInfinite", reflect.TypeOf((*PublicKey)(nil).IsInfinite))
|
||||
}
|
||||
|
||||
// Marshal mocks base method.
|
||||
func (m *MockPublicKey) Marshal() []byte {
|
||||
func (m *PublicKey) Marshal() []byte {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Marshal")
|
||||
ret0, _ := ret[0].([]byte)
|
||||
@@ -164,36 +164,36 @@ func (m *MockPublicKey) Marshal() []byte {
|
||||
}
|
||||
|
||||
// Marshal indicates an expected call of Marshal.
|
||||
func (mr *MockPublicKeyMockRecorder) Marshal() *gomock.Call {
|
||||
func (mr *PublicKeyMockRecorder) Marshal() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Marshal", reflect.TypeOf((*MockPublicKey)(nil).Marshal))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Marshal", reflect.TypeOf((*PublicKey)(nil).Marshal))
|
||||
}
|
||||
|
||||
// MockSignature is a mock of Signature interface.
|
||||
type MockSignature struct {
|
||||
type Signature struct {
|
||||
ctrl *gomock.Controller
|
||||
recorder *MockSignatureMockRecorder
|
||||
recorder *SignatureMockRecorder
|
||||
}
|
||||
|
||||
// MockSignatureMockRecorder is the mock recorder for MockSignature.
|
||||
type MockSignatureMockRecorder struct {
|
||||
mock *MockSignature
|
||||
type SignatureMockRecorder struct {
|
||||
mock *Signature
|
||||
}
|
||||
|
||||
// NewMockSignature creates a new mock instance.
|
||||
func NewMockSignature(ctrl *gomock.Controller) *MockSignature {
|
||||
mock := &MockSignature{ctrl: ctrl}
|
||||
mock.recorder = &MockSignatureMockRecorder{mock}
|
||||
// NewSignature creates a new mock instance.
|
||||
func NewSignature(ctrl *gomock.Controller) *Signature {
|
||||
mock := &Signature{ctrl: ctrl}
|
||||
mock.recorder = &SignatureMockRecorder{mock}
|
||||
return mock
|
||||
}
|
||||
|
||||
// EXPECT returns an object that allows the caller to indicate expected use.
|
||||
func (m *MockSignature) EXPECT() *MockSignatureMockRecorder {
|
||||
func (m *Signature) EXPECT() *SignatureMockRecorder {
|
||||
return m.recorder
|
||||
}
|
||||
|
||||
// AggregateVerify mocks base method.
|
||||
func (m *MockSignature) AggregateVerify(pubKeys []common.PublicKey, msgs [][32]byte) bool {
|
||||
func (m *Signature) AggregateVerify(pubKeys []common.PublicKey, msgs [][32]byte) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "AggregateVerify", pubKeys, msgs)
|
||||
ret0, _ := ret[0].(bool)
|
||||
@@ -201,13 +201,13 @@ func (m *MockSignature) AggregateVerify(pubKeys []common.PublicKey, msgs [][32]b
|
||||
}
|
||||
|
||||
// AggregateVerify indicates an expected call of AggregateVerify.
|
||||
func (mr *MockSignatureMockRecorder) AggregateVerify(pubKeys, msgs interface{}) *gomock.Call {
|
||||
func (mr *SignatureMockRecorder) AggregateVerify(pubKeys, msgs interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AggregateVerify", reflect.TypeOf((*MockSignature)(nil).AggregateVerify), pubKeys, msgs)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "AggregateVerify", reflect.TypeOf((*Signature)(nil).AggregateVerify), pubKeys, msgs)
|
||||
}
|
||||
|
||||
// Copy mocks base method.
|
||||
func (m *MockSignature) Copy() common.Signature {
|
||||
func (m *Signature) Copy() common.Signature {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Copy")
|
||||
ret0, _ := ret[0].(common.Signature)
|
||||
@@ -215,13 +215,13 @@ func (m *MockSignature) Copy() common.Signature {
|
||||
}
|
||||
|
||||
// Copy indicates an expected call of Copy.
|
||||
func (mr *MockSignatureMockRecorder) Copy() *gomock.Call {
|
||||
func (mr *SignatureMockRecorder) Copy() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Copy", reflect.TypeOf((*MockSignature)(nil).Copy))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Copy", reflect.TypeOf((*Signature)(nil).Copy))
|
||||
}
|
||||
|
||||
// Eth2FastAggregateVerify mocks base method.
|
||||
func (m *MockSignature) Eth2FastAggregateVerify(pubKeys []common.PublicKey, msg [32]byte) bool {
|
||||
func (m *Signature) Eth2FastAggregateVerify(pubKeys []common.PublicKey, msg [32]byte) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Eth2FastAggregateVerify", pubKeys, msg)
|
||||
ret0, _ := ret[0].(bool)
|
||||
@@ -229,13 +229,13 @@ func (m *MockSignature) Eth2FastAggregateVerify(pubKeys []common.PublicKey, msg
|
||||
}
|
||||
|
||||
// Eth2FastAggregateVerify indicates an expected call of Eth2FastAggregateVerify.
|
||||
func (mr *MockSignatureMockRecorder) Eth2FastAggregateVerify(pubKeys, msg interface{}) *gomock.Call {
|
||||
func (mr *SignatureMockRecorder) Eth2FastAggregateVerify(pubKeys, msg interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eth2FastAggregateVerify", reflect.TypeOf((*MockSignature)(nil).Eth2FastAggregateVerify), pubKeys, msg)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Eth2FastAggregateVerify", reflect.TypeOf((*Signature)(nil).Eth2FastAggregateVerify), pubKeys, msg)
|
||||
}
|
||||
|
||||
// FastAggregateVerify mocks base method.
|
||||
func (m *MockSignature) FastAggregateVerify(pubKeys []common.PublicKey, msg [32]byte) bool {
|
||||
func (m *Signature) FastAggregateVerify(pubKeys []common.PublicKey, msg [32]byte) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "FastAggregateVerify", pubKeys, msg)
|
||||
ret0, _ := ret[0].(bool)
|
||||
@@ -243,13 +243,13 @@ func (m *MockSignature) FastAggregateVerify(pubKeys []common.PublicKey, msg [32]
|
||||
}
|
||||
|
||||
// FastAggregateVerify indicates an expected call of FastAggregateVerify.
|
||||
func (mr *MockSignatureMockRecorder) FastAggregateVerify(pubKeys, msg interface{}) *gomock.Call {
|
||||
func (mr *SignatureMockRecorder) FastAggregateVerify(pubKeys, msg interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FastAggregateVerify", reflect.TypeOf((*MockSignature)(nil).FastAggregateVerify), pubKeys, msg)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "FastAggregateVerify", reflect.TypeOf((*Signature)(nil).FastAggregateVerify), pubKeys, msg)
|
||||
}
|
||||
|
||||
// Marshal mocks base method.
|
||||
func (m *MockSignature) Marshal() []byte {
|
||||
func (m *Signature) Marshal() []byte {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Marshal")
|
||||
ret0, _ := ret[0].([]byte)
|
||||
@@ -257,13 +257,13 @@ func (m *MockSignature) Marshal() []byte {
|
||||
}
|
||||
|
||||
// Marshal indicates an expected call of Marshal.
|
||||
func (mr *MockSignatureMockRecorder) Marshal() *gomock.Call {
|
||||
func (mr *SignatureMockRecorder) Marshal() *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Marshal", reflect.TypeOf((*MockSignature)(nil).Marshal))
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Marshal", reflect.TypeOf((*Signature)(nil).Marshal))
|
||||
}
|
||||
|
||||
// Verify mocks base method.
|
||||
func (m *MockSignature) Verify(pubKey common.PublicKey, msg []byte) bool {
|
||||
func (m *Signature) Verify(pubKey common.PublicKey, msg []byte) bool {
|
||||
m.ctrl.T.Helper()
|
||||
ret := m.ctrl.Call(m, "Verify", pubKey, msg)
|
||||
ret0, _ := ret[0].(bool)
|
||||
@@ -271,7 +271,7 @@ func (m *MockSignature) Verify(pubKey common.PublicKey, msg []byte) bool {
|
||||
}
|
||||
|
||||
// Verify indicates an expected call of Verify.
|
||||
func (mr *MockSignatureMockRecorder) Verify(pubKey, msg interface{}) *gomock.Call {
|
||||
func (mr *SignatureMockRecorder) Verify(pubKey, msg interface{}) *gomock.Call {
|
||||
mr.mock.ctrl.T.Helper()
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Verify", reflect.TypeOf((*MockSignature)(nil).Verify), pubKey, msg)
|
||||
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Verify", reflect.TypeOf((*Signature)(nil).Verify), pubKey, msg)
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package herumi
|
||||
|
||||
import "github.com/herumi/bls-eth-go-binary/bls"
|
||||
|
||||
// HerumiInit allows the required curve orders and appropriate sub-groups to be initialized.
|
||||
func HerumiInit() {
|
||||
// Init allows the required curve orders and appropriate sub-groups to be initialized.
|
||||
func Init() {
|
||||
if err := bls.Init(bls.BLS12_381); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -79,9 +79,9 @@ var keccak256Pool = sync.Pool{New: func() interface{} {
|
||||
return sha3.NewLegacyKeccak256()
|
||||
}}
|
||||
|
||||
// HashKeccak256 defines a function which returns the Keccak-256/SHA3
|
||||
// Keccak256 defines a function which returns the Keccak-256/SHA3
|
||||
// hash of the data passed in.
|
||||
func HashKeccak256(data []byte) [32]byte {
|
||||
func Keccak256(data []byte) [32]byte {
|
||||
var b [32]byte
|
||||
|
||||
h, ok := keccak256Pool.Get().(hash.Hash)
|
||||
@@ -102,8 +102,8 @@ func HashKeccak256(data []byte) [32]byte {
|
||||
return b
|
||||
}
|
||||
|
||||
// HashProto hashes a protocol buffer message using sha256.
|
||||
func HashProto(msg proto.Message) (result [32]byte, err error) {
|
||||
// Proto hashes a protocol buffer message using sha256.
|
||||
func Proto(msg proto.Message) (result [32]byte, err error) {
|
||||
if msg == nil || reflect.ValueOf(msg).IsNil() {
|
||||
return [32]byte{}, ErrNilProto
|
||||
}
|
||||
|
||||
@@ -33,25 +33,25 @@ func BenchmarkHash(b *testing.B) {
|
||||
|
||||
func TestHashKeccak256(t *testing.T) {
|
||||
hashOf0 := [32]byte{188, 54, 120, 158, 122, 30, 40, 20, 54, 70, 66, 41, 130, 143, 129, 125, 102, 18, 247, 180, 119, 214, 101, 145, 255, 150, 169, 224, 100, 188, 201, 138}
|
||||
h := hash.HashKeccak256([]byte{0})
|
||||
h := hash.Keccak256([]byte{0})
|
||||
assert.Equal(t, hashOf0, h)
|
||||
|
||||
hashOf1 := [32]byte{95, 231, 249, 119, 231, 29, 186, 46, 161, 166, 142, 33, 5, 123, 238, 187, 155, 226, 172, 48, 198, 65, 10, 163, 141, 79, 63, 190, 65, 220, 255, 210}
|
||||
h = hash.HashKeccak256([]byte{1})
|
||||
h = hash.Keccak256([]byte{1})
|
||||
assert.Equal(t, hashOf1, h)
|
||||
assert.Equal(t, false, hashOf0 == hashOf1)
|
||||
|
||||
// Same hashing test from go-ethereum for keccak256
|
||||
hashOfabc, err := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
|
||||
require.NoError(t, err)
|
||||
h = hash.HashKeccak256([]byte("abc"))
|
||||
h = hash.Keccak256([]byte("abc"))
|
||||
h32 := bytesutil.ToBytes32(hashOfabc)
|
||||
assert.Equal(t, h32, h)
|
||||
}
|
||||
|
||||
func BenchmarkHashKeccak256(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
hash.HashKeccak256([]byte("abc"))
|
||||
hash.Keccak256([]byte("abc"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,9 +62,9 @@ func TestHashProto(t *testing.T) {
|
||||
msg2 := &pb.Puzzle{
|
||||
Challenge: "hello",
|
||||
}
|
||||
h1, err := hash.HashProto(msg1)
|
||||
h1, err := hash.Proto(msg1)
|
||||
require.NoError(t, err)
|
||||
h2, err := hash.HashProto(msg2)
|
||||
h2, err := hash.Proto(msg2)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, h1, h2)
|
||||
}
|
||||
@@ -80,7 +80,7 @@ func TestHashProtoFuzz(t *testing.T) {
|
||||
for i := 0; i < 1000; i++ {
|
||||
msg := &pb.AddressBook{}
|
||||
f.Fuzz(msg)
|
||||
_, err := hash.HashProto(msg)
|
||||
_, err := hash.Proto(msg)
|
||||
_ = err
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,7 @@ func BenchmarkHashProto(b *testing.B) {
|
||||
}
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := hash.HashProto(att); err != nil {
|
||||
if _, err := hash.Proto(att); err != nil {
|
||||
b.Log(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user