mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-01-15 02:30:05 +08:00
remove payloadType check when unmarhaling
This commit is contained in:
parent
f24669b805
commit
9844518f63
@ -1,7 +1,6 @@
|
||||
package routing
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/libp2p/go-libp2p-core/crypto"
|
||||
@ -84,9 +83,6 @@ func UnmarshalSignedRoutingState(envelopeBytes []byte) (*SignedRoutingState, err
|
||||
// Fails if the signature is invalid, if the envelope has an unexpected payload type,
|
||||
// or if deserialization of the envelope payload fails.
|
||||
func SignedRoutingStateFromEnvelope(envelope *crypto.SignedEnvelope) (*SignedRoutingState, error) {
|
||||
if bytes.Compare(envelope.PayloadType, StateEnvelopePayloadType) != 0 {
|
||||
return nil, errors.New("unexpected envelope payload type")
|
||||
}
|
||||
var msg pb.RoutingStateRecord
|
||||
err := proto.Unmarshal(envelope.Payload, &msg)
|
||||
if err != nil {
|
||||
|
@ -35,15 +35,4 @@ func TestSignedRoutingStateFromEnvelope(t *testing.T) {
|
||||
_, err = UnmarshalSignedRoutingState(envBytes)
|
||||
test.ExpectError(t, err, "unwrapping RoutingState from envelope should fail if envelope was created with wrong domain string")
|
||||
})
|
||||
|
||||
t.Run("unwrapping from signed envelope fails if envelope has wrong payload type", func(t *testing.T) {
|
||||
stateBytes, err := state.Marshal()
|
||||
test.AssertNilError(t, err)
|
||||
payloadType := []byte("wrong-payload-type")
|
||||
env, err := crypto.MakeEnvelope(priv, StateEnvelopeDomain, payloadType, stateBytes)
|
||||
test.AssertNilError(t, err)
|
||||
envBytes, err := env.Marshal()
|
||||
_, err = UnmarshalSignedRoutingState(envBytes)
|
||||
test.ExpectError(t, err, "unwrapping RoutingState from envelope should fail if envelope was created with wrong payload type")
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user