-
Notifications
You must be signed in to change notification settings - Fork 400
/
t_ds.go
52 lines (44 loc) · 1.42 KB
/
t_ds.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
package models
import (
"strconv"
"strings"
"github.com/pkg/errors"
)
// SetTargetDS sets the DS fields.
func (rc *RecordConfig) SetTargetDS(keytag uint16, algorithm, digesttype uint8, digest string) error {
rc.DsKeyTag = keytag
rc.DsAlgorithm = algorithm
rc.DsDigestType = digesttype
rc.DsDigest = digest
if rc.Type == "" {
rc.Type = "DS"
}
if rc.Type != "DS" {
panic("assertion failed: SetTargetDS called when .Type is not DS")
}
return nil
}
// SetTargetDSStrings is like SetTargetDS but accepts strings.
func (rc *RecordConfig) SetTargetDSStrings(keytag, algorithm, digesttype, digest string) error {
u16keytag, err := strconv.ParseUint(keytag, 10, 16)
if err != nil {
return errors.Wrap(err, "DS KeyTag can't fit in 16 bits")
}
u8algorithm, err := strconv.ParseUint(algorithm, 10, 8)
if err != nil {
return errors.Wrap(err, "DS Algorithm can't fit in 8 bits")
}
u8digesttype, err := strconv.ParseUint(digesttype, 10, 8)
if err != nil {
return errors.Wrap(err, "DS DigestType can't fit in 8 bits")
}
return rc.SetTargetDS(uint16(u16keytag), uint8(u8algorithm), uint8(u8digesttype), digest)
}
// SetTargetDSString is like SetTargetDS but accepts one big string.
func (rc *RecordConfig) SetTargetDSString(s string) error {
part := strings.Fields(s)
if len(part) != 4 {
return errors.Errorf("DS value does not contain 4 fields: (%#v)", s)
}
return rc.SetTargetDSStrings(part[0], part[1], part[2], part[3])
}