diff --git a/internal/digest/digest.go b/internal/digest/digest.go index 9fcca642..6b111739 100644 --- a/internal/digest/digest.go +++ b/internal/digest/digest.go @@ -17,6 +17,8 @@ limitations under the License. package digest import ( + "crypto" + _ "crypto/sha1" _ "crypto/sha256" _ "crypto/sha512" "fmt" @@ -25,8 +27,19 @@ import ( _ "github.com/opencontainers/go-digest/blake3" ) -// Canonical is the primary digest algorithm used to calculate checksums. -const Canonical = digest.SHA256 +const ( + SHA1 digest.Algorithm = "sha1" +) + +var ( + // Canonical is the primary digest algorithm used to calculate checksums. + Canonical = digest.SHA256 +) + +func init() { + // Register SHA-1 algorithm for support of e.g. Git commit SHAs. + digest.RegisterAlgorithm(SHA1, crypto.SHA1) +} // AlgorithmForName returns the digest algorithm for the given name, or an // error of type digest.ErrDigestUnsupported if the algorithm is unavailable. diff --git a/internal/digest/writer_test.go b/internal/digest/writer_test.go index d58518ef..9ae63b88 100644 --- a/internal/digest/writer_test.go +++ b/internal/digest/writer_test.go @@ -102,6 +102,10 @@ func benchmarkMultiDigesterWrite(b *testing.B, algos []digest.Algorithm, pSize i func BenchmarkMultiDigester_Write(b *testing.B) { const pSize = 1024 * 2 + b.Run("sha1", func(b *testing.B) { + benchmarkMultiDigesterWrite(b, []digest.Algorithm{SHA1}, pSize) + }) + b.Run("sha256", func(b *testing.B) { benchmarkMultiDigesterWrite(b, []digest.Algorithm{digest.SHA256}, pSize) })