Add Signature.Equals

This commit is contained in:
Jae Kwon 2016-07-24 13:21:57 -07:00
parent 41cfb7b677
commit 4b11d62bdb
1 changed files with 18 additions and 0 deletions

View File

@ -1,6 +1,7 @@
package crypto
import (
"bytes"
"fmt"
. "github.com/tendermint/go-common"
@ -12,6 +13,7 @@ type Signature interface {
Bytes() []byte
IsZero() bool
String() string
Equals(Signature) bool
}
// Types of Signature implementations
@ -45,6 +47,14 @@ func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
func (sig SignatureEd25519) Equals(other Signature) bool {
if otherEd, ok := other.(SignatureEd25519); ok {
return bytes.Equal(sig[:], otherEd[:])
} else {
return false
}
}
//-------------------------------------
// Implements Signature
@ -57,3 +67,11 @@ func (sig SignatureSecp256k1) Bytes() []byte {
func (sig SignatureSecp256k1) IsZero() bool { return len(sig) == 0 }
func (sig SignatureSecp256k1) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
func (sig SignatureSecp256k1) Equals(other Signature) bool {
if otherEd, ok := other.(SignatureSecp256k1); ok {
return bytes.Equal(sig[:], otherEd[:])
} else {
return false
}
}