mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-26 18:04:22 +00:00
Support nil pointers for Binary.
If the thing does not already have a typebyte declared, a fake one will be given (0x01). A TypeByte of 0x00 is reserved for nil things. No nil-dogs.
This commit is contained in:
+7
-31
@@ -2,7 +2,6 @@ package account
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/tendermint/ed25519"
|
||||
"github.com/tendermint/tendermint/binary"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
@@ -18,47 +17,17 @@ type PubKey interface {
|
||||
|
||||
// Types of PubKey implementations
|
||||
const (
|
||||
PubKeyTypeNil = byte(0x00)
|
||||
PubKeyTypeEd25519 = byte(0x01)
|
||||
)
|
||||
|
||||
// for binary.readReflect
|
||||
var _ = binary.RegisterInterface(
|
||||
struct{ PubKey }{},
|
||||
binary.ConcreteType{PubKeyNil{}},
|
||||
binary.ConcreteType{PubKeyEd25519{}},
|
||||
)
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
// Implements PubKey
|
||||
type PubKeyNil struct{}
|
||||
|
||||
func (key PubKeyNil) TypeByte() byte { return PubKeyTypeNil }
|
||||
|
||||
func (key PubKeyNil) IsNil() bool { return true }
|
||||
|
||||
func (key PubKeyNil) Address() []byte {
|
||||
panic("PubKeyNil has no address")
|
||||
}
|
||||
|
||||
func (key PubKeyNil) VerifyBytes(msg []byte, sig_ Signature) bool {
|
||||
panic("PubKeyNil cannot verify messages")
|
||||
}
|
||||
|
||||
func (key PubKeyEd25519) ValidateBasic() error {
|
||||
if len(key) != ed25519.PublicKeySize {
|
||||
return errors.New("Invalid PubKeyEd25519 key size")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (key PubKeyNil) String() string {
|
||||
return "PubKeyNil{}"
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
// Implements PubKey
|
||||
type PubKeyEd25519 []byte
|
||||
|
||||
@@ -81,6 +50,13 @@ func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool {
|
||||
return ed25519.Verify(pubKeyBytes, msg, sigBytes)
|
||||
}
|
||||
|
||||
func (pubKey PubKeyEd25519) ValidateBasic() error {
|
||||
if len(pubKey) != ed25519.PublicKeySize {
|
||||
return errors.New("Invalid PubKeyEd25519 key size")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pubKey PubKeyEd25519) String() string {
|
||||
return Fmt("PubKeyEd25519{%X}", []byte(pubKey))
|
||||
}
|
||||
|
||||
@@ -14,30 +14,17 @@ type Signature interface {
|
||||
|
||||
// Types of Signature implementations
|
||||
const (
|
||||
SignatureTypeNil = byte(0x00)
|
||||
SignatureTypeEd25519 = byte(0x01)
|
||||
)
|
||||
|
||||
// for binary.readReflect
|
||||
var _ = binary.RegisterInterface(
|
||||
struct{ Signature }{},
|
||||
binary.ConcreteType{SignatureNil{}},
|
||||
binary.ConcreteType{SignatureEd25519{}},
|
||||
)
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
// Implements Signature
|
||||
type SignatureNil struct{}
|
||||
|
||||
func (sig SignatureNil) TypeByte() byte { return SignatureTypeNil }
|
||||
|
||||
func (sig SignatureNil) IsNil() bool { return true }
|
||||
|
||||
func (sig SignatureNil) String() string { return "SignatureNil{}" }
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
// Implements Signature
|
||||
type SignatureEd25519 []byte
|
||||
|
||||
|
||||
Reference in New Issue
Block a user