mirror of
https://github.com/miekg/dns.git
synced 2025-12-16 17:21:17 +01:00
Add length for base64 encodings
This commit is contained in:
parent
3d85d719a1
commit
f45d4d933d
1
msg.go
1
msg.go
@ -642,6 +642,7 @@ func unpackStructValue(val reflect.Value, msg []byte, off int) (off1 int, ok boo
|
|||||||
default:
|
default:
|
||||||
println("dns: unknown tag unpacking slice", val.Type().Field(i).Tag)
|
println("dns: unknown tag unpacking slice", val.Type().Field(i).Tag)
|
||||||
return lenmsg, false
|
return lenmsg, false
|
||||||
|
// Need to add domain-name for HIP
|
||||||
case "txt":
|
case "txt":
|
||||||
txt := make([]string,0)
|
txt := make([]string,0)
|
||||||
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
rdlength := int(val.FieldByName("Hdr").FieldByName("Rdlength").Uint())
|
||||||
|
|||||||
38
types.go
38
types.go
@ -6,6 +6,7 @@
|
|||||||
package dns
|
package dns
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/base64"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -503,7 +504,8 @@ func (rr *RR_CERT) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_CERT) Len() int {
|
func (rr *RR_CERT) Len() int {
|
||||||
return rr.Hdr.Len() + 5 + len(rr.Certificate) //too much for base64
|
return rr.Hdr.Len() + 5 +
|
||||||
|
base64.StdEncoding.DecodedLen(len(rr.Certificate))
|
||||||
}
|
}
|
||||||
|
|
||||||
// See RFC 2672.
|
// See RFC 2672.
|
||||||
@ -612,8 +614,8 @@ func (rr *RR_RRSIG) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_RRSIG) Len() int {
|
func (rr *RR_RRSIG) Len() int {
|
||||||
return rr.Hdr.Len() + len(rr.SignerName) + 1 + len(rr.Signature) + 18
|
return rr.Hdr.Len() + len(rr.SignerName) + 1 +
|
||||||
// TODO base64 string, should be less
|
base64.StdEncoding.DecodedLen(len(rr.Signature)) + 18
|
||||||
}
|
}
|
||||||
|
|
||||||
type RR_NSEC struct {
|
type RR_NSEC struct {
|
||||||
@ -794,8 +796,8 @@ func (rr *RR_IPSECKEY) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_IPSECKEY) Len() int {
|
func (rr *RR_IPSECKEY) Len() int {
|
||||||
// TODO: this is not correct
|
return rr.Hdr.Len() + 3 + len(rr.Gateway) + 1 +
|
||||||
return rr.Hdr.Len() + 3 + len(rr.Gateway) + len(rr.PublicKey)
|
base64.StdEncoding.DecodedLen(len(rr.PublicKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
type RR_DNSKEY struct {
|
type RR_DNSKEY struct {
|
||||||
@ -818,7 +820,8 @@ func (rr *RR_DNSKEY) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_DNSKEY) Len() int {
|
func (rr *RR_DNSKEY) Len() int {
|
||||||
return rr.Hdr.Len() + 4 + len(rr.PublicKey) // todo: base64
|
return rr.Hdr.Len() + 4 +
|
||||||
|
base64.StdEncoding.DecodedLen(len(rr.PublicKey))
|
||||||
}
|
}
|
||||||
|
|
||||||
type RR_NSEC3 struct {
|
type RR_NSEC3 struct {
|
||||||
@ -856,7 +859,7 @@ func (rr *RR_NSEC3) String() string {
|
|||||||
|
|
||||||
func (rr *RR_NSEC3) Len() int {
|
func (rr *RR_NSEC3) Len() int {
|
||||||
return rr.Hdr.Len() + 6 + len(rr.Salt)/2 + 1 + len(rr.NextDomain) + 1 + len(rr.TypeBitMap)
|
return rr.Hdr.Len() + 6 + len(rr.Salt)/2 + 1 + len(rr.NextDomain) + 1 + len(rr.TypeBitMap)
|
||||||
// TODO: size-base32 and typebitmap
|
// TODO: typebitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
type RR_NSEC3PARAM struct {
|
type RR_NSEC3PARAM struct {
|
||||||
@ -967,7 +970,8 @@ func (rr *RR_DHCID) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_DHCID) Len() int {
|
func (rr *RR_DHCID) Len() int {
|
||||||
return rr.Hdr.Len() + len(rr.Digest) // Slightly too much
|
return rr.Hdr.Len() +
|
||||||
|
base64.StdEncoding.DecodedLen(len(rr.Digest))
|
||||||
}
|
}
|
||||||
|
|
||||||
// RFC 2845.
|
// RFC 2845.
|
||||||
@ -1046,18 +1050,24 @@ func (rr *RR_HIP) Header() *RR_Header {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_HIP) String() string {
|
func (rr *RR_HIP) String() string {
|
||||||
s := rr.Hdr.String() +
|
s := rr.Hdr.String() +
|
||||||
" " + strconv.Itoa(int(rr.PublicKeyAlgorithm)) +
|
" " + strconv.Itoa(int(rr.PublicKeyAlgorithm)) +
|
||||||
" " + rr.Hit +
|
" " + rr.Hit +
|
||||||
" " + rr.PublicKey
|
" " + rr.PublicKey
|
||||||
for _, d := range rr.RendezvousServers {
|
for _, d := range rr.RendezvousServers {
|
||||||
s += " " + d
|
s += " " + d
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rr *RR_HIP) Len() int {
|
func (rr *RR_HIP) Len() int {
|
||||||
return rr.Hdr.Len() // TODO
|
l := rr.Hdr.Len() + 4 +
|
||||||
|
len(rr.Hit)/2 +
|
||||||
|
base64.StdEncoding.DecodedLen(len(rr.PublicKey))
|
||||||
|
for _, d := range rr.RendezvousServers {
|
||||||
|
l += len(d) + 1
|
||||||
|
}
|
||||||
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate the RRSIG's incep. and expir. time to the correct date.
|
// Translate the RRSIG's incep. and expir. time to the correct date.
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"encoding/base64"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Parse the rdata of each rrtype.
|
// Parse the rdata of each rrtype.
|
||||||
@ -407,10 +408,12 @@ func setHIP(h RR_Header, c chan lex, o, f string) (RR, *ParseError) {
|
|||||||
<-c // _BLANK
|
<-c // _BLANK
|
||||||
l = <-c // _STRING
|
l = <-c // _STRING
|
||||||
rr.Hit = l.token // This can not contain spaces, see RFC 5205 Section 6.
|
rr.Hit = l.token // This can not contain spaces, see RFC 5205 Section 6.
|
||||||
|
rr.HitLength = uint8(len(rr.Hit))/2
|
||||||
|
|
||||||
<-c // _BLANK
|
<-c // _BLANK
|
||||||
l = <-c // _STRING
|
l = <-c // _STRING
|
||||||
rr.PublicKey = l.token // This cannot contain spaces
|
rr.PublicKey = l.token // This cannot contain spaces
|
||||||
|
rr.PublicKeyLength = uint16(base64.StdEncoding.DecodedLen(len(rr.PublicKey)))
|
||||||
|
|
||||||
// RendezvousServers (if any)
|
// RendezvousServers (if any)
|
||||||
l = <-c
|
l = <-c
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user