-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
object: Improve testing and increase coverage for Object
type
#634
Changes from all commits
3c47093
cc4d4a1
b20b162
566bbee
5110db2
0c33fbc
ebb37bc
0422113
7d16474
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ func (o *Object) CalculateAndSetPayloadChecksum() { | |
|
||
// VerifyPayloadChecksum checks if payload checksum in the object | ||
// corresponds to its payload. | ||
func (o *Object) VerifyPayloadChecksum() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again: nspcc-dev/.github#29. my biggest concern is why we continue doing this. it is questionable (we do not have the answer on this) but still, we see such commits. we may "fix" it here and have thousands of structs that do not follow this rule. so what's the point? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're waiting for benchmarks to show copying happens and matters. Then we'll change it back. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mostly, existing ro methods are defined on types, not pointers. And some methods like this differ unreasonably. Im tryin to stick them to the most expected view basically. If there will be a particular reason to have a pointer-based method - we'll add it. Currently, there is no reason to pass pointer for payload verification |
||
func (o Object) VerifyPayloadChecksum() error { | ||
actual := CalculatePayloadChecksum(o.Payload()) | ||
|
||
cs, set := o.PayloadChecksum() | ||
|
@@ -54,7 +54,7 @@ func (o *Object) VerifyPayloadChecksum() error { | |
} | ||
|
||
// CalculateID calculates identifier for the object. | ||
func (o *Object) CalculateID() (oid.ID, error) { | ||
func (o Object) CalculateID() (oid.ID, error) { | ||
return sha256.Sum256(o.ToV2().GetHeader().StableMarshal(nil)), nil | ||
} | ||
|
||
|
@@ -73,7 +73,7 @@ func (o *Object) CalculateAndSetID() error { | |
|
||
// VerifyID checks if identifier in the object corresponds to | ||
// its structure. | ||
func (o *Object) VerifyID() error { | ||
func (o Object) VerifyID() error { | ||
id, err := o.CalculateID() | ||
if err != nil { | ||
return err | ||
|
@@ -113,13 +113,13 @@ func (o *Object) Sign(signer neofscrypto.Signer) error { | |
// SignedData returns actual payload to sign. | ||
// | ||
// See also [Object.Sign]. | ||
func (o *Object) SignedData() []byte { | ||
func (o Object) SignedData() []byte { | ||
return o.GetID().Marshal() | ||
} | ||
|
||
// VerifySignature verifies object ID signature. | ||
func (o *Object) VerifySignature() bool { | ||
m := (*object.Object)(o) | ||
func (o Object) VerifySignature() bool { | ||
m := (*object.Object)(&o) | ||
|
||
sigV2 := m.GetSignature() | ||
if sigV2 == nil { | ||
|
@@ -157,7 +157,7 @@ func (o *Object) SetVerificationFields(signer neofscrypto.Signer) error { | |
} | ||
|
||
// CheckVerificationFields checks all verification fields of the object. | ||
func (o *Object) CheckVerificationFields() error { | ||
func (o Object) CheckVerificationFields() error { | ||
if err := o.CheckHeaderVerificationFields(); err != nil { | ||
return fmt.Errorf("invalid header structure: %w", err) | ||
} | ||
|
@@ -172,7 +172,7 @@ func (o *Object) CheckVerificationFields() error { | |
var errInvalidSignature = errors.New("invalid signature") | ||
|
||
// CheckHeaderVerificationFields checks all verification fields except payload. | ||
func (o *Object) CheckHeaderVerificationFields() error { | ||
func (o Object) CheckHeaderVerificationFields() error { | ||
if !o.VerifySignature() { | ||
return errInvalidSignature | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
immo this is kinda stylish thing: i would prefer to always keep a new line before every
return
. it used to have it, but now it does not. white space change as @roman-khimov would say. do not insistThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit different, not a pure whitespace change since the logic is changed in these blocks. Works for me both ways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not an occasional whitespace change like #634 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i understand but this is also not a new functionality just the old one was changed. i try not to drop/add new lines in such cases even if i have a different style