From 00d39309811d52aee3666bb50f86469f9e0dbc09 Mon Sep 17 00:00:00 2001 From: Umputun Date: Mon, 11 Mar 2019 01:36:54 -0500 Subject: [PATCH] image hashing to sha256 --- backend/app/store/image/image.go | 4 ++-- backend/app/store/image/image_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/app/store/image/image.go b/backend/app/store/image/image.go index 6f395c36..1026bc7d 100644 --- a/backend/app/store/image/image.go +++ b/backend/app/store/image/image.go @@ -2,7 +2,7 @@ package image import ( - "crypto/sha1" + "crypto/sha256" "encoding/hex" "fmt" "hash/crc64" @@ -42,7 +42,7 @@ type FileSystem struct { // Files partitioned across multiple subdirectories. func (f *FileSystem) Save(name string, r io.Reader) (id string, err error) { - h := sha1.Sum([]byte(name)) + h := sha256.Sum224([]byte(name)) id = hex.EncodeToString(h[:]) if ext := path.Ext(name); ext != "" { id += ext diff --git a/backend/app/store/image/image_test.go b/backend/app/store/image/image_test.go index fd38699a..29017910 100644 --- a/backend/app/store/image/image_test.go +++ b/backend/app/store/image/image_test.go @@ -24,9 +24,9 @@ func TestImage_Save(t *testing.T) { } id, err := svc.Save("blah_ff1.png", strings.NewReader("blah blah")) assert.NoError(t, err) - assert.Equal(t, "6851dcde6024e03258a66705f29e14b506048c74.png", id) + assert.Equal(t, "fc77a87ad3c898b9603119711f99305145e272e103c904d85ee2deda.png", id) - dst := path.Join(loc, "02", id) + dst := path.Join(loc, "56", id) data, err := ioutil.ReadFile(dst) assert.NoError(t, err) assert.Equal(t, "blah blah", string(data))