Skip to content

Commit 91512e0

Browse files
committed
removes extra colon delimiter before componentid
without this change, the VEX.GenerateCanonicalID function produces a string like: :1671745003::pkg:oci/example@sha256:47fed8868b46b060efb8699dc40e981a0c785650223e03602d8c4493fc75b68c without this change, the VEX.GenerateCanonicalID function produces a string like: 1671745003:pkg:oci/example@sha256:47fed8868b46b060efb8699dc40e981a0c785650223e03602d8c4493fc75b68c since the string is hashed, the extra colon delimiter changes the hash in a meaningful way. the reason for this behavior is that the cstringFromComponent function produces a string with a leading colon, and those strings were then joined into a string with another leading colon. Signed-off-by: Sam Sanders <[email protected]>
1 parent f6bad3a commit 91512e0

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pkg/vex/vex.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (vexDoc *VEX) CanonicalHash() (string, error) {
232232
prods = append(prods, prodString)
233233
}
234234
sort.Strings(prods)
235-
cString += fmt.Sprintf(":%s", strings.Join(prods, ":"))
235+
cString += strings.Join(prods, ":")
236236
}
237237

238238
// 6. Hash the string in sha256 and return

pkg/vex/vex_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ func genTestDoc(t *testing.T) VEX {
167167

168168
func TestCanonicalHash(t *testing.T) {
169169
//nolint:gosec // Not a credential
170-
goldenHash := `3edda795cc8f075902800f0bb6a24f89b49e7e45fbceea96ce6061097460f139`
170+
goldenHash := `8ed99017785c3b43219018c7c50353c031cdaaf1c7efc146c683b0ce57123cf6`
171171

172172
otherTS, err := time.Parse(time.RFC3339, "2019-01-22T16:36:43-05:00")
173173
require.NoError(t, err)
@@ -190,7 +190,7 @@ func TestCanonicalHash(t *testing.T) {
190190
Status: "affected",
191191
})
192192
},
193-
"662d88a939419d4dc61406c3180711a89a729272abeabf2be7ef76c8c42fdfda",
193+
"cbfbba00d118572164b5b934e3ced71c1b02e171f942abfe66d42775dba703cf",
194194
false,
195195
},
196196
// Changing metadata should not change hash
@@ -220,15 +220,15 @@ func TestCanonicalHash(t *testing.T) {
220220
func(v *VEX) {
221221
v.Statements[0].Products[0].ID = "cool router, bro"
222222
},
223-
"6caa2fb361667bb70c5be5e70df2982c75a7a848d9de050397a87dc4c515566c",
223+
"010aaeb3d6bf69c486e199a48ec40038ca347d2603142dd48d97937d8477fe37",
224224
false,
225225
},
226226
// Changing document time changes the hash
227227
{
228228
func(v *VEX) {
229229
v.Timestamp = &otherTS
230230
},
231-
"b9e10ecafe5afbdd36582f932550ae42e4301849909a12305d75a7c268d95922",
231+
"d585979c1cc06797d2486382b3fd5e95d3a9b416525c95c9fefcef9863a595c8",
232232
false,
233233
},
234234
// Same timestamp in statement as doc should not change the hash
@@ -260,7 +260,7 @@ func TestGenerateCanonicalID(t *testing.T) {
260260
{
261261
// Normal generation
262262
prepare: func(v *VEX) {},
263-
expectedID: "https://openvex.dev/docs/public/vex-3edda795cc8f075902800f0bb6a24f89b49e7e45fbceea96ce6061097460f139",
263+
expectedID: "https://openvex.dev/docs/public/vex-8ed99017785c3b43219018c7c50353c031cdaaf1c7efc146c683b0ce57123cf6",
264264
},
265265
{
266266
// Existing IDs should not be changed

0 commit comments

Comments
 (0)