-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrrset.go
72 lines (56 loc) · 1.21 KB
/
rrset.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
package goresolver
import (
"log"
"github.com/miekg/dns"
)
type RRSet struct {
rrSet []dns.RR
rrSig *dns.RRSIG
}
func (resolver *Resolver) queryRRset(qname string, qtype uint16) (*RRSet, error) {
r, err := resolver.queryFn(qname, qtype)
if err != nil {
log.Printf("cannot lookup %v", err)
return nil, err
}
if r.Rcode == dns.RcodeNameError {
log.Printf("no such domain %s\n", qname)
return nil, ErrNoResult
}
result := NewSignedRRSet()
if r.Answer == nil {
return result, nil
}
result.rrSet = make([]dns.RR, 0, len(r.Answer))
for _, rr := range r.Answer {
switch t := rr.(type) {
case *dns.RRSIG:
result.rrSig = t
default:
if rr != nil {
result.rrSet = append(result.rrSet, rr)
}
}
}
return result, nil
}
func (sRRset *RRSet) IsSigned() bool {
return sRRset.rrSig != nil
}
func (sRRset *RRSet) IsEmpty() bool {
return len(sRRset.rrSet) < 1
}
func (sRRset *RRSet) SignerName() string {
return sRRset.rrSig.SignerName
}
func (sRRset *RRSet) CheckHeaderIntegrity(qname string) error {
if sRRset.rrSig != nil && sRRset.rrSig.Header().Name != qname {
return ErrForgedRRsig
}
return nil
}
func NewSignedRRSet() *RRSet {
return &RRSet{
rrSet: make([]dns.RR, 0),
}
}