2019-03-18 10:55:06 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package signing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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-03-18 10:55:06 +00:00
|
|
|
func EncodeOrderLimit(limit *pb.OrderLimit2) ([]byte, error) {
|
|
|
|
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-03-18 10:55:06 +00:00
|
|
|
func EncodeOrder(order *pb.Order2) ([]byte, error) {
|
|
|
|
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-03-18 10:55:06 +00:00
|
|
|
func EncodePieceHash(hash *pb.PieceHash) ([]byte, error) {
|
|
|
|
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.
|
|
|
|
func EncodeVoucher(voucher *pb.Voucher) ([]byte, error) {
|
|
|
|
signature := voucher.SatelliteSignature
|
|
|
|
voucher.SatelliteSignature = nil
|
|
|
|
out, err := proto.Marshal(voucher)
|
|
|
|
voucher.SatelliteSignature = signature
|
|
|
|
return out, err
|
|
|
|
}
|