-
Notifications
You must be signed in to change notification settings - Fork 0
/
generic.go
92 lines (82 loc) · 1.87 KB
/
generic.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
package signify
import (
"encoding/base64"
"errors"
)
const (
_pubUT = " signify public key"
_pkUT = " signify private key"
_empty = ""
_space = " "
_linefeed = "\n"
_variableSize = 0
_untrustedComment = "untrusted comment:"
_verifyThisKeyGenMessage = "Nachts sind alle blauen Katzen grau!"
)
var (
_algoEd25519 = [2]byte{'E', 'd'}
_pkUnlockBcrypt = [2]byte{'B', 'k'}
_pkUnlockExternal = [2]byte{'E', 'x'}
)
//
// INTERNAL LITTLE HELPER
//
// enc ...
func enc(raw []byte) (string, error) {
if raw == nil {
return _empty, errors.New("base64 encode: no raw message")
}
s := base64.StdEncoding.EncodeToString(raw)
return s, nil
}
// dec ...
func dec(b64 string) ([]byte, error) {
if b64 == _empty {
return nil, errors.New("base64 decode: no base64 message")
}
return base64.StdEncoding.DecodeString(b64)
}
// sliceTo64
func sliceTo64(in []byte) (r [64]byte, err error) {
if len(in) != 64 {
return r, errors.New("internal: sliceTo64 failed, input lengh")
}
// for i := 0; i < 64; i++ {
// r[i] = in[i]
// }
copy(r[:], in[:])
return r, nil
}
// sliceTo32
func sliceTo32(in []byte) (r [32]byte, err error) {
if len(in) != 32 {
return r, errors.New("internal: sliceTo32 failed, input lengh")
}
// for i := 0; i < 32; i++ {
// r[i] = in[i]
// }
copy(r[:], in[:])
return r, nil
}
// sliceTo8
func sliceTo8(in []byte) (r [8]byte, err error) {
if len(in) != 8 {
return r, errors.New("internal: sliceTo8 failed, input lengh")
}
// for i := 0; i < 8; i++ {
// r[i] = in[i]
// }
copy(r[:], in[:])
return r, nil
}
// sliceTo82
func sliceTo2(in []byte) (r [2]byte, err error) {
if len(in) != 2 {
return r, errors.New("internal: sliceTo2 failed, input lengh")
}
// for i := 0; i < 2; i++ {
// r[i] = in[i]
// }
copy(r[:], in[:])
return r, nil
}