Use BLAKE2b checksum instead of SHA-1 and SHA-512

This commit is contained in:
nemunaire 2017-11-24 20:08:14 +01:00
parent 9325419002
commit e6e6e6c206
7 changed files with 58 additions and 38 deletions

View file

@ -2,7 +2,6 @@ package api
import (
"bufio"
"crypto/sha512"
"encoding/base32"
"encoding/hex"
"errors"
@ -14,6 +13,8 @@ import (
"strings"
"srs.epita.fr/fic-server/libfic"
"github.com/dchest/blake2b"
)
var CloudDAVBase string
@ -29,13 +30,13 @@ type uploadedFile struct {
}
func importFile(uf uploadedFile, next func(string, string, []byte) (interface{}, error)) (interface{}, error) {
var hash [sha512.Size]byte
var hash [blake2b.Size]byte
var logStr string
var fromURI string
var getFile func(string) error
if uf.URI != "" && len(uf.Parts) > 0 {
hash = sha512.Sum512([]byte(uf.URI))
hash = blake2b.Sum512([]byte(uf.URI))
logStr = fmt.Sprintf("Import file from Cloud: %s =>", uf.Parts)
fromURI = uf.URI
getFile = func(dest string) error {
@ -53,12 +54,12 @@ func importFile(uf uploadedFile, next func(string, string, []byte) (interface{},
return nil
}
} else if uf.URI != "" {
hash = sha512.Sum512([]byte(uf.URI))
hash = blake2b.Sum512([]byte(uf.URI))
logStr = "Import file from Cloud: " + uf.URI + " =>"
fromURI = uf.URI
getFile = func(dest string) error { return getCloudFile(uf.URI, dest) }
} else if uf.Path != "" && len(uf.Parts) > 0 {
hash = sha512.Sum512([]byte(uf.Path))
hash = blake2b.Sum512([]byte(uf.Path))
logStr = fmt.Sprintf("Import file from local FS: %s =>", uf.Parts)
fromURI = uf.Path
getFile = func(dest string) error {
@ -81,7 +82,7 @@ func importFile(uf uploadedFile, next func(string, string, []byte) (interface{},
return nil
}
} else if uf.Path != "" {
hash = sha512.Sum512([]byte(uf.Path))
hash = blake2b.Sum512([]byte(uf.Path))
logStr = "Import file from local FS: " + uf.Path + " =>"
fromURI = uf.Path
getFile = func(dest string) error { return os.Symlink(uf.Path, dest) }