dnssec.go raw
1 package dns
2
3 import (
4 "encoding/json"
5 "fmt"
6 )
7
8 // ZoneDNSSEC wraps an NS1 /zone/{zone}/dnssec resource
9 type ZoneDNSSEC struct {
10 Zone string `json:"zone,omitempty"`
11 Keys *Keys `json:"keys,omitempty"`
12 Delegation *Delegation `json:"delegation,omitempty"`
13 }
14
15 // Keys holds a list of DNS Keys and a TTL
16 type Keys struct {
17 DNSKey []*Key `json:"dnskey,omitempty"`
18 TTL int `json:"ttl,omitempty"`
19 }
20
21 // Delegation holds a list of DNS Keys, a list of DS Keys, and a TTL
22 type Delegation struct {
23 DNSKey []*Key `json:"dnskey,omitempty"`
24 DS []*Key `json:"ds,omitempty"`
25 TTL int `json:"ttl,omitempty"`
26 }
27
28 // Key holds a DNS key
29 type Key struct {
30 Flags string
31 Protocol string
32 Algorithm string
33 PublicKey string
34 }
35
36 func (d ZoneDNSSEC) String() string {
37 return fmt.Sprintf("%s", d.Zone)
38 }
39
40 // UnmarshalJSON parses a Key from a list into a struct
41 func (k *Key) UnmarshalJSON(buf []byte) error {
42 tmp := []interface{}{&k.Flags, &k.Protocol, &k.Algorithm, &k.PublicKey}
43 if err := json.Unmarshal(buf, &tmp); err != nil {
44 return err
45 }
46 if l := len(tmp); l != 4 {
47 return fmt.Errorf("wrong number of fields in Key: %d != 4", l)
48 }
49 return nil
50 }
51