object: implement signing payload methods on GetRequest message
This commit is contained in:
parent
78f435a905
commit
439221cea8
2 changed files with 59 additions and 6 deletions
|
@ -1,5 +1,9 @@
|
|||
package object
|
||||
|
||||
import (
|
||||
"io"
|
||||
)
|
||||
|
||||
// SignedData returns marshaled payload of the Put request.
|
||||
//
|
||||
// If payload is nil, ErrHeaderNotFound returns.
|
||||
|
@ -43,3 +47,39 @@ func (m PutRequest) SignedDataSize() int {
|
|||
|
||||
return r.Size()
|
||||
}
|
||||
|
||||
// SignedData returns marshaled Address field.
|
||||
//
|
||||
// Resulting error is always nil.
|
||||
func (m GetRequest) SignedData() ([]byte, error) {
|
||||
addr := m.GetAddress()
|
||||
|
||||
return append(
|
||||
addr.CID.Bytes(),
|
||||
addr.ObjectID.Bytes()...,
|
||||
), nil
|
||||
}
|
||||
|
||||
// ReadSignedData copies marshaled Address field to passed buffer.
|
||||
//
|
||||
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
||||
func (m GetRequest) ReadSignedData(p []byte) error {
|
||||
addr := m.GetAddress()
|
||||
|
||||
if len(p) < addr.CID.Size()+addr.ObjectID.Size() {
|
||||
return io.ErrUnexpectedEOF
|
||||
}
|
||||
|
||||
off := copy(p, addr.CID.Bytes())
|
||||
|
||||
copy(p[off:], addr.ObjectID.Bytes())
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SignedDataSize returns the size of object address.
|
||||
func (m GetRequest) SignedDataSize() int {
|
||||
addr := m.GetAddress()
|
||||
|
||||
return addr.CID.Size() + addr.ObjectID.Size()
|
||||
}
|
||||
|
|
|
@ -19,14 +19,14 @@ func TestSignVerifyRequests(t *testing.T) {
|
|||
}
|
||||
|
||||
items := []struct {
|
||||
constructor func() sigType
|
||||
bodyCorrupt []func(sigType)
|
||||
constructor func() sigType
|
||||
payloadCorrupt []func(sigType)
|
||||
}{
|
||||
{ // PutRequest.PutHeader
|
||||
constructor: func() sigType {
|
||||
return MakePutRequestHeader(new(Object))
|
||||
},
|
||||
bodyCorrupt: []func(sigType){
|
||||
payloadCorrupt: []func(sigType){
|
||||
func(s sigType) {
|
||||
obj := s.(*PutRequest).GetR().(*PutRequest_Header).Header.GetObject()
|
||||
obj.SystemHeader.PayloadLength++
|
||||
|
@ -37,13 +37,26 @@ func TestSignVerifyRequests(t *testing.T) {
|
|||
constructor: func() sigType {
|
||||
return MakePutRequestChunk(make([]byte, 10))
|
||||
},
|
||||
bodyCorrupt: []func(sigType){
|
||||
payloadCorrupt: []func(sigType){
|
||||
func(s sigType) {
|
||||
h := s.(*PutRequest).GetR().(*PutRequest_Chunk)
|
||||
h.Chunk[0]++
|
||||
},
|
||||
},
|
||||
},
|
||||
{ // GetRequest
|
||||
constructor: func() sigType {
|
||||
return new(GetRequest)
|
||||
},
|
||||
payloadCorrupt: []func(sigType){
|
||||
func(s sigType) {
|
||||
s.(*GetRequest).Address.CID[0]++
|
||||
},
|
||||
func(s sigType) {
|
||||
s.(*GetRequest).Address.ObjectID[0]++
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, item := range items {
|
||||
|
@ -62,8 +75,8 @@ func TestSignVerifyRequests(t *testing.T) {
|
|||
require.Error(t, service.VerifyAccumulatedSignaturesWithToken(v))
|
||||
}
|
||||
|
||||
{ // body corruptions
|
||||
for _, corruption := range item.bodyCorrupt {
|
||||
{ // payload corruptions
|
||||
for _, corruption := range item.payloadCorrupt {
|
||||
v := item.constructor()
|
||||
|
||||
require.NoError(t, service.SignDataWithSessionToken(sk, v))
|
||||
|
|
Loading…
Reference in a new issue