Added support for mnemonic names in CERT rr

This behavior matches what bind does with thir formatting.
This commit is contained in:
Alex Sergeyev 2014-10-07 21:27:25 -04:00
parent 75472702d9
commit efb2e66078
2 changed files with 50 additions and 5 deletions

View File

@ -159,9 +159,40 @@ const (
_AD = 1 << 5 // authticated data
_CD = 1 << 4 // checking disabled
_LOC_EQUATOR = 1 << 31 // RFC 1876, Section 2.
)
// RFC 1876, Section 2
const _LOC_EQUATOR = 1 << 31
// RFC 4398, Section 2.1
const (
CertPKIX = 1 + iota
CertSPKI
CertPGP
CertIPIX
CertISPKI
CertIPGP
CertACPKIX
CertIACPKIX
CertURI = 253
CertOID = 254
)
var CertTypeToString = map[uint16]string{
CertPKIX: "PKIX",
CertSPKI: "SPKI",
CertPGP: "PGP",
CertIPIX: "IPIX",
CertISPKI: "ISPKI",
CertIPGP: "IPGP",
CertACPKIX: "ACPKIX",
CertIACPKIX: "IACPKIX",
CertURI: "URI",
CertOID: "OID",
}
var StringToCertType = reverseInt16(CertTypeToString)
// DNS queries.
type Question struct {
Name string `dns:"cdomain-name"` // "cdomain-name" specifies encoding (and may be compressed)
@ -627,9 +658,19 @@ func (rr *CERT) copy() RR {
}
func (rr *CERT) String() string {
return rr.Hdr.String() + strconv.Itoa(int(rr.Type)) +
var (
ok bool
certtype, algorithm string
)
if certtype, ok = CertTypeToString[rr.Type]; !ok {
certtype = strconv.Itoa(int(rr.Type))
}
if algorithm, ok = AlgorithmToString[rr.Algorithm]; !ok {
algorithm = strconv.Itoa(int(rr.Algorithm))
}
return rr.Hdr.String() + certtype +
" " + strconv.Itoa(int(rr.KeyTag)) +
" " + strconv.Itoa(int(rr.Algorithm)) +
" " + algorithm +
" " + rr.Certificate
}

View File

@ -1022,7 +1022,9 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
if l.length == 0 {
return rr, nil, l.comment
}
if i, e := strconv.Atoi(l.token); e != nil {
if v, ok := StringToCertType[l.token]; ok {
rr.Type = v
} else if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad CERT Type", l}, ""
} else {
rr.Type = uint16(i)
@ -1036,7 +1038,9 @@ func setCERT(h RR_Header, c chan lex, o, f string) (RR, *ParseError, string) {
}
<-c // _BLANK
l = <-c // _STRING
if i, e := strconv.Atoi(l.token); e != nil {
if v, ok := StringToAlgorithm[l.token]; ok {
rr.Algorithm = v
} else if i, e := strconv.Atoi(l.token); e != nil {
return nil, &ParseError{f, "bad CERT Algorithm", l}, ""
} else {
rr.Algorithm = uint8(i)