Fixed SSHFP parsing when multiple lines used for text representation.

This commit is contained in:
Alex Sergeyev 2015-05-07 09:50:44 -04:00
parent d00c3f21d4
commit d2bed60478
2 changed files with 32 additions and 14 deletions

View File

@ -548,6 +548,9 @@ a.example.com. IN A 127.0.0.1
8db7._openpgpkey.example.com. IN OPENPGPKEY mQCNAzIG
$ORIGIN a.example.com.
test IN A 127.0.0.1
IN SSHFP 1 2 (
BC6533CDC95A79078A39A56EA7635984ED655318ADA9
B6159E30723665DA95BB )
$ORIGIN b.example.com.
test IN CNAME test.a.example.com.
`
@ -1397,10 +1400,6 @@ func TestParseTLSA(t *testing.T) {
t.Error("failed to parse RR: ", err)
continue
}
if rr == nil {
t.Errorf("TLSA RR `%s` not parsed!", o)
continue
}
if rr.String() != o {
t.Errorf("`%s' should be equal to\n`%s', but is `%s'", o, o, rr.String())
} else {
@ -1408,3 +1407,25 @@ func TestParseTLSA(t *testing.T) {
}
}
}
func TestParseSSHFP(t *testing.T) {
lt := []string{
"test.example.org.\t300\tSSHFP\t1 2 (\n" +
"\t\t\t\t\tBC6533CDC95A79078A39A56EA7635984ED655318ADA9\n" +
"\t\t\t\t\tB6159E30723665DA95BB )",
"test.example.org.\t300\tSSHFP\t1 2 ( BC6533CDC 95A79078A39A56EA7635984ED655318AD A9B6159E3072366 5DA95BB )",
}
result := "test.example.org.\t300\tIN\tSSHFP\t1 2 BC6533CDC95A79078A39A56EA7635984ED655318ADA9B6159E30723665DA95BB"
for _, o := range lt {
rr, err := NewRR(o)
if err != nil {
t.Error("failed to parse RR: ", err)
continue
}
if rr.String() != result {
t.Errorf("`%s' should be equal to\n\n`%s', but is \n`%s'", o, result, rr.String())
} else {
t.Logf("RR is OK: `%s'", rr.String())
}
}
}

View File

@ -1485,8 +1485,11 @@ func setSSHFP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
}
rr.Type = uint8(i)
<-c // zBlank
l = <-c
rr.FingerPrint = l.token
s, e1, c1 := endingToString(c, "bad SSHFP Fingerprint", f)
if e1 != nil {
return nil, e1, c1
}
rr.FingerPrint = s
return rr, nil, ""
}
@ -1610,14 +1613,8 @@ func setNSAP(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
if l.length == 0 {
return rr, nil, l.comment
}
i, e := strconv.Atoi(l.token)
if e != nil {
return nil, &ParseError{f, "bad NSAP Length", l}, ""
}
rr.Length = uint8(i)
<-c // zBlank
s, e1, c1 := endingToString(c, "bad NSAP Nsap", f)
if e != nil {
if e1 != nil {
return nil, e1, c1
}
rr.Nsap = s
@ -2202,7 +2199,7 @@ var typeToparserFunc = map[uint16]parserFunc{
TypeSOA: parserFunc{setSOA, false},
TypeSPF: parserFunc{setSPF, true},
TypeSRV: parserFunc{setSRV, false},
TypeSSHFP: parserFunc{setSSHFP, false},
TypeSSHFP: parserFunc{setSSHFP, true},
TypeTALINK: parserFunc{setTALINK, false},
TypeTA: parserFunc{setTA, true},
TypeTLSA: parserFunc{setTLSA, true},