Début vérification de l'empreinte lors de l'envoi d'un fichier

This commit is contained in:
Benjamin
2022-03-13 12:29:05 +01:00
parent d7f1407c0c
commit 259bb3c730
6 changed files with 57 additions and 15 deletions

View File

@@ -2,13 +2,12 @@ package utils
import (
"bufio"
"fmt"
"os"
)
// ReceiveFile Permet de récupérer un fichier sur un reader
func ReceiveFile(fileName string, fileSize int, reader *bufio.Reader) bool {
file, fileErr := os.Create(fmt.Sprintf("/home/benjamin/sbe/%s", fileName))
func ReceiveFile(path string, fileSize int, reader *bufio.Reader) bool {
file, fileErr := os.Create(path)
if fileErr != nil {
return false
}

31
pkg/utils/Hasher.go Normal file
View File

@@ -0,0 +1,31 @@
package utils
import (
"bufio"
"crypto/sha256"
"fmt"
"io"
"log"
"os"
)
func HashFileCompare(path string, fingerPrint string) bool {
f, err := os.Open(path)
if err != nil {
log.Fatal(err)
}
defer f.Close()
input := bufio.NewReader(f)
hash := sha256.New()
if _, err := io.Copy(hash, input); err != nil {
log.Fatal(err)
}
sum := hash.Sum(nil)
fmt.Printf("%x\n", sum)
println(fingerPrint, fmt.Sprintf("%x", sum))
return fingerPrint == fmt.Sprintf("%x", sum)
}