Skip to content

Commit

Permalink
Change the log ID function to also include the origin string
Browse files Browse the repository at this point in the history
  • Loading branch information
mhutchinson committed Jan 23, 2023
1 parent 34660ba commit a560499
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion log/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,10 @@ import (
// for this log at distributors, and that will be used to feed
// checkpoints to witnesses.
func ID(origin string, key []byte) string {
return fmt.Sprintf("%x", sha256.Sum256(key))
// Hash both the origin and key, and then hash them together
// to create the final ID.
oh := sha256.Sum256([]byte(origin))
kh := sha256.Sum256(key)
hashMe := append([]byte(oh[:]), kh[:]...)
return fmt.Sprintf("%x", sha256.Sum256(hashMe))
}
4 changes: 2 additions & 2 deletions log/identifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ func TestID(t *testing.T) {
desc: "sumdb",
origin: "go.sum database tree",
pk: []byte("sum.golang.org+033de0ae+Ac4zctda0e5eza+HJyk9SxEdh+s3Ux18htTTAD8OuAn8"),
want: "3e9617dce5730053cb82f0481b9d289cd3c384a9219ef5509c91aa60d214794e",
want: "e0b4aa62acca10f5bc40bb803eea643cba17a908bd9cf4e9ef8d736bac47fb48",
},
{
desc: "usbarmory",
origin: "Armory Drive Prod 2",
pk: []byte("armory-drive-log+16541b8f+AYDPmG5pQp4Bgu0a1mr5uDZ196+t8lIVIfWQSPWmP+Jv"),
want: "50dfc1866b26a18b65834743645f90737c331bc5e99b44100e5ca555c17821e3",
want: "4ad2fce3c699522bf81ef663bdc973e83a27ea1b8c92ea6d030747d73cd9dae8",
},
} {
t.Run(test.desc, func(t *testing.T) {
Expand Down

0 comments on commit a560499

Please sign in to comment.