/
dnssec.go
50 lines (43 loc) · 1.16 KB
/
dnssec.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
package dns
import (
"encoding/json"
"fmt"
)
// ZoneDNSSEC wraps an NS1 /zone/{zone}/dnssec resource
type ZoneDNSSEC struct {
Zone string `json:"zone,omitempty"`
Keys *Keys `json:"keys,omitempty"`
Delegation *Delegation `json:"delegation,omitempty"`
}
// Keys holds a list of DNS Keys and a TTL
type Keys struct {
DNSKey []*Key `json:"dnskey,omitempty"`
TTL int `json:"ttl,omitempty"`
}
// Delegation holds a list of DNS Keys, a list of DS Keys, and a TTL
type Delegation struct {
DNSKey []*Key `json:"dnskey,omitempty"`
DS []*Key `json:"ds,omitempty"`
TTL int `json:"ttl,omitempty"`
}
// Key holds a DNS key
type Key struct {
Flags string
Protocol string
Algorithm string
PublicKey string
}
func (d ZoneDNSSEC) String() string {
return fmt.Sprintf("%s", d.Zone)
}
// UnmarshalJSON parses a Key from a list into a struct
func (k *Key) UnmarshalJSON(buf []byte) error {
tmp := []interface{}{&k.Flags, &k.Protocol, &k.Algorithm, &k.PublicKey}
if err := json.Unmarshal(buf, &tmp); err != nil {
return err
}
if l := len(tmp); l != 4 {
return fmt.Errorf("wrong number of fields in Key: %d != 4", l)
}
return nil
}