-
Notifications
You must be signed in to change notification settings - Fork 1
/
challengeFiles.go
48 lines (40 loc) · 1004 Bytes
/
challengeFiles.go
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
48
package main
import (
"crypto/sha256"
"fmt"
"os"
)
type challengeFile struct {
Filename string
Size int64
Location string
}
func readChallengeFile(path string) (challengeFile, error) {
var chaFi challengeFile
chaFi.Location = path
fi, err := os.Stat(path)
if err != nil {
return challengeFile{}, err
}
chaFi.Size = fi.Size()
chaFi.Filename = fi.Name()
return chaFi, nil
}
func readChallengeFiles(path string) map[string]challengeFile {
challengeFiles := make(map[string]challengeFile)
challengeFilesOS, err := os.ReadDir(path)
if err == nil {
/* challenge files directory exists */
for _, challengeFileOS := range challengeFilesOS {
if !challengeFileOS.IsDir() {
challengeFile, err := readChallengeFile(fmt.Sprintf("%s/%s", path, challengeFileOS.Name()))
if err == nil {
hash := sha256.New()
hash.Write([]byte(challengeFileOS.Name()))
challengeFiles[fmt.Sprintf("%x", hash.Sum(nil))] = challengeFile
}
}
}
}
return challengeFiles
}