-
Notifications
You must be signed in to change notification settings - Fork 2
/
hash.go
58 lines (54 loc) · 1.37 KB
/
hash.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
package api
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
)
// HashDetails by file_id
func (api *API) HashDetails(hash string) (string, error) {
url := fmt.Sprintf("%s/hash/%s", api.URL, hash)
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return "", err
}
req.Header.Add("apikey", api.Token)
return fmtResponse(api.Client.Do(req))
}
// HashesDetails by file_ids
func (api *API) HashesDetails(hashes []string) (string, error) {
url := fmt.Sprintf("%s/hash", api.URL)
payload := struct {
Hashes []string `json:"hash"`
}{
hashes,
}
j, _ := json.Marshal(payload)
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(j))
if err != nil {
return "", err
}
req.Header.Add("apikey", api.Token)
req.Header.Add("content-type", "application/json")
return fmtResponse(api.Client.Do(req))
}
// HashVulnerabilities by hash
func (api *API) HashVulnerabilities(hash string, limit, offset int) (string, error) {
url, _ := url.Parse(fmt.Sprintf("%s/vulnerability/%s", api.URL, hash))
q := url.Query()
if limit > 0 {
q.Set("limit", strconv.Itoa(limit))
}
if offset > 0 {
q.Set("offset", strconv.Itoa(offset))
}
url.RawQuery = q.Encode()
req, err := http.NewRequest(http.MethodGet, url.String(), nil)
if err != nil {
return "", err
}
req.Header.Add("apikey", api.Token)
return fmtResponse(api.Client.Do(req))
}