-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (38 loc) · 857 Bytes
/
Copy pathmain.go
File metadata and controls
47 lines (38 loc) · 857 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"ziphasher/hasher"
"ziphasher/zip"
)
var (
zipPath = flag.String("zip", "", "Path to the ZIP file")
algo = flag.String("algo", "sha256", "Hash algorithm: md5, sha1, sha256, sha512")
jsonOut = flag.Bool("json", false, "Enable JSON output")
)
func main() {
flag.Parse()
if *zipPath == "" {
log.Fatal("❌ Please provide a ZIP file path using -zip")
}
files, err := zip.ExtractZipToTemp(*zipPath)
if err != nil {
log.Fatalf("❌ Error while extracting ZIP file: %v", err)
}
result := make(map[string]string)
for _, file := range files {
hash, err := hasher.HashFile(file, *algo)
if err == nil {
result[file] = hash
}
}
if *jsonOut {
json.NewEncoder(log.Writer()).Encode(result)
} else {
for f, h := range result {
fmt.Printf("%s: %s\n", f, h)
}
}
}