diff --git a/v2/object/convert.go b/v2/object/convert.go index 7beb6405..a18d43f4 100644 --- a/v2/object/convert.go +++ b/v2/object/convert.go @@ -283,6 +283,42 @@ func HeaderFromGRPCMessage(m *object.Header) *Header { return h } +func HeaderWithSignatureToGRPCMessage(h *HeaderWithSignature) *object.HeaderWithSignature { + if h == nil { + return nil + } + + m := new(object.HeaderWithSignature) + + m.SetHeader( + HeaderToGRPCMessage(h.GetHeader()), + ) + + m.SetSignature( + refs.SignatureToGRPCMessage(h.GetSignature()), + ) + + return m +} + +func HeaderWithSignatureFromGRPCMessage(m *object.HeaderWithSignature) *HeaderWithSignature { + if m == nil { + return nil + } + + h := new(HeaderWithSignature) + + h.SetHeader( + HeaderFromGRPCMessage(m.GetHeader()), + ) + + h.SetSignature( + refs.SignatureFromGRPCMessage(m.GetSignature()), + ) + + return h +} + func ObjectToGRPCMessage(o *Object) *object.Object { if o == nil { return nil @@ -942,8 +978,8 @@ func GetHeaderPartFullToGRPCMessage(r *GetHeaderPartFull) *object.HeadResponse_B m := new(object.HeadResponse_Body_Header) - m.SetHeader( - HeaderToGRPCMessage(r.GetHeader()), + m.SetHeaderWithSignature( + HeaderWithSignatureToGRPCMessage(r.GetHeaderWithSignature()), ) return m @@ -956,8 +992,8 @@ func GetHeaderPartFullFromGRPCMessage(m *object.HeadResponse_Body_Header) *GetHe r := new(GetHeaderPartFull) - r.SetHeader( - HeaderFromGRPCMessage(m.GetHeader()), + r.SetHeaderWithSignature( + HeaderWithSignatureFromGRPCMessage(m.GetHeaderWithSignature()), ) return r diff --git a/v2/object/grpc/service.go b/v2/object/grpc/service.go index 515d3e81..025af1c9 100644 --- a/v2/object/grpc/service.go +++ b/v2/object/grpc/service.go @@ -330,8 +330,8 @@ func (m *HeadResponse_Body_ShortHeader) SetShortHeader(v *ShortHeader) { } } -// GetHeader returns object header. -func (m *HeadResponse_Body_Header) GetHeader() *Header { +// GetHeaderWithSignature returns object header. +func (m *HeadResponse_Body_Header) GetHeaderWithSignature() *HeaderWithSignature { if m != nil { return m.Header } @@ -339,13 +339,27 @@ func (m *HeadResponse_Body_Header) GetHeader() *Header { return nil } -// SetHeader sets object header. -func (m *HeadResponse_Body_Header) SetHeader(v *Header) { +// SetHeaderWithSignature sets object header. +func (m *HeadResponse_Body_Header) SetHeaderWithSignature(v *HeaderWithSignature) { if m != nil { m.Header = v } } +// SetHeader sets object header. +func (m *HeaderWithSignature) SetHeader(v *Header) { + if m != nil { + m.Header = v + } +} + +// SetSignature of the header. +func (m *HeaderWithSignature) SetSignature(v *refs.Signature) { + if m != nil { + m.Signature = v + } +} + // SetHeader sets full header of the object. func (m *HeadResponse_Body) SetHeader(v *HeadResponse_Body_Header) { if m != nil { diff --git a/v2/object/grpc/service.pb.go b/v2/object/grpc/service.pb.go index 2c8fc74f..46462c68 100644 Binary files a/v2/object/grpc/service.pb.go and b/v2/object/grpc/service.pb.go differ diff --git a/v2/object/marshal.go b/v2/object/marshal.go index f19c54fe..c1ceea14 100644 --- a/v2/object/marshal.go +++ b/v2/object/marshal.go @@ -33,6 +33,9 @@ const ( hdrAttributesField = 10 hdrSplitField = 11 + hdrWithSigHeaderField = 1 + hdrWithSigSignatureField = 2 + objIDField = 1 objSignatureField = 2 objHeaderField = 3 @@ -385,6 +388,48 @@ func (h *Header) StableSize() (size int) { return size } +func (h *HeaderWithSignature) StableMarshal(buf []byte) ([]byte, error) { + if h == nil { + return []byte{}, nil + } + + if buf == nil { + buf = make([]byte, h.StableSize()) + } + + var ( + offset, n int + err error + ) + + n, err = proto.NestedStructureMarshal(hdrWithSigHeaderField, buf[offset:], h.header) + if err != nil { + return nil, err + } + + offset += n + + n, err = proto.NestedStructureMarshal(hdrWithSigSignatureField, buf[offset:], h.signature) + if err != nil { + return nil, err + } + + offset += n + + return buf, nil +} + +func (h *HeaderWithSignature) StableSize() (size int) { + if h == nil { + return 0 + } + + size += proto.NestedStructureSize(hdrVersionField, h.header) + size += proto.NestedStructureSize(hdrContainerIDField, h.signature) + + return size +} + func (o *Object) StableMarshal(buf []byte) ([]byte, error) { if o == nil { return []byte{}, nil diff --git a/v2/object/marshal_test.go b/v2/object/marshal_test.go index 04f3a390..e63683b1 100644 --- a/v2/object/marshal_test.go +++ b/v2/object/marshal_test.go @@ -590,8 +590,12 @@ func generateHeadResponseBody(flag bool) *object.HeadResponseBody { short.SetShortHeader(generateShortHeader("short id")) part = short } else { + hdrWithSig := new(object.HeaderWithSignature) + hdrWithSig.SetHeader(generateHeader(30)) + hdrWithSig.SetSignature(generateSignature("sig", "key")) + full := new(object.GetHeaderPartFull) - full.SetHeader(generateHeader(30)) + full.SetHeaderWithSignature(hdrWithSig) part = full } diff --git a/v2/object/types.go b/v2/object/types.go index cdce248d..5c6c9ac4 100644 --- a/v2/object/types.go +++ b/v2/object/types.go @@ -57,6 +57,12 @@ type Header struct { split *SplitHeader } +type HeaderWithSignature struct { + header *Header + + signature *refs.Signature +} + type Object struct { objectID *refs.ObjectID @@ -136,7 +142,7 @@ type GetHeaderPart interface { } type GetHeaderPartFull struct { - hdr *Header + hdr *HeaderWithSignature } type GetHeaderPartShort struct { @@ -528,6 +534,34 @@ func (h *Header) SetSplit(v *SplitHeader) { } } +func (h *HeaderWithSignature) GetHeader() *Header { + if h != nil { + return h.header + } + + return nil +} + +func (h *HeaderWithSignature) SetHeader(v *Header) { + if h != nil { + h.header = v + } +} + +func (h *HeaderWithSignature) GetSignature() *refs.Signature { + if h != nil { + return h.signature + } + + return nil +} + +func (h *HeaderWithSignature) SetSignature(v *refs.Signature) { + if h != nil { + h.signature = v + } +} + func (o *Object) GetObjectID() *refs.ObjectID { if o != nil { return o.objectID @@ -1138,7 +1172,7 @@ func (r *HeadRequest) SetVerificationHeader(v *session.RequestVerificationHeader } } -func (h *GetHeaderPartFull) GetHeader() *Header { +func (h *GetHeaderPartFull) GetHeaderWithSignature() *HeaderWithSignature { if h != nil { return h.hdr } @@ -1146,7 +1180,7 @@ func (h *GetHeaderPartFull) GetHeader() *Header { return nil } -func (h *GetHeaderPartFull) SetHeader(v *Header) { +func (h *GetHeaderPartFull) SetHeaderWithSignature(v *HeaderWithSignature) { if h != nil { h.hdr = v }