Use much more descriptive names for the maps

Alg_str -> AlgorithmToString
 Rr_str  -> TypeToString

And for the reverse maps also.
This commit is contained in:
Miek Gieben 2012-12-02 09:29:54 +01:00
parent db014f9891
commit 2a3b818b95
7 changed files with 38 additions and 38 deletions

8
dns.go
View File

@ -162,14 +162,14 @@ func (h *RR_Header) String() string {
}
s = s + strconv.FormatInt(int64(h.Ttl), 10) + "\t"
if _, ok := Class_str[h.Class]; ok {
s += Class_str[h.Class] + "\t"
if _, ok := ClassToString[h.Class]; ok {
s += ClassToString[h.Class] + "\t"
} else {
s += "CLASS" + strconv.Itoa(int(h.Class)) + "\t"
}
if _, ok := Rr_str[h.Rrtype]; ok {
s += Rr_str[h.Rrtype] + "\t"
if _, ok := TypeToString[h.Rrtype]; ok {
s += TypeToString[h.Rrtype] + "\t"
} else {
s += "TYPE" + strconv.Itoa(int(h.Rrtype)) + "\t"
}

View File

@ -701,7 +701,7 @@ func rawSignatureData(rrset []RR, s *RR_RRSIG) (buf []byte) {
}
// Map for algorithm names.
var Alg_str = map[uint8]string{
var AlgorithmToString = map[uint8]string{
RSAMD5: "RSAMD5",
DH: "DH",
DSA: "DSA",
@ -719,4 +719,4 @@ var Alg_str = map[uint8]string{
}
// Map of algorithm strings.
var Str_alg = reverseInt8(Alg_str)
var StringToAlgorithm = reverseInt8(AlgorithmToString)

View File

@ -93,7 +93,7 @@ func (r *RR_DNSKEY) Generate(bits int) (PrivateKey, error) {
func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
switch t := p.(type) {
case *rsa.PrivateKey:
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + Alg_str[r.Algorithm] + ")"
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + AlgorithmToString[r.Algorithm] + ")"
modulus := unpackBase64(t.PublicKey.N.Bytes())
e := big.NewInt(int64(t.PublicKey.E))
publicExponent := unpackBase64(e.Bytes())
@ -125,13 +125,13 @@ func (r *RR_DNSKEY) PrivateKeyString(p PrivateKey) (s string) {
"Exponent2: " + exponent2 + "\n" +
"Coefficient: " + coefficient + "\n"
case *ecdsa.PrivateKey:
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + Alg_str[r.Algorithm] + ")"
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + AlgorithmToString[r.Algorithm] + ")"
private := unpackBase64(t.D.Bytes())
s = _FORMAT +
"Algorithm: " + algorithm + "\n" +
"PrivateKey: " + private + "\n"
case *dsa.PrivateKey:
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + Alg_str[r.Algorithm] + ")"
algorithm := strconv.Itoa(int(r.Algorithm)) + " (" + AlgorithmToString[r.Algorithm] + ")"
prime := unpackBase64(t.PublicKey.Parameters.P.Bytes())
subprime := unpackBase64(t.PublicKey.Parameters.Q.Bytes())
base := unpackBase64(t.PublicKey.Parameters.G.Bytes())

20
msg.go
View File

@ -78,7 +78,7 @@ type Msg struct {
}
// Map of strings for each RR wire type.
var Rr_str = map[uint16]string{
var TypeToString = map[uint16]string{
TypeCNAME: "CNAME",
TypeHINFO: "HINFO",
TypeTLSA: "TSLA",
@ -141,17 +141,17 @@ var Rr_str = map[uint16]string{
}
// Reverse, needed for string parsing.
var Str_rr = reverseInt16(Rr_str)
var Str_class = reverseInt16(Class_str)
var StringToType = reverseInt16(TypeToString)
var StringToClass = reverseInt16(ClassToString)
// Map of opcodes strings.
var Str_opcode = reverseInt(Opcode_str)
var StringToOpcode = reverseInt(OpcodeToString)
// Map of rcodes strings.
var Str_rcode = reverseInt(Rcode_str)
var StringToRcode = reverseInt(RcodeToString)
// Map of strings for each CLASS wire type.
var Class_str = map[uint16]string{
var ClassToString = map[uint16]string{
ClassINET: "IN",
ClassCSNET: "CS",
ClassCHAOS: "CH",
@ -161,7 +161,7 @@ var Class_str = map[uint16]string{
}
// Map of strings for opcodes.
var Opcode_str = map[int]string{
var OpcodeToString = map[int]string{
OpcodeQuery: "QUERY",
OpcodeIQuery: "IQUERY",
OpcodeStatus: "STATUS",
@ -170,7 +170,7 @@ var Opcode_str = map[int]string{
}
// Map of strings for rcodes.
var Rcode_str = map[int]string{
var RcodeToString = map[int]string{
RcodeSuccess: "NOERROR",
RcodeFormatError: "FORMERR",
RcodeServerFailure: "SERVFAIL",
@ -1130,8 +1130,8 @@ func (h *MsgHdr) String() string {
return "<nil> MsgHdr"
}
s := ";; opcode: " + Opcode_str[h.Opcode]
s += ", status: " + Rcode_str[h.Rcode]
s := ";; opcode: " + OpcodeToString[h.Opcode]
s += ", status: " + RcodeToString[h.Rcode]
s += ", id: " + strconv.Itoa(int(h.Id)) + "\n"
s += ";; flags:"

View File

@ -159,14 +159,14 @@ func (q *Question) String() (s string) {
} else {
s = ";" + q.Name + "\t"
}
if _, ok := Class_str[q.Qclass]; ok {
s += Class_str[q.Qclass] + "\t"
if _, ok := ClassToString[q.Qclass]; ok {
s += ClassToString[q.Qclass] + "\t"
} else {
s += "CLASS" + strconv.Itoa(int(q.Qtype))
}
if _, ok := Rr_str[q.Qtype]; ok {
s += " " + Rr_str[q.Qtype]
if _, ok := TypeToString[q.Qtype]; ok {
s += " " + TypeToString[q.Qtype]
} else {
s += " " + "TYPE" + strconv.Itoa(int(q.Qtype))
}
@ -753,7 +753,7 @@ func (rr *RR_RRSIG) Copy() RR {
}
func (rr *RR_RRSIG) String() string {
return rr.Hdr.String() + Rr_str[rr.TypeCovered] +
return rr.Hdr.String() + TypeToString[rr.TypeCovered] +
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + strconv.Itoa(int(rr.Labels)) +
" " + strconv.FormatInt(int64(rr.OrigTtl), 10) +
@ -781,8 +781,8 @@ func (rr *RR_NSEC) Copy() RR { return &RR_NSEC{*rr.Hdr.CopyHeader(), r
func (rr *RR_NSEC) String() string {
s := rr.Hdr.String() + rr.NextDomain
for i := 0; i < len(rr.TypeBitMap); i++ {
if _, ok := Rr_str[rr.TypeBitMap[i]]; ok {
s += " " + Rr_str[rr.TypeBitMap[i]]
if _, ok := TypeToString[rr.TypeBitMap[i]]; ok {
s += " " + TypeToString[rr.TypeBitMap[i]]
} else {
s += " " + "TYPE" + strconv.Itoa(int(rr.TypeBitMap[i]))
}
@ -1052,8 +1052,8 @@ func (rr *RR_NSEC3) String() string {
" " + saltString(rr.Salt) +
" " + rr.NextDomain
for i := 0; i < len(rr.TypeBitMap); i++ {
if _, ok := Rr_str[rr.TypeBitMap[i]]; ok {
s += " " + Rr_str[rr.TypeBitMap[i]]
if _, ok := TypeToString[rr.TypeBitMap[i]]; ok {
s += " " + TypeToString[rr.TypeBitMap[i]]
} else {
s += " " + "TYPE" + strconv.Itoa(int(rr.TypeBitMap[i]))
}

View File

@ -489,7 +489,7 @@ func zlexer(s *scan, c chan lex) {
l.token = string(str[:stri])
if !rrtype {
if t, ok := Str_rr[strings.ToUpper(l.token)]; ok {
if t, ok := StringToType[strings.ToUpper(l.token)]; ok {
l.value = _RRTYPE
l.torc = t
rrtype = true
@ -507,7 +507,7 @@ func zlexer(s *scan, c chan lex) {
}
}
}
if t, ok := Str_class[strings.ToUpper(l.token)]; ok {
if t, ok := StringToClass[strings.ToUpper(l.token)]; ok {
l.value = _CLASS
l.torc = t
} else {
@ -602,7 +602,7 @@ func zlexer(s *scan, c chan lex) {
l.value = _STRING
l.token = string(str[:stri])
if !rrtype {
if t, ok := Str_rr[strings.ToUpper(l.token)]; ok {
if t, ok := StringToType[strings.ToUpper(l.token)]; ok {
l.value = _RRTYPE
l.torc = t
rrtype = true

View File

@ -1063,7 +1063,7 @@ func setRRSIG(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
rr := new(RR_RRSIG)
rr.Hdr = h
l := <-c
if t, ok := Str_rr[strings.ToUpper(l.token)]; !ok {
if t, ok := StringToType[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad RRSIG Typecovered", l}
} else {
rr.TypeCovered = t
@ -1161,7 +1161,7 @@ func setNSEC(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
case _BLANK:
// Ok
case _STRING:
if k, ok = Str_rr[strings.ToUpper(l.token)]; !ok {
if k, ok = StringToType[strings.ToUpper(l.token)]; !ok {
if k, ok = typeToInt(l.token); !ok {
return nil, &ParseError{f, "bad NSEC TypeBitMap", l}
}
@ -1223,7 +1223,7 @@ func setNSEC3(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
case _BLANK:
// Ok
case _STRING:
if k, ok = Str_rr[strings.ToUpper(l.token)]; !ok {
if k, ok = StringToType[strings.ToUpper(l.token)]; !ok {
if k, ok = typeToInt(l.token); !ok {
return nil, &ParseError{f, "bad NSEC3 TypeBitMap", l}
}
@ -1422,7 +1422,7 @@ 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 {
if i, ok := Str_alg[strings.ToUpper(l.token)]; !ok {
if i, ok := StringToAlgorithm[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad DS Algorithm", l}
} else {
rr.Algorithm = i
@ -1457,7 +1457,7 @@ func setCDS(h RR_Header, c chan lex, f string) (RR, *ParseError) {
<-c // _BLANK
l = <-c
if i, e := strconv.Atoi(l.token); e != nil {
if i, ok := Str_alg[strings.ToUpper(l.token)]; !ok {
if i, ok := StringToAlgorithm[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad CDS Algorithm", l}
} else {
rr.Algorithm = i
@ -1492,7 +1492,7 @@ 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 {
if i, ok := Str_alg[strings.ToUpper(l.token)]; !ok {
if i, ok := StringToAlgorithm[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad DLV Algorithm", l}
} else {
rr.Algorithm = i
@ -1527,7 +1527,7 @@ 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 {
if i, ok := Str_alg[strings.ToUpper(l.token)]; !ok {
if i, ok := StringToAlgorithm[strings.ToUpper(l.token)]; !ok {
return nil, &ParseError{f, "bad TA Algorithm", l}
} else {
rr.Algorithm = i