Crypto v0.43 Audit updates (#9292)
* fix tests * calculate fieldSize for esdca test * remove require declaration for consistency Co-authored-by: technicallyty <48813565+tytech3@users.noreply.github.com>
This commit is contained in:
parent
709ab089c1
commit
025d072ff1
@ -24,7 +24,7 @@ func (suite *SKSuite) TestPubKey() {
|
||||
suite.True(suite.sk.PublicKey.Equal(&pk.PublicKey))
|
||||
}
|
||||
|
||||
func (suite *SKSuite) Bytes() {
|
||||
func (suite *SKSuite) TestBytes() {
|
||||
bz := suite.sk.Bytes()
|
||||
suite.Len(bz, 32)
|
||||
var sk *PrivKey
|
||||
|
||||
@ -26,7 +26,9 @@ type PubKey struct {
|
||||
address tmcrypto.Address
|
||||
}
|
||||
|
||||
// Address creates an ADR-28 address for ECDSA keys. protoName is a concrete proto structure id.
|
||||
// Address gets the address associated with a pubkey. If no address exists, it returns a newly created ADR-28 address
|
||||
// for ECDSA keys.
|
||||
// protoName is a concrete proto structure id.
|
||||
func (pk *PubKey) Address(protoName string) tmcrypto.Address {
|
||||
if pk.address == nil {
|
||||
pk.address = address.Hash(protoName, pk.Bytes())
|
||||
|
||||
@ -48,9 +48,11 @@ func (suite *PKSuite) TestString() {
|
||||
}
|
||||
|
||||
func (suite *PKSuite) TestBytes() {
|
||||
require := suite.Require()
|
||||
bz := suite.sk.Bytes()
|
||||
fieldSize := (suite.sk.Curve.Params().BitSize + 7) / 8
|
||||
suite.Len(bz, fieldSize)
|
||||
var pk *PubKey
|
||||
require.Nil(pk.Bytes())
|
||||
suite.Nil(pk.Bytes())
|
||||
}
|
||||
|
||||
func (suite *PKSuite) TestMarshal() {
|
||||
|
||||
@ -33,6 +33,9 @@ func (m *PrivKey) Sign(msg []byte) ([]byte, error) {
|
||||
|
||||
// Bytes serialize the private key.
|
||||
func (m *PrivKey) Bytes() []byte {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.Secret.Bytes()
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ package secp256r1
|
||||
import (
|
||||
"testing"
|
||||
|
||||
proto "github.com/gogo/protobuf/proto"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"github.com/tendermint/tendermint/crypto"
|
||||
|
||||
@ -41,7 +41,7 @@ func (suite *SKSuite) TestPubKey() {
|
||||
suite.True(suite.sk.(*PrivKey).Secret.PublicKey.Equal(&pk.(*PubKey).Key.PublicKey))
|
||||
}
|
||||
|
||||
func (suite *SKSuite) Bytes() {
|
||||
func (suite *SKSuite) TestBytes() {
|
||||
bz := suite.sk.Bytes()
|
||||
suite.Len(bz, fieldSize)
|
||||
var sk *PrivKey
|
||||
|
||||
@ -15,6 +15,9 @@ func (m *PubKey) String() string {
|
||||
|
||||
// Bytes implements SDK PubKey interface.
|
||||
func (m *PubKey) Bytes() []byte {
|
||||
if m == nil {
|
||||
return nil
|
||||
}
|
||||
return m.Key.Bytes()
|
||||
}
|
||||
|
||||
|
||||
@ -44,6 +44,13 @@ func (suite *PKSuite) TestType() {
|
||||
suite.Require().Equal(name, suite.pk.Type())
|
||||
}
|
||||
|
||||
func (suite *PKSuite) TestBytes() {
|
||||
bz := suite.pk.Bytes()
|
||||
suite.Len(bz, fieldSize+1)
|
||||
var pk *PubKey
|
||||
suite.Nil(pk.Bytes())
|
||||
}
|
||||
|
||||
func (suite *PKSuite) TestEquals() {
|
||||
require := suite.Require()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user