2019-03-18 10:55:06 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package signing
|
|
|
|
|
|
|
|
import (
|
2019-06-05 14:47:01 +01:00
|
|
|
"context"
|
|
|
|
|
2019-03-18 10:55:06 +00:00
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
|
|
|
|
"storj.io/storj/pkg/pb"
|
|
|
|
)
|
|
|
|
|
2019-05-30 20:01:55 +01:00
|
|
|
// EncodeOrderLimit encodes order limit into bytes for signing. Removes signature from serialized limit.
|
2019-07-01 16:54:11 +01:00
|
|
|
func EncodeOrderLimit(ctx context.Context, limit *pb.OrderLimit) (_ []byte, err error) {
|
2019-06-05 14:47:01 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-03-18 10:55:06 +00:00
|
|
|
signature := limit.SatelliteSignature
|
|
|
|
limit.SatelliteSignature = nil
|
2019-05-30 20:01:55 +01:00
|
|
|
out, err := proto.Marshal(limit)
|
|
|
|
limit.SatelliteSignature = signature
|
|
|
|
return out, err
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 20:01:55 +01:00
|
|
|
// EncodeOrder encodes order into bytes for signing. Removes signature from serialized order.
|
2019-07-01 16:54:11 +01:00
|
|
|
func EncodeOrder(ctx context.Context, order *pb.Order) (_ []byte, err error) {
|
2019-06-05 14:47:01 +01:00
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-03-18 10:55:06 +00:00
|
|
|
signature := order.UplinkSignature
|
|
|
|
order.UplinkSignature = nil
|
2019-05-30 20:01:55 +01:00
|
|
|
out, err := proto.Marshal(order)
|
|
|
|
order.UplinkSignature = signature
|
|
|
|
return out, err
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
|
|
|
|
2019-05-30 20:01:55 +01:00
|
|
|
// EncodePieceHash encodes piece hash into bytes for signing. Removes signature from serialized hash.
|
2019-06-05 14:47:01 +01:00
|
|
|
func EncodePieceHash(ctx context.Context, hash *pb.PieceHash) (_ []byte, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-03-18 10:55:06 +00:00
|
|
|
signature := hash.Signature
|
|
|
|
hash.Signature = nil
|
2019-05-30 20:01:55 +01:00
|
|
|
out, err := proto.Marshal(hash)
|
|
|
|
hash.Signature = signature
|
|
|
|
return out, err
|
2019-03-18 10:55:06 +00:00
|
|
|
}
|
2019-05-30 20:52:33 +01:00
|
|
|
|
|
|
|
// EncodeVoucher encodes voucher into bytes for signing.
|
2019-06-05 14:47:01 +01:00
|
|
|
func EncodeVoucher(ctx context.Context, voucher *pb.Voucher) (_ []byte, err error) {
|
|
|
|
defer mon.Task()(&ctx)(&err)
|
2019-05-30 20:52:33 +01:00
|
|
|
signature := voucher.SatelliteSignature
|
|
|
|
voucher.SatelliteSignature = nil
|
|
|
|
out, err := proto.Marshal(voucher)
|
|
|
|
voucher.SatelliteSignature = signature
|
|
|
|
return out, err
|
|
|
|
}
|