diff --git a/parse_test.go b/parse_test.go index 38edb64b..5725665a 100644 --- a/parse_test.go +++ b/parse_test.go @@ -106,7 +106,7 @@ func TestParse(t *testing.T) { "miek.nl. IN A 127.0.0.1": "miek.nl.\t3600\tIN\tA\t127.0.0.1", "miek.nl. IN DNSKEY 256 3 5 AwEAAb+8lGNCxJgLS8rYVer6EnHVuIkQDghdjdtewDzU3G5R7PbMbKVRvH2Ma7pQyYceoaqWZQirSj72euPWfPxQnMy9ucCylA+FuH9cSjIcPf4PqJfdupHk9X6EBYjxrCLY4p1/yBwgyBIRJtZtAqM3ceAH2WovEJD6rTtOuHo5AluJ": "miek.nl.\t3600\tIN\tDNSKEY\t256 3 5 AwEAAb+8lGNCxJgLS8rYVer6EnHVuIkQDghdjdtewDzU3G5R7PbMbKVRvH2Ma7pQyYceoaqWZQirSj72euPWfPxQnMy9ucCylA+FuH9cSjIcPf4PqJfdupHk9X6EBYjxrCLY4p1/yBwgyBIRJtZtAqM3ceAH2WovEJD6rTtOuHo5AluJ", -// "nlnetlabs.nl. 3175 IN DNSKEY 256 3 8 AwEAAdR7XR95OaAN9Rz7TbtPalQ9guQk7zfxTHYNKhsiwTZA9z+F16nD0VeBlk7dNik3ETpT2GLAwr9sntG898JwurCDe353wHPvjZtMCdiTVp3cRCrjuCEvoFpmZNN82H0gaH/4v8mkv/QBDAkDSncYjz/FqHKAeYy3cMcjY6RyVweh": "nlnetlabs.nl.\t3175\tIN\tDNSKEY\t256 3 8 AwEAAdR7XR95OaAN9Rz7TbtPalQ9guQk7zfxTHYNKhsiwTZA9z+F16nD0VeBlk7dNik3ETpT2GLAwr9sntG898JwurCDe353wHPvjZtMCdiTVp3cRCrjuCEvoFpmZNN82H0gaH/4v8mkv/QBDAkDSncYjz/FqHKAeYy3cMcjY6RyVweh", + "nlnetlabs.nl. 3175 IN DNSKEY 256 3 8 AwEAAdR7XR95OaAN9Rz7TbtPalQ9guQk7zfxTHYNKhsiwTZA9z+F16nD0VeBlk7dNik3ETpT2GLAwr9sntG898JwurCDe353wHPvjZtMCdiTVp3cRCrjuCEvoFpmZNN82H0gaH/4v8mkv/QBDAkDSncYjz/FqHKAeYy3cMcjY6RyVweh": "nlnetlabs.nl.\t3175\tIN\tDNSKEY\t256 3 8 AwEAAdR7XR95OaAN9Rz7TbtPalQ9guQk7zfxTHYNKhsiwTZA9z+F16nD0VeBlk7dNik3ETpT2GLAwr9sntG898JwurCDe353wHPvjZtMCdiTVp3cRCrjuCEvoFpmZNN82H0gaH/4v8mkv/QBDAkDSncYjz/FqHKAeYy3cMcjY6RyVweh", "dnsex.nl. 86400 IN SOA elektron.atoom.net. miekg.atoom.net. 1299256910 14400 3600 604800 86400": "dnsex.nl.\t86400\tIN\tSOA\telektron.atoom.net. miekg.atoom.net. 1299256910 14400 3600 604800 86400", "dnsex.nl. 86400 IN RRSIG SOA 8 2 86400 20110403154150 20110304154150 23334 dnsex.nl. QN6hwJQLEBqRVKmO2LgkuRSx9bkKIZxXlTVtHg5SaiN+8RCTckGtUXkQ vmZiBt3RdIWAjaabQYpEZHgvyjfy4Wwu/9RPDYnLt/qoyr4QKAdujchc m+fMDSbbcC7AN08i5D/dUWfNOHXjRJLY7t7AYB9DBt32LazIb0EU9QiW 5Cg=": diff --git a/zscan_rr.go b/zscan_rr.go index 14e00468..55ea7397 100644 --- a/zscan_rr.go +++ b/zscan_rr.go @@ -13,27 +13,6 @@ import ( // or immediately a _NEWLINE. If this is not the case we flag // an error: garbage after rdata. -func slurpRemainder(c chan Lex) error { - l := <-c - if DEBUG { fmt.Printf("%\v", l) } - switch l.value { - case _BLANK: - l = <-c - if DEBUG { fmt.Printf("%\v", l) } - if l.value != _NEWLINE && l.value != _EOF { - return &ParseError{"garbage after rdata", l} - } - // Ok - case _NEWLINE: - // Ok - case _EOF: - // Ok - default: - return &ParseError{"garbage after rdata", l} - } - return nil -} - func setRR(h RR_Header, c chan Lex) (RR, error) { var ( r RR @@ -88,9 +67,11 @@ func setRR(h RR_Header, c chan Lex) (RR, error) { if se := slurpRemainder(c); se != nil { return nil, se } - // These types have a variable ending either chunks of txt or chunks/base64 or hex. - // They need to search for the end of the RR themselves, hence they look for the ending - // newline. Thus there is no need to slurp the remainder, because there is none + // These types have a variable ending either chunks of txt or chunks/base64 or hex. + // They need to search for the end of the RR themselves, hence they look for the ending + // newline. Thus there is no need to slurp the remainder, because there is none. + case TypeDNSKEY: + r, e = setDNSKEY(h, c) case TypeRRSIG: r, e = setRRSIG(h, c) case TypeNSEC: @@ -100,12 +81,37 @@ func setRR(h RR_Header, c chan Lex) (RR, error) { case TypeTXT: r, e = setTXT(h, c) default: - // Don't the have the token the holds the RRtype - return nil, &ParseError{"Unknown RR type", Lex{} } + // Don't the have the token the holds the RRtype + return nil, &ParseError{"Unknown RR type", Lex{}} } return r, e } +func slurpRemainder(c chan Lex) error { + l := <-c + if DEBUG { + fmt.Printf("%\v", l) + } + switch l.value { + case _BLANK: + l = <-c + if DEBUG { + fmt.Printf("%\v", l) + } + if l.value != _NEWLINE && l.value != _EOF { + return &ParseError{"garbage after rdata", l} + } + // Ok + case _NEWLINE: + // Ok + case _EOF: + // Ok + default: + return &ParseError{"garbage after rdata", l} + } + return nil +} + func setA(h RR_Header, c chan Lex) (RR, error) { rr := new(RR_A) rr.Hdr = h @@ -315,7 +321,7 @@ func setNSEC(h RR_Header, c chan Lex) (RR, error) { rr.TypeBitMap = append(rr.TypeBitMap, k) } default: - return nil, &ParseError{"bad NSEC garbage in type bitmap", l} + return nil, &ParseError{"bad NSEC garbage in type bitmap", l} } l = <-c } @@ -377,31 +383,31 @@ func setNSEC3(h RR_Header, c chan Lex) (RR, error) { } func setDNSKEY(h RR_Header, c chan Lex) (RR, error) { - rr := new(RR_DNSKEY) - rr.Hdr = h + rr := new(RR_DNSKEY) + rr.Hdr = h - l := <-c - if i, e := strconv.Atoi(l.token); e != nil { + l := <-c + if i, e := strconv.Atoi(l.token); e != nil { return nil, &ParseError{"bad DNSKEY", l} - } else { - rr.Flags = uint16(i) - } + } else { + rr.Flags = uint16(i) + } <-c // _BLANK l = <-c // _STRING - if i, e := strconv.Atoi(l.token); e != nil { + if i, e := strconv.Atoi(l.token); e != nil { return nil, &ParseError{"bad DNSKEY", l} - } else { - rr.Protocol = uint8(i) - } + } else { + rr.Protocol = uint8(i) + } <-c // _BLANK l = <-c // _STRING - if i, e := strconv.Atoi(l.token); e != nil { + if i, e := strconv.Atoi(l.token); e != nil { return nil, &ParseError{"bad DNSKEY", l} - } else { - rr.Algorithm = uint8(i) - } - l = <-c - var s string + } else { + rr.Algorithm = uint8(i) + } + l = <-c + var s string for l.value != _NEWLINE && l.value != _EOF { switch l.value { case _STRING: