diff --git a/v2/service/convert.go b/v2/service/convert.go deleted file mode 100644 index 6bffe276..00000000 --- a/v2/service/convert.go +++ /dev/null @@ -1,689 +0,0 @@ -package service - -import ( - "fmt" - - "github.com/nspcc-dev/neofs-api-go/v2/acl" - "github.com/nspcc-dev/neofs-api-go/v2/refs" - service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" -) - -func VersionToGRPCMessage(v *Version) *service.Version { - if v == nil { - return nil - } - - msg := new(service.Version) - - msg.SetMajor(v.GetMajor()) - msg.SetMinor(v.GetMinor()) - - return msg -} - -func VersionFromGRPCMessage(m *service.Version) *Version { - if m == nil { - return nil - } - - v := new(Version) - - v.SetMajor(m.GetMajor()) - v.SetMinor(m.GetMinor()) - - return v -} - -func XHeaderToGRPCMessage(x *XHeader) *service.XHeader { - if x == nil { - return nil - } - - m := new(service.XHeader) - - m.SetKey(x.GetKey()) - m.SetValue(x.GetValue()) - - return m -} - -func XHeaderFromGRPCMessage(m *service.XHeader) *XHeader { - if m == nil { - return nil - } - - x := new(XHeader) - - x.SetKey(m.GetKey()) - x.SetValue(m.GetValue()) - - return x -} - -func SessionTokenToGRPCMessage(t *SessionToken) *service.SessionToken { - if t == nil { - return nil - } - - m := new(service.SessionToken) - - m.SetBody( - SessionTokenBodyToGRPCMessage(t.GetBody()), - ) - - m.SetSignature( - SignatureToGRPCMessage(t.GetSignature()), - ) - - return m -} - -func SessionTokenFromGRPCMessage(m *service.SessionToken) *SessionToken { - if m == nil { - return nil - } - - t := new(SessionToken) - - t.SetBody( - SessionTokenBodyFromGRPCMessage(m.GetBody()), - ) - - t.SetSignature( - SignatureFromGRPCMessage(m.GetSignature()), - ) - - return t -} - -func BearerTokenToGRPCMessage(t *BearerToken) *service.BearerToken { - if t == nil { - return nil - } - - m := new(service.BearerToken) - - m.SetBody( - BearerTokenBodyToGRPCMessage(t.GetBody()), - ) - - m.SetSignature( - SignatureToGRPCMessage(t.GetSignature()), - ) - - return m -} - -func BearerTokenFromGRPCMessage(m *service.BearerToken) *BearerToken { - if m == nil { - return nil - } - - bt := new(BearerToken) - - bt.SetBody( - BearerTokenBodyFromGRPCMessage(m.GetBody()), - ) - - bt.SetSignature( - SignatureFromGRPCMessage(m.GetSignature()), - ) - - return bt -} - -func RequestVerificationHeaderToGRPCMessage(r *RequestVerificationHeader) *service.RequestVerificationHeader { - if r == nil { - return nil - } - - m := new(service.RequestVerificationHeader) - - m.SetBodySignature( - SignatureToGRPCMessage(r.GetBodySignature()), - ) - - m.SetMetaSignature( - SignatureToGRPCMessage(r.GetMetaSignature()), - ) - - m.SetOriginSignature( - SignatureToGRPCMessage(r.GetOriginSignature()), - ) - - m.SetOrigin( - RequestVerificationHeaderToGRPCMessage(r.GetOrigin()), - ) - - return m -} - -func RequestVerificationHeaderFromGRPCMessage(m *service.RequestVerificationHeader) *RequestVerificationHeader { - if m == nil { - return nil - } - - r := new(RequestVerificationHeader) - - r.SetBodySignature( - SignatureFromGRPCMessage(m.GetBodySignature()), - ) - - r.SetMetaSignature( - SignatureFromGRPCMessage(m.GetMetaSignature()), - ) - - r.SetOriginSignature( - SignatureFromGRPCMessage(m.GetOriginSignature()), - ) - - r.SetOrigin( - RequestVerificationHeaderFromGRPCMessage(m.GetOrigin()), - ) - - return r -} - -func RequestMetaHeaderToGRPCMessage(r *RequestMetaHeader) *service.RequestMetaHeader { - if r == nil { - return nil - } - - m := new(service.RequestMetaHeader) - - m.SetTtl(r.GetTTL()) - m.SetEpoch(r.GetEpoch()) - - m.SetVersion( - VersionToGRPCMessage(r.GetVersion()), - ) - - m.SetSessionToken( - SessionTokenToGRPCMessage(r.GetSessionToken()), - ) - - m.SetBearerToken( - BearerTokenToGRPCMessage(r.GetBearerToken()), - ) - - m.SetOrigin( - RequestMetaHeaderToGRPCMessage(r.GetOrigin()), - ) - - xHeaders := r.GetXHeaders() - xHdrMsg := make([]*service.XHeader, 0, len(xHeaders)) - - for i := range xHeaders { - xHdrMsg = append(xHdrMsg, XHeaderToGRPCMessage(xHeaders[i])) - } - - m.SetXHeaders(xHdrMsg) - - return m -} - -func RequestMetaHeaderFromGRPCMessage(m *service.RequestMetaHeader) *RequestMetaHeader { - if m == nil { - return nil - } - - r := new(RequestMetaHeader) - - r.SetTTL(m.GetTtl()) - r.SetEpoch(m.GetEpoch()) - - r.SetVersion( - VersionFromGRPCMessage(m.GetVersion()), - ) - - r.SetSessionToken( - SessionTokenFromGRPCMessage(m.GetSessionToken()), - ) - - r.SetBearerToken( - BearerTokenFromGRPCMessage(m.GetBearerToken()), - ) - - r.SetOrigin( - RequestMetaHeaderFromGRPCMessage(m.GetOrigin()), - ) - - xHdrMsg := m.GetXHeaders() - xHeaders := make([]*XHeader, 0, len(xHdrMsg)) - - for i := range xHdrMsg { - xHeaders = append(xHeaders, XHeaderFromGRPCMessage(xHdrMsg[i])) - } - - r.SetXHeaders(xHeaders) - - return r -} - -func SignatureToGRPCMessage(s *Signature) *service.Signature { - if s == nil { - return nil - } - - m := new(service.Signature) - - m.SetKey(s.GetKey()) - m.SetSign(s.GetSign()) - - return m -} - -func SignatureFromGRPCMessage(m *service.Signature) *Signature { - if m == nil { - return nil - } - - s := new(Signature) - - s.SetKey(m.GetKey()) - s.SetSign(m.GetSign()) - - return s -} - -func TokenLifetimeToGRPCMessage(tl *TokenLifetime) *service.TokenLifetime { - if tl == nil { - return nil - } - - m := new(service.TokenLifetime) - - m.SetExp(tl.GetExp()) - m.SetNbf(tl.GetNbf()) - m.SetIat(tl.GetIat()) - - return m -} - -func TokenLifetimeFromGRPCMessage(m *service.TokenLifetime) *TokenLifetime { - if m == nil { - return nil - } - - tl := new(TokenLifetime) - - tl.SetExp(m.GetExp()) - tl.SetNbf(m.GetNbf()) - tl.SetIat(m.GetIat()) - - return tl -} - -func BearerTokenBodyToGRPCMessage(v *BearerTokenBody) *service.BearerToken_Body { - if v == nil { - return nil - } - - m := new(service.BearerToken_Body) - - m.SetEaclTable( - acl.TableToGRPCMessage(v.GetEACL()), - ) - - m.SetOwnerId( - refs.OwnerIDToGRPCMessage(v.GetOwnerID()), - ) - - m.SetLifetime( - TokenLifetimeToGRPCMessage(v.GetLifetime()), - ) - - return m -} - -func BearerTokenBodyFromGRPCMessage(m *service.BearerToken_Body) *BearerTokenBody { - if m == nil { - return nil - } - - bt := new(BearerTokenBody) - - bt.SetEACL( - acl.TableFromGRPCMessage(m.GetEaclTable()), - ) - - bt.SetOwnerID( - refs.OwnerIDFromGRPCMessage(m.GetOwnerId()), - ) - - bt.SetLifetime( - TokenLifetimeFromGRPCMessage(m.GetLifetime()), - ) - - return bt -} - -func RequestHeadersToGRPC( - src interface { - GetMetaHeader() *RequestMetaHeader - GetVerificationHeader() *RequestVerificationHeader - }, - dst interface { - SetMetaHeader(*service.RequestMetaHeader) - SetVerifyHeader(*service.RequestVerificationHeader) - }, -) { - dst.SetMetaHeader( - RequestMetaHeaderToGRPCMessage(src.GetMetaHeader()), - ) - - dst.SetVerifyHeader( - RequestVerificationHeaderToGRPCMessage(src.GetVerificationHeader()), - ) -} - -func RequestHeadersFromGRPC( - src interface { - GetMetaHeader() *service.RequestMetaHeader - GetVerifyHeader() *service.RequestVerificationHeader - }, - dst interface { - SetMetaHeader(*RequestMetaHeader) - SetVerificationHeader(*RequestVerificationHeader) - }, -) { - dst.SetMetaHeader( - RequestMetaHeaderFromGRPCMessage(src.GetMetaHeader()), - ) - - dst.SetVerificationHeader( - RequestVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), - ) -} - -func ResponseVerificationHeaderToGRPCMessage(r *ResponseVerificationHeader) *service.ResponseVerificationHeader { - if r == nil { - return nil - } - - m := new(service.ResponseVerificationHeader) - - m.SetBodySignature( - SignatureToGRPCMessage(r.GetBodySignature()), - ) - - m.SetMetaSignature( - SignatureToGRPCMessage(r.GetMetaSignature()), - ) - - m.SetOriginSignature( - SignatureToGRPCMessage(r.GetOriginSignature()), - ) - - m.SetOrigin( - ResponseVerificationHeaderToGRPCMessage(r.GetOrigin()), - ) - - return m -} - -func ResponseVerificationHeaderFromGRPCMessage(m *service.ResponseVerificationHeader) *ResponseVerificationHeader { - if m == nil { - return nil - } - - r := new(ResponseVerificationHeader) - - r.SetBodySignature( - SignatureFromGRPCMessage(m.GetBodySignature()), - ) - - r.SetMetaSignature( - SignatureFromGRPCMessage(m.GetMetaSignature()), - ) - - r.SetOriginSignature( - SignatureFromGRPCMessage(m.GetOriginSignature()), - ) - - r.SetOrigin( - ResponseVerificationHeaderFromGRPCMessage(m.GetOrigin()), - ) - - return r -} - -func ResponseMetaHeaderToGRPCMessage(r *ResponseMetaHeader) *service.ResponseMetaHeader { - if r == nil { - return nil - } - - m := new(service.ResponseMetaHeader) - - m.SetTtl(r.GetTTL()) - m.SetEpoch(r.GetEpoch()) - - m.SetVersion( - VersionToGRPCMessage(r.GetVersion()), - ) - - m.SetOrigin( - ResponseMetaHeaderToGRPCMessage(r.GetOrigin()), - ) - - xHeaders := r.GetXHeaders() - xHdrMsg := make([]*service.XHeader, 0, len(xHeaders)) - - for i := range xHeaders { - xHdrMsg = append(xHdrMsg, XHeaderToGRPCMessage(xHeaders[i])) - } - - m.SetXHeaders(xHdrMsg) - - return m -} - -func ResponseMetaHeaderFromGRPCMessage(m *service.ResponseMetaHeader) *ResponseMetaHeader { - if m == nil { - return nil - } - - r := new(ResponseMetaHeader) - - r.SetTTL(m.GetTtl()) - r.SetEpoch(m.GetEpoch()) - - r.SetVersion( - VersionFromGRPCMessage(m.GetVersion()), - ) - - r.SetOrigin( - ResponseMetaHeaderFromGRPCMessage(m.GetOrigin()), - ) - - xHdrMsg := m.GetXHeaders() - xHeaders := make([]*XHeader, 0, len(xHdrMsg)) - - for i := range xHdrMsg { - xHeaders = append(xHeaders, XHeaderFromGRPCMessage(xHdrMsg[i])) - } - - r.SetXHeaders(xHeaders) - - return r -} - -func ResponseHeadersToGRPC( - src interface { - GetMetaHeader() *ResponseMetaHeader - GetVerificationHeader() *ResponseVerificationHeader - }, - dst interface { - SetMetaHeader(*service.ResponseMetaHeader) - SetVerifyHeader(*service.ResponseVerificationHeader) - }, -) { - dst.SetMetaHeader( - ResponseMetaHeaderToGRPCMessage(src.GetMetaHeader()), - ) - - dst.SetVerifyHeader( - ResponseVerificationHeaderToGRPCMessage(src.GetVerificationHeader()), - ) -} - -func ResponseHeadersFromGRPC( - src interface { - GetMetaHeader() *service.ResponseMetaHeader - GetVerifyHeader() *service.ResponseVerificationHeader - }, - dst interface { - SetMetaHeader(*ResponseMetaHeader) - SetVerificationHeader(*ResponseVerificationHeader) - }, -) { - dst.SetMetaHeader( - ResponseMetaHeaderFromGRPCMessage(src.GetMetaHeader()), - ) - - dst.SetVerificationHeader( - ResponseVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), - ) -} - -func ObjectSessionVerbToGRPCField(v ObjectSessionVerb) service.ObjectSessionContext_Verb { - switch v { - case ObjectVerbPut: - return service.ObjectSessionContext_PUT - case ObjectVerbGet: - return service.ObjectSessionContext_GET - case ObjectVerbHead: - return service.ObjectSessionContext_HEAD - case ObjectVerbSearch: - return service.ObjectSessionContext_SEARCH - case ObjectVerbDelete: - return service.ObjectSessionContext_DELETE - case ObjectVerbRange: - return service.ObjectSessionContext_RANGE - case ObjectVerbRangeHash: - return service.ObjectSessionContext_RANGEHASH - default: - return service.ObjectSessionContext_VERB_UNSPECIFIED - } -} - -func ObjectSessionVerbFromGRPCField(v service.ObjectSessionContext_Verb) ObjectSessionVerb { - switch v { - case service.ObjectSessionContext_PUT: - return ObjectVerbPut - case service.ObjectSessionContext_GET: - return ObjectVerbGet - case service.ObjectSessionContext_HEAD: - return ObjectVerbHead - case service.ObjectSessionContext_SEARCH: - return ObjectVerbSearch - case service.ObjectSessionContext_DELETE: - return ObjectVerbDelete - case service.ObjectSessionContext_RANGE: - return ObjectVerbRange - case service.ObjectSessionContext_RANGEHASH: - return ObjectVerbRangeHash - default: - return ObjectVerbUnknown - } -} - -func ObjectSessionContextToGRPCMessage(c *ObjectSessionContext) *service.ObjectSessionContext { - if c == nil { - return nil - } - - m := new(service.ObjectSessionContext) - - m.SetVerb( - ObjectSessionVerbToGRPCField(c.GetVerb()), - ) - - m.SetAddress( - refs.AddressToGRPCMessage(c.GetAddress()), - ) - - return m -} - -func ObjectSessionContextFromGRPCMessage(m *service.ObjectSessionContext) *ObjectSessionContext { - if m == nil { - return nil - } - - c := new(ObjectSessionContext) - - c.SetVerb( - ObjectSessionVerbFromGRPCField(m.GetVerb()), - ) - - c.SetAddress( - refs.AddressFromGRPCMessage(m.GetAddress()), - ) - - return c -} - -func SessionTokenBodyToGRPCMessage(t *SessionTokenBody) *service.SessionToken_Body { - if t == nil { - return nil - } - - m := new(service.SessionToken_Body) - - switch v := t.GetContext(); t := v.(type) { - case nil: - case *ObjectSessionContext: - m.SetObjectServiceContext( - ObjectSessionContextToGRPCMessage(t), - ) - default: - panic(fmt.Sprintf("unknown session context %T", t)) - } - - m.SetId(t.GetID()) - - m.SetOwnerId( - refs.OwnerIDToGRPCMessage(t.GetOwnerID()), - ) - - m.SetLifetime( - TokenLifetimeToGRPCMessage(t.GetLifetime()), - ) - - m.SetSessionKey(t.GetSessionKey()) - - return m -} - -func SessionTokenBodyFromGRPCMessage(m *service.SessionToken_Body) *SessionTokenBody { - if m == nil { - return nil - } - - t := new(SessionTokenBody) - - switch v := m.GetContext().(type) { - case nil: - case *service.SessionToken_Body_Object: - t.SetContext( - ObjectSessionContextFromGRPCMessage(v.Object), - ) - default: - panic(fmt.Sprintf("unknown session context %T", v)) - } - - t.SetID(m.GetId()) - - t.SetOwnerID( - refs.OwnerIDFromGRPCMessage(m.GetOwnerId()), - ) - - t.SetLifetime( - TokenLifetimeFromGRPCMessage(m.GetLifetime()), - ) - - t.SetSessionKey(m.GetSessionKey()) - - return t -} diff --git a/v2/service/grpc/verify.go b/v2/service/grpc/verify.go deleted file mode 100644 index c9081fd6..00000000 --- a/v2/service/grpc/verify.go +++ /dev/null @@ -1,71 +0,0 @@ -package service - -// 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 - } -} - -// SetBodySignature sets signature of the request body. -func (m *RequestVerificationHeader) SetBodySignature(v *Signature) { - if m != nil { - m.BodySignature = v - } -} - -// SetMetaSignature sets signature of the request meta. -func (m *RequestVerificationHeader) SetMetaSignature(v *Signature) { - if m != nil { - m.MetaSignature = v - } -} - -// SetOriginSignature sets signature of the origin verification header of the request. -func (m *RequestVerificationHeader) SetOriginSignature(v *Signature) { - if m != nil { - m.OriginSignature = v - } -} - -// SetOrigin sets origin verification header of the request. -func (m *RequestVerificationHeader) SetOrigin(v *RequestVerificationHeader) { - if m != nil { - m.Origin = v - } -} - -// SetBodySignature sets signature of the response body. -func (m *ResponseVerificationHeader) SetBodySignature(v *Signature) { - if m != nil { - m.BodySignature = v - } -} - -// SetMetaSignature sets signature of the response meta. -func (m *ResponseVerificationHeader) SetMetaSignature(v *Signature) { - if m != nil { - m.MetaSignature = v - } -} - -// SetOriginSignature sets signature of the origin verification header of the response. -func (m *ResponseVerificationHeader) SetOriginSignature(v *Signature) { - if m != nil { - m.OriginSignature = v - } -} - -// SetOrigin sets origin verification header of the response. -func (m *ResponseVerificationHeader) SetOrigin(v *ResponseVerificationHeader) { - if m != nil { - m.Origin = v - } -} diff --git a/v2/service/grpc/version.go b/v2/service/grpc/version.go deleted file mode 100644 index cca5fe40..00000000 --- a/v2/service/grpc/version.go +++ /dev/null @@ -1,3 +0,0 @@ -package service - -var APIVersion = Version{Major: 2, Minor: 0} diff --git a/v2/service/marshal.go b/v2/service/marshal.go deleted file mode 100644 index f30c9dff..00000000 --- a/v2/service/marshal.go +++ /dev/null @@ -1,752 +0,0 @@ -package service - -import ( - "github.com/nspcc-dev/neofs-api-go/util/proto" -) - -const ( - signatureKeyField = 1 - signatureValueField = 2 - - versionMajorField = 1 - versionMinorField = 2 - - xheaderKeyField = 1 - xheaderValueField = 2 - - lifetimeExpirationField = 1 - lifetimeNotValidBeforeField = 2 - lifetimeIssuedAtField = 3 - - objectCtxVerbField = 1 - objectCtxAddressField = 2 - - sessionTokenBodyIDField = 1 - sessionTokenBodyOwnerField = 2 - sessionTokenBodyLifetimeField = 3 - sessionTokenBodyKeyField = 4 - sessionTokenBodyObjectCtxField = 5 - - sessionTokenBodyField = 1 - sessionTokenSignatureField = 2 - - bearerTokenBodyACLField = 1 - bearerTokenBodyOwnerField = 2 - bearerTokenBodyLifetimeField = 3 - - bearerTokenBodyField = 1 - bearerTokenSignatureField = 2 - - reqMetaHeaderVersionField = 1 - reqMetaHeaderEpochField = 2 - reqMetaHeaderTTLField = 3 - reqMetaHeaderXHeadersField = 4 - reqMetaHeaderSessionTokenField = 5 - reqMetaHeaderBearerTokenField = 6 - reqMetaHeaderOriginField = 7 - - reqVerifHeaderBodySignatureField = 1 - reqVerifHeaderMetaSignatureField = 2 - reqVerifHeaderOriginSignatureField = 3 - reqVerifHeaderOriginField = 4 - - respMetaHeaderVersionField = 1 - respMetaHeaderEpochField = 2 - respMetaHeaderTTLField = 3 - respMetaHeaderXHeadersField = 4 - respMetaHeaderOriginField = 5 - - respVerifHeaderBodySignatureField = 1 - respVerifHeaderMetaSignatureField = 2 - respVerifHeaderOriginSignatureField = 3 - respVerifHeaderOriginField = 4 -) - -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 -} - -func (x *XHeader) StableMarshal(buf []byte) ([]byte, error) { - if x == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, x.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.StringMarshal(xheaderKeyField, buf[offset:], x.key) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.StringMarshal(xheaderValueField, buf[offset:], x.val) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (x *XHeader) StableSize() (size int) { - if x == nil { - return 0 - } - - size += proto.StringSize(xheaderKeyField, x.key) - size += proto.StringSize(xheaderValueField, x.val) - - return size -} - -func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) { - if l == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, l.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (l *TokenLifetime) StableSize() (size int) { - if l == nil { - return 0 - } - - size += proto.UInt64Size(lifetimeExpirationField, l.exp) - size += proto.UInt64Size(lifetimeNotValidBeforeField, l.nbf) - size += proto.UInt64Size(lifetimeIssuedAtField, l.iat) - - return size -} - -func (c *ObjectSessionContext) StableMarshal(buf []byte) ([]byte, error) { - if c == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, c.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb)) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (c *ObjectSessionContext) StableSize() (size int) { - if c == nil { - return 0 - } - - size += proto.EnumSize(objectCtxVerbField, int32(c.verb)) - size += proto.NestedStructureSize(objectCtxAddressField, c.addr) - - return size -} - -func (t *SessionTokenBody) StableMarshal(buf []byte) ([]byte, error) { - if t == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, t.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf[offset:], t.lifetime) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.BytesMarshal(sessionTokenBodyKeyField, buf[offset:], t.sessionKey) - if err != nil { - return nil, err - } - - offset += n - - if t.ctx != nil { - switch v := t.ctx.(type) { - case *ObjectSessionContext: - _, err = proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf[offset:], v) - if err != nil { - return nil, err - } - default: - panic("cannot marshal unknown session token context") - } - } - - return buf, nil -} - -func (t *SessionTokenBody) StableSize() (size int) { - if t == nil { - return 0 - } - - size += proto.BytesSize(sessionTokenBodyIDField, t.id) - size += proto.NestedStructureSize(sessionTokenBodyOwnerField, t.ownerID) - size += proto.NestedStructureSize(sessionTokenBodyLifetimeField, t.lifetime) - size += proto.BytesSize(sessionTokenBodyKeyField, t.sessionKey) - - if t.ctx != nil { - switch v := t.ctx.(type) { - case *ObjectSessionContext: - size += proto.NestedStructureSize(sessionTokenBodyObjectCtxField, v) - default: - panic("cannot marshal unknown session token context") - } - } - - return size -} - -func (t *SessionToken) StableMarshal(buf []byte) ([]byte, error) { - if t == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, t.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.NestedStructureMarshal(sessionTokenBodyField, buf[offset:], t.body) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.NestedStructureMarshal(sessionTokenSignatureField, buf[offset:], t.sig) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (t *SessionToken) StableSize() (size int) { - if t == nil { - return 0 - } - - size += proto.NestedStructureSize(sessionTokenBodyField, t.body) - size += proto.NestedStructureSize(sessionTokenSignatureField, t.sig) - - return size -} - -func (bt *BearerTokenBody) StableMarshal(buf []byte) ([]byte, error) { - if bt == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, bt.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.NestedStructureMarshal(bearerTokenBodyACLField, buf[offset:], bt.eacl) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(bearerTokenBodyOwnerField, buf[offset:], bt.ownerID) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.NestedStructureMarshal(bearerTokenBodyLifetimeField, buf[offset:], bt.lifetime) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (bt *BearerTokenBody) StableSize() (size int) { - if bt == nil { - return 0 - } - - size += proto.NestedStructureSize(bearerTokenBodyACLField, bt.eacl) - size += proto.NestedStructureSize(bearerTokenBodyOwnerField, bt.ownerID) - size += proto.NestedStructureSize(bearerTokenBodyLifetimeField, bt.lifetime) - - return size -} - -func (bt *BearerToken) StableMarshal(buf []byte) ([]byte, error) { - if bt == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, bt.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.NestedStructureMarshal(bearerTokenBodyField, buf[offset:], bt.body) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.NestedStructureMarshal(bearerTokenSignatureField, buf[offset:], bt.sig) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (bt *BearerToken) StableSize() (size int) { - if bt == nil { - return 0 - } - - size += proto.NestedStructureSize(bearerTokenBodyField, bt.body) - size += proto.NestedStructureSize(bearerTokenSignatureField, bt.sig) - - return size -} - -func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) { - if r == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf[offset:], r.version) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl) - if err != nil { - return nil, err - } - - offset += n - - for i := range r.xHeaders { - n, err = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], r.xHeaders[i]) - if err != nil { - return nil, err - } - - offset += n - } - - n, err = proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf[offset:], r.sessionToken) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf[offset:], r.bearerToken) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (r *RequestMetaHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - if r.version != nil { - size += proto.NestedStructureSize(reqMetaHeaderVersionField, r.version) - } - - size += proto.UInt64Size(reqMetaHeaderEpochField, r.epoch) - size += proto.UInt32Size(reqMetaHeaderTTLField, r.ttl) - - for i := range r.xHeaders { - size += proto.NestedStructureSize(reqMetaHeaderXHeadersField, r.xHeaders[i]) - } - - size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken) - size += proto.NestedStructureSize(reqMetaHeaderBearerTokenField, r.bearerToken) - size += proto.NestedStructureSize(reqMetaHeaderOriginField, r.origin) - - return size -} - -func (r *RequestVerificationHeader) StableMarshal(buf []byte) ([]byte, error) { - if r == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf[offset:], r.bodySig) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf[offset:], r.originSig) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf[offset:], r.origin) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (r *RequestVerificationHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(reqVerifHeaderBodySignatureField, r.bodySig) - size += proto.NestedStructureSize(reqVerifHeaderMetaSignatureField, r.metaSig) - size += proto.NestedStructureSize(reqVerifHeaderOriginSignatureField, r.originSig) - size += proto.NestedStructureSize(reqVerifHeaderOriginField, r.origin) - - return size -} - -func (r *ResponseMetaHeader) StableMarshal(buf []byte) ([]byte, error) { - if r == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.NestedStructureMarshal(respMetaHeaderVersionField, buf[offset:], r.version) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl) - if err != nil { - return nil, err - } - - offset += n - - for i := range r.xHeaders { - n, err = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], r.xHeaders[i]) - if err != nil { - return nil, err - } - - offset += n - } - - _, err = proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (r *ResponseMetaHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - if r.version != nil { - size += proto.NestedStructureSize(respMetaHeaderVersionField, r.version) - } - - size += proto.UInt64Size(respMetaHeaderEpochField, r.epoch) - size += proto.UInt32Size(respMetaHeaderTTLField, r.ttl) - - for i := range r.xHeaders { - size += proto.NestedStructureSize(respMetaHeaderXHeadersField, r.xHeaders[i]) - } - - size += proto.NestedStructureSize(respMetaHeaderOriginField, r.origin) - - return size -} - -func (r *ResponseVerificationHeader) StableMarshal(buf []byte) ([]byte, error) { - if r == nil { - return []byte{}, nil - } - - if buf == nil { - buf = make([]byte, r.StableSize()) - } - - var ( - offset, n int - err error - ) - - n, err = proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf[offset:], r.bodySig) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) - if err != nil { - return nil, err - } - - offset += n - - n, err = proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf[offset:], r.originSig) - if err != nil { - return nil, err - } - - offset += n - - _, err = proto.NestedStructureMarshal(respVerifHeaderOriginField, buf[offset:], r.origin) - if err != nil { - return nil, err - } - - return buf, nil -} - -func (r *ResponseVerificationHeader) StableSize() (size int) { - if r == nil { - return 0 - } - - size += proto.NestedStructureSize(respVerifHeaderBodySignatureField, r.bodySig) - size += proto.NestedStructureSize(respVerifHeaderMetaSignatureField, r.metaSig) - size += proto.NestedStructureSize(respVerifHeaderOriginSignatureField, r.originSig) - size += proto.NestedStructureSize(respVerifHeaderOriginField, r.origin) - - return size -} diff --git a/v2/service/marshal_test.go b/v2/service/marshal_test.go deleted file mode 100644 index 63030ae4..00000000 --- a/v2/service/marshal_test.go +++ /dev/null @@ -1,401 +0,0 @@ -package service_test - -import ( - "fmt" - "testing" - - "github.com/nspcc-dev/neofs-api-go/v2/acl" - "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" - grpc "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" - "github.com/stretchr/testify/require" -) - -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 := service.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 := service.VersionFromGRPCMessage(transport) - require.Equal(t, versionFrom, versionTo) - }) -} - -func TestXHeader_StableMarshal(t *testing.T) { - xheaderFrom := generateXHeader("X-Header-Key", "X-Header-Value") - transport := new(grpc.XHeader) - - t.Run("non empty", func(t *testing.T) { - wire, err := xheaderFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - xheaderTo := service.XHeaderFromGRPCMessage(transport) - require.Equal(t, xheaderFrom, xheaderTo) - }) -} - -func TestTokenLifetime_StableMarshal(t *testing.T) { - lifetimeFrom := generateLifetime(10, 20, 30) - transport := new(grpc.TokenLifetime) - - t.Run("non empty", func(t *testing.T) { - wire, err := lifetimeFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - lifetimeTo := service.TokenLifetimeFromGRPCMessage(transport) - require.Equal(t, lifetimeFrom, lifetimeTo) - }) -} - -func TestObjectSessionContext_StableMarshal(t *testing.T) { - objectCtxFrom := generateObjectCtx("Object ID") - transport := new(grpc.ObjectSessionContext) - - t.Run("non empty", func(t *testing.T) { - wire, err := objectCtxFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - objectCtxTo := service.ObjectSessionContextFromGRPCMessage(transport) - require.Equal(t, objectCtxFrom, objectCtxTo) - }) -} - -func TestSessionTokenBody_StableMarshal(t *testing.T) { - sessionTokenBodyFrom := generateSessionTokenBody("Session Token Body") - transport := new(grpc.SessionToken_Body) - - t.Run("non empty", func(t *testing.T) { - wire, err := sessionTokenBodyFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - sessionTokenBodyTo := service.SessionTokenBodyFromGRPCMessage(transport) - require.Equal(t, sessionTokenBodyFrom, sessionTokenBodyTo) - }) -} - -func TestSessionToken_StableMarshal(t *testing.T) { - sessionTokenFrom := generateSessionToken("Session Token") - transport := new(grpc.SessionToken) - - t.Run("non empty", func(t *testing.T) { - wire, err := sessionTokenFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - sessionTokenTo := service.SessionTokenFromGRPCMessage(transport) - require.Equal(t, sessionTokenFrom, sessionTokenTo) - }) -} - -func TestBearerTokenBody_StableMarshal(t *testing.T) { - bearerTokenBodyFrom := generateBearerTokenBody("Bearer Token Body") - transport := new(grpc.BearerToken_Body) - - t.Run("non empty", func(t *testing.T) { - wire, err := bearerTokenBodyFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - bearerTokenBodyTo := service.BearerTokenBodyFromGRPCMessage(transport) - require.Equal(t, bearerTokenBodyFrom, bearerTokenBodyTo) - }) -} - -func TestBearerToken_StableMarshal(t *testing.T) { - bearerTokenFrom := generateBearerToken("Bearer Token") - transport := new(grpc.BearerToken) - - t.Run("non empty", func(t *testing.T) { - wire, err := bearerTokenFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - bearerTokenTo := service.BearerTokenFromGRPCMessage(transport) - require.Equal(t, bearerTokenFrom, bearerTokenTo) - }) -} - -func TestRequestMetaHeader_StableMarshal(t *testing.T) { - metaHeaderOrigin := generateRequestMetaHeader(10, "Bearer One", "Session One") - metaHeaderFrom := generateRequestMetaHeader(20, "Bearer Two", "Session Two") - metaHeaderFrom.SetOrigin(metaHeaderOrigin) - transport := new(grpc.RequestMetaHeader) - - t.Run("non empty", func(t *testing.T) { - wire, err := metaHeaderFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - metaHeaderTo := service.RequestMetaHeaderFromGRPCMessage(transport) - require.Equal(t, metaHeaderFrom, metaHeaderTo) - }) -} - -func TestRequestVerificationHeader_StableMarshal(t *testing.T) { - verifHeaderOrigin := generateRequestVerificationHeader("Key", "Inside") - verifHeaderFrom := generateRequestVerificationHeader("Value", "Outside") - verifHeaderFrom.SetOrigin(verifHeaderOrigin) - transport := new(grpc.RequestVerificationHeader) - - t.Run("non empty", func(t *testing.T) { - wire, err := verifHeaderFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - verifHeaderTo := service.RequestVerificationHeaderFromGRPCMessage(transport) - require.Equal(t, verifHeaderFrom, verifHeaderTo) - }) -} - -func TestResponseMetaHeader_StableMarshal(t *testing.T) { - metaHeaderOrigin := generateResponseMetaHeader(10) - metaHeaderFrom := generateResponseMetaHeader(20) - metaHeaderFrom.SetOrigin(metaHeaderOrigin) - transport := new(grpc.ResponseMetaHeader) - - t.Run("non empty", func(t *testing.T) { - wire, err := metaHeaderFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - metaHeaderTo := service.ResponseMetaHeaderFromGRPCMessage(transport) - require.Equal(t, metaHeaderFrom, metaHeaderTo) - }) -} - -func TestResponseVerificationHeader_StableMarshal(t *testing.T) { - verifHeaderOrigin := generateResponseVerificationHeader("Key", "Inside") - verifHeaderFrom := generateResponseVerificationHeader("Value", "Outside") - verifHeaderFrom.SetOrigin(verifHeaderOrigin) - transport := new(grpc.ResponseVerificationHeader) - - t.Run("non empty", func(t *testing.T) { - wire, err := verifHeaderFrom.StableMarshal(nil) - require.NoError(t, err) - - err = transport.Unmarshal(wire) - require.NoError(t, err) - - verifHeaderTo := service.ResponseVerificationHeaderFromGRPCMessage(transport) - require.Equal(t, verifHeaderFrom, verifHeaderTo) - }) -} - -func generateSignature(k, v string) *service.Signature { - sig := new(service.Signature) - sig.SetKey([]byte(k)) - sig.SetSign([]byte(v)) - - return sig -} - -func generateVersion(maj, min uint32) *service.Version { - version := new(service.Version) - version.SetMajor(maj) - version.SetMinor(min) - - return version -} - -func generateXHeader(k, v string) *service.XHeader { - xheader := new(service.XHeader) - xheader.SetKey(k) - xheader.SetValue(v) - - return xheader -} - -func generateLifetime(exp, nbf, iat uint64) *service.TokenLifetime { - lifetime := new(service.TokenLifetime) - lifetime.SetExp(exp) - lifetime.SetNbf(nbf) - lifetime.SetIat(iat) - - return lifetime -} - -func generateObjectCtx(id string) *service.ObjectSessionContext { - objectCtx := new(service.ObjectSessionContext) - objectCtx.SetVerb(service.ObjectVerbPut) - - cid := new(refs.ContainerID) - cid.SetValue([]byte("ContainerID")) - - oid := new(refs.ObjectID) - oid.SetValue([]byte(id)) - - addr := new(refs.Address) - addr.SetContainerID(cid) - addr.SetObjectID(oid) - - objectCtx.SetAddress(addr) - - return objectCtx -} - -func generateEACL(n int, k, v string) *acl.Table { - target := new(acl.TargetInfo) - target.SetTarget(acl.TargetUser) - - keys := make([][]byte, n) - - for i := 0; i < n; i++ { - s := fmt.Sprintf("Public Key %d", i+1) - keys[i] = []byte(s) - } - - filter := new(acl.HeaderFilter) - filter.SetHeaderType(acl.HeaderTypeObject) - filter.SetMatchType(acl.MatchTypeStringEqual) - filter.SetName(k) - filter.SetValue(v) - - record := new(acl.Record) - record.SetOperation(acl.OperationHead) - record.SetAction(acl.ActionDeny) - record.SetTargets([]*acl.TargetInfo{target}) - record.SetFilters([]*acl.HeaderFilter{filter}) - - table := new(acl.Table) - cid := new(refs.ContainerID) - cid.SetValue([]byte("Container ID")) - - table.SetContainerID(cid) - table.SetRecords([]*acl.Record{record}) - - return table -} - -func generateSessionTokenBody(id string) *service.SessionTokenBody { - owner := new(refs.OwnerID) - owner.SetValue([]byte("Owner ID")) - - tokenBody := new(service.SessionTokenBody) - tokenBody.SetID([]byte(id)) - tokenBody.SetOwnerID(owner) - tokenBody.SetSessionKey([]byte(id)) - tokenBody.SetLifetime(generateLifetime(1, 2, 3)) - tokenBody.SetContext(generateObjectCtx(id)) - - return tokenBody -} - -func generateSessionToken(id string) *service.SessionToken { - sessionToken := new(service.SessionToken) - sessionToken.SetBody(generateSessionTokenBody(id)) - sessionToken.SetSignature(generateSignature("id", id)) - - return sessionToken -} - -func generateBearerTokenBody(id string) *service.BearerTokenBody { - owner := new(refs.OwnerID) - owner.SetValue([]byte(id)) - - tokenBody := new(service.BearerTokenBody) - tokenBody.SetOwnerID(owner) - tokenBody.SetLifetime(generateLifetime(1, 2, 3)) - tokenBody.SetEACL(generateEACL(10, "id", id)) - - return tokenBody -} - -func generateBearerToken(id string) *service.BearerToken { - bearerToken := new(service.BearerToken) - bearerToken.SetBody(generateBearerTokenBody(id)) - bearerToken.SetSignature(generateSignature("id", id)) - - return bearerToken -} - -func generateRequestMetaHeader(n int, b, s string) *service.RequestMetaHeader { - reqMetaHeader := new(service.RequestMetaHeader) - reqMetaHeader.SetVersion(generateVersion(2, 0)) - reqMetaHeader.SetEpoch(uint64(n)) - reqMetaHeader.SetTTL(uint32(n)) - reqMetaHeader.SetXHeaders([]*service.XHeader{ - generateXHeader("key-one", "val-one"), - generateXHeader("key-two", "val-two"), - }) - reqMetaHeader.SetBearerToken(generateBearerToken(b)) - reqMetaHeader.SetSessionToken(generateSessionToken(s)) - - return reqMetaHeader -} - -func generateRequestVerificationHeader(k, v string) *service.RequestVerificationHeader { - reqVerifHeader := new(service.RequestVerificationHeader) - reqVerifHeader.SetBodySignature(generateSignature(k+"body", v+"body")) - reqVerifHeader.SetMetaSignature(generateSignature(k+"meta", v+"meta")) - reqVerifHeader.SetOriginSignature(generateSignature(k+"orig", v+"orig")) - - return reqVerifHeader -} - -func generateResponseMetaHeader(n int) *service.ResponseMetaHeader { - respMetaHeader := new(service.ResponseMetaHeader) - respMetaHeader.SetVersion(generateVersion(2, 0)) - respMetaHeader.SetEpoch(uint64(n)) - respMetaHeader.SetTTL(uint32(n)) - respMetaHeader.SetXHeaders([]*service.XHeader{ - generateXHeader("key-one", "val-one"), - generateXHeader("key-two", "val-two"), - }) - - return respMetaHeader -} - -func generateResponseVerificationHeader(k, v string) *service.ResponseVerificationHeader { - respVerifHeader := new(service.ResponseVerificationHeader) - respVerifHeader.SetBodySignature(generateSignature(k+"body", v+"body")) - respVerifHeader.SetMetaSignature(generateSignature(k+"meta", v+"meta")) - respVerifHeader.SetOriginSignature(generateSignature(k+"orig", v+"orig")) - - return respVerifHeader -} diff --git a/v2/service/service.go b/v2/service/service.go deleted file mode 100644 index b40106ab..00000000 --- a/v2/service/service.go +++ /dev/null @@ -1,721 +0,0 @@ -package service - -import ( - "github.com/nspcc-dev/neofs-api-go/v2/acl" - "github.com/nspcc-dev/neofs-api-go/v2/refs" -) - -type Signature struct { - key, sign []byte -} - -type Version struct { - major, minor uint32 -} - -type XHeader struct { - key, val string -} - -type TokenLifetime struct { - exp, nbf, iat uint64 -} - -type ObjectSessionVerb uint32 - -type ObjectSessionContext struct { - verb ObjectSessionVerb - - addr *refs.Address -} - -type SessionTokenContext interface { - sessionTokenContext() -} - -type SessionTokenBody struct { - id []byte - - ownerID *refs.OwnerID - - lifetime *TokenLifetime - - sessionKey []byte - - ctx SessionTokenContext -} - -type SessionToken struct { - body *SessionTokenBody - - sig *Signature -} - -type BearerTokenBody struct { - eacl *acl.Table - - ownerID *refs.OwnerID - - lifetime *TokenLifetime -} - -type BearerToken struct { - body *BearerTokenBody - - sig *Signature -} - -type RequestVerificationHeader struct { - bodySig, metaSig, originSig *Signature - - origin *RequestVerificationHeader -} - -type RequestMetaHeader struct { - version *Version - - ttl uint32 - - epoch uint64 - - xHeaders []*XHeader - - sessionToken *SessionToken - - bearerToken *BearerToken - - origin *RequestMetaHeader -} - -type ResponseVerificationHeader struct { - bodySig, metaSig, originSig *Signature - - origin *ResponseVerificationHeader -} - -type ResponseMetaHeader struct { - version *Version - - ttl uint32 - - epoch uint64 - - xHeaders []*XHeader - - origin *ResponseMetaHeader -} - -const ( - ObjectVerbUnknown ObjectSessionVerb = iota - ObjectVerbPut - ObjectVerbGet - ObjectVerbHead - ObjectVerbSearch - ObjectVerbDelete - ObjectVerbRange - ObjectVerbRangeHash -) - -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 - } -} - -func (x *XHeader) GetKey() string { - if x != nil { - return x.key - } - - return "" -} - -func (x *XHeader) SetKey(v string) { - if x != nil { - x.key = v - } -} - -func (x *XHeader) GetValue() string { - if x != nil { - return x.val - } - - return "" -} - -func (x *XHeader) SetValue(v string) { - if x != nil { - x.val = v - } -} - -func (r *RequestVerificationHeader) GetBodySignature() *Signature { - if r != nil { - return r.bodySig - } - - return nil -} - -func (r *RequestVerificationHeader) SetBodySignature(v *Signature) { - if r != nil { - r.bodySig = v - } -} - -func (r *RequestVerificationHeader) GetMetaSignature() *Signature { - if r != nil { - return r.metaSig - } - - return nil -} - -func (r *RequestVerificationHeader) SetMetaSignature(v *Signature) { - if r != nil { - r.metaSig = v - } -} - -func (r *RequestVerificationHeader) GetOriginSignature() *Signature { - if r != nil { - return r.originSig - } - - return nil -} - -func (r *RequestVerificationHeader) SetOriginSignature(v *Signature) { - if r != nil { - r.originSig = v - } -} - -func (r *RequestVerificationHeader) GetOrigin() *RequestVerificationHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *RequestVerificationHeader) SetOrigin(v *RequestVerificationHeader) { - if r != nil { - r.origin = v - } -} - -func (r *RequestMetaHeader) GetVersion() *Version { - if r != nil { - return r.version - } - - return nil -} - -func (r *RequestMetaHeader) SetVersion(v *Version) { - if r != nil { - r.version = v - } -} - -func (r *RequestMetaHeader) GetTTL() uint32 { - if r != nil { - return r.ttl - } - - return 0 -} - -func (r *RequestMetaHeader) SetTTL(v uint32) { - if r != nil { - r.ttl = v - } -} - -func (r *RequestMetaHeader) GetEpoch() uint64 { - if r != nil { - return r.epoch - } - - return 0 -} - -func (r *RequestMetaHeader) SetEpoch(v uint64) { - if r != nil { - r.epoch = v - } -} - -func (r *RequestMetaHeader) GetXHeaders() []*XHeader { - if r != nil { - return r.xHeaders - } - - return nil -} - -func (r *RequestMetaHeader) SetXHeaders(v []*XHeader) { - if r != nil { - r.xHeaders = v - } -} - -func (r *RequestMetaHeader) GetSessionToken() *SessionToken { - if r != nil { - return r.sessionToken - } - - return nil -} - -func (r *RequestMetaHeader) SetSessionToken(v *SessionToken) { - if r != nil { - r.sessionToken = v - } -} - -func (r *RequestMetaHeader) GetBearerToken() *BearerToken { - if r != nil { - return r.bearerToken - } - - return nil -} - -func (r *RequestMetaHeader) SetBearerToken(v *BearerToken) { - if r != nil { - r.bearerToken = v - } -} - -func (r *RequestMetaHeader) GetOrigin() *RequestMetaHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *RequestMetaHeader) SetOrigin(v *RequestMetaHeader) { - if r != nil { - r.origin = v - } -} - -func (l *TokenLifetime) GetExp() uint64 { - if l != nil { - return l.exp - } - - return 0 -} - -func (l *TokenLifetime) SetExp(v uint64) { - if l != nil { - l.exp = v - } -} - -func (l *TokenLifetime) GetNbf() uint64 { - if l != nil { - return l.nbf - } - - return 0 -} - -func (l *TokenLifetime) SetNbf(v uint64) { - if l != nil { - l.nbf = v - } -} - -func (l *TokenLifetime) GetIat() uint64 { - if l != nil { - return l.iat - } - - return 0 -} - -func (l *TokenLifetime) SetIat(v uint64) { - if l != nil { - l.iat = v - } -} - -func (bt *BearerTokenBody) GetEACL() *acl.Table { - if bt != nil { - return bt.eacl - } - - return nil -} - -func (bt *BearerTokenBody) SetEACL(v *acl.Table) { - if bt != nil { - bt.eacl = v - } -} - -func (bt *BearerTokenBody) GetOwnerID() *refs.OwnerID { - if bt != nil { - return bt.ownerID - } - - return nil -} - -func (bt *BearerTokenBody) SetOwnerID(v *refs.OwnerID) { - if bt != nil { - bt.ownerID = v - } -} - -func (bt *BearerTokenBody) GetLifetime() *TokenLifetime { - if bt != nil { - return bt.lifetime - } - - return nil -} - -func (bt *BearerTokenBody) SetLifetime(v *TokenLifetime) { - if bt != nil { - bt.lifetime = v - } -} - -func (bt *BearerToken) GetBody() *BearerTokenBody { - if bt != nil { - return bt.body - } - - return nil -} - -func (bt *BearerToken) SetBody(v *BearerTokenBody) { - if bt != nil { - bt.body = v - } -} - -func (bt *BearerToken) GetSignature() *Signature { - if bt != nil { - return bt.sig - } - - return nil -} - -func (bt *BearerToken) SetSignature(v *Signature) { - if bt != nil { - bt.sig = v - } -} - -func (r *ResponseVerificationHeader) GetBodySignature() *Signature { - if r != nil { - return r.bodySig - } - - return nil -} - -func (r *ResponseVerificationHeader) SetBodySignature(v *Signature) { - if r != nil { - r.bodySig = v - } -} - -func (r *ResponseVerificationHeader) GetMetaSignature() *Signature { - if r != nil { - return r.metaSig - } - - return nil -} - -func (r *ResponseVerificationHeader) SetMetaSignature(v *Signature) { - if r != nil { - r.metaSig = v - } -} - -func (r *ResponseVerificationHeader) GetOriginSignature() *Signature { - if r != nil { - return r.originSig - } - - return nil -} - -func (r *ResponseVerificationHeader) SetOriginSignature(v *Signature) { - if r != nil { - r.originSig = v - } -} - -func (r *ResponseVerificationHeader) GetOrigin() *ResponseVerificationHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *ResponseVerificationHeader) SetOrigin(v *ResponseVerificationHeader) { - if r != nil { - r.origin = v - } -} - -func (r *ResponseMetaHeader) GetVersion() *Version { - if r != nil { - return r.version - } - - return nil -} - -func (r *ResponseMetaHeader) SetVersion(v *Version) { - if r != nil { - r.version = v - } -} - -func (r *ResponseMetaHeader) GetTTL() uint32 { - if r != nil { - return r.ttl - } - - return 0 -} - -func (r *ResponseMetaHeader) SetTTL(v uint32) { - if r != nil { - r.ttl = v - } -} - -func (r *ResponseMetaHeader) GetEpoch() uint64 { - if r != nil { - return r.epoch - } - - return 0 -} - -func (r *ResponseMetaHeader) SetEpoch(v uint64) { - if r != nil { - r.epoch = v - } -} - -func (r *ResponseMetaHeader) GetXHeaders() []*XHeader { - if r != nil { - return r.xHeaders - } - - return nil -} - -func (r *ResponseMetaHeader) SetXHeaders(v []*XHeader) { - if r != nil { - r.xHeaders = v - } -} - -func (r *ResponseMetaHeader) GetOrigin() *ResponseMetaHeader { - if r != nil { - return r.origin - } - - return nil -} - -func (r *ResponseMetaHeader) SetOrigin(v *ResponseMetaHeader) { - if r != nil { - r.origin = v - } -} - -func (c *ObjectSessionContext) sessionTokenContext() {} - -func (c *ObjectSessionContext) GetVerb() ObjectSessionVerb { - if c != nil { - return c.verb - } - - return ObjectVerbUnknown -} - -func (c *ObjectSessionContext) SetVerb(v ObjectSessionVerb) { - if c != nil { - c.verb = v - } -} - -func (c *ObjectSessionContext) GetAddress() *refs.Address { - if c != nil { - return c.addr - } - - return nil -} - -func (c *ObjectSessionContext) SetAddress(v *refs.Address) { - if c != nil { - c.addr = v - } -} - -func (t *SessionTokenBody) GetID() []byte { - if t != nil { - return t.id - } - - return nil -} - -func (t *SessionTokenBody) SetID(v []byte) { - if t != nil { - t.id = v - } -} - -func (t *SessionTokenBody) GetOwnerID() *refs.OwnerID { - if t != nil { - return t.ownerID - } - - return nil -} - -func (t *SessionTokenBody) SetOwnerID(v *refs.OwnerID) { - if t != nil { - t.ownerID = v - } -} - -func (t *SessionTokenBody) GetLifetime() *TokenLifetime { - if t != nil { - return t.lifetime - } - - return nil -} - -func (t *SessionTokenBody) SetLifetime(v *TokenLifetime) { - if t != nil { - t.lifetime = v - } -} - -func (t *SessionTokenBody) GetSessionKey() []byte { - if t != nil { - return t.sessionKey - } - - return nil -} - -func (t *SessionTokenBody) SetSessionKey(v []byte) { - if t != nil { - t.sessionKey = v - } -} - -func (t *SessionTokenBody) GetContext() SessionTokenContext { - if t != nil { - return t.ctx - } - - return nil -} - -func (t *SessionTokenBody) SetContext(v SessionTokenContext) { - if t != nil { - t.ctx = v - } -} - -func (t *SessionToken) GetBody() *SessionTokenBody { - if t != nil { - return t.body - } - - return nil -} - -func (t *SessionToken) SetBody(v *SessionTokenBody) { - if t != nil { - t.body = v - } -} - -func (t *SessionToken) GetSignature() *Signature { - if t != nil { - return t.sig - } - - return nil -} - -func (t *SessionToken) SetSignature(v *Signature) { - if t != nil { - t.sig = v - } -} diff --git a/v2/session/convert.go b/v2/session/convert.go index 5d5a60e7..5d73dc43 100644 --- a/v2/session/convert.go +++ b/v2/session/convert.go @@ -1,8 +1,10 @@ package session import ( + "fmt" + + "github.com/nspcc-dev/neofs-api-go/v2/acl" "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc" ) @@ -17,9 +19,7 @@ func CreateRequestBodyToGRPCMessage(c *CreateRequestBody) *session.CreateRequest refs.OwnerIDToGRPCMessage(c.GetOwnerID()), ) - m.SetLifetime( - service.TokenLifetimeToGRPCMessage(c.GetLifetime()), - ) + m.SetExpiration(c.GetExpiration()) return m } @@ -35,9 +35,7 @@ func CreateRequestBodyFromGRPCMessage(m *session.CreateRequest_Body) *CreateRequ refs.OwnerIDFromGRPCMessage(m.GetOwnerId()), ) - c.SetLifetime( - service.TokenLifetimeFromGRPCMessage(m.GetLifetime()), - ) + c.SetExpiration(m.GetExpiration()) return c } @@ -53,7 +51,7 @@ func CreateRequestToGRPCMessage(c *CreateRequest) *session.CreateRequest { CreateRequestBodyToGRPCMessage(c.GetBody()), ) - service.RequestHeadersToGRPC(c, m) + RequestHeadersToGRPC(c, m) return m } @@ -69,7 +67,7 @@ func CreateRequestFromGRPCMessage(m *session.CreateRequest) *CreateRequest { CreateRequestBodyFromGRPCMessage(m.GetBody()), ) - service.RequestHeadersFromGRPC(m, c) + RequestHeadersFromGRPC(m, c) return c } @@ -111,7 +109,7 @@ func CreateResponseToGRPCMessage(c *CreateResponse) *session.CreateResponse { CreateResponseBodyToGRPCMessage(c.GetBody()), ) - service.ResponseHeadersToGRPC(c, m) + ResponseHeadersToGRPC(c, m) return m } @@ -127,7 +125,555 @@ func CreateResponseFromGRPCMessage(m *session.CreateResponse) *CreateResponse { CreateResponseBodyFromGRPCMessage(m.GetBody()), ) - service.ResponseHeadersFromGRPC(m, c) + ResponseHeadersFromGRPC(m, c) return c } + +func TokenLifetimeToGRPCMessage(tl *TokenLifetime) *session.SessionToken_Body_TokenLifetime { + if tl == nil { + return nil + } + + m := new(session.SessionToken_Body_TokenLifetime) + + m.SetExp(tl.GetExp()) + m.SetNbf(tl.GetNbf()) + m.SetIat(tl.GetIat()) + + return m +} + +func TokenLifetimeFromGRPCMessage(m *session.SessionToken_Body_TokenLifetime) *TokenLifetime { + if m == nil { + return nil + } + + tl := new(TokenLifetime) + + tl.SetExp(m.GetExp()) + tl.SetNbf(m.GetNbf()) + tl.SetIat(m.GetIat()) + + return tl +} + +func XHeaderToGRPCMessage(x *XHeader) *session.XHeader { + if x == nil { + return nil + } + + m := new(session.XHeader) + + m.SetKey(x.GetKey()) + m.SetValue(x.GetValue()) + + return m +} + +func XHeaderFromGRPCMessage(m *session.XHeader) *XHeader { + if m == nil { + return nil + } + + x := new(XHeader) + + x.SetKey(m.GetKey()) + x.SetValue(m.GetValue()) + + return x +} + +func SessionTokenToGRPCMessage(t *SessionToken) *session.SessionToken { + if t == nil { + return nil + } + + m := new(session.SessionToken) + + m.SetBody( + SessionTokenBodyToGRPCMessage(t.GetBody()), + ) + + m.SetSignature( + refs.SignatureToGRPCMessage(t.GetSignature()), + ) + + return m +} + +func SessionTokenFromGRPCMessage(m *session.SessionToken) *SessionToken { + if m == nil { + return nil + } + + t := new(SessionToken) + + t.SetBody( + SessionTokenBodyFromGRPCMessage(m.GetBody()), + ) + + t.SetSignature( + refs.SignatureFromGRPCMessage(m.GetSignature()), + ) + + return t +} + +func RequestVerificationHeaderToGRPCMessage(r *RequestVerificationHeader) *session.RequestVerificationHeader { + if r == nil { + return nil + } + + m := new(session.RequestVerificationHeader) + + m.SetBodySignature( + refs.SignatureToGRPCMessage(r.GetBodySignature()), + ) + + m.SetMetaSignature( + refs.SignatureToGRPCMessage(r.GetMetaSignature()), + ) + + m.SetOriginSignature( + refs.SignatureToGRPCMessage(r.GetOriginSignature()), + ) + + m.SetOrigin( + RequestVerificationHeaderToGRPCMessage(r.GetOrigin()), + ) + + return m +} + +func RequestVerificationHeaderFromGRPCMessage(m *session.RequestVerificationHeader) *RequestVerificationHeader { + if m == nil { + return nil + } + + r := new(RequestVerificationHeader) + + r.SetBodySignature( + refs.SignatureFromGRPCMessage(m.GetBodySignature()), + ) + + r.SetMetaSignature( + refs.SignatureFromGRPCMessage(m.GetMetaSignature()), + ) + + r.SetOriginSignature( + refs.SignatureFromGRPCMessage(m.GetOriginSignature()), + ) + + r.SetOrigin( + RequestVerificationHeaderFromGRPCMessage(m.GetOrigin()), + ) + + return r +} + +func RequestMetaHeaderToGRPCMessage(r *RequestMetaHeader) *session.RequestMetaHeader { + if r == nil { + return nil + } + + m := new(session.RequestMetaHeader) + + m.SetTtl(r.GetTTL()) + m.SetEpoch(r.GetEpoch()) + + m.SetVersion( + refs.VersionToGRPCMessage(r.GetVersion()), + ) + + m.SetSessionToken( + SessionTokenToGRPCMessage(r.GetSessionToken()), + ) + + m.SetBearerToken( + acl.BearerTokenToGRPCMessage(r.GetBearerToken()), + ) + + m.SetOrigin( + RequestMetaHeaderToGRPCMessage(r.GetOrigin()), + ) + + xHeaders := r.GetXHeaders() + xHdrMsg := make([]*session.XHeader, 0, len(xHeaders)) + + for i := range xHeaders { + xHdrMsg = append(xHdrMsg, XHeaderToGRPCMessage(xHeaders[i])) + } + + m.SetXHeaders(xHdrMsg) + + return m +} + +func RequestMetaHeaderFromGRPCMessage(m *session.RequestMetaHeader) *RequestMetaHeader { + if m == nil { + return nil + } + + r := new(RequestMetaHeader) + + r.SetTTL(m.GetTtl()) + r.SetEpoch(m.GetEpoch()) + + r.SetVersion( + refs.VersionFromGRPCMessage(m.GetVersion()), + ) + + r.SetSessionToken( + SessionTokenFromGRPCMessage(m.GetSessionToken()), + ) + + r.SetBearerToken( + acl.BearerTokenFromGRPCMessage(m.GetBearerToken()), + ) + + r.SetOrigin( + RequestMetaHeaderFromGRPCMessage(m.GetOrigin()), + ) + + xHdrMsg := m.GetXHeaders() + xHeaders := make([]*XHeader, 0, len(xHdrMsg)) + + for i := range xHdrMsg { + xHeaders = append(xHeaders, XHeaderFromGRPCMessage(xHdrMsg[i])) + } + + r.SetXHeaders(xHeaders) + + return r +} + +func RequestHeadersToGRPC( + src interface { + GetMetaHeader() *RequestMetaHeader + GetVerificationHeader() *RequestVerificationHeader + }, + dst interface { + SetMetaHeader(*session.RequestMetaHeader) + SetVerifyHeader(*session.RequestVerificationHeader) + }, +) { + dst.SetMetaHeader( + RequestMetaHeaderToGRPCMessage(src.GetMetaHeader()), + ) + + dst.SetVerifyHeader( + RequestVerificationHeaderToGRPCMessage(src.GetVerificationHeader()), + ) +} + +func RequestHeadersFromGRPC( + src interface { + GetMetaHeader() *session.RequestMetaHeader + GetVerifyHeader() *session.RequestVerificationHeader + }, + dst interface { + SetMetaHeader(*RequestMetaHeader) + SetVerificationHeader(*RequestVerificationHeader) + }, +) { + dst.SetMetaHeader( + RequestMetaHeaderFromGRPCMessage(src.GetMetaHeader()), + ) + + dst.SetVerificationHeader( + RequestVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), + ) +} + +func ResponseVerificationHeaderToGRPCMessage(r *ResponseVerificationHeader) *session.ResponseVerificationHeader { + if r == nil { + return nil + } + + m := new(session.ResponseVerificationHeader) + + m.SetBodySignature( + refs.SignatureToGRPCMessage(r.GetBodySignature()), + ) + + m.SetMetaSignature( + refs.SignatureToGRPCMessage(r.GetMetaSignature()), + ) + + m.SetOriginSignature( + refs.SignatureToGRPCMessage(r.GetOriginSignature()), + ) + + m.SetOrigin( + ResponseVerificationHeaderToGRPCMessage(r.GetOrigin()), + ) + + return m +} + +func ResponseVerificationHeaderFromGRPCMessage(m *session.ResponseVerificationHeader) *ResponseVerificationHeader { + if m == nil { + return nil + } + + r := new(ResponseVerificationHeader) + + r.SetBodySignature( + refs.SignatureFromGRPCMessage(m.GetBodySignature()), + ) + + r.SetMetaSignature( + refs.SignatureFromGRPCMessage(m.GetMetaSignature()), + ) + + r.SetOriginSignature( + refs.SignatureFromGRPCMessage(m.GetOriginSignature()), + ) + + r.SetOrigin( + ResponseVerificationHeaderFromGRPCMessage(m.GetOrigin()), + ) + + return r +} + +func ResponseMetaHeaderToGRPCMessage(r *ResponseMetaHeader) *session.ResponseMetaHeader { + if r == nil { + return nil + } + + m := new(session.ResponseMetaHeader) + + m.SetTtl(r.GetTTL()) + m.SetEpoch(r.GetEpoch()) + + m.SetVersion( + refs.VersionToGRPCMessage(r.GetVersion()), + ) + + m.SetOrigin( + ResponseMetaHeaderToGRPCMessage(r.GetOrigin()), + ) + + xHeaders := r.GetXHeaders() + xHdrMsg := make([]*session.XHeader, 0, len(xHeaders)) + + for i := range xHeaders { + xHdrMsg = append(xHdrMsg, XHeaderToGRPCMessage(xHeaders[i])) + } + + m.SetXHeaders(xHdrMsg) + + return m +} + +func ResponseMetaHeaderFromGRPCMessage(m *session.ResponseMetaHeader) *ResponseMetaHeader { + if m == nil { + return nil + } + + r := new(ResponseMetaHeader) + + r.SetTTL(m.GetTtl()) + r.SetEpoch(m.GetEpoch()) + + r.SetVersion( + refs.VersionFromGRPCMessage(m.GetVersion()), + ) + + r.SetOrigin( + ResponseMetaHeaderFromGRPCMessage(m.GetOrigin()), + ) + + xHdrMsg := m.GetXHeaders() + xHeaders := make([]*XHeader, 0, len(xHdrMsg)) + + for i := range xHdrMsg { + xHeaders = append(xHeaders, XHeaderFromGRPCMessage(xHdrMsg[i])) + } + + r.SetXHeaders(xHeaders) + + return r +} + +func ResponseHeadersToGRPC( + src interface { + GetMetaHeader() *ResponseMetaHeader + GetVerificationHeader() *ResponseVerificationHeader + }, + dst interface { + SetMetaHeader(*session.ResponseMetaHeader) + SetVerifyHeader(*session.ResponseVerificationHeader) + }, +) { + dst.SetMetaHeader( + ResponseMetaHeaderToGRPCMessage(src.GetMetaHeader()), + ) + + dst.SetVerifyHeader( + ResponseVerificationHeaderToGRPCMessage(src.GetVerificationHeader()), + ) +} + +func ResponseHeadersFromGRPC( + src interface { + GetMetaHeader() *session.ResponseMetaHeader + GetVerifyHeader() *session.ResponseVerificationHeader + }, + dst interface { + SetMetaHeader(*ResponseMetaHeader) + SetVerificationHeader(*ResponseVerificationHeader) + }, +) { + dst.SetMetaHeader( + ResponseMetaHeaderFromGRPCMessage(src.GetMetaHeader()), + ) + + dst.SetVerificationHeader( + ResponseVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()), + ) +} + +func ObjectSessionVerbToGRPCField(v ObjectSessionVerb) session.ObjectSessionContext_Verb { + switch v { + case ObjectVerbPut: + return session.ObjectSessionContext_PUT + case ObjectVerbGet: + return session.ObjectSessionContext_GET + case ObjectVerbHead: + return session.ObjectSessionContext_HEAD + case ObjectVerbSearch: + return session.ObjectSessionContext_SEARCH + case ObjectVerbDelete: + return session.ObjectSessionContext_DELETE + case ObjectVerbRange: + return session.ObjectSessionContext_RANGE + case ObjectVerbRangeHash: + return session.ObjectSessionContext_RANGEHASH + default: + return session.ObjectSessionContext_VERB_UNSPECIFIED + } +} + +func ObjectSessionVerbFromGRPCField(v session.ObjectSessionContext_Verb) ObjectSessionVerb { + switch v { + case session.ObjectSessionContext_PUT: + return ObjectVerbPut + case session.ObjectSessionContext_GET: + return ObjectVerbGet + case session.ObjectSessionContext_HEAD: + return ObjectVerbHead + case session.ObjectSessionContext_SEARCH: + return ObjectVerbSearch + case session.ObjectSessionContext_DELETE: + return ObjectVerbDelete + case session.ObjectSessionContext_RANGE: + return ObjectVerbRange + case session.ObjectSessionContext_RANGEHASH: + return ObjectVerbRangeHash + default: + return ObjectVerbUnknown + } +} + +func ObjectSessionContextToGRPCMessage(c *ObjectSessionContext) *session.ObjectSessionContext { + if c == nil { + return nil + } + + m := new(session.ObjectSessionContext) + + m.SetVerb( + ObjectSessionVerbToGRPCField(c.GetVerb()), + ) + + m.SetAddress( + refs.AddressToGRPCMessage(c.GetAddress()), + ) + + return m +} + +func ObjectSessionContextFromGRPCMessage(m *session.ObjectSessionContext) *ObjectSessionContext { + if m == nil { + return nil + } + + c := new(ObjectSessionContext) + + c.SetVerb( + ObjectSessionVerbFromGRPCField(m.GetVerb()), + ) + + c.SetAddress( + refs.AddressFromGRPCMessage(m.GetAddress()), + ) + + return c +} + +func SessionTokenBodyToGRPCMessage(t *SessionTokenBody) *session.SessionToken_Body { + if t == nil { + return nil + } + + m := new(session.SessionToken_Body) + + switch v := t.GetContext(); t := v.(type) { + case nil: + case *ObjectSessionContext: + m.SetObjectSessionContext( + ObjectSessionContextToGRPCMessage(t), + ) + default: + panic(fmt.Sprintf("unknown session context %T", t)) + } + + m.SetId(t.GetID()) + + m.SetOwnerId( + refs.OwnerIDToGRPCMessage(t.GetOwnerID()), + ) + + m.SetLifetime( + TokenLifetimeToGRPCMessage(t.GetLifetime()), + ) + + m.SetSessionKey(t.GetSessionKey()) + + return m +} + +func SessionTokenBodyFromGRPCMessage(m *session.SessionToken_Body) *SessionTokenBody { + if m == nil { + return nil + } + + t := new(SessionTokenBody) + + switch v := m.GetContext().(type) { + case nil: + case *session.SessionToken_Body_Object: + t.SetContext( + ObjectSessionContextFromGRPCMessage(v.Object), + ) + default: + panic(fmt.Sprintf("unknown session context %T", v)) + } + + t.SetID(m.GetId()) + + t.SetOwnerID( + refs.OwnerIDFromGRPCMessage(m.GetOwnerId()), + ) + + t.SetLifetime( + TokenLifetimeFromGRPCMessage(m.GetLifetime()), + ) + + t.SetSessionKey(m.GetSessionKey()) + + return t +} diff --git a/v2/session/grpc/service.go b/v2/session/grpc/service.go index 8c786486..caaf7d9d 100644 --- a/v2/session/grpc/service.go +++ b/v2/session/grpc/service.go @@ -2,7 +2,6 @@ package session import ( refs "github.com/nspcc-dev/neofs-api-go/v2/refs/grpc" - service "github.com/nspcc-dev/neofs-api-go/v2/service/grpc" ) // SetOwnerId sets identifier of the session initiator. @@ -12,10 +11,10 @@ func (m *CreateRequest_Body) SetOwnerId(v *refs.OwnerID) { } } -// SetLifetime sets lifetime of the session. -func (m *CreateRequest_Body) SetLifetime(v *service.TokenLifetime) { +// SetExpiration sets lifetime of the session. +func (m *CreateRequest_Body) SetExpiration(v uint64) { if m != nil { - m.Lifetime = v + m.Expiration = v } } @@ -27,14 +26,14 @@ func (m *CreateRequest) SetBody(v *CreateRequest_Body) { } // SetMetaHeader sets meta header of the request. -func (m *CreateRequest) SetMetaHeader(v *service.RequestMetaHeader) { +func (m *CreateRequest) SetMetaHeader(v *RequestMetaHeader) { if m != nil { m.MetaHeader = v } } // SetVerifyHeader sets verification header of the request. -func (m *CreateRequest) SetVerifyHeader(v *service.RequestVerificationHeader) { +func (m *CreateRequest) SetVerifyHeader(v *RequestVerificationHeader) { if m != nil { m.VerifyHeader = v } @@ -62,14 +61,14 @@ func (m *CreateResponse) SetBody(v *CreateResponse_Body) { } // SetMetaHeader sets meta header of the response. -func (m *CreateResponse) SetMetaHeader(v *service.ResponseMetaHeader) { +func (m *CreateResponse) SetMetaHeader(v *ResponseMetaHeader) { if m != nil { m.MetaHeader = v } } // SetVerifyHeader sets verification header of the response. -func (m *CreateResponse) SetVerifyHeader(v *service.ResponseVerificationHeader) { +func (m *CreateResponse) SetVerifyHeader(v *ResponseVerificationHeader) { if m != nil { m.VerifyHeader = v } diff --git a/v2/service/grpc/meta.go b/v2/session/grpc/types.go similarity index 64% rename from v2/service/grpc/meta.go rename to v2/session/grpc/types.go index 9f5c1922..27dcd4bb 100644 --- a/v2/service/grpc/meta.go +++ b/v2/session/grpc/types.go @@ -1,4 +1,4 @@ -package service +package session import ( acl "github.com/nspcc-dev/neofs-api-go/v2/acl/grpc" @@ -19,36 +19,22 @@ func (m *XHeader) SetValue(v string) { } } -// 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 - } -} - // SetExp sets epoch number of the token expiration. -func (m *TokenLifetime) SetExp(v uint64) { +func (m *SessionToken_Body_TokenLifetime) SetExp(v uint64) { if m != nil { m.Exp = v } } // SetNbf sets starting epoch number of the token. -func (m *TokenLifetime) SetNbf(v uint64) { +func (m *SessionToken_Body_TokenLifetime) SetNbf(v uint64) { if m != nil { m.Nbf = v } } // SetIat sets the number of the epoch in which the token was issued. -func (m *TokenLifetime) SetIat(v uint64) { +func (m *SessionToken_Body_TokenLifetime) SetIat(v uint64) { if m != nil { m.Iat = v } @@ -69,7 +55,7 @@ func (m *SessionToken_Body) SetOwnerId(v *refs.OwnerID) { } // SetLifetime sets lifetime of the session token. -func (m *SessionToken_Body) SetLifetime(v *TokenLifetime) { +func (m *SessionToken_Body) SetLifetime(v *SessionToken_Body_TokenLifetime) { if m != nil { m.Lifetime = v } @@ -83,7 +69,7 @@ func (m *SessionToken_Body) SetSessionKey(v []byte) { } // SetObjectAddressContext sets object context of the session token. -func (m *SessionToken_Body) SetObjectServiceContext(v *ObjectSessionContext) { +func (m *SessionToken_Body) SetObjectSessionContext(v *ObjectSessionContext) { if m != nil { m.Context = &SessionToken_Body_Object{ Object: v, @@ -113,49 +99,14 @@ func (m *SessionToken) SetBody(v *SessionToken_Body) { } // SetSignature sets session token signature. -func (m *SessionToken) SetSignature(v *Signature) { - if m != nil { - m.Signature = v - } -} - -// SetEaclTable sets eACL table of the bearer token. -func (m *BearerToken_Body) SetEaclTable(v *acl.EACLTable) { - if m != nil { - m.EaclTable = v - } -} - -// SetOwnerId sets identifier of the bearer token owner. -func (m *BearerToken_Body) SetOwnerId(v *refs.OwnerID) { - if m != nil { - m.OwnerId = v - } -} - -// SetLifetime sets lifetime of the bearer token. -func (m *BearerToken_Body) SetLifetime(v *TokenLifetime) { - if m != nil { - m.Lifetime = v - } -} - -// SetBody sets bearer token body. -func (m *BearerToken) SetBody(v *BearerToken_Body) { - if m != nil { - m.Body = v - } -} - -// SetSignature sets bearer token signature. -func (m *BearerToken) SetSignature(v *Signature) { +func (m *SessionToken) SetSignature(v *refs.Signature) { if m != nil { m.Signature = v } } // SetVersion sets client protocol version. -func (m *RequestMetaHeader) SetVersion(v *Version) { +func (m *RequestMetaHeader) SetVersion(v *refs.Version) { if m != nil { m.Version = v } @@ -190,7 +141,7 @@ func (m *RequestMetaHeader) SetSessionToken(v *SessionToken) { } // SetBearerToken sets bearer token of the request. -func (m *RequestMetaHeader) SetBearerToken(v *BearerToken) { +func (m *RequestMetaHeader) SetBearerToken(v *acl.BearerToken) { if m != nil { m.BearerToken = v } @@ -204,7 +155,7 @@ func (m *RequestMetaHeader) SetOrigin(v *RequestMetaHeader) { } // SetVersion sets server protocol version. -func (m *ResponseMetaHeader) SetVersion(v *Version) { +func (m *ResponseMetaHeader) SetVersion(v *refs.Version) { if m != nil { m.Version = v } @@ -237,3 +188,59 @@ func (m *ResponseMetaHeader) SetOrigin(v *ResponseMetaHeader) { m.Origin = v } } + +// SetBodySignature sets signature of the request body. +func (m *RequestVerificationHeader) SetBodySignature(v *refs.Signature) { + if m != nil { + m.BodySignature = v + } +} + +// SetMetaSignature sets signature of the request meta. +func (m *RequestVerificationHeader) SetMetaSignature(v *refs.Signature) { + if m != nil { + m.MetaSignature = v + } +} + +// SetOriginSignature sets signature of the origin verification header of the request. +func (m *RequestVerificationHeader) SetOriginSignature(v *refs.Signature) { + if m != nil { + m.OriginSignature = v + } +} + +// SetOrigin sets origin verification header of the request. +func (m *RequestVerificationHeader) SetOrigin(v *RequestVerificationHeader) { + if m != nil { + m.Origin = v + } +} + +// SetBodySignature sets signature of the response body. +func (m *ResponseVerificationHeader) SetBodySignature(v *refs.Signature) { + if m != nil { + m.BodySignature = v + } +} + +// SetMetaSignature sets signature of the response meta. +func (m *ResponseVerificationHeader) SetMetaSignature(v *refs.Signature) { + if m != nil { + m.MetaSignature = v + } +} + +// SetOriginSignature sets signature of the origin verification header of the response. +func (m *ResponseVerificationHeader) SetOriginSignature(v *refs.Signature) { + if m != nil { + m.OriginSignature = v + } +} + +// SetOrigin sets origin verification header of the response. +func (m *ResponseVerificationHeader) SetOrigin(v *ResponseVerificationHeader) { + if m != nil { + m.Origin = v + } +} diff --git a/v2/session/marshal.go b/v2/session/marshal.go index 2256b900..9bd4eb1d 100644 --- a/v2/session/marshal.go +++ b/v2/session/marshal.go @@ -5,11 +5,54 @@ import ( ) const ( - createReqBodyOwnerField = 1 - createReqBodyLifetimeField = 2 + createReqBodyOwnerField = 1 + createReqBodyExpirationField = 2 createRespBodyIDField = 1 createRespBodyKeyField = 2 + + xheaderKeyField = 1 + xheaderValueField = 2 + + lifetimeExpirationField = 1 + lifetimeNotValidBeforeField = 2 + lifetimeIssuedAtField = 3 + + objectCtxVerbField = 1 + objectCtxAddressField = 2 + + sessionTokenBodyIDField = 1 + sessionTokenBodyOwnerField = 2 + sessionTokenBodyLifetimeField = 3 + sessionTokenBodyKeyField = 4 + sessionTokenBodyObjectCtxField = 5 + + sessionTokenBodyField = 1 + sessionTokenSignatureField = 2 + + reqMetaHeaderVersionField = 1 + reqMetaHeaderEpochField = 2 + reqMetaHeaderTTLField = 3 + reqMetaHeaderXHeadersField = 4 + reqMetaHeaderSessionTokenField = 5 + reqMetaHeaderBearerTokenField = 6 + reqMetaHeaderOriginField = 7 + + reqVerifHeaderBodySignatureField = 1 + reqVerifHeaderMetaSignatureField = 2 + reqVerifHeaderOriginSignatureField = 3 + reqVerifHeaderOriginField = 4 + + respMetaHeaderVersionField = 1 + respMetaHeaderEpochField = 2 + respMetaHeaderTTLField = 3 + respMetaHeaderXHeadersField = 4 + respMetaHeaderOriginField = 5 + + respVerifHeaderBodySignatureField = 1 + respVerifHeaderMetaSignatureField = 2 + respVerifHeaderOriginSignatureField = 3 + respVerifHeaderOriginField = 4 ) func (c *CreateRequestBody) StableMarshal(buf []byte) ([]byte, error) { @@ -33,7 +76,7 @@ func (c *CreateRequestBody) StableMarshal(buf []byte) ([]byte, error) { offset += n - _, err = proto.NestedStructureMarshal(createReqBodyLifetimeField, buf[offset:], c.lifetime) + _, err = proto.UInt64Marshal(createReqBodyExpirationField, buf[offset:], c.expiration) if err != nil { return nil, err } @@ -47,7 +90,7 @@ func (c *CreateRequestBody) StableSize() (size int) { } size += proto.NestedStructureSize(createReqBodyOwnerField, c.ownerID) - size += proto.NestedStructureSize(createReqBodyLifetimeField, c.lifetime) + size += proto.UInt64Size(createReqBodyExpirationField, c.expiration) return size } @@ -91,3 +134,524 @@ func (c *CreateResponseBody) StableSize() (size int) { return size } + +func (x *XHeader) StableMarshal(buf []byte) ([]byte, error) { + if x == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, x.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.StringMarshal(xheaderKeyField, buf[offset:], x.key) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.StringMarshal(xheaderValueField, buf[offset:], x.val) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (x *XHeader) StableSize() (size int) { + if x == nil { + return 0 + } + + size += proto.StringSize(xheaderKeyField, x.key) + size += proto.StringSize(xheaderValueField, x.val) + + return size +} + +func (l *TokenLifetime) StableMarshal(buf []byte) ([]byte, error) { + if l == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, l.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.UInt64Marshal(lifetimeExpirationField, buf[offset:], l.exp) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.UInt64Marshal(lifetimeNotValidBeforeField, buf[offset:], l.nbf) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.UInt64Marshal(lifetimeIssuedAtField, buf[offset:], l.iat) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (l *TokenLifetime) StableSize() (size int) { + if l == nil { + return 0 + } + + size += proto.UInt64Size(lifetimeExpirationField, l.exp) + size += proto.UInt64Size(lifetimeNotValidBeforeField, l.nbf) + size += proto.UInt64Size(lifetimeIssuedAtField, l.iat) + + return size +} + +func (c *ObjectSessionContext) StableMarshal(buf []byte) ([]byte, error) { + if c == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, c.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.EnumMarshal(objectCtxVerbField, buf[offset:], int32(c.verb)) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.NestedStructureMarshal(objectCtxAddressField, buf[offset:], c.addr) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (c *ObjectSessionContext) StableSize() (size int) { + if c == nil { + return 0 + } + + size += proto.EnumSize(objectCtxVerbField, int32(c.verb)) + size += proto.NestedStructureSize(objectCtxAddressField, c.addr) + + return size +} + +func (t *SessionTokenBody) StableMarshal(buf []byte) ([]byte, error) { + if t == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, t.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.BytesMarshal(sessionTokenBodyIDField, buf[offset:], t.id) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(sessionTokenBodyOwnerField, buf[offset:], t.ownerID) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(sessionTokenBodyLifetimeField, buf[offset:], t.lifetime) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.BytesMarshal(sessionTokenBodyKeyField, buf[offset:], t.sessionKey) + if err != nil { + return nil, err + } + + offset += n + + if t.ctx != nil { + switch v := t.ctx.(type) { + case *ObjectSessionContext: + _, err = proto.NestedStructureMarshal(sessionTokenBodyObjectCtxField, buf[offset:], v) + if err != nil { + return nil, err + } + default: + panic("cannot marshal unknown session token context") + } + } + + return buf, nil +} + +func (t *SessionTokenBody) StableSize() (size int) { + if t == nil { + return 0 + } + + size += proto.BytesSize(sessionTokenBodyIDField, t.id) + size += proto.NestedStructureSize(sessionTokenBodyOwnerField, t.ownerID) + size += proto.NestedStructureSize(sessionTokenBodyLifetimeField, t.lifetime) + size += proto.BytesSize(sessionTokenBodyKeyField, t.sessionKey) + + if t.ctx != nil { + switch v := t.ctx.(type) { + case *ObjectSessionContext: + size += proto.NestedStructureSize(sessionTokenBodyObjectCtxField, v) + default: + panic("cannot marshal unknown session token context") + } + } + + return size +} + +func (t *SessionToken) StableMarshal(buf []byte) ([]byte, error) { + if t == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, t.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.NestedStructureMarshal(sessionTokenBodyField, buf[offset:], t.body) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.NestedStructureMarshal(sessionTokenSignatureField, buf[offset:], t.sig) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (t *SessionToken) StableSize() (size int) { + if t == nil { + return 0 + } + + size += proto.NestedStructureSize(sessionTokenBodyField, t.body) + size += proto.NestedStructureSize(sessionTokenSignatureField, t.sig) + + return size +} + +func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) { + if r == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, r.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.NestedStructureMarshal(reqMetaHeaderVersionField, buf[offset:], r.version) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.UInt64Marshal(reqMetaHeaderEpochField, buf[offset:], r.epoch) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.UInt32Marshal(reqMetaHeaderTTLField, buf[offset:], r.ttl) + if err != nil { + return nil, err + } + + offset += n + + for i := range r.xHeaders { + n, err = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], r.xHeaders[i]) + if err != nil { + return nil, err + } + + offset += n + } + + n, err = proto.NestedStructureMarshal(reqMetaHeaderSessionTokenField, buf[offset:], r.sessionToken) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(reqMetaHeaderBearerTokenField, buf[offset:], r.bearerToken) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.NestedStructureMarshal(reqMetaHeaderOriginField, buf[offset:], r.origin) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (r *RequestMetaHeader) StableSize() (size int) { + if r == nil { + return 0 + } + + if r.version != nil { + size += proto.NestedStructureSize(reqMetaHeaderVersionField, r.version) + } + + size += proto.UInt64Size(reqMetaHeaderEpochField, r.epoch) + size += proto.UInt32Size(reqMetaHeaderTTLField, r.ttl) + + for i := range r.xHeaders { + size += proto.NestedStructureSize(reqMetaHeaderXHeadersField, r.xHeaders[i]) + } + + size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken) + size += proto.NestedStructureSize(reqMetaHeaderBearerTokenField, r.bearerToken) + size += proto.NestedStructureSize(reqMetaHeaderOriginField, r.origin) + + return size +} + +func (r *RequestVerificationHeader) StableMarshal(buf []byte) ([]byte, error) { + if r == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, r.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.NestedStructureMarshal(reqVerifHeaderBodySignatureField, buf[offset:], r.bodySig) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(reqVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(reqVerifHeaderOriginSignatureField, buf[offset:], r.originSig) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.NestedStructureMarshal(reqVerifHeaderOriginField, buf[offset:], r.origin) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (r *RequestVerificationHeader) StableSize() (size int) { + if r == nil { + return 0 + } + + size += proto.NestedStructureSize(reqVerifHeaderBodySignatureField, r.bodySig) + size += proto.NestedStructureSize(reqVerifHeaderMetaSignatureField, r.metaSig) + size += proto.NestedStructureSize(reqVerifHeaderOriginSignatureField, r.originSig) + size += proto.NestedStructureSize(reqVerifHeaderOriginField, r.origin) + + return size +} + +func (r *ResponseMetaHeader) StableMarshal(buf []byte) ([]byte, error) { + if r == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, r.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.NestedStructureMarshal(respMetaHeaderVersionField, buf[offset:], r.version) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.UInt64Marshal(respMetaHeaderEpochField, buf[offset:], r.epoch) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.UInt32Marshal(respMetaHeaderTTLField, buf[offset:], r.ttl) + if err != nil { + return nil, err + } + + offset += n + + for i := range r.xHeaders { + n, err = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], r.xHeaders[i]) + if err != nil { + return nil, err + } + + offset += n + } + + _, err = proto.NestedStructureMarshal(respMetaHeaderOriginField, buf[offset:], r.origin) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (r *ResponseMetaHeader) StableSize() (size int) { + if r == nil { + return 0 + } + + if r.version != nil { + size += proto.NestedStructureSize(respMetaHeaderVersionField, r.version) + } + + size += proto.UInt64Size(respMetaHeaderEpochField, r.epoch) + size += proto.UInt32Size(respMetaHeaderTTLField, r.ttl) + + for i := range r.xHeaders { + size += proto.NestedStructureSize(respMetaHeaderXHeadersField, r.xHeaders[i]) + } + + size += proto.NestedStructureSize(respMetaHeaderOriginField, r.origin) + + return size +} + +func (r *ResponseVerificationHeader) StableMarshal(buf []byte) ([]byte, error) { + if r == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, r.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.NestedStructureMarshal(respVerifHeaderBodySignatureField, buf[offset:], r.bodySig) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(respVerifHeaderMetaSignatureField, buf[offset:], r.metaSig) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(respVerifHeaderOriginSignatureField, buf[offset:], r.originSig) + if err != nil { + return nil, err + } + + offset += n + + _, err = proto.NestedStructureMarshal(respVerifHeaderOriginField, buf[offset:], r.origin) + if err != nil { + return nil, err + } + + return buf, nil +} + +func (r *ResponseVerificationHeader) StableSize() (size int) { + if r == nil { + return 0 + } + + size += proto.NestedStructureSize(respVerifHeaderBodySignatureField, r.bodySig) + size += proto.NestedStructureSize(respVerifHeaderMetaSignatureField, r.metaSig) + size += proto.NestedStructureSize(respVerifHeaderOriginSignatureField, r.originSig) + size += proto.NestedStructureSize(respVerifHeaderOriginField, r.origin) + + return size +} diff --git a/v2/session/marshal_test.go b/v2/session/marshal_test.go index 685a4775..0f038c0b 100644 --- a/v2/session/marshal_test.go +++ b/v2/session/marshal_test.go @@ -1,10 +1,11 @@ package session_test import ( + "fmt" "testing" + "github.com/nspcc-dev/neofs-api-go/v2/acl" "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" grpc "github.com/nspcc-dev/neofs-api-go/v2/session/grpc" "github.com/stretchr/testify/require" @@ -42,8 +43,160 @@ func TestCreateResponseBody_StableMarshal(t *testing.T) { }) } +func TestXHeader_StableMarshal(t *testing.T) { + xheaderFrom := generateXHeader("X-Header-Key", "X-Header-Value") + transport := new(grpc.XHeader) + + t.Run("non empty", func(t *testing.T) { + wire, err := xheaderFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + xheaderTo := session.XHeaderFromGRPCMessage(transport) + require.Equal(t, xheaderFrom, xheaderTo) + }) +} + +func TestTokenLifetime_StableMarshal(t *testing.T) { + lifetimeFrom := generateLifetime(10, 20, 30) + transport := new(grpc.SessionToken_Body_TokenLifetime) + + t.Run("non empty", func(t *testing.T) { + wire, err := lifetimeFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + lifetimeTo := session.TokenLifetimeFromGRPCMessage(transport) + require.Equal(t, lifetimeFrom, lifetimeTo) + }) +} + +func TestObjectSessionContext_StableMarshal(t *testing.T) { + objectCtxFrom := generateObjectCtx("Object ID") + transport := new(grpc.ObjectSessionContext) + + t.Run("non empty", func(t *testing.T) { + wire, err := objectCtxFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + objectCtxTo := session.ObjectSessionContextFromGRPCMessage(transport) + require.Equal(t, objectCtxFrom, objectCtxTo) + }) +} + +func TestSessionTokenBody_StableMarshal(t *testing.T) { + sessionTokenBodyFrom := generateSessionTokenBody("Session Token Body") + transport := new(grpc.SessionToken_Body) + + t.Run("non empty", func(t *testing.T) { + wire, err := sessionTokenBodyFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + sessionTokenBodyTo := session.SessionTokenBodyFromGRPCMessage(transport) + require.Equal(t, sessionTokenBodyFrom, sessionTokenBodyTo) + }) +} + +func TestSessionToken_StableMarshal(t *testing.T) { + sessionTokenFrom := generateSessionToken("Session Token") + transport := new(grpc.SessionToken) + + t.Run("non empty", func(t *testing.T) { + wire, err := sessionTokenFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + sessionTokenTo := session.SessionTokenFromGRPCMessage(transport) + require.Equal(t, sessionTokenFrom, sessionTokenTo) + }) +} + +func TestRequestMetaHeader_StableMarshal(t *testing.T) { + metaHeaderOrigin := generateRequestMetaHeader(10, "Bearer One", "Session One") + metaHeaderFrom := generateRequestMetaHeader(20, "Bearer Two", "Session Two") + metaHeaderFrom.SetOrigin(metaHeaderOrigin) + transport := new(grpc.RequestMetaHeader) + + t.Run("non empty", func(t *testing.T) { + wire, err := metaHeaderFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + metaHeaderTo := session.RequestMetaHeaderFromGRPCMessage(transport) + require.Equal(t, metaHeaderFrom, metaHeaderTo) + }) +} + +func TestRequestVerificationHeader_StableMarshal(t *testing.T) { + verifHeaderOrigin := generateRequestVerificationHeader("Key", "Inside") + verifHeaderFrom := generateRequestVerificationHeader("Value", "Outside") + verifHeaderFrom.SetOrigin(verifHeaderOrigin) + transport := new(grpc.RequestVerificationHeader) + + t.Run("non empty", func(t *testing.T) { + wire, err := verifHeaderFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + verifHeaderTo := session.RequestVerificationHeaderFromGRPCMessage(transport) + require.Equal(t, verifHeaderFrom, verifHeaderTo) + }) +} + +func TestResponseMetaHeader_StableMarshal(t *testing.T) { + metaHeaderOrigin := generateResponseMetaHeader(10) + metaHeaderFrom := generateResponseMetaHeader(20) + metaHeaderFrom.SetOrigin(metaHeaderOrigin) + transport := new(grpc.ResponseMetaHeader) + + t.Run("non empty", func(t *testing.T) { + wire, err := metaHeaderFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + metaHeaderTo := session.ResponseMetaHeaderFromGRPCMessage(transport) + require.Equal(t, metaHeaderFrom, metaHeaderTo) + }) +} + +func TestResponseVerificationHeader_StableMarshal(t *testing.T) { + verifHeaderOrigin := generateResponseVerificationHeader("Key", "Inside") + verifHeaderFrom := generateResponseVerificationHeader("Value", "Outside") + verifHeaderFrom.SetOrigin(verifHeaderOrigin) + transport := new(grpc.ResponseVerificationHeader) + + t.Run("non empty", func(t *testing.T) { + wire, err := verifHeaderFrom.StableMarshal(nil) + require.NoError(t, err) + + err = transport.Unmarshal(wire) + require.NoError(t, err) + + verifHeaderTo := session.ResponseVerificationHeaderFromGRPCMessage(transport) + require.Equal(t, verifHeaderFrom, verifHeaderTo) + }) +} + func generateCreateSessionRequestBody(id string) *session.CreateRequestBody { - lifetime := new(service.TokenLifetime) + lifetime := new(session.TokenLifetime) lifetime.SetIat(1) lifetime.SetNbf(2) lifetime.SetExp(3) @@ -53,7 +206,7 @@ func generateCreateSessionRequestBody(id string) *session.CreateRequestBody { s := new(session.CreateRequestBody) s.SetOwnerID(owner) - s.SetLifetime(lifetime) + s.SetExpiration(10) return s } @@ -65,3 +218,185 @@ func generateCreateSessionResponseBody(id, key string) *session.CreateResponseBo return s } + +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 +} + +func generateXHeader(k, v string) *session.XHeader { + xheader := new(session.XHeader) + xheader.SetKey(k) + xheader.SetValue(v) + + return xheader +} + +func generateLifetime(exp, nbf, iat uint64) *session.TokenLifetime { + lifetime := new(session.TokenLifetime) + lifetime.SetExp(exp) + lifetime.SetNbf(nbf) + lifetime.SetIat(iat) + + return lifetime +} + +func generateBearerLifetime(exp, nbf, iat uint64) *acl.TokenLifetime { + lifetime := new(acl.TokenLifetime) + lifetime.SetExp(exp) + lifetime.SetNbf(nbf) + lifetime.SetIat(iat) + + return lifetime +} + +func generateObjectCtx(id string) *session.ObjectSessionContext { + objectCtx := new(session.ObjectSessionContext) + objectCtx.SetVerb(session.ObjectVerbPut) + + cid := new(refs.ContainerID) + cid.SetValue([]byte("ContainerID")) + + oid := new(refs.ObjectID) + oid.SetValue([]byte(id)) + + addr := new(refs.Address) + addr.SetContainerID(cid) + addr.SetObjectID(oid) + + objectCtx.SetAddress(addr) + + return objectCtx +} + +func generateEACL(n int, k, v string) *acl.Table { + target := new(acl.TargetInfo) + target.SetTarget(acl.TargetUser) + + keys := make([][]byte, n) + + for i := 0; i < n; i++ { + s := fmt.Sprintf("Public Key %d", i+1) + keys[i] = []byte(s) + } + + filter := new(acl.HeaderFilter) + filter.SetHeaderType(acl.HeaderTypeObject) + filter.SetMatchType(acl.MatchTypeStringEqual) + filter.SetName(k) + filter.SetValue(v) + + record := new(acl.Record) + record.SetOperation(acl.OperationHead) + record.SetAction(acl.ActionDeny) + record.SetTargets([]*acl.TargetInfo{target}) + record.SetFilters([]*acl.HeaderFilter{filter}) + + table := new(acl.Table) + cid := new(refs.ContainerID) + cid.SetValue([]byte("Container ID")) + + table.SetContainerID(cid) + table.SetRecords([]*acl.Record{record}) + + return table +} + +func generateSessionTokenBody(id string) *session.SessionTokenBody { + owner := new(refs.OwnerID) + owner.SetValue([]byte("Owner ID")) + + tokenBody := new(session.SessionTokenBody) + tokenBody.SetID([]byte(id)) + tokenBody.SetOwnerID(owner) + tokenBody.SetSessionKey([]byte(id)) + tokenBody.SetLifetime(generateLifetime(1, 2, 3)) + tokenBody.SetContext(generateObjectCtx(id)) + + return tokenBody +} + +func generateSessionToken(id string) *session.SessionToken { + sessionToken := new(session.SessionToken) + sessionToken.SetBody(generateSessionTokenBody(id)) + sessionToken.SetSignature(generateSignature("id", id)) + + return sessionToken +} + +func generateBearerTokenBody(id string) *acl.BearerTokenBody { + owner := new(refs.OwnerID) + owner.SetValue([]byte(id)) + + tokenBody := new(acl.BearerTokenBody) + tokenBody.SetOwnerID(owner) + tokenBody.SetLifetime(generateBearerLifetime(1, 2, 3)) + tokenBody.SetEACL(generateEACL(10, "id", id)) + + return tokenBody +} + +func generateBearerToken(id string) *acl.BearerToken { + bearerToken := new(acl.BearerToken) + bearerToken.SetBody(generateBearerTokenBody(id)) + bearerToken.SetSignature(generateSignature("id", id)) + + return bearerToken +} + +func generateRequestMetaHeader(n int, b, s string) *session.RequestMetaHeader { + reqMetaHeader := new(session.RequestMetaHeader) + reqMetaHeader.SetVersion(generateVersion(2, 0)) + reqMetaHeader.SetEpoch(uint64(n)) + reqMetaHeader.SetTTL(uint32(n)) + reqMetaHeader.SetXHeaders([]*session.XHeader{ + generateXHeader("key-one", "val-one"), + generateXHeader("key-two", "val-two"), + }) + reqMetaHeader.SetBearerToken(generateBearerToken(b)) + reqMetaHeader.SetSessionToken(generateSessionToken(s)) + + return reqMetaHeader +} + +func generateRequestVerificationHeader(k, v string) *session.RequestVerificationHeader { + reqVerifHeader := new(session.RequestVerificationHeader) + reqVerifHeader.SetBodySignature(generateSignature(k+"body", v+"body")) + reqVerifHeader.SetMetaSignature(generateSignature(k+"meta", v+"meta")) + reqVerifHeader.SetOriginSignature(generateSignature(k+"orig", v+"orig")) + + return reqVerifHeader +} + +func generateResponseMetaHeader(n int) *session.ResponseMetaHeader { + respMetaHeader := new(session.ResponseMetaHeader) + respMetaHeader.SetVersion(generateVersion(2, 0)) + respMetaHeader.SetEpoch(uint64(n)) + respMetaHeader.SetTTL(uint32(n)) + respMetaHeader.SetXHeaders([]*session.XHeader{ + generateXHeader("key-one", "val-one"), + generateXHeader("key-two", "val-two"), + }) + + return respMetaHeader +} + +func generateResponseVerificationHeader(k, v string) *session.ResponseVerificationHeader { + respVerifHeader := new(session.ResponseVerificationHeader) + respVerifHeader.SetBodySignature(generateSignature(k+"body", v+"body")) + respVerifHeader.SetMetaSignature(generateSignature(k+"meta", v+"meta")) + respVerifHeader.SetOriginSignature(generateSignature(k+"orig", v+"orig")) + + return respVerifHeader +} diff --git a/v2/session/types.go b/v2/session/types.go index 77729ce7..9e876033 100644 --- a/v2/session/types.go +++ b/v2/session/types.go @@ -1,22 +1,22 @@ package session import ( + "github.com/nspcc-dev/neofs-api-go/v2/acl" "github.com/nspcc-dev/neofs-api-go/v2/refs" - "github.com/nspcc-dev/neofs-api-go/v2/service" ) type CreateRequestBody struct { ownerID *refs.OwnerID - lifetime *service.TokenLifetime + expiration uint64 } type CreateRequest struct { body *CreateRequestBody - metaHeader *service.RequestMetaHeader + metaHeader *RequestMetaHeader - verifyHeader *service.RequestVerificationHeader + verifyHeader *RequestVerificationHeader } type CreateResponseBody struct { @@ -28,11 +28,100 @@ type CreateResponseBody struct { type CreateResponse struct { body *CreateResponseBody - metaHeader *service.ResponseMetaHeader + metaHeader *ResponseMetaHeader - verifyHeader *service.ResponseVerificationHeader + verifyHeader *ResponseVerificationHeader } +type XHeader struct { + key, val string +} + +type TokenLifetime struct { + exp, nbf, iat uint64 +} + +type ObjectSessionVerb uint32 + +type ObjectSessionContext struct { + verb ObjectSessionVerb + + addr *refs.Address +} + +type SessionTokenContext interface { + sessionTokenContext() +} + +type SessionTokenBody struct { + id []byte + + ownerID *refs.OwnerID + + lifetime *TokenLifetime + + sessionKey []byte + + ctx SessionTokenContext +} + +type SessionToken struct { + body *SessionTokenBody + + sig *refs.Signature +} + +type RequestVerificationHeader struct { + bodySig, metaSig, originSig *refs.Signature + + origin *RequestVerificationHeader +} + +type RequestMetaHeader struct { + version *refs.Version + + ttl uint32 + + epoch uint64 + + xHeaders []*XHeader + + sessionToken *SessionToken + + bearerToken *acl.BearerToken + + origin *RequestMetaHeader +} + +type ResponseVerificationHeader struct { + bodySig, metaSig, originSig *refs.Signature + + origin *ResponseVerificationHeader +} + +type ResponseMetaHeader struct { + version *refs.Version + + ttl uint32 + + epoch uint64 + + xHeaders []*XHeader + + origin *ResponseMetaHeader +} + +const ( + ObjectVerbUnknown ObjectSessionVerb = iota + ObjectVerbPut + ObjectVerbGet + ObjectVerbHead + ObjectVerbSearch + ObjectVerbDelete + ObjectVerbRange + ObjectVerbRangeHash +) + func (c *CreateRequestBody) GetOwnerID() *refs.OwnerID { if c != nil { return c.ownerID @@ -47,17 +136,17 @@ func (c *CreateRequestBody) SetOwnerID(v *refs.OwnerID) { } } -func (c *CreateRequestBody) GetLifetime() *service.TokenLifetime { +func (c *CreateRequestBody) GetExpiration() uint64 { if c != nil { - return c.lifetime + return c.expiration } - return nil + return 0 } -func (c *CreateRequestBody) SetLifetime(v *service.TokenLifetime) { +func (c *CreateRequestBody) SetExpiration(v uint64) { if c != nil { - c.lifetime = v + c.expiration = v } } @@ -75,7 +164,7 @@ func (c *CreateRequest) SetBody(v *CreateRequestBody) { } } -func (c *CreateRequest) GetMetaHeader() *service.RequestMetaHeader { +func (c *CreateRequest) GetMetaHeader() *RequestMetaHeader { if c != nil { return c.metaHeader } @@ -83,13 +172,13 @@ func (c *CreateRequest) GetMetaHeader() *service.RequestMetaHeader { return nil } -func (c *CreateRequest) SetMetaHeader(v *service.RequestMetaHeader) { +func (c *CreateRequest) SetMetaHeader(v *RequestMetaHeader) { if c != nil { c.metaHeader = v } } -func (c *CreateRequest) GetVerificationHeader() *service.RequestVerificationHeader { +func (c *CreateRequest) GetVerificationHeader() *RequestVerificationHeader { if c != nil { return c.verifyHeader } @@ -97,7 +186,7 @@ func (c *CreateRequest) GetVerificationHeader() *service.RequestVerificationHead return nil } -func (c *CreateRequest) SetVerificationHeader(v *service.RequestVerificationHeader) { +func (c *CreateRequest) SetVerificationHeader(v *RequestVerificationHeader) { if c != nil { c.verifyHeader = v } @@ -145,7 +234,7 @@ func (c *CreateResponse) SetBody(v *CreateResponseBody) { } } -func (c *CreateResponse) GetMetaHeader() *service.ResponseMetaHeader { +func (c *CreateResponse) GetMetaHeader() *ResponseMetaHeader { if c != nil { return c.metaHeader } @@ -153,13 +242,13 @@ func (c *CreateResponse) GetMetaHeader() *service.ResponseMetaHeader { return nil } -func (c *CreateResponse) SetMetaHeader(v *service.ResponseMetaHeader) { +func (c *CreateResponse) SetMetaHeader(v *ResponseMetaHeader) { if c != nil { c.metaHeader = v } } -func (c *CreateResponse) GetVerificationHeader() *service.ResponseVerificationHeader { +func (c *CreateResponse) GetVerificationHeader() *ResponseVerificationHeader { if c != nil { return c.verifyHeader } @@ -167,8 +256,486 @@ func (c *CreateResponse) GetVerificationHeader() *service.ResponseVerificationHe return nil } -func (c *CreateResponse) SetVerificationHeader(v *service.ResponseVerificationHeader) { +func (c *CreateResponse) SetVerificationHeader(v *ResponseVerificationHeader) { if c != nil { c.verifyHeader = v } } + +func (x *XHeader) GetKey() string { + if x != nil { + return x.key + } + + return "" +} + +func (x *XHeader) SetKey(v string) { + if x != nil { + x.key = v + } +} + +func (x *XHeader) GetValue() string { + if x != nil { + return x.val + } + + return "" +} + +func (x *XHeader) SetValue(v string) { + if x != nil { + x.val = v + } +} + +func (r *RequestVerificationHeader) GetBodySignature() *refs.Signature { + if r != nil { + return r.bodySig + } + + return nil +} + +func (r *RequestVerificationHeader) SetBodySignature(v *refs.Signature) { + if r != nil { + r.bodySig = v + } +} + +func (r *RequestVerificationHeader) GetMetaSignature() *refs.Signature { + if r != nil { + return r.metaSig + } + + return nil +} + +func (r *RequestVerificationHeader) SetMetaSignature(v *refs.Signature) { + if r != nil { + r.metaSig = v + } +} + +func (r *RequestVerificationHeader) GetOriginSignature() *refs.Signature { + if r != nil { + return r.originSig + } + + return nil +} + +func (r *RequestVerificationHeader) SetOriginSignature(v *refs.Signature) { + if r != nil { + r.originSig = v + } +} + +func (r *RequestVerificationHeader) GetOrigin() *RequestVerificationHeader { + if r != nil { + return r.origin + } + + return nil +} + +func (r *RequestVerificationHeader) SetOrigin(v *RequestVerificationHeader) { + if r != nil { + r.origin = v + } +} + +func (r *RequestMetaHeader) GetVersion() *refs.Version { + if r != nil { + return r.version + } + + return nil +} + +func (r *RequestMetaHeader) SetVersion(v *refs.Version) { + if r != nil { + r.version = v + } +} + +func (r *RequestMetaHeader) GetTTL() uint32 { + if r != nil { + return r.ttl + } + + return 0 +} + +func (r *RequestMetaHeader) SetTTL(v uint32) { + if r != nil { + r.ttl = v + } +} + +func (r *RequestMetaHeader) GetEpoch() uint64 { + if r != nil { + return r.epoch + } + + return 0 +} + +func (r *RequestMetaHeader) SetEpoch(v uint64) { + if r != nil { + r.epoch = v + } +} + +func (r *RequestMetaHeader) GetXHeaders() []*XHeader { + if r != nil { + return r.xHeaders + } + + return nil +} + +func (r *RequestMetaHeader) SetXHeaders(v []*XHeader) { + if r != nil { + r.xHeaders = v + } +} + +func (r *RequestMetaHeader) GetSessionToken() *SessionToken { + if r != nil { + return r.sessionToken + } + + return nil +} + +func (r *RequestMetaHeader) SetSessionToken(v *SessionToken) { + if r != nil { + r.sessionToken = v + } +} + +func (r *RequestMetaHeader) GetBearerToken() *acl.BearerToken { + if r != nil { + return r.bearerToken + } + + return nil +} + +func (r *RequestMetaHeader) SetBearerToken(v *acl.BearerToken) { + if r != nil { + r.bearerToken = v + } +} + +func (r *RequestMetaHeader) GetOrigin() *RequestMetaHeader { + if r != nil { + return r.origin + } + + return nil +} + +func (r *RequestMetaHeader) SetOrigin(v *RequestMetaHeader) { + if r != nil { + r.origin = v + } +} + +func (l *TokenLifetime) GetExp() uint64 { + if l != nil { + return l.exp + } + + return 0 +} + +func (l *TokenLifetime) SetExp(v uint64) { + if l != nil { + l.exp = v + } +} + +func (l *TokenLifetime) GetNbf() uint64 { + if l != nil { + return l.nbf + } + + return 0 +} + +func (l *TokenLifetime) SetNbf(v uint64) { + if l != nil { + l.nbf = v + } +} + +func (l *TokenLifetime) GetIat() uint64 { + if l != nil { + return l.iat + } + + return 0 +} + +func (l *TokenLifetime) SetIat(v uint64) { + if l != nil { + l.iat = v + } +} + +func (r *ResponseVerificationHeader) GetBodySignature() *refs.Signature { + if r != nil { + return r.bodySig + } + + return nil +} + +func (r *ResponseVerificationHeader) SetBodySignature(v *refs.Signature) { + if r != nil { + r.bodySig = v + } +} + +func (r *ResponseVerificationHeader) GetMetaSignature() *refs.Signature { + if r != nil { + return r.metaSig + } + + return nil +} + +func (r *ResponseVerificationHeader) SetMetaSignature(v *refs.Signature) { + if r != nil { + r.metaSig = v + } +} + +func (r *ResponseVerificationHeader) GetOriginSignature() *refs.Signature { + if r != nil { + return r.originSig + } + + return nil +} + +func (r *ResponseVerificationHeader) SetOriginSignature(v *refs.Signature) { + if r != nil { + r.originSig = v + } +} + +func (r *ResponseVerificationHeader) GetOrigin() *ResponseVerificationHeader { + if r != nil { + return r.origin + } + + return nil +} + +func (r *ResponseVerificationHeader) SetOrigin(v *ResponseVerificationHeader) { + if r != nil { + r.origin = v + } +} + +func (r *ResponseMetaHeader) GetVersion() *refs.Version { + if r != nil { + return r.version + } + + return nil +} + +func (r *ResponseMetaHeader) SetVersion(v *refs.Version) { + if r != nil { + r.version = v + } +} + +func (r *ResponseMetaHeader) GetTTL() uint32 { + if r != nil { + return r.ttl + } + + return 0 +} + +func (r *ResponseMetaHeader) SetTTL(v uint32) { + if r != nil { + r.ttl = v + } +} + +func (r *ResponseMetaHeader) GetEpoch() uint64 { + if r != nil { + return r.epoch + } + + return 0 +} + +func (r *ResponseMetaHeader) SetEpoch(v uint64) { + if r != nil { + r.epoch = v + } +} + +func (r *ResponseMetaHeader) GetXHeaders() []*XHeader { + if r != nil { + return r.xHeaders + } + + return nil +} + +func (r *ResponseMetaHeader) SetXHeaders(v []*XHeader) { + if r != nil { + r.xHeaders = v + } +} + +func (r *ResponseMetaHeader) GetOrigin() *ResponseMetaHeader { + if r != nil { + return r.origin + } + + return nil +} + +func (r *ResponseMetaHeader) SetOrigin(v *ResponseMetaHeader) { + if r != nil { + r.origin = v + } +} + +func (c *ObjectSessionContext) sessionTokenContext() {} + +func (c *ObjectSessionContext) GetVerb() ObjectSessionVerb { + if c != nil { + return c.verb + } + + return ObjectVerbUnknown +} + +func (c *ObjectSessionContext) SetVerb(v ObjectSessionVerb) { + if c != nil { + c.verb = v + } +} + +func (c *ObjectSessionContext) GetAddress() *refs.Address { + if c != nil { + return c.addr + } + + return nil +} + +func (c *ObjectSessionContext) SetAddress(v *refs.Address) { + if c != nil { + c.addr = v + } +} + +func (t *SessionTokenBody) GetID() []byte { + if t != nil { + return t.id + } + + return nil +} + +func (t *SessionTokenBody) SetID(v []byte) { + if t != nil { + t.id = v + } +} + +func (t *SessionTokenBody) GetOwnerID() *refs.OwnerID { + if t != nil { + return t.ownerID + } + + return nil +} + +func (t *SessionTokenBody) SetOwnerID(v *refs.OwnerID) { + if t != nil { + t.ownerID = v + } +} + +func (t *SessionTokenBody) GetLifetime() *TokenLifetime { + if t != nil { + return t.lifetime + } + + return nil +} + +func (t *SessionTokenBody) SetLifetime(v *TokenLifetime) { + if t != nil { + t.lifetime = v + } +} + +func (t *SessionTokenBody) GetSessionKey() []byte { + if t != nil { + return t.sessionKey + } + + return nil +} + +func (t *SessionTokenBody) SetSessionKey(v []byte) { + if t != nil { + t.sessionKey = v + } +} + +func (t *SessionTokenBody) GetContext() SessionTokenContext { + if t != nil { + return t.ctx + } + + return nil +} + +func (t *SessionTokenBody) SetContext(v SessionTokenContext) { + if t != nil { + t.ctx = v + } +} + +func (t *SessionToken) GetBody() *SessionTokenBody { + if t != nil { + return t.body + } + + return nil +} + +func (t *SessionToken) SetBody(v *SessionTokenBody) { + if t != nil { + t.body = v + } +} + +func (t *SessionToken) GetSignature() *refs.Signature { + if t != nil { + return t.sig + } + + return nil +} + +func (t *SessionToken) SetSignature(v *refs.Signature) { + if t != nil { + t.sig = v + } +}