forked from TrueCloudLab/frostfs-api-go
Move version and signature structures to refs package
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
f1addc4cc5
commit
db12420c99
16 changed files with 363 additions and 86 deletions
|
@ -43,7 +43,7 @@ func ContainerToGRPCMessage(c *Container) *container.Container {
|
|||
m := new(container.Container)
|
||||
|
||||
m.SetVersion(
|
||||
service.VersionToGRPCMessage(c.GetVersion()),
|
||||
refs.VersionToGRPCMessage(c.GetVersion()),
|
||||
)
|
||||
|
||||
m.SetOwnerId(
|
||||
|
@ -78,7 +78,7 @@ func ContainerFromGRPCMessage(m *container.Container) *Container {
|
|||
c := new(Container)
|
||||
|
||||
c.SetVersion(
|
||||
service.VersionFromGRPCMessage(m.GetVersion()),
|
||||
refs.VersionFromGRPCMessage(m.GetVersion()),
|
||||
)
|
||||
|
||||
c.SetOwnerID(
|
||||
|
@ -117,7 +117,7 @@ func PutRequestBodyToGRPCMessage(r *PutRequestBody) *container.PutRequest_Body {
|
|||
)
|
||||
|
||||
m.SetSignature(
|
||||
service.SignatureToGRPCMessage(r.GetSignature()),
|
||||
refs.SignatureToGRPCMessage(r.GetSignature()),
|
||||
)
|
||||
|
||||
return m
|
||||
|
@ -135,7 +135,7 @@ func PutRequestBodyFromGRPCMessage(m *container.PutRequest_Body) *PutRequestBody
|
|||
)
|
||||
|
||||
r.SetSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
)
|
||||
|
||||
return r
|
||||
|
@ -365,7 +365,7 @@ func DeleteRequestBodyToGRPCMessage(r *DeleteRequestBody) *container.DeleteReque
|
|||
)
|
||||
|
||||
m.SetSignature(
|
||||
service.SignatureToGRPCMessage(r.GetSignature()),
|
||||
refs.SignatureToGRPCMessage(r.GetSignature()),
|
||||
)
|
||||
|
||||
return m
|
||||
|
@ -383,7 +383,7 @@ func DeleteRequestBodyFromGRPCMessage(m *container.DeleteRequest_Body) *DeleteRe
|
|||
)
|
||||
|
||||
r.SetSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
)
|
||||
|
||||
return r
|
||||
|
@ -615,7 +615,7 @@ func SetExtendedACLRequestBodyToGRPCMessage(r *SetExtendedACLRequestBody) *conta
|
|||
)
|
||||
|
||||
m.SetSignature(
|
||||
service.SignatureToGRPCMessage(r.GetSignature()))
|
||||
refs.SignatureToGRPCMessage(r.GetSignature()))
|
||||
|
||||
return m
|
||||
}
|
||||
|
@ -632,7 +632,7 @@ func SetExtendedACLRequestBodyFromGRPCMessage(m *container.SetExtendedACLRequest
|
|||
)
|
||||
|
||||
r.SetSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
)
|
||||
|
||||
return r
|
||||
|
@ -794,7 +794,7 @@ func GetExtendedACLResponseBodyToGRPCMessage(r *GetExtendedACLResponseBody) *con
|
|||
)
|
||||
|
||||
m.SetSignature(
|
||||
service.SignatureToGRPCMessage(r.GetSignature()),
|
||||
refs.SignatureToGRPCMessage(r.GetSignature()),
|
||||
)
|
||||
|
||||
return m
|
||||
|
@ -812,7 +812,7 @@ func GetExtendedACLResponseBodyFromGRPCMessage(m *container.GetExtendedACLRespon
|
|||
)
|
||||
|
||||
r.SetSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
)
|
||||
|
||||
return r
|
||||
|
|
|
@ -14,7 +14,7 @@ func (m *PutRequest_Body) SetContainer(v *Container) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.Signature = v
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ func (m *DeleteRequest_Body) SetContainerId(v *refs.ContainerID) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.Signature = v
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ func (m *SetExtendedACLRequest_Body) SetEacl(v *acl.EACLTable) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.Signature = v
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ func (m *GetExtendedACLResponse_Body) SetEacl(v *acl.EACLTable) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.Signature = v
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package container
|
|||
import (
|
||||
netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap/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.
|
||||
|
@ -56,7 +55,7 @@ func (m *Container) SetPlacementPolicy(v *netmap.PlacementPolicy) {
|
|||
}
|
||||
|
||||
// SetVersion sets version of the container.
|
||||
func (m *Container) SetVersion(v *service.Version) {
|
||||
func (m *Container) SetVersion(v *refs.Version) {
|
||||
if m != nil {
|
||||
m.Version = v
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/nspcc-dev/neofs-api-go/v2/container"
|
||||
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/service"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
|
@ -248,7 +247,7 @@ func generateContainer(n string) *container.Container {
|
|||
owner := new(refs.OwnerID)
|
||||
owner.SetValue([]byte("Owner ID"))
|
||||
|
||||
version := new(service.Version)
|
||||
version := new(refs.Version)
|
||||
version.SetMajor(2)
|
||||
version.SetMinor(0)
|
||||
|
||||
|
@ -267,8 +266,8 @@ func generateContainer(n string) *container.Container {
|
|||
return cnr
|
||||
}
|
||||
|
||||
func generateSignature(k, v string) *service.Signature {
|
||||
sig := new(service.Signature)
|
||||
func generateSignature(k, v string) *refs.Signature {
|
||||
sig := new(refs.Signature)
|
||||
sig.SetKey([]byte(k))
|
||||
sig.SetSign([]byte(v))
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ type Attribute struct {
|
|||
}
|
||||
|
||||
type Container struct {
|
||||
version *service.Version
|
||||
version *refs.Version
|
||||
|
||||
ownerID *refs.OwnerID
|
||||
|
||||
|
@ -28,7 +28,7 @@ type Container struct {
|
|||
type PutRequestBody struct {
|
||||
cnr *Container
|
||||
|
||||
sig *service.Signature
|
||||
sig *refs.Signature
|
||||
}
|
||||
|
||||
type PutRequest struct {
|
||||
|
@ -78,7 +78,7 @@ type GetResponse struct {
|
|||
type DeleteRequestBody struct {
|
||||
cid *refs.ContainerID
|
||||
|
||||
sig *service.Signature
|
||||
sig *refs.Signature
|
||||
}
|
||||
|
||||
type DeleteRequest struct {
|
||||
|
@ -126,7 +126,7 @@ type ListResponse struct {
|
|||
type SetExtendedACLRequestBody struct {
|
||||
eacl *acl.Table
|
||||
|
||||
sig *service.Signature
|
||||
sig *refs.Signature
|
||||
}
|
||||
|
||||
type SetExtendedACLRequest struct {
|
||||
|
@ -162,7 +162,7 @@ type GetExtendedACLRequest struct {
|
|||
type GetExtendedACLResponseBody struct {
|
||||
eacl *acl.Table
|
||||
|
||||
sig *service.Signature
|
||||
sig *refs.Signature
|
||||
}
|
||||
|
||||
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 {
|
||||
return c.version
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ func (c *Container) GetVersion() *service.Version {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (c *Container) SetVersion(v *service.Version) {
|
||||
func (c *Container) SetVersion(v *refs.Version) {
|
||||
if c != nil {
|
||||
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 {
|
||||
return r.sig
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ func (r *PutRequestBody) GetSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *PutRequestBody) SetSignature(v *service.Signature) {
|
||||
func (r *PutRequestBody) SetSignature(v *refs.Signature) {
|
||||
if r != nil {
|
||||
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 {
|
||||
return r.sig
|
||||
}
|
||||
|
@ -545,7 +545,7 @@ func (r *DeleteRequestBody) GetSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *DeleteRequestBody) SetSignature(v *service.Signature) {
|
||||
func (r *DeleteRequestBody) SetSignature(v *refs.Signature) {
|
||||
if r != nil {
|
||||
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 {
|
||||
return r.sig
|
||||
}
|
||||
|
@ -769,7 +769,7 @@ func (r *SetExtendedACLRequestBody) GetSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *SetExtendedACLRequestBody) SetSignature(v *service.Signature) {
|
||||
func (r *SetExtendedACLRequestBody) SetSignature(v *refs.Signature) {
|
||||
if r != nil {
|
||||
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 {
|
||||
return r.sig
|
||||
}
|
||||
|
@ -937,7 +937,7 @@ func (r *GetExtendedACLResponseBody) GetSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *GetExtendedACLResponseBody) SetSignature(v *service.Signature) {
|
||||
func (r *GetExtendedACLResponseBody) SetSignature(v *refs.Signature) {
|
||||
if r != nil {
|
||||
r.sig = v
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ func ShortHeaderToGRPCMessage(h *ShortHeader) *object.ShortHeader {
|
|||
m := new(object.ShortHeader)
|
||||
|
||||
m.SetVersion(
|
||||
service.VersionToGRPCMessage(h.GetVersion()),
|
||||
refs.VersionToGRPCMessage(h.GetVersion()),
|
||||
)
|
||||
|
||||
m.SetCreationEpoch(h.GetCreationEpoch())
|
||||
|
@ -59,7 +59,7 @@ func ShortHeaderFromGRPCMessage(m *object.ShortHeader) *ShortHeader {
|
|||
h := new(ShortHeader)
|
||||
|
||||
h.SetVersion(
|
||||
service.VersionFromGRPCMessage(m.GetVersion()),
|
||||
refs.VersionFromGRPCMessage(m.GetVersion()),
|
||||
)
|
||||
|
||||
h.SetCreationEpoch(m.GetCreationEpoch())
|
||||
|
@ -119,7 +119,7 @@ func SplitHeaderToGRPCMessage(h *SplitHeader) *object.Header_Split {
|
|||
)
|
||||
|
||||
m.SetParentSignature(
|
||||
service.SignatureToGRPCMessage(h.GetParentSignature()),
|
||||
refs.SignatureToGRPCMessage(h.GetParentSignature()),
|
||||
)
|
||||
|
||||
m.SetParentHeader(
|
||||
|
@ -154,7 +154,7 @@ func SplitHeaderFromGRPCMessage(m *object.Header_Split) *SplitHeader {
|
|||
)
|
||||
|
||||
h.SetParentSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetParentSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetParentSignature()),
|
||||
)
|
||||
|
||||
h.SetParentHeader(
|
||||
|
@ -181,7 +181,7 @@ func HeaderToGRPCMessage(h *Header) *object.Header {
|
|||
m := new(object.Header)
|
||||
|
||||
m.SetVersion(
|
||||
service.VersionToGRPCMessage(h.GetVersion()),
|
||||
refs.VersionToGRPCMessage(h.GetVersion()),
|
||||
)
|
||||
|
||||
m.SetContainerId(
|
||||
|
@ -236,7 +236,7 @@ func HeaderFromGRPCMessage(m *object.Header) *Header {
|
|||
h := new(Header)
|
||||
|
||||
h.SetVersion(
|
||||
service.VersionFromGRPCMessage(m.GetVersion()),
|
||||
refs.VersionFromGRPCMessage(m.GetVersion()),
|
||||
)
|
||||
|
||||
h.SetContainerID(
|
||||
|
@ -295,7 +295,7 @@ func ObjectToGRPCMessage(o *Object) *object.Object {
|
|||
)
|
||||
|
||||
m.SetSignature(
|
||||
service.SignatureToGRPCMessage(o.GetSignature()),
|
||||
refs.SignatureToGRPCMessage(o.GetSignature()),
|
||||
)
|
||||
|
||||
m.SetHeader(
|
||||
|
@ -319,7 +319,7 @@ func ObjectFromGRPCMessage(m *object.Object) *Object {
|
|||
)
|
||||
|
||||
o.SetSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
)
|
||||
|
||||
o.SetHeader(
|
||||
|
@ -407,7 +407,7 @@ func GetObjectPartInitToGRPCMessage(r *GetObjectPartInit) *object.GetResponse_Bo
|
|||
)
|
||||
|
||||
m.SetSignature(
|
||||
service.SignatureToGRPCMessage(r.GetSignature()),
|
||||
refs.SignatureToGRPCMessage(r.GetSignature()),
|
||||
)
|
||||
|
||||
m.SetHeader(
|
||||
|
@ -429,7 +429,7 @@ func GetObjectPartInitFromGRPCMessage(m *object.GetResponse_Body_Init) *GetObjec
|
|||
)
|
||||
|
||||
r.SetSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
)
|
||||
|
||||
r.SetHeader(
|
||||
|
@ -555,7 +555,7 @@ func PutObjectPartInitToGRPCMessage(r *PutObjectPartInit) *object.PutRequest_Bod
|
|||
)
|
||||
|
||||
m.SetSignature(
|
||||
service.SignatureToGRPCMessage(r.GetSignature()),
|
||||
refs.SignatureToGRPCMessage(r.GetSignature()),
|
||||
)
|
||||
|
||||
m.SetHeader(
|
||||
|
@ -579,7 +579,7 @@ func PutObjectPartInitFromGRPCMessage(m *object.PutRequest_Body_Init) *PutObject
|
|||
)
|
||||
|
||||
r.SetSignature(
|
||||
service.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
refs.SignatureFromGRPCMessage(m.GetSignature()),
|
||||
)
|
||||
|
||||
r.SetHeader(
|
||||
|
|
|
@ -48,7 +48,7 @@ func (m *GetResponse_Body_Init) SetObjectId(v *refs.ObjectID) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.Signature = v
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ func (m *PutRequest_Body_Init) SetObjectId(v *refs.ObjectID) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.Signature = v
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func (m *Header_Split) SetPrevious(v *refs.ObjectID) {
|
|||
}
|
||||
|
||||
// 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 {
|
||||
m.ParentSignature = v
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ func (m *Header) SetCreationEpoch(v uint64) {
|
|||
}
|
||||
|
||||
// SetVersion sets version of the object format.
|
||||
func (m *Header) SetVersion(v *service.Version) {
|
||||
func (m *Header) SetVersion(v *refs.Version) {
|
||||
if m != nil {
|
||||
m.Version = v
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ func (m *Object) SetObjectId(v *refs.ObjectID) {
|
|||
}
|
||||
|
||||
// SetSignature sets signature of the object identifier.
|
||||
func (m *Object) SetSignature(v *service.Signature) {
|
||||
func (m *Object) SetSignature(v *refs.Signature) {
|
||||
if m != nil {
|
||||
m.Signature = v
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func (m *Object) SetPayload(v []byte) {
|
|||
}
|
||||
|
||||
// SetVersion sets version of the object.
|
||||
func (m *ShortHeader) SetVersion(v *service.Version) {
|
||||
func (m *ShortHeader) SetVersion(v *refs.Version) {
|
||||
if m != nil {
|
||||
m.Version = v
|
||||
}
|
||||
|
|
|
@ -381,16 +381,16 @@ func generateContainerID(id string) *refs.ContainerID {
|
|||
return cid
|
||||
}
|
||||
|
||||
func generateSignature(k, v string) *service.Signature {
|
||||
sig := new(service.Signature)
|
||||
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) *service.Version {
|
||||
version := new(service.Version)
|
||||
func generateVersion(maj, min uint32) *refs.Version {
|
||||
version := new(refs.Version)
|
||||
version.SetMajor(maj)
|
||||
version.SetMinor(min)
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ type Type uint32
|
|||
type MatchType uint32
|
||||
|
||||
type ShortHeader struct {
|
||||
version *service.Version
|
||||
version *refs.Version
|
||||
|
||||
creatEpoch uint64
|
||||
|
||||
|
@ -28,7 +28,7 @@ type Attribute struct {
|
|||
type SplitHeader struct {
|
||||
par, prev *refs.ObjectID
|
||||
|
||||
parSig *service.Signature
|
||||
parSig *refs.Signature
|
||||
|
||||
parHdr *Header
|
||||
|
||||
|
@ -36,7 +36,7 @@ type SplitHeader struct {
|
|||
}
|
||||
|
||||
type Header struct {
|
||||
version *service.Version
|
||||
version *refs.Version
|
||||
|
||||
cid *refs.ContainerID
|
||||
|
||||
|
@ -60,7 +60,7 @@ type Header struct {
|
|||
type Object struct {
|
||||
objectID *refs.ObjectID
|
||||
|
||||
idSig *service.Signature
|
||||
idSig *refs.Signature
|
||||
|
||||
header *Header
|
||||
|
||||
|
@ -88,7 +88,7 @@ type GetObjectPart interface {
|
|||
type GetObjectPartInit struct {
|
||||
id *refs.ObjectID
|
||||
|
||||
sig *service.Signature
|
||||
sig *refs.Signature
|
||||
|
||||
hdr *Header
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ type PutObjectPart interface {
|
|||
type PutObjectPartInit struct {
|
||||
id *refs.ObjectID
|
||||
|
||||
sig *service.Signature
|
||||
sig *refs.Signature
|
||||
|
||||
hdr *Header
|
||||
|
||||
|
@ -318,7 +318,7 @@ const (
|
|||
MatchStringEqual
|
||||
)
|
||||
|
||||
func (h *ShortHeader) GetVersion() *service.Version {
|
||||
func (h *ShortHeader) GetVersion() *refs.Version {
|
||||
if h != nil {
|
||||
return h.version
|
||||
}
|
||||
|
@ -326,7 +326,7 @@ func (h *ShortHeader) GetVersion() *service.Version {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *ShortHeader) SetVersion(v *service.Version) {
|
||||
func (h *ShortHeader) SetVersion(v *refs.Version) {
|
||||
if h != nil {
|
||||
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 {
|
||||
return h.parSig
|
||||
}
|
||||
|
@ -452,7 +452,7 @@ func (h *SplitHeader) GetParentSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *SplitHeader) SetParentSignature(v *service.Signature) {
|
||||
func (h *SplitHeader) SetParentSignature(v *refs.Signature) {
|
||||
if h != nil {
|
||||
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 {
|
||||
return h.version
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ func (h *Header) GetVersion() *service.Version {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (h *Header) SetVersion(v *service.Version) {
|
||||
func (h *Header) SetVersion(v *refs.Version) {
|
||||
if h != nil {
|
||||
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 {
|
||||
return o.idSig
|
||||
}
|
||||
|
@ -662,7 +662,7 @@ func (o *Object) GetSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (o *Object) SetSignature(v *service.Signature) {
|
||||
func (o *Object) SetSignature(v *refs.Signature) {
|
||||
if o != nil {
|
||||
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 {
|
||||
return r.sig
|
||||
}
|
||||
|
@ -788,7 +788,7 @@ func (r *GetObjectPartInit) GetSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *GetObjectPartInit) SetSignature(v *service.Signature) {
|
||||
func (r *GetObjectPartInit) SetSignature(v *refs.Signature) {
|
||||
if r != nil {
|
||||
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 {
|
||||
return r.sig
|
||||
}
|
||||
|
@ -904,7 +904,7 @@ func (r *PutObjectPartInit) GetSignature() *service.Signature {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (r *PutObjectPartInit) SetSignature(v *service.Signature) {
|
||||
func (r *PutObjectPartInit) SetSignature(v *refs.Signature) {
|
||||
if r != nil {
|
||||
r.sig = v
|
||||
}
|
||||
|
|
|
@ -139,3 +139,55 @@ func ChecksumFromGRPCMessage(m *refs.Checksum) *Checksum {
|
|||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -48,3 +48,31 @@ func (m *Checksum) SetSum(v []byte) {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,12 @@ const (
|
|||
|
||||
checksumTypeField = 1
|
||||
checksumValueField = 2
|
||||
|
||||
signatureKeyField = 1
|
||||
signatureValueField = 2
|
||||
|
||||
versionMajorField = 1
|
||||
versionMinorField = 2
|
||||
)
|
||||
|
||||
func (o *OwnerID) StableMarshal(buf []byte) ([]byte, error) {
|
||||
|
@ -173,3 +179,83 @@ func (c *Checksum) StableSize() (size int) {
|
|||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -106,3 +106,51 @@ func TestChecksum_StableMarshal(t *testing.T) {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -26,6 +26,14 @@ type Checksum struct {
|
|||
|
||||
type ChecksumType uint32
|
||||
|
||||
type Signature struct {
|
||||
key, sign []byte
|
||||
}
|
||||
|
||||
type Version struct {
|
||||
major, minor uint32
|
||||
}
|
||||
|
||||
const (
|
||||
UnknownChecksum ChecksumType = iota
|
||||
TillichZemor
|
||||
|
@ -129,3 +137,59 @@ func (c *Checksum) SetSum(v []byte) {
|
|||
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"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/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/session"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -42,12 +43,12 @@ type metaHeader interface {
|
|||
type verificationHeader interface {
|
||||
stableMarshaler
|
||||
|
||||
GetBodySignature() *service.Signature
|
||||
SetBodySignature(*service.Signature)
|
||||
GetMetaSignature() *service.Signature
|
||||
SetMetaSignature(*service.Signature)
|
||||
GetOriginSignature() *service.Signature
|
||||
SetOriginSignature(*service.Signature)
|
||||
GetBodySignature() *refs.Signature
|
||||
SetBodySignature(*refs.Signature)
|
||||
GetMetaSignature() *refs.Signature
|
||||
SetMetaSignature(*refs.Signature)
|
||||
GetOriginSignature() *refs.Signature
|
||||
SetOriginSignature(*refs.Signature)
|
||||
|
||||
setOrigin(stableMarshaler)
|
||||
getOrigin() verificationHeader
|
||||
|
@ -129,14 +130,14 @@ func (s stableMarshalerWrapper) SignedDataSize() int {
|
|||
return 0
|
||||
}
|
||||
|
||||
func keySignatureHandler(s *service.Signature) signature.KeySignatureHandler {
|
||||
func keySignatureHandler(s *refs.Signature) signature.KeySignatureHandler {
|
||||
return func(key []byte, sig []byte) {
|
||||
s.SetKey(key)
|
||||
s.SetSign(sig)
|
||||
}
|
||||
}
|
||||
|
||||
func keySignatureSource(s *service.Signature) signature.KeySignatureSource {
|
||||
func keySignatureSource(s *refs.Signature) signature.KeySignatureSource {
|
||||
return func() ([]byte, []byte) {
|
||||
return s.GetKey(), s.GetSign()
|
||||
}
|
||||
|
@ -204,8 +205,8 @@ func SignServiceMessage(key *ecdsa.PrivateKey, msg interface{}) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*service.Signature)) error {
|
||||
sig := new(service.Signature)
|
||||
func signServiceMessagePart(key *ecdsa.PrivateKey, part stableMarshaler, sigWrite func(*refs.Signature)) error {
|
||||
sig := new(refs.Signature)
|
||||
|
||||
// sign part
|
||||
if err := signature.SignDataWithHandler(
|
||||
|
@ -280,7 +281,7 @@ func verifyMatryoshkaLevel(body stableMarshaler, meta metaHeader, verify verific
|
|||
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(
|
||||
&stableMarshalerWrapper{part},
|
||||
keySignatureSource(sigRdr()),
|
||||
|
|
Loading…
Reference in a new issue