Allow mnemonic algorithm numbers in DS (and DS-like) records

This commit is contained in:
Miek Gieben 2012-02-27 19:17:58 +01:00
parent 0c0b97f72b
commit ea57a49d94
3 changed files with 26 additions and 3 deletions

View File

@ -604,3 +604,6 @@ var Alg_str = map[uint8]string{
PRIVATEDNS: "PRIVATEDNS",
PRIVATEOID: "PRIVATEOID",
}
// Map of algorithm strings.
var Str_alg = reverseInt8(Alg_str)

8
msg.go
View File

@ -1048,6 +1048,14 @@ func unpackRR(msg []byte, off int) (rr RR, off1 int, ok bool) {
}
// Reverse a map
func reverseInt8(m map[uint8]string) map[string]uint8 {
n := make(map[string]uint8)
for u, s := range m {
n[s] = u
}
return n
}
func reverseInt16(m map[uint16]string) map[string]uint16 {
n := make(map[string]uint16)
for u, s := range m {

View File

@ -789,7 +789,11 @@ func setDS(h RR_Header, c chan lex, f string) (RR, *ParseError) {
<-c // _BLANK
l = <-c
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad DS Algorithm", l}
if i, ok := Str_alg[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad DS Algorithm", l}
} else {
rr.Algorithm = i
}
} else {
rr.Algorithm = uint8(i)
}
@ -830,7 +834,11 @@ func setDLV(h RR_Header, c chan lex, f string) (RR, *ParseError) {
<-c // _BLANK
l = <-c
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad DLV Algorithm", l}
if i, ok := Str_alg[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad DLV Algorithm", l}
} else {
rr.Algorithm = i
}
} else {
rr.Algorithm = uint8(i)
}
@ -871,7 +879,11 @@ func setTA(h RR_Header, c chan lex, f string) (RR, *ParseError) {
<-c // _BLANK
l = <-c
if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad TA Algorithm", l}
if i, ok := Str_alg[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad TA Algorithm", l}
} else {
rr.Algorithm = i
}
} else {
rr.Algorithm = uint8(i)
}