rename Equals -> Equal, add some comments

This commit is contained in:
Yusef Napora 2019-11-19 09:19:17 -06:00
parent 295e3eca01
commit 08da615203
3 changed files with 7 additions and 3 deletions

View File

@ -109,6 +109,7 @@ func (e *SignedEnvelope) Payload() []byte {
return e.payload
}
// Marshal returns a byte slice containing a serailized protobuf representation of a SignedEnvelope.
func (e *SignedEnvelope) Marshal() ([]byte, error) {
key, err := PublicKeyToProto(e.publicKey)
if err != nil {
@ -123,7 +124,10 @@ func (e *SignedEnvelope) Marshal() ([]byte, error) {
return proto.Marshal(&msg)
}
func (e *SignedEnvelope) Equals(other *SignedEnvelope) bool {
// Equal returns true if the other SignedEnvelope has the same
// public key, payload, payload type, and signature. This
// implies that they were also created with the same domain string.
func (e *SignedEnvelope) Equal(other *SignedEnvelope) bool {
return e.publicKey.Equals(other.publicKey) &&
bytes.Compare(e.payloadType, other.payloadType) == 0 &&
bytes.Compare(e.payload, other.payload) == 0 &&

View File

@ -45,7 +45,7 @@ func TestEnvelopeHappyPath(t *testing.T) {
t.Error("payload of envelope does not match input")
}
if !envelope.Equals(deserialized) {
if !envelope.Equal(deserialized) {
t.Error("round-trip serde results in unequal envelope structures")
}
}

View File

@ -98,7 +98,7 @@ type AddrBook interface {
// AddCertifiedAddrs adds addresses from a routing.RoutingState record
// contained in a serialized SignedEnvelope.
AddCertifiedAddrs(envelopeBytes []byte, ttl time.Duration) error
AddCertifiedAddrs(envelope []byte, ttl time.Duration) error
// SetAddr calls mgr.SetAddrs(p, addr, ttl)
SetAddr(p peer.ID, addr ma.Multiaddr, ttl time.Duration)