From 420d9560625be602670c8323d2a6e44a3ce2d4d9 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 29 Sep 2020 15:18:52 +0300 Subject: [PATCH] [#162] sdk/object: Detach header verification functions Signed-off-by: Leonard Lyubich --- pkg/object/fmt.go | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/object/fmt.go b/pkg/object/fmt.go index 61a08b61..04cb5f41 100644 --- a/pkg/object/fmt.go +++ b/pkg/object/fmt.go @@ -124,10 +124,8 @@ func VerifyIDSignature(obj *Object) error { ) } -// SetVerificationFields calculates and sets all verification fields of the object. -func SetVerificationFields(key *ecdsa.PrivateKey, obj *RawObject) error { - CalculateAndSetPayloadChecksum(obj) - +// SetIDWithSignature sets object identifier and signature. +func SetIDWithSignature(key *ecdsa.PrivateKey, obj *RawObject) error { if err := CalculateAndSetID(obj); err != nil { return errors.Wrap(err, "could not set identifier") } @@ -139,14 +137,17 @@ func SetVerificationFields(key *ecdsa.PrivateKey, obj *RawObject) error { return nil } +// SetVerificationFields calculates and sets all verification fields of the object. +func SetVerificationFields(key *ecdsa.PrivateKey, obj *RawObject) error { + CalculateAndSetPayloadChecksum(obj) + + return SetIDWithSignature(key, obj) +} + // CheckVerificationFields checks all verification fields of the object. func CheckVerificationFields(obj *Object) error { - if err := VerifyIDSignature(obj); err != nil { - return errors.Wrap(err, "invalid signature") - } - - if err := VerifyID(obj); err != nil { - return errors.Wrap(err, "invalid identifier") + if err := CheckHeaderVerificationFields(obj); err != nil { + return errors.Wrap(err, "invalid header structure") } if err := VerifyPayloadChecksum(obj); err != nil { @@ -155,3 +156,16 @@ func CheckVerificationFields(obj *Object) error { return nil } + +// CheckHeaderVerificationFields checks all verification fields except payload. +func CheckHeaderVerificationFields(obj *Object) error { + if err := VerifyIDSignature(obj); err != nil { + return errors.Wrap(err, "invalid signature") + } + + if err := VerifyID(obj); err != nil { + return errors.Wrap(err, "invalid identifier") + } + + return nil +}