@@ -29,10 +29,6 @@ pub(super) struct PacketBuilder<'a, 'b> {
2929 /// Smallest absolute position in the associated buffer that must be occupied by this packet's
3030 /// frames
3131 pub ( super ) min_size : usize ,
32- /// Largest absolute position in the buffer that may be occupied by this packet's frames
33- ///
34- /// This takes the size of the cryptographic tag into account.
35- pub ( super ) max_size : usize ,
3632 pub ( super ) tag_len : usize ,
3733 pub ( super ) _span : tracing:: span:: EnteredSpan ,
3834}
@@ -173,7 +169,6 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
173169 exact_number,
174170 short_header : header. is_short ( ) ,
175171 min_size,
176- max_size,
177172 tag_len,
178173 ack_eliciting,
179174 _span : span,
@@ -253,7 +248,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
253248 /// Encrypt packet, returning the length of the packet and whether padding was added
254249 pub ( super ) fn finish ( self , conn : & mut Connection ) -> ( usize , bool ) {
255250 debug_assert ! (
256- self . buf. len( ) <= self . max_size ,
251+ self . buf. len( ) <= self . buf . datagram_max_offset ( ) - self . tag_len ,
257252 "packet exceeds maximum size"
258253 ) ;
259254 let pad = self . buf . len ( ) < self . min_size ;
@@ -304,7 +299,7 @@ impl<'a, 'b> PacketBuilder<'a, 'b> {
304299 /// This leaves space in the datagram for the cryptographic tag that needs to be written
305300 /// when the packet is finished.
306301 pub ( super ) fn frame_space_remaining ( & self ) -> usize {
307- debug_assert ! ( self . max_size > = self . buf. len ( ) , "packet exceeds bounds" ) ;
308- self . max_size . saturating_sub ( self . buf . len ( ) )
302+ let max_offset = self . buf . datagram_max_offset ( ) - self . tag_len ;
303+ max_offset . saturating_sub ( self . buf . len ( ) )
309304 }
310305}
0 commit comments