From 9c8a7dfffe2f4596dcbde2c923a7539914bb252f Mon Sep 17 00:00:00 2001 From: jvoisin Date: Mon, 11 Mar 2024 23:03:23 +0100 Subject: [PATCH] Make use of HashFromBytes everywhere It feels a bit silly to have a function and to not make use of it. --- internal/crypto/crypto.go | 3 +-- internal/ui/static/static.go | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/crypto/crypto.go b/internal/crypto/crypto.go index 0b0ab6c6..c99beeb8 100644 --- a/internal/crypto/crypto.go +++ b/internal/crypto/crypto.go @@ -17,8 +17,7 @@ import ( // HashFromBytes returns a SHA-256 checksum of the input. func HashFromBytes(value []byte) string { - sum := sha256.Sum256(value) - return fmt.Sprintf("%x", sum) + return fmt.Sprintf("%x", sha256.Sum256(value)) } // Hash returns a SHA-256 checksum of a string. diff --git a/internal/ui/static/static.go b/internal/ui/static/static.go index a3deb6d9..c417d23f 100644 --- a/internal/ui/static/static.go +++ b/internal/ui/static/static.go @@ -5,10 +5,11 @@ package static // import "miniflux.app/v2/internal/ui/static" import ( "bytes" - "crypto/sha256" "embed" "fmt" + "miniflux.app/v2/internal/crypto" + "github.com/tdewolff/minify/v2" "github.com/tdewolff/minify/v2/css" "github.com/tdewolff/minify/v2/js" @@ -48,7 +49,7 @@ func CalculateBinaryFileChecksums() error { return err } - binaryFileChecksums[dirEntry.Name()] = fmt.Sprintf("%x", sha256.Sum256(data)) + binaryFileChecksums[dirEntry.Name()] = crypto.HashFromBytes(data) } return nil @@ -102,7 +103,7 @@ func GenerateStylesheetsBundles() error { } StylesheetBundles[bundle] = minifiedData - StylesheetBundleChecksums[bundle] = fmt.Sprintf("%x", sha256.Sum256(minifiedData)) + StylesheetBundleChecksums[bundle] = crypto.HashFromBytes(minifiedData) } return nil @@ -166,7 +167,7 @@ func GenerateJavascriptBundles() error { } JavascriptBundles[bundle] = minifiedData - JavascriptBundleChecksums[bundle] = fmt.Sprintf("%x", sha256.Sum256(minifiedData)) + JavascriptBundleChecksums[bundle] = crypto.HashFromBytes(minifiedData) } return nil