From 98caf09f0ff46f96018d94e63eb25da5faa155d2 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 18 Aug 2021 14:48:14 +0200 Subject: [PATCH] fix go-digest to make sure the algorithms are registered Previously, ioutils imported the crypty/sha256 package, because it was used by the HashData() utility. As a side-effect of that import, the sha256 algorithm was registered through its `init()` function. Now that the HashData() utility is removed, the import is no longer needed in this package, but some parts of our code depended on the side-effect, and without this, it fail to recognise the algorithms, unless something else happens to import crypto/sha256 / crypto/sha512, which made our tests fail: ``` === Failed === FAIL: reference TestLoad (0.00s) store_test.go:53: failed to parse reference: unsupported digest algorithm === FAIL: reference TestSave (0.00s) store_test.go:82: failed to parse reference: unsupported digest algorithm === FAIL: reference TestAddDeleteGet (0.00s) store_test.go:174: could not parse reference: unsupported digest algorithm === FAIL: reference TestInvalidTags (0.00s) store_test.go:355: assertion failed: error is not nil: unsupported digest algorithm ``` While it would be better to do the import in the actual locations where it's expected, there may be code-paths we overlook, so instead adding the import here temporarily. Until the PR in go-digest has been merged and released. Signed-off-by: Sebastiaan van Stijn --- pkg/ioutils/readers.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pkg/ioutils/readers.go b/pkg/ioutils/readers.go index 49d6936b14..de00b95e3f 100644 --- a/pkg/ioutils/readers.go +++ b/pkg/ioutils/readers.go @@ -3,6 +3,11 @@ package ioutils // import "github.com/docker/docker/pkg/ioutils" import ( "context" "io" + + // make sure crypto.SHA256, crypto.sha512 and crypto.SHA384 are registered + // TODO remove once https://github.com/opencontainers/go-digest/pull/64 is merged. + _ "crypto/sha256" + _ "crypto/sha512" ) // ReadCloserWrapper wraps an io.Reader, and implements an io.ReadCloser