Skip to content

Commit c440e83

Browse files
committed
chore: switch from gob to JSON encoding for digests
The gob encoder is dependent on the order in which it sees types. So, even encoding a completely new type could change the "digest" of a type with the same values. This is not in the flavor or producing a digest. This change switches to JSON, which will produce a consistent encoding. Signed-off-by: Donnie Adams <[email protected]>
1 parent b98000c commit c440e83

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

pkg/hash/sha256.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ package hash
22

33
import (
44
"crypto/sha256"
5-
"encoding/gob"
65
"encoding/hex"
6+
"encoding/json"
77
)
88

99
func ID(parts ...string) string {
@@ -26,7 +26,7 @@ func Digest(obj any) string {
2626
case string:
2727
hash.Write([]byte(v))
2828
default:
29-
if err := gob.NewEncoder(hash).Encode(obj); err != nil {
29+
if err := json.NewEncoder(hash).Encode(obj); err != nil {
3030
panic(err)
3131
}
3232
}

0 commit comments

Comments
 (0)