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.PublicKey = k.PublicKey
|
||||
wire := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(keywire, wire, 0, nil, false)
|
||||
n, ok := packStruct(keywire, wire, 0)
|
||||
if !ok {
|
||||
return 0
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func (k *RR_DNSKEY) ToDS(h int) *RR_DS {
|
|||
keywire.Algorithm = k.Algorithm
|
||||
keywire.PublicKey = k.PublicKey
|
||||
wire := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(keywire, wire, 0, nil, false)
|
||||
n, ok := packStruct(keywire, wire, 0)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ func (s *RR_RRSIG) Sign(k PrivateKey, rrset RRset) error {
|
|||
|
||||
// Create the desired binary blob
|
||||
signdata := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(sigwire, signdata, 0, nil, false)
|
||||
n, ok := packStruct(sigwire, signdata, 0)
|
||||
if !ok {
|
||||
return ErrPack
|
||||
}
|
||||
|
@ -300,7 +300,7 @@ func (s *RR_RRSIG) Verify(k *RR_DNSKEY, rrset RRset) error {
|
|||
sigwire.SignerName = strings.ToLower(s.SignerName)
|
||||
// Create the desired binary blob
|
||||
signeddata := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(sigwire, signeddata, 0, nil, false)
|
||||
n, ok := packStruct(sigwire, signeddata, 0)
|
||||
if !ok {
|
||||
return ErrPack
|
||||
}
|
||||
|
|
14
msg.go
14
msg.go
|
@ -542,7 +542,13 @@ func structValue(any interface{}) reflect.Value {
|
|||
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)
|
||||
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
|
||||
}
|
||||
|
||||
off1, ok = packStruct(rr, msg, off, compression, compress)
|
||||
off1, ok = packStructCompress(rr, msg, off, compression, compress)
|
||||
if !ok {
|
||||
return len(msg), false
|
||||
}
|
||||
|
@ -1019,9 +1025,9 @@ func (dns *Msg) Pack() (msg []byte, ok bool) {
|
|||
|
||||
// Pack it in: header and then the pieces.
|
||||
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++ {
|
||||
off, ok = packStruct(&question[i], msg, off, compression, dns.Compress)
|
||||
off, ok = packStructCompress(&question[i], msg, off, compression, dns.Compress)
|
||||
// println("Question", off)
|
||||
}
|
||||
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.Salt = salt
|
||||
wire := make([]byte, DefaultMsgSize)
|
||||
n, ok := packStruct(saltwire, wire, 0, nil, false)
|
||||
n, ok := packStruct(saltwire, wire, 0)
|
||||
if !ok {
|
||||
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.MAC = requestMAC
|
||||
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]
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
|||
tsig := new(timerWireFmt)
|
||||
tsig.TimeSigned = rr.TimeSigned
|
||||
tsig.Fudge = rr.Fudge
|
||||
n, _ := packStruct(tsig, tsigvar, 0, nil, false)
|
||||
n, _ := packStruct(tsig, tsigvar, 0)
|
||||
tsigvar = tsigvar[:n]
|
||||
} else {
|
||||
tsig := new(tsigWireFmt)
|
||||
|
@ -183,7 +183,7 @@ func tsigBuffer(msgbuf []byte, rr *RR_TSIG, requestMAC string, timersOnly bool)
|
|||
tsig.Error = rr.Error
|
||||
tsig.OtherLen = rr.OtherLen
|
||||
tsig.OtherData = rr.OtherData
|
||||
n, _ := packStruct(tsig, tsigvar, 0, nil, false)
|
||||
n, _ := packStruct(tsig, tsigvar, 0)
|
||||
tsigvar = tsigvar[:n]
|
||||
}
|
||||
if rr.MAC != "" {
|
||||
|
|
Loading…
Reference in New Issue