image hashing to sha256

This commit is contained in:
Umputun
2019-03-11 01:36:54 -05:00
parent 4def2affd8
commit 00d3930981
2 changed files with 4 additions and 4 deletions
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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))