-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileHashlooker.go
109 lines (96 loc) · 2.67 KB
/
fileHashlooker.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package main
import (
"crypto/sha1"
"fmt"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/widget"
"io/ioutil"
"log"
"os"
"time"
)
// Declare conformity with editor interface
var _ hashlooker = (*fileHashlooker)(nil)
type line struct {
Key string
Value string
}
type fileHashlooker struct {
uri fyne.URI
hgui *hgui
client *Client
sha1 string
hashlookupData []line
hashlookupBindings []binding.DataMap
}
func newFileHashlooker(u fyne.URI, hgui *hgui) hashlooker {
// Compute Sha-1
singleFile, err := ioutil.ReadFile(u.Path())
if err != nil {
dialog.ShowError(err, hgui.win)
}
h := sha1.New()
h.Write(singleFile)
digest := fmt.Sprintf("%x", h.Sum(nil))
// Init hashlookup client
defaultTimeout := time.Second * 10
client := NewClient("https://hashlookup.circl.lu", os.Getenv("HASHLOOKUP_API_KEY"), defaultTimeout)
// Init bindings
hashlookupData := []line{}
hashlookupBindings := []binding.DataMap{}
return &fileHashlooker{uri: u, hgui: hgui, sha1: digest, client: client, hashlookupData: hashlookupData, hashlookupBindings: hashlookupBindings}
}
func (g *fileHashlooker) content() fyne.CanvasObject {
t := widget.NewTable(
func() (int, int) { return len(g.hashlookupData), 2 },
func() fyne.CanvasObject {
return widget.NewLabel("Cell 000, 000")
},
func(id widget.TableCellID, cell fyne.CanvasObject) {
//label := cell.(*widget.Label)
switch id.Col {
case 0:
tmphead, err := g.hashlookupBindings[id.Row].GetItem("Key")
if err != nil {
log.Fatal(err)
}
cell.(*widget.Label).Bind(tmphead.(binding.String))
case 1:
tmpvalue, err := g.hashlookupBindings[id.Row].GetItem("Value")
if err != nil {
log.Fatal(err)
}
cell.(*widget.Label).Bind(tmpvalue.(binding.String))
}
})
t.SetColumnWidth(0, 200)
t.SetColumnWidth(1, 800)
go func() {
var err error
results, err := g.client.LookupSHA1(g.sha1)
if err != nil {
log.Fatal(err)
}
// update the string from hashlookup
for key, value := range results.ChildrenMap() {
tmpline := line{Key: fmt.Sprintf("%v", key), Value: fmt.Sprintf("%v", value)}
g.hashlookupData = append(g.hashlookupData, tmpline)
g.hashlookupBindings = append(g.hashlookupBindings, binding.BindStruct(&tmpline))
}
t.Refresh()
}()
return t
}
func (g *fileHashlooker) close() {
// Close the tab
fmt.Println("Here I should be closing the tab.")
}
func (g *fileHashlooker) run() {
// Run the hashlookup analysis
fmt.Println("Here I should be running the analysis.")
}
func (g *fileHashlooker) export() {
fmt.Println("Here I should be performing some export function.")
}