SetString for DNSKEY and RRSIG
This commit is contained in:
parent
2eecc66477
commit
91b41d02bb
|
@ -112,6 +112,7 @@ func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
|
|||
return
|
||||
}
|
||||
|
||||
// Do I want Read/SetString or both???
|
||||
func (k *RR_DNSKEY) Read(q io.Reader) os.Error {
|
||||
r, e := Zparse(q)
|
||||
if e != nil || r == nil {
|
||||
|
|
|
@ -131,7 +131,11 @@ func TestParse(t *testing.T) {
|
|||
"nlnetlabs.nl.\t3175\tIN\tDNSKEY\t256 3 8 AwEAAdR7XR95OaAN9Rz7TbtPalQ9guQk7zfxTHYNKhsiwTZA9z+F16nD0VeBlk7dNik3ETpT2GLAwr9sntG898JwurCDe353wHPvjZtMCdiTVp3cRCrjuCEvoFpmZNN82H0gaH/4v8mkv/QBDAkDSncYjz/FqHKAeYy3cMcjY6RyVweh",
|
||||
}
|
||||
for test, result := range tests {
|
||||
r, _ := Zparse(strings.NewReader(test))
|
||||
r, err := Zparse(strings.NewReader(test))
|
||||
if err != nil || r == nil{
|
||||
t.Logf("Error of nil r %v %s\n", err, test)
|
||||
t.Fail()
|
||||
}
|
||||
if r.String() != result {
|
||||
t.Logf("\"%s\" should be equal to\n\"%s\"\n", r, result)
|
||||
t.Fail()
|
||||
|
@ -139,9 +143,18 @@ func TestParse(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
//
|
||||
func TestSetString(t *testing.T) {
|
||||
a := new(RR_A)
|
||||
a.SetString("miek.nl. IN A 127.0.0.1")
|
||||
println(a.String())
|
||||
t.Log(a.String())
|
||||
b := new(RR_AAAA)
|
||||
b.SetString("miek.nl. IN AAAA ::1")
|
||||
t.Log(b.String())
|
||||
c := new(RR_MX)
|
||||
c.SetString("miek.nl. IN MX 10 miek.nl.")
|
||||
t.Log(c.String())
|
||||
d := new(RR_NS)
|
||||
d.SetString("miek.nl. IN NS ns1.miek.nl")
|
||||
t.Log(d.String())
|
||||
t.Fail()
|
||||
}
|
||||
|
|
37
types.go
37
types.go
|
@ -582,6 +582,27 @@ func (rr *RR_RRSIG) String() string {
|
|||
" " + rr.Signature
|
||||
}
|
||||
|
||||
func (rr *RR_RRSIG) SetString(s string) (*RR_RRSIG, bool) {
|
||||
p := parse(s)
|
||||
if p == nil {
|
||||
return nil, false
|
||||
}
|
||||
if _, ok := p.(*RR_RRSIG); !ok {
|
||||
return nil, false
|
||||
}
|
||||
rr.Hdr = p.(*RR_RRSIG).Hdr
|
||||
rr.TypeCovered = p.(*RR_RRSIG).TypeCovered
|
||||
rr.Algorithm = p.(*RR_RRSIG).Algorithm
|
||||
rr.Labels = p.(*RR_RRSIG).Labels
|
||||
rr.OrigTtl = p.(*RR_RRSIG).OrigTtl
|
||||
rr.Expiration = p.(*RR_RRSIG).Expiration
|
||||
rr.Inception = p.(*RR_RRSIG).Inception
|
||||
rr.KeyTag = p.(*RR_RRSIG).KeyTag
|
||||
rr.SignerName = p.(*RR_RRSIG).SignerName
|
||||
rr.Signature = p.(*RR_RRSIG).Signature
|
||||
return rr, true
|
||||
}
|
||||
|
||||
type RR_NSEC struct {
|
||||
Hdr RR_Header
|
||||
NextDomain string "domain-name"
|
||||
|
@ -727,6 +748,22 @@ func (rr *RR_DNSKEY) String() string {
|
|||
" " + rr.PublicKey
|
||||
}
|
||||
|
||||
func (rr *RR_DNSKEY) SetString(s string) (*RR_DNSKEY, bool) {
|
||||
p := parse(s)
|
||||
if p == nil {
|
||||
return nil, false
|
||||
}
|
||||
if _, ok := p.(*RR_DNSKEY); !ok {
|
||||
return nil, false
|
||||
}
|
||||
rr.Hdr = p.(*RR_DNSKEY).Hdr
|
||||
rr.Flags = p.(*RR_DNSKEY).Flags
|
||||
rr.Protocol = p.(*RR_DNSKEY).Protocol
|
||||
rr.Algorithm = p.(*RR_DNSKEY).Algorithm
|
||||
rr.PublicKey = p.(*RR_DNSKEY).PublicKey
|
||||
return rr, true
|
||||
}
|
||||
|
||||
type RR_NSEC3 struct {
|
||||
Hdr RR_Header
|
||||
Hash uint8
|
||||
|
|
4
types.rl
4
types.rl
|
@ -5,6 +5,10 @@
|
|||
rr.(*RR_A).Hdr = *hdr
|
||||
rr.(*RR_A).A = net.ParseIP(data[mark:p])
|
||||
}
|
||||
action rdata_aaaa {
|
||||
rr.(*RR_AAAA).Hdr = *hdr
|
||||
rr.(*RR_AAAA).AAAA = net.ParseIP(data[mark:p])
|
||||
}
|
||||
action rdata_ns {
|
||||
rr.(*RR_NS).Hdr = *hdr
|
||||
rr.(*RR_NS).Ns = tok.T[0]
|
||||
|
|
|
@ -122,6 +122,7 @@ func Zparse(q io.Reader) (rr RR, err os.Error) {
|
|||
# RR definitions
|
||||
rhs = (
|
||||
('A'i %qtype bl t) %rdata_a
|
||||
| ('AAAA'i %qtype bl t) %rdata_aaaa
|
||||
| ('NS'i %qtype bl t) %rdata_ns
|
||||
| ('CNAME'i %qtype bl t) %rdata_cname
|
||||
| ('SOA'i %qtype bl t bl t bl n bl n bl n bl n bl n) %rdata_soa
|
||||
|
|
Loading…
Reference in New Issue