forked from michenriksen/gitrob
/
signatures.go
46 lines (42 loc) · 955 Bytes
/
signatures.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
package matching
import (
"encoding/json"
"errors"
"fmt"
"github.com/codeEmitter/gitrob/common"
"io/ioutil"
)
type Signatures struct {
FileSignatures []FileSignature
ContentSignatures []ContentSignature
}
func (s *Signatures) loadSignatures(path string) error {
if !common.FileExists(path) {
return errors.New(fmt.Sprintf("Missing signature file: %s.\n", path))
}
data, readError := ioutil.ReadFile(path)
if readError != nil {
return readError
}
if unmarshalError := json.Unmarshal(data, &s); unmarshalError != nil {
return unmarshalError
}
return nil
}
func (s *Signatures) Load(mode int) error {
var e error
if mode != 3 {
e = s.loadSignatures("./filesignatures.json")
if e != nil {
return e
}
}
if mode != 1 {
//source: https://github.com/dxa4481/truffleHogRegexes/blob/master/truffleHogRegexes/regexes.json
e = s.loadSignatures("./contentsignatures.json")
if e != nil {
return e
}
}
return nil
}