ccb158c99b
What: add monkit.Task to a bunch of functions that are missing it Why: this will significantly help our instrumentation, data collection, and tracing about what's going on in the network
51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package signing
|
|
|
|
import (
|
|
"context"
|
|
|
|
"storj.io/storj/pkg/pb"
|
|
"storj.io/storj/pkg/storj"
|
|
)
|
|
|
|
// Signee is able to verify that the data signature belongs to the signee.
|
|
type Signee interface {
|
|
ID() storj.NodeID
|
|
HashAndVerifySignature(ctx context.Context, data, signature []byte) error
|
|
}
|
|
|
|
// VerifyOrderLimitSignature verifies that the signature inside order limit belongs to the satellite.
|
|
func VerifyOrderLimitSignature(ctx context.Context, satellite Signee, signed *pb.OrderLimit2) (err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
bytes, err := EncodeOrderLimit(ctx, signed)
|
|
if err != nil {
|
|
return Error.Wrap(err)
|
|
}
|
|
|
|
return satellite.HashAndVerifySignature(ctx, bytes, signed.SatelliteSignature)
|
|
}
|
|
|
|
// VerifyOrderSignature verifies that the signature inside order belongs to the uplink.
|
|
func VerifyOrderSignature(ctx context.Context, uplink Signee, signed *pb.Order2) (err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
bytes, err := EncodeOrder(ctx, signed)
|
|
if err != nil {
|
|
return Error.Wrap(err)
|
|
}
|
|
|
|
return uplink.HashAndVerifySignature(ctx, bytes, signed.UplinkSignature)
|
|
}
|
|
|
|
// VerifyPieceHashSignature verifies that the signature inside piece hash belongs to the signer, which is either uplink or storage node.
|
|
func VerifyPieceHashSignature(ctx context.Context, signee Signee, signed *pb.PieceHash) (err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
bytes, err := EncodePieceHash(ctx, signed)
|
|
if err != nil {
|
|
return Error.Wrap(err)
|
|
}
|
|
|
|
return signee.HashAndVerifySignature(ctx, bytes, signed.Signature)
|
|
}
|