Move version and signature structures to refs package

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-08-20 12:43:47 +03:00 committed by Stanislav Bogatyrev
parent f1addc4cc5
commit db12420c99
16 changed files with 363 additions and 86 deletions

View file

@ -43,7 +43,7 @@ func ContainerToGRPCMessage(c *Container) *container.Container {
m := new(container.Container) m := new(container.Container)
m.SetVersion( m.SetVersion(
service.VersionToGRPCMessage(c.GetVersion()), refs.VersionToGRPCMessage(c.GetVersion()),
) )
m.SetOwnerId( m.SetOwnerId(
@ -78,7 +78,7 @@ func ContainerFromGRPCMessage(m *container.Container) *Container {
c := new(Container) c := new(Container)
c.SetVersion( c.SetVersion(
service.VersionFromGRPCMessage(m.GetVersion()), refs.VersionFromGRPCMessage(m.GetVersion()),
) )
c.SetOwnerID( c.SetOwnerID(
@ -117,7 +117,7 @@ func PutRequestBodyToGRPCMessage(r *PutRequestBody) *container.PutRequest_Body {
) )
m.SetSignature( m.SetSignature(
service.SignatureToGRPCMessage(r.GetSignature()), refs.SignatureToGRPCMessage(r.GetSignature()),
) )
return m return m
@ -135,7 +135,7 @@ func PutRequestBodyFromGRPCMessage(m *container.PutRequest_Body) *PutRequestBody
) )
r.SetSignature( r.SetSignature(
service.SignatureFromGRPCMessage(m.GetSignature()), refs.SignatureFromGRPCMessage(m.GetSignature()),
) )
return r return r
@ -365,7 +365,7 @@ func DeleteRequestBodyToGRPCMessage(r *DeleteRequestBody) *container.DeleteReque
) )
m.SetSignature( m.SetSignature(
service.SignatureToGRPCMessage(r.GetSignature()), refs.SignatureToGRPCMessage(r.GetSignature()),
) )
return m return m
@ -383,7 +383,7 @@ func DeleteRequestBodyFromGRPCMessage(m *container.DeleteRequest_Body) *DeleteRe
) )
r.SetSignature( r.SetSignature(
service.SignatureFromGRPCMessage(m.GetSignature()), refs.SignatureFromGRPCMessage(m.GetSignature()),
) )
return r return r
@ -615,7 +615,7 @@ func SetExtendedACLRequestBodyToGRPCMessage(r *SetExtendedACLRequestBody) *conta
) )
m.SetSignature( m.SetSignature(
service.SignatureToGRPCMessage(r.GetSignature())) refs.SignatureToGRPCMessage(r.GetSignature()))
return m return m
} }
@ -632,7 +632,7 @@ func SetExtendedACLRequestBodyFromGRPCMessage(m *container.SetExtendedACLRequest
) )
r.SetSignature( r.SetSignature(
service.SignatureFromGRPCMessage(m.GetSignature()), refs.SignatureFromGRPCMessage(m.GetSignature()),
) )
return r return r
@ -794,7 +794,7 @@ func GetExtendedACLResponseBodyToGRPCMessage(r *GetExtendedACLResponseBody) *con
) )
m.SetSignature( m.SetSignature(
service.SignatureToGRPCMessage(r.GetSignature()), refs.SignatureToGRPCMessage(r.GetSignature()),
) )
return m return m
@ -812,7 +812,7 @@ func GetExtendedACLResponseBodyFromGRPCMessage(m *container.GetExtendedACLRespon
) )
r.SetSignature( r.SetSignature(
service.SignatureFromGRPCMessage(m.GetSignature()), refs.SignatureFromGRPCMessage(m.GetSignature()),
) )
return r return r

View file

@ -14,7 +14,7 @@ func (m *PutRequest_Body) SetContainer(v *Container) {
} }
// SetSignature sets signature of the container structure. // SetSignature sets signature of the container structure.
func (m *PutRequest_Body) SetSignature(v *service.Signature) { func (m *PutRequest_Body) SetSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.Signature = v m.Signature = v
} }
@ -77,7 +77,7 @@ func (m *DeleteRequest_Body) SetContainerId(v *refs.ContainerID) {
} }
// SetSignature sets signature of the container identifier. // SetSignature sets signature of the container identifier.
func (m *DeleteRequest_Body) SetSignature(v *service.Signature) { func (m *DeleteRequest_Body) SetSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.Signature = v m.Signature = v
} }
@ -243,7 +243,7 @@ func (m *SetExtendedACLRequest_Body) SetEacl(v *acl.EACLTable) {
} }
// SetSignature sets signature of the eACL table. // SetSignature sets signature of the eACL table.
func (m *SetExtendedACLRequest_Body) SetSignature(v *service.Signature) { func (m *SetExtendedACLRequest_Body) SetSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.Signature = v m.Signature = v
} }
@ -327,7 +327,7 @@ func (m *GetExtendedACLResponse_Body) SetEacl(v *acl.EACLTable) {
} }
// SetSignature sets signature of the eACL table. // SetSignature sets signature of the eACL table.
func (m *GetExtendedACLResponse_Body) SetSignature(v *service.Signature) { func (m *GetExtendedACLResponse_Body) SetSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.Signature = v m.Signature = v
} }

View file

@ -3,7 +3,6 @@ package container
import ( import (
netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc" netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/grpc"
refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc"
service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc"
) )
// SetKey sets key to the container attribute. // SetKey sets key to the container attribute.
@ -56,7 +55,7 @@ func (m *Container) SetPlacementPolicy(v *netmap.PlacementPolicy) {
} }
// SetVersion sets version of the container. // SetVersion sets version of the container.
func (m *Container) SetVersion(v *service.Version) { func (m *Container) SetVersion(v *refs.Version) {
if m != nil { if m != nil {
m.Version = v m.Version = v
} }

View file

@ -8,7 +8,6 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/container" "github.com/nspcc-dev/neofs-api-go/v2/container"
grpc "github.com/nspcc-dev/neofs-api-go/v2/container/grpc" grpc "github.com/nspcc-dev/neofs-api-go/v2/container/grpc"
"github.com/nspcc-dev/neofs-api-go/v2/refs" "github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/service"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -248,7 +247,7 @@ func generateContainer(n string) *container.Container {
owner := new(refs.OwnerID) owner := new(refs.OwnerID)
owner.SetValue([]byte("Owner ID")) owner.SetValue([]byte("Owner ID"))
version := new(service.Version) version := new(refs.Version)
version.SetMajor(2) version.SetMajor(2)
version.SetMinor(0) version.SetMinor(0)
@ -267,8 +266,8 @@ func generateContainer(n string) *container.Container {
return cnr return cnr
} }
func generateSignature(k, v string) *service.Signature { func generateSignature(k, v string) *refs.Signature {
sig := new(service.Signature) sig := new(refs.Signature)
sig.SetKey([]byte(k)) sig.SetKey([]byte(k))
sig.SetSign([]byte(v)) sig.SetSign([]byte(v))

View file

@ -12,7 +12,7 @@ type Attribute struct {
} }
type Container struct { type Container struct {
version *service.Version version *refs.Version
ownerID *refs.OwnerID ownerID *refs.OwnerID
@ -28,7 +28,7 @@ type Container struct {
type PutRequestBody struct { type PutRequestBody struct {
cnr *Container cnr *Container
sig *service.Signature sig *refs.Signature
} }
type PutRequest struct { type PutRequest struct {
@ -78,7 +78,7 @@ type GetResponse struct {
type DeleteRequestBody struct { type DeleteRequestBody struct {
cid *refs.ContainerID cid *refs.ContainerID
sig *service.Signature sig *refs.Signature
} }
type DeleteRequest struct { type DeleteRequest struct {
@ -126,7 +126,7 @@ type ListResponse struct {
type SetExtendedACLRequestBody struct { type SetExtendedACLRequestBody struct {
eacl *acl.Table eacl *acl.Table
sig *service.Signature sig *refs.Signature
} }
type SetExtendedACLRequest struct { type SetExtendedACLRequest struct {
@ -162,7 +162,7 @@ type GetExtendedACLRequest struct {
type GetExtendedACLResponseBody struct { type GetExtendedACLResponseBody struct {
eacl *acl.Table eacl *acl.Table
sig *service.Signature sig *refs.Signature
} }
type GetExtendedACLResponse struct { type GetExtendedACLResponse struct {
@ -201,7 +201,7 @@ func (a *Attribute) SetValue(v string) {
} }
} }
func (c *Container) GetVersion() *service.Version { func (c *Container) GetVersion() *refs.Version {
if c != nil { if c != nil {
return c.version return c.version
} }
@ -209,7 +209,7 @@ func (c *Container) GetVersion() *service.Version {
return nil return nil
} }
func (c *Container) SetVersion(v *service.Version) { func (c *Container) SetVersion(v *refs.Version) {
if c != nil { if c != nil {
c.version = v c.version = v
} }
@ -299,7 +299,7 @@ func (r *PutRequestBody) SetContainer(v *Container) {
} }
} }
func (r *PutRequestBody) GetSignature() *service.Signature { func (r *PutRequestBody) GetSignature() *refs.Signature {
if r != nil { if r != nil {
return r.sig return r.sig
} }
@ -307,7 +307,7 @@ func (r *PutRequestBody) GetSignature() *service.Signature {
return nil return nil
} }
func (r *PutRequestBody) SetSignature(v *service.Signature) { func (r *PutRequestBody) SetSignature(v *refs.Signature) {
if r != nil { if r != nil {
r.sig = v r.sig = v
} }
@ -537,7 +537,7 @@ func (r *DeleteRequestBody) SetContainerID(v *refs.ContainerID) {
} }
} }
func (r *DeleteRequestBody) GetSignature() *service.Signature { func (r *DeleteRequestBody) GetSignature() *refs.Signature {
if r != nil { if r != nil {
return r.sig return r.sig
} }
@ -545,7 +545,7 @@ func (r *DeleteRequestBody) GetSignature() *service.Signature {
return nil return nil
} }
func (r *DeleteRequestBody) SetSignature(v *service.Signature) { func (r *DeleteRequestBody) SetSignature(v *refs.Signature) {
if r != nil { if r != nil {
r.sig = v r.sig = v
} }
@ -761,7 +761,7 @@ func (r *SetExtendedACLRequestBody) SetEACL(v *acl.Table) {
} }
} }
func (r *SetExtendedACLRequestBody) GetSignature() *service.Signature { func (r *SetExtendedACLRequestBody) GetSignature() *refs.Signature {
if r != nil { if r != nil {
return r.sig return r.sig
} }
@ -769,7 +769,7 @@ func (r *SetExtendedACLRequestBody) GetSignature() *service.Signature {
return nil return nil
} }
func (r *SetExtendedACLRequestBody) SetSignature(v *service.Signature) { func (r *SetExtendedACLRequestBody) SetSignature(v *refs.Signature) {
if r != nil { if r != nil {
r.sig = v r.sig = v
} }
@ -929,7 +929,7 @@ func (r *GetExtendedACLResponseBody) SetEACL(v *acl.Table) {
} }
} }
func (r *GetExtendedACLResponseBody) GetSignature() *service.Signature { func (r *GetExtendedACLResponseBody) GetSignature() *refs.Signature {
if r != nil { if r != nil {
return r.sig return r.sig
} }
@ -937,7 +937,7 @@ func (r *GetExtendedACLResponseBody) GetSignature() *service.Signature {
return nil return nil
} }
func (r *GetExtendedACLResponseBody) SetSignature(v *service.Signature) { func (r *GetExtendedACLResponseBody) SetSignature(v *refs.Signature) {
if r != nil { if r != nil {
r.sig = v r.sig = v
} }

View file

@ -33,7 +33,7 @@ func ShortHeaderToGRPCMessage(h *ShortHeader) *object.ShortHeader {
m := new(object.ShortHeader) m := new(object.ShortHeader)
m.SetVersion( m.SetVersion(
service.VersionToGRPCMessage(h.GetVersion()), refs.VersionToGRPCMessage(h.GetVersion()),
) )
m.SetCreationEpoch(h.GetCreationEpoch()) m.SetCreationEpoch(h.GetCreationEpoch())
@ -59,7 +59,7 @@ func ShortHeaderFromGRPCMessage(m *object.ShortHeader) *ShortHeader {
h := new(ShortHeader) h := new(ShortHeader)
h.SetVersion( h.SetVersion(
service.VersionFromGRPCMessage(m.GetVersion()), refs.VersionFromGRPCMessage(m.GetVersion()),
) )
h.SetCreationEpoch(m.GetCreationEpoch()) h.SetCreationEpoch(m.GetCreationEpoch())
@ -119,7 +119,7 @@ func SplitHeaderToGRPCMessage(h *SplitHeader) *object.Header_Split {
) )
m.SetParentSignature( m.SetParentSignature(
service.SignatureToGRPCMessage(h.GetParentSignature()), refs.SignatureToGRPCMessage(h.GetParentSignature()),
) )
m.SetParentHeader( m.SetParentHeader(
@ -154,7 +154,7 @@ func SplitHeaderFromGRPCMessage(m *object.Header_Split) *SplitHeader {
) )
h.SetParentSignature( h.SetParentSignature(
service.SignatureFromGRPCMessage(m.GetParentSignature()), refs.SignatureFromGRPCMessage(m.GetParentSignature()),
) )
h.SetParentHeader( h.SetParentHeader(
@ -181,7 +181,7 @@ func HeaderToGRPCMessage(h *Header) *object.Header {
m := new(object.Header) m := new(object.Header)
m.SetVersion( m.SetVersion(
service.VersionToGRPCMessage(h.GetVersion()), refs.VersionToGRPCMessage(h.GetVersion()),
) )
m.SetContainerId( m.SetContainerId(
@ -236,7 +236,7 @@ func HeaderFromGRPCMessage(m *object.Header) *Header {
h := new(Header) h := new(Header)
h.SetVersion( h.SetVersion(
service.VersionFromGRPCMessage(m.GetVersion()), refs.VersionFromGRPCMessage(m.GetVersion()),
) )
h.SetContainerID( h.SetContainerID(
@ -295,7 +295,7 @@ func ObjectToGRPCMessage(o *Object) *object.Object {
) )
m.SetSignature( m.SetSignature(
service.SignatureToGRPCMessage(o.GetSignature()), refs.SignatureToGRPCMessage(o.GetSignature()),
) )
m.SetHeader( m.SetHeader(
@ -319,7 +319,7 @@ func ObjectFromGRPCMessage(m *object.Object) *Object {
) )
o.SetSignature( o.SetSignature(
service.SignatureFromGRPCMessage(m.GetSignature()), refs.SignatureFromGRPCMessage(m.GetSignature()),
) )
o.SetHeader( o.SetHeader(
@ -407,7 +407,7 @@ func GetObjectPartInitToGRPCMessage(r *GetObjectPartInit) *object.GetResponse_Bo
) )
m.SetSignature( m.SetSignature(
service.SignatureToGRPCMessage(r.GetSignature()), refs.SignatureToGRPCMessage(r.GetSignature()),
) )
m.SetHeader( m.SetHeader(
@ -429,7 +429,7 @@ func GetObjectPartInitFromGRPCMessage(m *object.GetResponse_Body_Init) *GetObjec
) )
r.SetSignature( r.SetSignature(
service.SignatureFromGRPCMessage(m.GetSignature()), refs.SignatureFromGRPCMessage(m.GetSignature()),
) )
r.SetHeader( r.SetHeader(
@ -555,7 +555,7 @@ func PutObjectPartInitToGRPCMessage(r *PutObjectPartInit) *object.PutRequest_Bod
) )
m.SetSignature( m.SetSignature(
service.SignatureToGRPCMessage(r.GetSignature()), refs.SignatureToGRPCMessage(r.GetSignature()),
) )
m.SetHeader( m.SetHeader(
@ -579,7 +579,7 @@ func PutObjectPartInitFromGRPCMessage(m *object.PutRequest_Body_Init) *PutObject
) )
r.SetSignature( r.SetSignature(
service.SignatureFromGRPCMessage(m.GetSignature()), refs.SignatureFromGRPCMessage(m.GetSignature()),
) )
r.SetHeader( r.SetHeader(

View file

@ -48,7 +48,7 @@ func (m *GetResponse_Body_Init) SetObjectId(v *refs.ObjectID) {
} }
// SetSignature sets signature of the object identifier. // SetSignature sets signature of the object identifier.
func (m *GetResponse_Body_Init) SetSignature(v *service.Signature) { func (m *GetResponse_Body_Init) SetSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.Signature = v m.Signature = v
} }
@ -122,7 +122,7 @@ func (m *PutRequest_Body_Init) SetObjectId(v *refs.ObjectID) {
} }
// SetSignature sets signature of the object identifier. // SetSignature sets signature of the object identifier.
func (m *PutRequest_Body_Init) SetSignature(v *service.Signature) { func (m *PutRequest_Body_Init) SetSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.Signature = v m.Signature = v
} }

View file

@ -34,7 +34,7 @@ func (m *Header_Split) SetPrevious(v *refs.ObjectID) {
} }
// SetParentSignature sets signature of the parent object header. // SetParentSignature sets signature of the parent object header.
func (m *Header_Split) SetParentSignature(v *service.Signature) { func (m *Header_Split) SetParentSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.ParentSignature = v m.ParentSignature = v
} }
@ -76,7 +76,7 @@ func (m *Header) SetCreationEpoch(v uint64) {
} }
// SetVersion sets version of the object format. // SetVersion sets version of the object format.
func (m *Header) SetVersion(v *service.Version) { func (m *Header) SetVersion(v *refs.Version) {
if m != nil { if m != nil {
m.Version = v m.Version = v
} }
@ -139,7 +139,7 @@ func (m *Object) SetObjectId(v *refs.ObjectID) {
} }
// SetSignature sets signature of the object identifier. // SetSignature sets signature of the object identifier.
func (m *Object) SetSignature(v *service.Signature) { func (m *Object) SetSignature(v *refs.Signature) {
if m != nil { if m != nil {
m.Signature = v m.Signature = v
} }
@ -160,7 +160,7 @@ func (m *Object) SetPayload(v []byte) {
} }
// SetVersion sets version of the object. // SetVersion sets version of the object.
func (m *ShortHeader) SetVersion(v *service.Version) { func (m *ShortHeader) SetVersion(v *refs.Version) {
if m != nil { if m != nil {
m.Version = v m.Version = v
} }

View file

@ -381,16 +381,16 @@ func generateContainerID(id string) *refs.ContainerID {
return cid return cid
} }
func generateSignature(k, v string) *service.Signature { func generateSignature(k, v string) *refs.Signature {
sig := new(service.Signature) sig := new(refs.Signature)
sig.SetKey([]byte(k)) sig.SetKey([]byte(k))
sig.SetSign([]byte(v)) sig.SetSign([]byte(v))
return sig return sig
} }
func generateVersion(maj, min uint32) *service.Version { func generateVersion(maj, min uint32) *refs.Version {
version := new(service.Version) version := new(refs.Version)
version.SetMajor(maj) version.SetMajor(maj)
version.SetMinor(min) version.SetMinor(min)

View file

@ -10,7 +10,7 @@ type Type uint32
type MatchType uint32 type MatchType uint32
type ShortHeader struct { type ShortHeader struct {
version *service.Version version *refs.Version
creatEpoch uint64 creatEpoch uint64
@ -28,7 +28,7 @@ type Attribute struct {
type SplitHeader struct { type SplitHeader struct {
par, prev *refs.ObjectID par, prev *refs.ObjectID
parSig *service.Signature parSig *refs.Signature
parHdr *Header parHdr *Header
@ -36,7 +36,7 @@ type SplitHeader struct {
} }
type Header struct { type Header struct {
version *service.Version version *refs.Version
cid *refs.ContainerID cid *refs.ContainerID
@ -60,7 +60,7 @@ type Header struct {
type Object struct { type Object struct {
objectID *refs.ObjectID objectID *refs.ObjectID
idSig *service.Signature idSig *refs.Signature
header *Header header *Header
@ -88,7 +88,7 @@ type GetObjectPart interface {
type GetObjectPartInit struct { type GetObjectPartInit struct {
id *refs.ObjectID id *refs.ObjectID
sig *service.Signature sig *refs.Signature
hdr *Header hdr *Header
} }
@ -116,7 +116,7 @@ type PutObjectPart interface {
type PutObjectPartInit struct { type PutObjectPartInit struct {
id *refs.ObjectID id *refs.ObjectID
sig *service.Signature sig *refs.Signature
hdr *Header hdr *Header
@ -318,7 +318,7 @@ const (
MatchStringEqual MatchStringEqual
) )
func (h *ShortHeader) GetVersion() *service.Version { func (h *ShortHeader) GetVersion() *refs.Version {
if h != nil { if h != nil {
return h.version return h.version
} }
@ -326,7 +326,7 @@ func (h *ShortHeader) GetVersion() *service.Version {
return nil return nil
} }
func (h *ShortHeader) SetVersion(v *service.Version) { func (h *ShortHeader) SetVersion(v *refs.Version) {
if h != nil { if h != nil {
h.version = v h.version = v
} }
@ -444,7 +444,7 @@ func (h *SplitHeader) SetPrevious(v *refs.ObjectID) {
} }
} }
func (h *SplitHeader) GetParentSignature() *service.Signature { func (h *SplitHeader) GetParentSignature() *refs.Signature {
if h != nil { if h != nil {
return h.parSig return h.parSig
} }
@ -452,7 +452,7 @@ func (h *SplitHeader) GetParentSignature() *service.Signature {
return nil return nil
} }
func (h *SplitHeader) SetParentSignature(v *service.Signature) { func (h *SplitHeader) SetParentSignature(v *refs.Signature) {
if h != nil { if h != nil {
h.parSig = v h.parSig = v
} }
@ -486,7 +486,7 @@ func (h *SplitHeader) SetChildren(v []*refs.ObjectID) {
} }
} }
func (h *Header) GetVersion() *service.Version { func (h *Header) GetVersion() *refs.Version {
if h != nil { if h != nil {
return h.version return h.version
} }
@ -494,7 +494,7 @@ func (h *Header) GetVersion() *service.Version {
return nil return nil
} }
func (h *Header) SetVersion(v *service.Version) { func (h *Header) SetVersion(v *refs.Version) {
if h != nil { if h != nil {
h.version = v h.version = v
} }
@ -654,7 +654,7 @@ func (o *Object) SetObjectID(v *refs.ObjectID) {
} }
} }
func (o *Object) GetSignature() *service.Signature { func (o *Object) GetSignature() *refs.Signature {
if o != nil { if o != nil {
return o.idSig return o.idSig
} }
@ -662,7 +662,7 @@ func (o *Object) GetSignature() *service.Signature {
return nil return nil
} }
func (o *Object) SetSignature(v *service.Signature) { func (o *Object) SetSignature(v *refs.Signature) {
if o != nil { if o != nil {
o.idSig = v o.idSig = v
} }
@ -780,7 +780,7 @@ func (r *GetObjectPartInit) SetObjectID(v *refs.ObjectID) {
} }
} }
func (r *GetObjectPartInit) GetSignature() *service.Signature { func (r *GetObjectPartInit) GetSignature() *refs.Signature {
if r != nil { if r != nil {
return r.sig return r.sig
} }
@ -788,7 +788,7 @@ func (r *GetObjectPartInit) GetSignature() *service.Signature {
return nil return nil
} }
func (r *GetObjectPartInit) SetSignature(v *service.Signature) { func (r *GetObjectPartInit) SetSignature(v *refs.Signature) {
if r != nil { if r != nil {
r.sig = v r.sig = v
} }
@ -896,7 +896,7 @@ func (r *PutObjectPartInit) SetObjectID(v *refs.ObjectID) {
} }
} }
func (r *PutObjectPartInit) GetSignature() *service.Signature { func (r *PutObjectPartInit) GetSignature() *refs.Signature {
if r != nil { if r != nil {
return r.sig return r.sig
} }
@ -904,7 +904,7 @@ func (r *PutObjectPartInit) GetSignature() *service.Signature {
return nil return nil
} }
func (r *PutObjectPartInit) SetSignature(v *service.Signature) { func (r *PutObjectPartInit) SetSignature(v *refs.Signature) {
if r != nil { if r != nil {
r.sig = v r.sig = v
} }

View file

@ -139,3 +139,55 @@ func ChecksumFromGRPCMessage(m *refs.Checksum) *Checksum {
return c return c
} }
func VersionToGRPCMessage(v *Version) *refs.Version {
if v == nil {
return nil
}
msg := new(refs.Version)
msg.SetMajor(v.GetMajor())
msg.SetMinor(v.GetMinor())
return msg
}
func VersionFromGRPCMessage(m *refs.Version) *Version {
if m == nil {
return nil
}
v := new(Version)
v.SetMajor(m.GetMajor())
v.SetMinor(m.GetMinor())
return v
}
func SignatureToGRPCMessage(s *Signature) *refs.Signature {
if s == nil {
return nil
}
m := new(refs.Signature)
m.SetKey(s.GetKey())
m.SetSign(s.GetSign())
return m
}
func SignatureFromGRPCMessage(m *refs.Signature) *Signature {
if m == nil {
return nil
}
s := new(Signature)
s.SetKey(m.GetKey())
s.SetSign(m.GetSign())
return s
}

View file

@ -48,3 +48,31 @@ func (m *Checksum) SetSum(v []byte) {
m.Sum = v m.Sum = v
} }
} }
// SetMajor sets major version number.
func (m *Version) SetMajor(v uint32) {
if m != nil {
m.Major = v
}
}
// SetMinor sets minor version number.
func (m *Version) SetMinor(v uint32) {
if m != nil {
m.Minor = v
}
}
// SetKey sets public key in a binary format.
func (m *Signature) SetKey(v []byte) {
if m != nil {
m.Key = v
}
}
// SetSign sets signature.
func (m *Signature) SetSign(v []byte) {
if m != nil {
m.Sign = v
}
}

View file

@ -16,6 +16,12 @@ const (
checksumTypeField = 1 checksumTypeField = 1
checksumValueField = 2 checksumValueField = 2
signatureKeyField = 1
signatureValueField = 2
versionMajorField = 1
versionMinorField = 2
) )
func (o *OwnerID) StableMarshal(buf []byte) ([]byte, error) { func (o *OwnerID) StableMarshal(buf []byte) ([]byte, error) {
@ -173,3 +179,83 @@ func (c *Checksum) StableSize() (size int) {
return size return size
} }
func (s *Signature) StableMarshal(buf []byte) ([]byte, error) {
if s == nil {
return []byte{}, nil
}
if buf == nil {
buf = make([]byte, s.StableSize())
}
var (
offset, n int
err error
)
n, err = proto.BytesMarshal(signatureKeyField, buf[offset:], s.key)
if err != nil {
return nil, err
}
offset += n
_, err = proto.BytesMarshal(signatureValueField, buf[offset:], s.sign)
if err != nil {
return nil, err
}
return buf, nil
}
func (s *Signature) StableSize() (size int) {
if s == nil {
return 0
}
size += proto.BytesSize(signatureKeyField, s.key)
size += proto.BytesSize(signatureValueField, s.sign)
return size
}
func (v *Version) StableMarshal(buf []byte) ([]byte, error) {
if v == nil {
return []byte{}, nil
}
if buf == nil {
buf = make([]byte, v.StableSize())
}
var (
offset, n int
err error
)
n, err = proto.UInt32Marshal(versionMajorField, buf[offset:], v.major)
if err != nil {
return nil, err
}
offset += n
_, err = proto.UInt32Marshal(versionMinorField, buf[offset:], v.minor)
if err != nil {
return nil, err
}
return buf, nil
}
func (v *Version) StableSize() (size int) {
if v == nil {
return 0
}
size += proto.UInt32Size(versionMajorField, v.major)
size += proto.UInt32Size(versionMinorField, v.minor)
return size
}

View file

@ -106,3 +106,51 @@ func TestChecksum_StableMarshal(t *testing.T) {
require.Equal(t, checksumFrom, checksumTo) require.Equal(t, checksumFrom, checksumTo)
}) })
} }
func TestSignature_StableMarshal(t *testing.T) {
signatureFrom := generateSignature("Public Key", "Signature")
transport := new(grpc.Signature)
t.Run("non empty", func(t *testing.T) {
wire, err := signatureFrom.StableMarshal(nil)
require.NoError(t, err)
err = transport.Unmarshal(wire)
require.NoError(t, err)
signatureTo := refs.SignatureFromGRPCMessage(transport)
require.Equal(t, signatureFrom, signatureTo)
})
}
func TestVersion_StableMarshal(t *testing.T) {
versionFrom := generateVersion(2, 0)
transport := new(grpc.Version)
t.Run("non empty", func(t *testing.T) {
wire, err := versionFrom.StableMarshal(nil)
require.NoError(t, err)
err = transport.Unmarshal(wire)
require.NoError(t, err)
versionTo := refs.VersionFromGRPCMessage(transport)
require.Equal(t, versionFrom, versionTo)
})
}
func generateSignature(k, v string) *refs.Signature {
sig := new(refs.Signature)
sig.SetKey([]byte(k))
sig.SetSign([]byte(v))
return sig
}
func generateVersion(maj, min uint32) *refs.Version {
version := new(refs.Version)
version.SetMajor(maj)
version.SetMinor(min)
return version
}

View file

@ -26,6 +26,14 @@ type Checksum struct {
type ChecksumType uint32 type ChecksumType uint32
type Signature struct {
key, sign []byte
}
type Version struct {
major, minor uint32
}
const ( const (
UnknownChecksum ChecksumType = iota UnknownChecksum ChecksumType = iota
TillichZemor TillichZemor
@ -129,3 +137,59 @@ func (c *Checksum) SetSum(v []byte) {
c.sum = v c.sum = v
} }
} }
func (s *Signature) GetKey() []byte {
if s != nil {
return s.key
}
return nil
}
func (s *Signature) SetKey(v []byte) {
if s != nil {
s.key = v
}
}
func (s *Signature) GetSign() []byte {
if s != nil {
return s.sign
}
return nil
}
func (s *Signature) SetSign(v []byte) {
if s != nil {
s.sign = v
}
}
func (v *Version) GetMajor() uint32 {
if v != nil {
return v.major
}
return 0
}
func (v *Version) SetMajor(val uint32) {
if v != nil {
v.major = val
}
}
func (v *Version) GetMinor() uint32 {
if v != nil {
return v.minor
}
return 0
}
func (v *Version) SetMinor(val uint32) {
if v != nil {
v.minor = val
}
}

View file

@ -8,6 +8,7 @@ import (
"github.com/nspcc-dev/neofs-api-go/v2/accounting" "github.com/nspcc-dev/neofs-api-go/v2/accounting"
"github.com/nspcc-dev/neofs-api-go/v2/container" "github.com/nspcc-dev/neofs-api-go/v2/container"
"github.com/nspcc-dev/neofs-api-go/v2/object" "github.com/nspcc-dev/neofs-api-go/v2/object"
"github.com/nspcc-dev/neofs-api-go/v2/refs"
"github.com/nspcc-dev/neofs-api-go/v2/service" "github.com/nspcc-dev/neofs-api-go/v2/service"
"github.com/nspcc-dev/neofs-api-go/v2/session" "github.com/nspcc-dev/neofs-api-go/v2/session"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -42,12 +43,12 @@ type metaHeader interface {
type verificationHeader interface { type verificationHeader interface {
stableMarshaler stableMarshaler
GetBodySignature() *service.Signature GetBodySignature() *refs.Signature
SetBodySignature(*service.Signature) SetBodySignature(*refs.Signature)
GetMetaSignature() *service.Signature GetMetaSignature() *refs.Signature
SetMetaSignature(*service.Signature) SetMetaSignature(*refs.Signature)
GetOriginSignature() *service.Signature GetOriginSignature() *refs.Signature
SetOriginSignature(*service.Signature) SetOriginSignature(*refs.Signature)
setOrigin(stableMarshaler) setOrigin(stableMarshaler)
getOrigin() verificationHeader getOrigin() verificationHeader
@ -129,14 +130,14 @@ func (s stableMarshalerWrapper) SignedDataSize() int {
return 0 return 0
} }
func keySignatureHandler(s *service.Signature) signature.KeySignatureHandler { func keySignatureHandler(s *refs.Signature) signature.KeySignatureHandler {
return func(key []byte, sig []byte) { return func(key []byte, sig []byte) {
s.SetKey(key) s.SetKey(key)
s.SetSign(sig) s.SetSign(sig)
} }
} }
func keySignatureSource(s *service.Signature) signature.KeySignatureSource { func keySignatureSource(s *refs.Signature) signature.KeySignatureSource {
return func() ([]byte, []byte) { return func() ([]byte, []byte) {
return s.GetKey(), s.GetSign() return s.GetKey(), s.GetSign()
} }
@ -204,8 +205,8 @@ func SignServiceMessage(key *ecdsa.PrivateKey, msg interface{}) error {
return nil return nil
} }
func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*service.Signature)) error { func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*refs.Signature)) error {
sig := new(service.Signature) sig := new(refs.Signature)
// sign part // sign part
if err := signature.SignDataWithHandler( if err := signature.SignDataWithHandler(
@ -280,7 +281,7 @@ func verifyMatryoshkaLevel(body stableMarshaler, meta metaHeader, verify verific
return verifyMatryoshkaLevel(body, meta.getOrigin(), origin) return verifyMatryoshkaLevel(body, meta.getOrigin(), origin)
} }
func verifyServiceMessagePart(part stableMarshaler, sigRdr func() *service.Signature) error { func verifyServiceMessagePart(part stableMarshaler, sigRdr func() *refs.Signature) error {
return signature.VerifyDataWithSource( return signature.VerifyDataWithSource(
&stableMarshalerWrapper{part}, &stableMarshalerWrapper{part},
keySignatureSource(sigRdr()), keySignatureSource(sigRdr()),