-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
74 lines (64 loc) · 1.72 KB
/
helpers.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
package dactyloscopy
import (
"fmt"
"strings"
"golang.org/x/crypto/cryptobyte"
)
func skip16(data cryptobyte.String) error {
var skipsize uint16 = 0
if !data.ReadUint16(&skipsize) {
return fmt.Errorf("could not read skip size")
}
if skipsize > 0 {
if !data.Skip(int(skipsize)) {
return fmt.Errorf("could not skip")
}
}
return nil
}
func read16Length16Pair(dataBlock cryptobyte.String, output *[]uint16) error {
var (
valueList cryptobyte.String
singleValue uint16
)
if !dataBlock.ReadUint16LengthPrefixed(&valueList) {
return fmt.Errorf("could not read list of values")
}
for !valueList.Empty() {
valueList.ReadUint16(&singleValue)
*output = append(*output, singleValue)
}
return nil
}
func read16Length8Pair(dataBlock cryptobyte.String, output *[]uint8) error {
var (
valueList cryptobyte.String
singleValue uint8
)
if !dataBlock.ReadUint16LengthPrefixed(&valueList) {
return fmt.Errorf("could not read list of values")
}
for !valueList.Empty() {
valueList.ReadUint8(&singleValue)
*output = append(*output, singleValue)
}
return nil
}
// sliceToDash16 converts a slice of number values and make a dash delimited
// string representation.. Used for making printable fingerprints.
func sliceToDash16(input []uint16) string {
var outSlice []string
for _, i := range input {
outSlice = append(outSlice, fmt.Sprintf("%d", i))
}
return strings.Join(outSlice, "-")
}
// sliceToDash8 converts a slice of number values and make a dash delimited
// string representation.. Used for making printable fingerprints.
func sliceToDash8(input []uint8) string {
var outSlice []string
for _, i := range input {
outSlice = append(outSlice, fmt.Sprintf("%d", i))
}
return strings.Join(outSlice, "-")
}