storj/pkg/auth/signing/encode.go
JT Olio ccb158c99b
pkg/auth: add monkit task to missing places (#2123)
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
2019-06-05 07:47:01 -06:00

53 lines
1.6 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package signing
import (
"context"
"github.com/gogo/protobuf/proto"
"storj.io/storj/pkg/pb"
)
// EncodeOrderLimit encodes order limit into bytes for signing. Removes signature from serialized limit.
func EncodeOrderLimit(ctx context.Context, limit *pb.OrderLimit2) (_ []byte, err error) {
defer mon.Task()(&ctx)(&err)
signature := limit.SatelliteSignature
limit.SatelliteSignature = nil
out, err := proto.Marshal(limit)
limit.SatelliteSignature = signature
return out, err
}
// EncodeOrder encodes order into bytes for signing. Removes signature from serialized order.
func EncodeOrder(ctx context.Context, order *pb.Order2) (_ []byte, err error) {
defer mon.Task()(&ctx)(&err)
signature := order.UplinkSignature
order.UplinkSignature = nil
out, err := proto.Marshal(order)
order.UplinkSignature = signature
return out, err
}
// EncodePieceHash encodes piece hash into bytes for signing. Removes signature from serialized hash.
func EncodePieceHash(ctx context.Context, hash *pb.PieceHash) (_ []byte, err error) {
defer mon.Task()(&ctx)(&err)
signature := hash.Signature
hash.Signature = nil
out, err := proto.Marshal(hash)
hash.Signature = signature
return out, err
}
// EncodeVoucher encodes voucher into bytes for signing.
func EncodeVoucher(ctx context.Context, voucher *pb.Voucher) (_ []byte, err error) {
defer mon.Task()(&ctx)(&err)
signature := voucher.SatelliteSignature
voucher.SatelliteSignature = nil
out, err := proto.Marshal(voucher)
voucher.SatelliteSignature = signature
return out, err
}