-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.go
55 lines (47 loc) · 1.07 KB
/
types.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
package main
import (
"bytes"
"fmt"
"regexp"
)
type AppKey []byte
type UserSalt []byte
type UserKey []byte
type UserFingerprint []byte
type UserFingerprints []UserFingerprint
type Plaintext []byte
type Ciphertext []byte
type Username string
type Password string
type FsFilepath string
type CryFilename string
type CryPath string
func (s Password) String() string {
return "*****"
}
func (userFingerprints *UserFingerprints) Contains(userFingerprint UserFingerprint) bool {
for _, fp := range *userFingerprints {
if bytes.Equal(fp, userFingerprint) {
return true
}
}
return false
}
func (userFingerprints *UserFingerprints) Load(config string) error {
pattern := regexp.MustCompile(`[^a-zA-Z0-9\-_]+`) // base64url-encoded
split := pattern.Split(config, -1)
for i, fpStr := range split {
if fpStr == "" {
continue
}
fp, err := strDecode(fpStr)
if err != nil {
return err
}
if len(fp) != USER_FINGERPRINT_LENGTH {
return fmt.Errorf("invalid fingerprint length for record %d", i)
}
*userFingerprints = append(*userFingerprints, fp)
}
return nil
}