Browse Source

Add Signature.Equals

pull/1782/head
Jae Kwon 8 years ago
parent
commit
4b11d62bdb
1 changed files with 18 additions and 0 deletions
  1. +18
    -0
      signature.go

+ 18
- 0
signature.go 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
}
}

Loading…
Cancel
Save