Skip to content

Commit ace8a36

Browse files
committed
fix: use sha256 for packages by default
1 parent e013b76 commit ace8a36

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎internal/archive/archive.go‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,19 @@ func findDigest(release control.Section, path string, order []digestField) (dige
367367
return "", digestField{}
368368
}
369369

370+
// packageDigestFields lists the checksum fields Chisel looks up in a package
371+
// section, in order of preference. Unlike index files, packages are fetched
372+
// by their named pool path, so the by-hash layout does not constrain this
373+
// order. SHA256 is preferred so that the digest recorded in the manifest
374+
// keeps matching the one consumers expect for as long as archives publish
375+
// it; the strongest available digest is used only when they do not.
376+
var packageDigestFields = []digestField{
377+
{"SHA256", cache.SHA256},
378+
{"SHA512", cache.SHA512},
379+
}
380+
370381
func packageDigest(section control.Section) (digest string, kind cache.DigestKind) {
371-
for _, f := range digestFields {
382+
for _, f := range packageDigestFields {
372383
if d := section.Get(f.name); d != "" {
373384
return d, f.kind
374385
}

‎internal/archive/archive_test.go‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,11 @@ func (s *httpSuite) TestFetchSHA512Digests(c *C) {
306306

307307
func (s *httpSuite) TestFetchBothDigests(c *C) {
308308
// An archive publishing both SHA256 and SHA512 sections (index table and
309-
// package fields) must be handled, with the strongest digest preferred
310-
// for verification, caching and the manifest.
309+
// package fields) must be handled. For packages, SHA256 is preferred for
310+
// verification, caching and the manifest, so the recorded digest keeps
311+
// matching the one consumers expect; the strongest digest is used only
312+
// when the archive does not publish SHA256. Index files still use the
313+
// strongest digest, as required by the by-hash layout.
311314
s.prepareArchiveAdjustRelease("stonking", "25.10", "amd64", []string{"main", "universe"},
312315
[]string{"SHA256", "SHA512"}, nil)
313316

@@ -330,15 +333,15 @@ func (s *httpSuite) TestFetchBothDigests(c *C) {
330333
Name: "mypkg1",
331334
Version: "1.1",
332335
Arch: "amd64",
333-
Digest: "27c6e88def3d3848f4a068040bddbf908ab90e33bf93fc24fd02af7ed6a1953151302f2c59306313f065163143b51f1000cd22d102b7a58d7efd6430f5e162fb",
334-
DigestKind: cache.SHA512,
336+
Digest: "1f08ef04cfe7a8087ee38a1ea35fa1810246648136c3c42d5a61ad6503d85e05",
337+
DigestKind: cache.SHA256,
335338
})
336339
c.Assert(read(pkg), Equals, "mypkg1 1.1 data")
337340

338341
// Pin the cache key: with both digests advertised, the package is cached
339-
// under its strongest digest.
340-
_, err = os.Stat(filepath.Join(options.CacheDir, "sha512",
341-
"27c6e88def3d3848f4a068040bddbf908ab90e33bf93fc24fd02af7ed6a1953151302f2c59306313f065163143b51f1000cd22d102b7a58d7efd6430f5e162fb"))
342+
// under its SHA256 digest.
343+
_, err = os.Stat(filepath.Join(options.CacheDir, "sha256",
344+
"1f08ef04cfe7a8087ee38a1ea35fa1810246648136c3c42d5a61ad6503d85e05"))
342345
c.Assert(err, IsNil)
343346
}
344347

0 commit comments

Comments
 (0)