@@ -491,7 +491,7 @@ func (r *Resource) GoString() string {
491
491
// A ResourceBody is a DNS resource record minus the header.
492
492
type ResourceBody interface {
493
493
// pack packs a Resource except for its header.
494
- pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error )
494
+ pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error )
495
495
496
496
// realType returns the actual type of the Resource. This is used to
497
497
// fill in the header Type field.
@@ -502,7 +502,7 @@ type ResourceBody interface {
502
502
}
503
503
504
504
// pack appends the wire format of the Resource to msg.
505
- func (r * Resource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
505
+ func (r * Resource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
506
506
if r .Body == nil {
507
507
return msg , errNilResouceBody
508
508
}
@@ -750,6 +750,9 @@ func (p *Parser) AllAnswers() ([]Resource, error) {
750
750
}
751
751
752
752
// SkipAnswer skips a single Answer Resource.
753
+ //
754
+ // It does not perform a complete validation of the resource header, which means
755
+ // it may return a nil error when the [AnswerHeader] would actually return an error.
753
756
func (p * Parser ) SkipAnswer () error {
754
757
return p .skipResource (sectionAnswers )
755
758
}
@@ -800,6 +803,9 @@ func (p *Parser) AllAuthorities() ([]Resource, error) {
800
803
}
801
804
802
805
// SkipAuthority skips a single Authority Resource.
806
+ //
807
+ // It does not perform a complete validation of the resource header, which means
808
+ // it may return a nil error when the [AuthorityHeader] would actually return an error.
803
809
func (p * Parser ) SkipAuthority () error {
804
810
return p .skipResource (sectionAuthorities )
805
811
}
@@ -850,6 +856,9 @@ func (p *Parser) AllAdditionals() ([]Resource, error) {
850
856
}
851
857
852
858
// SkipAdditional skips a single Additional Resource.
859
+ //
860
+ // It does not perform a complete validation of the resource header, which means
861
+ // it may return a nil error when the [AdditionalHeader] would actually return an error.
853
862
func (p * Parser ) SkipAdditional () error {
854
863
return p .skipResource (sectionAdditionals )
855
864
}
@@ -1128,7 +1137,7 @@ func (m *Message) AppendPack(b []byte) ([]byte, error) {
1128
1137
// DNS messages can be a maximum of 512 bytes long. Without compression,
1129
1138
// many DNS response messages are over this limit, so enabling
1130
1139
// compression will help ensure compliance.
1131
- compression := map [string ]int {}
1140
+ compression := map [string ]uint16 {}
1132
1141
1133
1142
for i := range m .Questions {
1134
1143
var err error
@@ -1219,7 +1228,7 @@ type Builder struct {
1219
1228
1220
1229
// compression is a mapping from name suffixes to their starting index
1221
1230
// in msg.
1222
- compression map [string ]int
1231
+ compression map [string ]uint16
1223
1232
}
1224
1233
1225
1234
// NewBuilder creates a new builder with compression disabled.
@@ -1256,7 +1265,7 @@ func NewBuilder(buf []byte, h Header) Builder {
1256
1265
//
1257
1266
// Compression should be enabled before any sections are added for best results.
1258
1267
func (b * Builder ) EnableCompression () {
1259
- b .compression = map [string ]int {}
1268
+ b .compression = map [string ]uint16 {}
1260
1269
}
1261
1270
1262
1271
func (b * Builder ) startCheck (s section ) error {
@@ -1672,7 +1681,7 @@ func (h *ResourceHeader) GoString() string {
1672
1681
// pack appends the wire format of the ResourceHeader to oldMsg.
1673
1682
//
1674
1683
// lenOff is the offset in msg where the Length field was packed.
1675
- func (h * ResourceHeader ) pack (oldMsg []byte , compression map [string ]int , compressionOff int ) (msg []byte , lenOff int , err error ) {
1684
+ func (h * ResourceHeader ) pack (oldMsg []byte , compression map [string ]uint16 , compressionOff int ) (msg []byte , lenOff int , err error ) {
1676
1685
msg = oldMsg
1677
1686
if msg , err = h .Name .pack (msg , compression , compressionOff ); err != nil {
1678
1687
return oldMsg , 0 , & nestedError {"Name" , err }
@@ -1945,7 +1954,7 @@ func (n *Name) GoString() string {
1945
1954
//
1946
1955
// The compression map will be updated with new domain suffixes. If compression
1947
1956
// is nil, compression will not be used.
1948
- func (n * Name ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
1957
+ func (n * Name ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
1949
1958
oldMsg := msg
1950
1959
1951
1960
if n .Length > nonEncodedNameMax {
@@ -2009,7 +2018,7 @@ func (n *Name) pack(msg []byte, compression map[string]int, compressionOff int)
2009
2018
// multiple times (for next labels).
2010
2019
nameAsStr = string (n .Data [:n .Length ])
2011
2020
}
2012
- compression [nameAsStr [i :]] = newPtr
2021
+ compression [nameAsStr [i :]] = uint16 ( newPtr )
2013
2022
}
2014
2023
}
2015
2024
}
@@ -2142,7 +2151,7 @@ type Question struct {
2142
2151
}
2143
2152
2144
2153
// pack appends the wire format of the Question to msg.
2145
- func (q * Question ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2154
+ func (q * Question ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2146
2155
msg , err := q .Name .pack (msg , compression , compressionOff )
2147
2156
if err != nil {
2148
2157
return msg , & nestedError {"Name" , err }
@@ -2238,7 +2247,7 @@ func (r *CNAMEResource) realType() Type {
2238
2247
}
2239
2248
2240
2249
// pack appends the wire format of the CNAMEResource to msg.
2241
- func (r * CNAMEResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2250
+ func (r * CNAMEResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2242
2251
return r .CNAME .pack (msg , compression , compressionOff )
2243
2252
}
2244
2253
@@ -2266,7 +2275,7 @@ func (r *MXResource) realType() Type {
2266
2275
}
2267
2276
2268
2277
// pack appends the wire format of the MXResource to msg.
2269
- func (r * MXResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2278
+ func (r * MXResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2270
2279
oldMsg := msg
2271
2280
msg = packUint16 (msg , r .Pref )
2272
2281
msg , err := r .MX .pack (msg , compression , compressionOff )
@@ -2305,7 +2314,7 @@ func (r *NSResource) realType() Type {
2305
2314
}
2306
2315
2307
2316
// pack appends the wire format of the NSResource to msg.
2308
- func (r * NSResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2317
+ func (r * NSResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2309
2318
return r .NS .pack (msg , compression , compressionOff )
2310
2319
}
2311
2320
@@ -2332,7 +2341,7 @@ func (r *PTRResource) realType() Type {
2332
2341
}
2333
2342
2334
2343
// pack appends the wire format of the PTRResource to msg.
2335
- func (r * PTRResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2344
+ func (r * PTRResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2336
2345
return r .PTR .pack (msg , compression , compressionOff )
2337
2346
}
2338
2347
@@ -2369,7 +2378,7 @@ func (r *SOAResource) realType() Type {
2369
2378
}
2370
2379
2371
2380
// pack appends the wire format of the SOAResource to msg.
2372
- func (r * SOAResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2381
+ func (r * SOAResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2373
2382
oldMsg := msg
2374
2383
msg , err := r .NS .pack (msg , compression , compressionOff )
2375
2384
if err != nil {
@@ -2441,7 +2450,7 @@ func (r *TXTResource) realType() Type {
2441
2450
}
2442
2451
2443
2452
// pack appends the wire format of the TXTResource to msg.
2444
- func (r * TXTResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2453
+ func (r * TXTResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2445
2454
oldMsg := msg
2446
2455
for _ , s := range r .TXT {
2447
2456
var err error
@@ -2497,7 +2506,7 @@ func (r *SRVResource) realType() Type {
2497
2506
}
2498
2507
2499
2508
// pack appends the wire format of the SRVResource to msg.
2500
- func (r * SRVResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2509
+ func (r * SRVResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2501
2510
oldMsg := msg
2502
2511
msg = packUint16 (msg , r .Priority )
2503
2512
msg = packUint16 (msg , r .Weight )
@@ -2548,7 +2557,7 @@ func (r *AResource) realType() Type {
2548
2557
}
2549
2558
2550
2559
// pack appends the wire format of the AResource to msg.
2551
- func (r * AResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2560
+ func (r * AResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2552
2561
return packBytes (msg , r .A [:]), nil
2553
2562
}
2554
2563
@@ -2582,7 +2591,7 @@ func (r *AAAAResource) GoString() string {
2582
2591
}
2583
2592
2584
2593
// pack appends the wire format of the AAAAResource to msg.
2585
- func (r * AAAAResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2594
+ func (r * AAAAResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2586
2595
return packBytes (msg , r .AAAA [:]), nil
2587
2596
}
2588
2597
@@ -2622,7 +2631,7 @@ func (r *OPTResource) realType() Type {
2622
2631
return TypeOPT
2623
2632
}
2624
2633
2625
- func (r * OPTResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2634
+ func (r * OPTResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2626
2635
for _ , opt := range r .Options {
2627
2636
msg = packUint16 (msg , opt .Code )
2628
2637
l := uint16 (len (opt .Data ))
@@ -2680,7 +2689,7 @@ func (r *UnknownResource) realType() Type {
2680
2689
}
2681
2690
2682
2691
// pack appends the wire format of the UnknownResource to msg.
2683
- func (r * UnknownResource ) pack (msg []byte , compression map [string ]int , compressionOff int ) ([]byte , error ) {
2692
+ func (r * UnknownResource ) pack (msg []byte , compression map [string ]uint16 , compressionOff int ) ([]byte , error ) {
2684
2693
return packBytes (msg , r .Data [:]), nil
2685
2694
}
2686
2695
0 commit comments