Skip to content

Commit

Permalink
add Identity.IsZero method
Browse files Browse the repository at this point in the history
This commit adds the `IsZero() bool` method to the `Identity` type.
It returns true if the identity is equal to the Identity zero value.
A 'valid' identity won't be zero since `H(data)` will not produce
a hash value of all zero bits with overwhelming probability if a H
is a collision-resistant hash function.

The `IsZero` method is inline with the accepted Go JSON proposal
adding the struct tag `omitzero`.
Ref: golang/go#45669 (comment)

Signed-off-by: Andreas Auernhammer <[email protected]>
  • Loading branch information
aead committed Sep 11, 2024
1 parent fa3041e commit afd92ae
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ type Identity struct {
hash [32]byte
}

var zeroIdentity = Identity{}

// IsZero returns true if i is the Identity zero value.
func (i Identity) IsZero() bool { return i == zeroIdentity }

// MarshalBinary returns a binary representation of the identity.
func (i Identity) MarshalBinary() ([]byte, error) {
var buf [35]byte
Expand Down

0 comments on commit afd92ae

Please sign in to comment.