Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make use of HashFromBytes everywhere #2482

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions internal/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions internal/ui/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading