@@ -13,13 +13,13 @@ import (
1313)
1414
1515type (
16- ObjectHashFunc func (obj any ) ( string , error )
16+ ObjectHashFunc func (obj any ) string
1717 EqualFunc func (a , b string ) bool
1818)
1919
2020// ObjectHasher hashes and object and can compare hashes for equality
2121type ObjectHasher interface {
22- Hash (obj any ) ( string , error )
22+ Hash (obj any ) string
2323 Equal (a , b string ) bool
2424}
2525
@@ -28,7 +28,7 @@ type hasher struct {
2828 EqualFunc
2929}
3030
31- func (h * hasher ) Hash (obj interface {}) ( string , error ) {
31+ func (h * hasher ) Hash (obj interface {}) string {
3232 return h .ObjectHashFunc (obj )
3333}
3434
@@ -54,25 +54,24 @@ func NewObjectHash() ObjectHasher {
5454
5555// SecureObject canonicalizes the object before hashing with sha512 and then
5656// with xxhash
57- func SecureObject (obj interface {}) ( string , error ) {
57+ func SecureObject (obj interface {}) string {
5858 hasher := sha512 .New512_256 ()
5959 printer := spew.ConfigState {
6060 Indent : " " ,
6161 SortKeys : true ,
6262 DisableMethods : true ,
6363 SpewKeys : true ,
6464 }
65- _ , err := printer .Fprintf (hasher , "%#v" , obj )
66- if err != nil {
67- return "" , err
68- }
65+ // sha512's hasher.Write never returns an error, and Fprintf just passes up
66+ // the underlying Write call's error, so we can safely ignore the error here
67+ _ , _ = printer .Fprintf (hasher , "%#v" , obj )
6968 // xxhash the sha512 hash to get a shorter value
7069 xxhasher := xxhash .New ()
71- _ , err = xxhasher . Write ( hasher . Sum ( nil ))
72- if err != nil {
73- return "" , err
74- }
75- return rand .SafeEncodeString (fmt .Sprint (xxhasher .Sum (nil ))), nil
70+
71+ // xxhash's hasher.Write never returns an error, so we can safely ignore
72+ // the error here tpp
73+ _ , _ = xxhasher . Write ( hasher . Sum ( nil ))
74+ return rand .SafeEncodeString (fmt .Sprint (xxhasher .Sum (nil )))
7675}
7776
7877// SecureEqual compares hashes safely
@@ -81,19 +80,19 @@ func SecureEqual(a, b string) bool {
8180}
8281
8382// Object canonicalizes the object before hashing with xxhash
84- func Object (obj interface {}) ( string , error ) {
83+ func Object (obj interface {}) string {
8584 hasher := xxhash .New ()
8685 printer := spew.ConfigState {
8786 Indent : " " ,
8887 SortKeys : true ,
8988 DisableMethods : true ,
9089 SpewKeys : true ,
9190 }
92- _ , err := printer . Fprintf ( hasher , "%#v" , obj )
93- if err != nil {
94- return "" , err
95- }
96- return rand .SafeEncodeString (fmt .Sprint (hasher .Sum (nil ))), nil
91+
92+ // xxhash's hasher.Write never returns an error, and Fprintf just passes up
93+ // the underlying Write call's error, so we can safely ignore the error here
94+ _ , _ = printer . Fprintf ( hasher , "%#v" , obj )
95+ return rand .SafeEncodeString (fmt .Sprint (hasher .Sum (nil )))
9796}
9897
9998// Equal compares hashes safely
0 commit comments