Début vérification de l'empreinte lors de l'envoi d'un fichier
This commit is contained in:
@@ -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
31
pkg/utils/Hasher.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user