[#162] sdk/object: Detach header verification functions

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-29 15:18:52 +03:00 committed by Alex Vanin
parent 2cc58e36f8
commit 420d956062

View file

@ -124,10 +124,8 @@ func VerifyIDSignature(obj *Object) error {
) )
} }
// SetVerificationFields calculates and sets all verification fields of the object. // SetIDWithSignature sets object identifier and signature.
func SetVerificationFields(key *ecdsa.PrivateKey, obj *RawObject) error { func SetIDWithSignature(key *ecdsa.PrivateKey, obj *RawObject) error {
CalculateAndSetPayloadChecksum(obj)
if err := CalculateAndSetID(obj); err != nil { if err := CalculateAndSetID(obj); err != nil {
return errors.Wrap(err, "could not set identifier") return errors.Wrap(err, "could not set identifier")
} }
@ -139,14 +137,17 @@ func SetVerificationFields(key *ecdsa.PrivateKey, obj *RawObject) error {
return nil return nil
} }
// CheckVerificationFields checks all verification fields of the object. // SetVerificationFields calculates and sets all verification fields of the object.
func CheckVerificationFields(obj *Object) error { func SetVerificationFields(key *ecdsa.PrivateKey, obj *RawObject) error {
if err := VerifyIDSignature(obj); err != nil { CalculateAndSetPayloadChecksum(obj)
return errors.Wrap(err, "invalid signature")
return SetIDWithSignature(key, obj)
} }
if err := VerifyID(obj); err != nil { // CheckVerificationFields checks all verification fields of the object.
return errors.Wrap(err, "invalid identifier") func CheckVerificationFields(obj *Object) error {
if err := CheckHeaderVerificationFields(obj); err != nil {
return errors.Wrap(err, "invalid header structure")
} }
if err := VerifyPayloadChecksum(obj); err != nil { if err := VerifyPayloadChecksum(obj); err != nil {
@ -155,3 +156,16 @@ func CheckVerificationFields(obj *Object) error {
return nil 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
}