Make a packStructCompress() to leave packStruct() simpler
This commit is contained in:
parent
2e4ea2628c
commit
f1a3b31384
|
@ -91,7 +91,7 @@ func (k *RR_DNSKEY) KeyTag() uint16 {
|
||||||
keywire.Algorithm = k.Algorithm
|
keywire.Algorithm = k.Algorithm
|
||||||
keywire.PublicKey = k.PublicKey
|
keywire.PublicKey = k.PublicKey
|
||||||
wire := make([]byte, DefaultMsgSize)
|
wire := make([]byte, DefaultMsgSize)
|
||||||
n, ok := packStruct(keywire, wire, 0, nil, false)
|
n, ok := packStruct(keywire, wire, 0)
|
||||||
if !ok {
|
if !ok {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -126,7 +126,7 @@ func (k *RR_DNSKEY) ToDS(h int) *RR_DS {
|
||||||
keywire.Algorithm = k.Algorithm
|
keywire.Algorithm = k.Algorithm
|
||||||
keywire.PublicKey = k.PublicKey
|
keywire.PublicKey = k.PublicKey
|
||||||
wire := make([]byte, DefaultMsgSize)
|
wire := make([]byte, DefaultMsgSize)
|
||||||
n, ok := packStruct(keywire, wire, 0, nil, false)
|
n, ok := packStruct(keywire, wire, 0)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -205,7 +205,7 @@ func (s *RR_RRSIG) Sign(k PrivateKey, rrset RRset) error {
|
||||||
|
|
||||||
// Create the desired binary blob
|
// Create the desired binary blob
|
||||||
signdata := make([]byte, DefaultMsgSize)
|
signdata := make([]byte, DefaultMsgSize)
|
||||||
n, ok := packStruct(sigwire, signdata, 0, nil, false)
|
n, ok := packStruct(sigwire, signdata, 0)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrPack
|
return ErrPack
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ func (s *RR_RRSIG) Verify(k *RR_DNSKEY, rrset RRset) error {
|
||||||
sigwire.SignerName = strings.ToLower(s.SignerName)
|
sigwire.SignerName = strings.ToLower(s.SignerName)
|
||||||
// Create the desired binary blob
|
// Create the desired binary blob
|
||||||
signeddata := make([]byte, DefaultMsgSize)
|
signeddata := make([]byte, DefaultMsgSize)
|
||||||
n, ok := packStruct(sigwire, signeddata, 0, nil, false)
|
n, ok := packStruct(sigwire, signeddata, 0)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ErrPack
|
return ErrPack
|
||||||
}
|
}
|
||||||
|
|
14
msg.go
14
msg.go
|
@ -542,7 +542,13 @@ func structValue(any interface{}) reflect.Value {
|
||||||
return reflect.ValueOf(any).Elem()
|
return reflect.ValueOf(any).Elem()
|
||||||
}
|
}
|
||||||
|
|
||||||
func packStruct(any interface{}, msg []byte, off int, compression map[string]int, compress bool) (off1 int, ok bool) {
|
func packStruct(any interface{}, msg []byte, off int) (off1 int, ok bool) {
|
||||||
|
off, ok = packStructValue(structValue(any), msg, off, nil, false)
|
||||||
|
return off, ok
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func packStructCompress(any interface{}, msg []byte, off int, compression map[string]int, compress bool) (off1 int, ok bool) {
|
||||||
off, ok = packStructValue(structValue(any), msg, off, compression, compress)
|
off, ok = packStructValue(structValue(any), msg, off, compression, compress)
|
||||||
return off, ok
|
return off, ok
|
||||||
}
|
}
|
||||||
|
@ -878,7 +884,7 @@ func packRR(rr RR, msg []byte, off int, compression map[string]int, compress boo
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
}
|
}
|
||||||
|
|
||||||
off1, ok = packStruct(rr, msg, off, compression, compress)
|
off1, ok = packStructCompress(rr, msg, off, compression, compress)
|
||||||
if !ok {
|
if !ok {
|
||||||
return len(msg), false
|
return len(msg), false
|
||||||
}
|
}
|
||||||
|
@ -1019,9 +1025,9 @@ func (dns *Msg) Pack() (msg []byte, ok bool) {
|
||||||
|
|
||||||
// Pack it in: header and then the pieces.
|
// Pack it in: header and then the pieces.
|
||||||
off := 0
|
off := 0
|
||||||
off, ok = packStruct(&dh, msg, off, compression, dns.Compress)
|
off, ok = packStructCompress(&dh, msg, off, compression, dns.Compress)
|
||||||
for i := 0; i < len(question); i++ {
|
for i := 0; i < len(question); i++ {
|
||||||
off, ok = packStruct(&question[i], msg, off, compression, dns.Compress)
|
off, ok = packStructCompress(&question[i], msg, off, compression, dns.Compress)
|
||||||
// println("Question", off)
|
// println("Question", off)
|
||||||
}
|
}
|
||||||
for i := 0; i < len(answer); i++ {
|
for i := 0; i < len(answer); i++ {
|
||||||
|
|
2
nsec3.go
2
nsec3.go
|
@ -17,7 +17,7 @@ func HashName(label string, ha, iter int, salt string) string {
|
||||||
saltwire := new(saltWireFmt)
|
saltwire := new(saltWireFmt)
|
||||||
saltwire.Salt = salt
|
saltwire.Salt = salt
|
||||||
wire := make([]byte, DefaultMsgSize)
|
wire := make([]byte, DefaultMsgSize)
|
||||||
n, ok := packStruct(saltwire, wire, 0, nil, false)
|
n, ok := packStruct(saltwire, wire, 0)
|
||||||
if !ok {
|
if !ok {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
6
tsig.go
6
tsig.go
|
@ -161,7 +161,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
||||||
m.MACSize = uint16(len(requestMAC) / 2)
|
m.MACSize = uint16(len(requestMAC) / 2)
|
||||||
m.MAC = requestMAC
|
m.MAC = requestMAC
|
||||||
macbuf = make([]byte, len(requestMAC)) // reqmac should be twice as long
|
macbuf = make([]byte, len(requestMAC)) // reqmac should be twice as long
|
||||||
n, _ := packStruct(m, macbuf, 0, nil, false)
|
n, _ := packStruct(m, macbuf, 0)
|
||||||
macbuf = macbuf[:n]
|
macbuf = macbuf[:n]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
||||||
tsig := new(timerWireFmt)
|
tsig := new(timerWireFmt)
|
||||||
tsig.TimeSigned = rr.TimeSigned
|
tsig.TimeSigned = rr.TimeSigned
|
||||||
tsig.Fudge = rr.Fudge
|
tsig.Fudge = rr.Fudge
|
||||||
n, _ := packStruct(tsig, tsigvar, 0, nil, false)
|
n, _ := packStruct(tsig, tsigvar, 0)
|
||||||
tsigvar = tsigvar[:n]
|
tsigvar = tsigvar[:n]
|
||||||
} else {
|
} else {
|
||||||
tsig := new(tsigWireFmt)
|
tsig := new(tsigWireFmt)
|
||||||
|
@ -183,7 +183,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
||||||
tsig.Error = rr.Error
|
tsig.Error = rr.Error
|
||||||
tsig.OtherLen = rr.OtherLen
|
tsig.OtherLen = rr.OtherLen
|
||||||
tsig.OtherData = rr.OtherData
|
tsig.OtherData = rr.OtherData
|
||||||
n, _ := packStruct(tsig, tsigvar, 0, nil, false)
|
n, _ := packStruct(tsig, tsigvar, 0)
|
||||||
tsigvar = tsigvar[:n]
|
tsigvar = tsigvar[:n]
|
||||||
}
|
}
|
||||||
if rr.MAC != "" {
|
if rr.MAC != "" {
|
||||||
|
|
Loading…
Reference in New Issue