mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-03-30 13:20:06 +08:00
remove payloadType check when unmarhaling
This commit is contained in:
parent
f24669b805
commit
9844518f63
@ -1,7 +1,6 @@
|
|||||||
package routing
|
package routing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"github.com/libp2p/go-libp2p-core/crypto"
|
"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,
|
// Fails if the signature is invalid, if the envelope has an unexpected payload type,
|
||||||
// or if deserialization of the envelope payload fails.
|
// or if deserialization of the envelope payload fails.
|
||||||
func SignedRoutingStateFromEnvelope(envelope *crypto.SignedEnvelope) (*SignedRoutingState, error) {
|
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
|
var msg pb.RoutingStateRecord
|
||||||
err := proto.Unmarshal(envelope.Payload, &msg)
|
err := proto.Unmarshal(envelope.Payload, &msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -35,15 +35,4 @@ func TestSignedRoutingStateFromEnvelope(t *testing.T) {
|
|||||||
_, err = UnmarshalSignedRoutingState(envBytes)
|
_, err = UnmarshalSignedRoutingState(envBytes)
|
||||||
test.ExpectError(t, err, "unwrapping RoutingState from envelope should fail if envelope was created with wrong domain string")
|
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