2020-05-06 10:16:15 +00:00
|
|
|
package object
|
|
|
|
|
2020-05-06 10:33:03 +00:00
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// SignedData returns payload bytes of the request.
|
2020-05-06 10:16:15 +00:00
|
|
|
//
|
|
|
|
// If payload is nil, ErrHeaderNotFound returns.
|
|
|
|
func (m PutRequest) SignedData() ([]byte, error) {
|
2020-05-06 11:15:07 +00:00
|
|
|
sz := m.SignedDataSize()
|
|
|
|
if sz < 0 {
|
2020-05-06 10:16:15 +00:00
|
|
|
return nil, ErrHeaderNotFound
|
|
|
|
}
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
data := make([]byte, sz)
|
2020-05-06 10:16:15 +00:00
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
return data, m.ReadSignedData(data)
|
2020-05-06 10:16:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
2020-05-06 10:16:15 +00:00
|
|
|
//
|
2020-05-06 11:15:07 +00:00
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
2020-05-06 10:16:15 +00:00
|
|
|
func (m PutRequest) ReadSignedData(p []byte) error {
|
|
|
|
r := m.GetR()
|
|
|
|
if r == nil {
|
|
|
|
return ErrHeaderNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := r.MarshalTo(p)
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedDataSize returns the size of payload of the Put request.
|
|
|
|
//
|
|
|
|
// If payload is nil, -1 returns.
|
|
|
|
func (m PutRequest) SignedDataSize() int {
|
|
|
|
r := m.GetR()
|
|
|
|
if r == nil {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
return r.Size()
|
|
|
|
}
|
2020-05-06 10:33:03 +00:00
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// SignedData returns payload bytes of the request.
|
2020-05-06 10:33:03 +00:00
|
|
|
func (m GetRequest) SignedData() ([]byte, error) {
|
2020-05-06 11:15:07 +00:00
|
|
|
data := make([]byte, m.SignedDataSize())
|
2020-05-06 10:33:03 +00:00
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
return data, m.ReadSignedData(data)
|
2020-05-06 10:33:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
2020-05-06 10:33:03 +00:00
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m GetRequest) ReadSignedData(p []byte) error {
|
|
|
|
addr := m.GetAddress()
|
|
|
|
|
2020-05-06 10:54:13 +00:00
|
|
|
if len(p) < m.SignedDataSize() {
|
2020-05-06 10:33:03 +00:00
|
|
|
return io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
off := copy(p, addr.CID.Bytes())
|
|
|
|
|
|
|
|
copy(p[off:], addr.ObjectID.Bytes())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// SignedDataSize returns payload size of the request.
|
2020-05-06 10:33:03 +00:00
|
|
|
func (m GetRequest) SignedDataSize() int {
|
2020-05-06 10:54:13 +00:00
|
|
|
return addressSize(m.GetAddress())
|
|
|
|
}
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// SignedData returns payload bytes of the request.
|
2020-05-06 10:54:13 +00:00
|
|
|
func (m HeadRequest) SignedData() ([]byte, error) {
|
2020-05-06 11:15:07 +00:00
|
|
|
data := make([]byte, m.SignedDataSize())
|
2020-05-06 10:54:13 +00:00
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
return data, m.ReadSignedData(data)
|
2020-05-06 10:54:13 +00:00
|
|
|
}
|
2020-05-06 10:33:03 +00:00
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
2020-05-06 10:54:13 +00:00
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m HeadRequest) ReadSignedData(p []byte) error {
|
|
|
|
if len(p) < m.SignedDataSize() {
|
|
|
|
return io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
if m.GetFullHeaders() {
|
|
|
|
p[0] = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
off := 1 + copy(p[1:], m.Address.CID.Bytes())
|
|
|
|
|
|
|
|
copy(p[off:], m.Address.ObjectID.Bytes())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// SignedDataSize returns payload size of the request.
|
2020-05-06 10:54:13 +00:00
|
|
|
func (m HeadRequest) SignedDataSize() int {
|
|
|
|
return addressSize(m.Address) + 1
|
|
|
|
}
|
|
|
|
|
2020-05-06 11:15:07 +00:00
|
|
|
// SignedData returns payload bytes of the request.
|
|
|
|
func (m DeleteRequest) SignedData() ([]byte, error) {
|
|
|
|
data := make([]byte, m.SignedDataSize())
|
|
|
|
|
|
|
|
return data, m.ReadSignedData(data)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ReadSignedData copies payload bytes to passed buffer.
|
|
|
|
//
|
|
|
|
// If the buffer size is insufficient, io.ErrUnexpectedEOF returns.
|
|
|
|
func (m DeleteRequest) ReadSignedData(p []byte) error {
|
|
|
|
if len(p) < m.SignedDataSize() {
|
|
|
|
return io.ErrUnexpectedEOF
|
|
|
|
}
|
|
|
|
|
|
|
|
off := copy(p, m.OwnerID.Bytes())
|
|
|
|
|
|
|
|
copy(p[off:], addressBytes(m.Address))
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SignedDataSize returns payload size of the request.
|
|
|
|
func (m DeleteRequest) SignedDataSize() int {
|
|
|
|
return m.OwnerID.Size() + addressSize(m.Address)
|
|
|
|
}
|
|
|
|
|
2020-05-06 10:54:13 +00:00
|
|
|
func addressSize(addr Address) int {
|
2020-05-06 10:33:03 +00:00
|
|
|
return addr.CID.Size() + addr.ObjectID.Size()
|
|
|
|
}
|
2020-05-06 10:54:13 +00:00
|
|
|
|
|
|
|
func addressBytes(addr Address) []byte {
|
|
|
|
return append(addr.CID.Bytes(), addr.ObjectID.Bytes()...)
|
|
|
|
}
|