v2/service: Implement response uni-structures

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-08-17 13:23:41 +03:00 committed by Stanislav Bogatyrev
parent 1d5773b6ff
commit 890d8291e7
2 changed files with 290 additions and 0 deletions

View file

@ -363,3 +363,149 @@ func RequestHeadersFromGRPC(
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]))
}
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]))
}
return r
}
func ResponseHeadersToGRPC(
src interface {
GetResponseMetaHeader() *ResponseMetaHeader
GetResponseVerificationHeader() *ResponseVerificationHeader
},
dst interface {
SetMetaHeader(*service.ResponseMetaHeader)
SetVerifyHeader(*service.ResponseVerificationHeader)
},
) {
dst.SetMetaHeader(
ResponseMetaHeaderToGRPCMessage(src.GetResponseMetaHeader()),
)
dst.SetVerifyHeader(
ResponseVerificationHeaderToGRPCMessage(src.GetResponseVerificationHeader()),
)
}
func ResponseHeadersFromGRPC(
src interface {
GetMetaHeader() *service.ResponseMetaHeader
GetVerifyHeader() *service.ResponseVerificationHeader
},
dst interface {
SetResponseMetaHeader(*ResponseMetaHeader)
SetResponseVerificationHeader(*ResponseVerificationHeader)
},
) {
dst.SetResponseMetaHeader(
ResponseMetaHeaderFromGRPCMessage(src.GetMetaHeader()),
)
dst.SetResponseVerificationHeader(
ResponseVerificationHeaderFromGRPCMessage(src.GetVerifyHeader()),
)
}

View file

@ -61,6 +61,24 @@ type RequestMetaHeader struct {
origin *RequestMetaHeader
}
type ResponseVerificationHeader struct {
bodySig, metaSig, originSig *Signature
origin *ResponseVerificationHeader
}
type ResponseMetaHeader struct {
version *Version
ttl uint32
epoch uint64
xHeaders []*XHeader
origin *ResponseMetaHeader
}
func (s *Signature) GetKey() []byte {
if s != nil {
return s.key
@ -442,3 +460,129 @@ func (bt *BearerToken) SetSignature(v *Signature) {
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
}
}