object: Add CreateIntegrityHeader function

CreateIntegrityHeader function allow to optimize
object put pipeline in neofs nodes.
This commit is contained in:
alexvanin 2020-01-16 14:38:08 +03:00
parent c2f63107d0
commit f1418ef79d

View file

@ -63,6 +63,7 @@ func (m Object) verifySignature(key []byte, ih *IntegrityHeader) error {
// Verify performs local integrity check by finding verification header and // Verify performs local integrity check by finding verification header and
// integrity header. If header integrity is passed, function verifies // integrity header. If header integrity is passed, function verifies
// checksum of the object payload. // checksum of the object payload.
// todo: move this verification logic into separate library
func (m Object) Verify() error { func (m Object) Verify() error {
var ( var (
err error err error
@ -111,22 +112,32 @@ func (m Object) Verify() error {
return nil return nil
} }
// Sign creates new integrity header and adds it to the end of the list of // CreateIntegrityHeader returns signed integrity header for the object
// extended headers. func CreateIntegrityHeader(obj *Object, key *ecdsa.PrivateKey) (*Header, error) {
func (m *Object) Sign(key *ecdsa.PrivateKey) error { headerChecksum, err := obj.headersChecksum(false)
headerChecksum, err := m.headersChecksum(false)
if err != nil { if err != nil {
return err return nil, err
} }
headerChecksumSignature, err := crypto.Sign(key, headerChecksum) headerChecksumSignature, err := crypto.Sign(key, headerChecksum)
if err != nil { if err != nil {
return err return nil, err
} }
m.AddHeader(&Header{Value: &Header_Integrity{
return &Header{Value: &Header_Integrity{
Integrity: &IntegrityHeader{ Integrity: &IntegrityHeader{
HeadersChecksum: headerChecksum, HeadersChecksum: headerChecksum,
ChecksumSignature: headerChecksumSignature, ChecksumSignature: headerChecksumSignature,
}, },
}}) }}, nil
}
// Sign creates new integrity header and adds it to the end of the list of
// extended headers.
func (m *Object) Sign(key *ecdsa.PrivateKey) error {
ih, err := CreateIntegrityHeader(m, key)
if err != nil {
return err
}
m.AddHeader(ih)
return nil return nil
} }