Use SHA256 in Gravatar URLs

This commit is contained in:
Deluan 2024-07-23 17:49:46 -04:00
parent f577704d7a
commit 76c3f5131a
2 changed files with 5 additions and 5 deletions

View file

@ -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
}

View file

@ -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)))