From 76c3f5131a092cbaaa1024ad42cc287285c6157f Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 23 Jul 2024 17:49:46 -0400 Subject: [PATCH] Use SHA256 in Gravatar URLs --- utils/gravatar/gravatar.go | 4 ++-- utils/gravatar/gravatar_test.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/gravatar/gravatar.go b/utils/gravatar/gravatar.go index e0c7fe68e..1ab2464c6 100644 --- a/utils/gravatar/gravatar.go +++ b/utils/gravatar/gravatar.go @@ -1,7 +1,7 @@ package gravatar import ( - "crypto/md5" + "crypto/sha256" "fmt" "strings" ) @@ -13,7 +13,7 @@ const maxSize = 2048 func Url(email string, size int) string { email = strings.ToLower(email) email = strings.TrimSpace(email) - hash := md5.Sum([]byte(email)) + hash := sha256.Sum256([]byte(email)) if size < 1 { size = defaultSize } diff --git a/utils/gravatar/gravatar_test.go b/utils/gravatar/gravatar_test.go index a66c25af9..25ceeb642 100644 --- a/utils/gravatar/gravatar_test.go +++ b/utils/gravatar/gravatar_test.go @@ -19,13 +19,13 @@ func TestGravatar(t *testing.T) { var _ = Describe("Gravatar", func() { It("returns a well formatted gravatar URL", func() { - Expect(gravatar.Url("my@email.com", 100)).To(Equal("https://www.gravatar.com/avatar/4f384e9f3e8e625aae72b52658323d70?s=100")) + Expect(gravatar.Url("my@email.com", 100)).To(Equal("https://www.gravatar.com/avatar/cf3d8259741b19a2b09e17d4fa9a97c63adc44bf2a5fa075cdcb5491f525feaa?s=100")) }) It("sets the default size", func() { - Expect(gravatar.Url("my@email.com", 0)).To(Equal("https://www.gravatar.com/avatar/4f384e9f3e8e625aae72b52658323d70?s=80")) + Expect(gravatar.Url("my@email.com", 0)).To(Equal("https://www.gravatar.com/avatar/cf3d8259741b19a2b09e17d4fa9a97c63adc44bf2a5fa075cdcb5491f525feaa?s=80")) }) It("caps maximum size", func() { - Expect(gravatar.Url("my@email.com", 3000)).To(Equal("https://www.gravatar.com/avatar/4f384e9f3e8e625aae72b52658323d70?s=2048")) + Expect(gravatar.Url("my@email.com", 3000)).To(Equal("https://www.gravatar.com/avatar/cf3d8259741b19a2b09e17d4fa9a97c63adc44bf2a5fa075cdcb5491f525feaa?s=2048")) }) It("ignores case", func() { Expect(gravatar.Url("MY@email.com", 0)).To(Equal(gravatar.Url("my@email.com", 0)))