| 1 | // Copyright (c) 2019 Parity Technologies (UK) Ltd. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 |
| 4 | // <LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0> or the MIT |
| 5 | // license <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 6 | // option. All files in the project carrying such notice may not be copied, |
| 7 | // modified, or distributed except according to those terms. |
| 8 | |
| 9 | //! Deflate compression extension mostly conformant with [RFC 7692][rfc7692]. |
| 10 | //! |
| 11 | //! [rfc7692]: https://tools.ietf.org/html/rfc7692 |
| 12 | |
| 13 | use craterust-analyzer cargo soketto 0.8.1 crate/::{ |
| 14 | as_u64rust-analyzer cargo soketto 0.8.1 as_u64()., |
| 15 | baserust-analyzer cargo soketto 0.8.1 base/::{Headerrust-analyzer cargo soketto 0.8.1 base/Header#, OpCoderust-analyzer cargo soketto 0.8.1 base/OpCode#}, |
| 16 | connectionrust-analyzer cargo soketto 0.8.1 connection/::Moderust-analyzer cargo soketto 0.8.1 connection/Mode#, |
| 17 | extensionrust-analyzer cargo soketto 0.8.1 extension/::{Extensionrust-analyzer cargo soketto 0.8.1 extension/Extension#, Paramrust-analyzer cargo soketto 0.8.1 extension/Param#}, |
| 18 | BoxedErrorrust-analyzer cargo soketto 0.8.1 BoxedError#, Storagerust-analyzer cargo soketto 0.8.1 Storage#, |
| 19 | }; |
| 20 | use flate2rust-analyzer cargo flate2 1.1.9 crate/::{writerust-analyzer cargo flate2 1.1.9 write/::DeflateDecoderrust-analyzer cargo flate2 1.1.9 deflate/write/DeflateDecoder#, Compressrust-analyzer cargo flate2 1.1.9 mem/Compress#, Compressionrust-analyzer cargo flate2 1.1.9 Compression#, FlushCompressrust-analyzer cargo flate2 1.1.9 mem/FlushCompress#, Statusrust-analyzer cargo flate2 1.1.9 mem/Status#}; |
| 21 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 22 | convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryIntorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#, |
| 23 | iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}, |
| 24 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/, |
| 25 | }; |
| 26 | |
| 27 | const SERVER_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_NO_CONTEXT_TAKEOVER.: &str = "server_no_context_takeover"; |
| 28 | const SERVER_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_MAX_WINDOW_BITS.: &str = "server_max_window_bits"; |
| 29 | |
| 30 | const CLIENT_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_NO_CONTEXT_TAKEOVER.: &str = "client_no_context_takeover"; |
| 31 | const CLIENT_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_MAX_WINDOW_BITS.: &str = "client_max_window_bits"; |
| 32 | |
| 33 | /// The deflate extension type. |
| 34 | /// |
| 35 | /// The extension does currently not support max. window bits other than the |
| 36 | /// default, which is 15 and will ask for no context takeover during handshake. |
| 37 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 38 | pub struct Deflaterust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate# { |
| 39 | moderust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#mode.: Moderust-analyzer cargo soketto 0.8.1 connection/Mode#, |
| 40 | enabledrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#enabled.: bool, |
| 41 | bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>, |
| 42 | paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Paramrust-analyzer cargo soketto 0.8.1 extension/Param#<'static>>, |
| 43 | our_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#our_max_window_bits.: u8, |
| 44 | their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#their_max_window_bits.: u8, |
| 45 | await_last_fragmentrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#await_last_fragment.: bool, |
| 46 | } |
| 47 | |
| 48 | impl Deflaterust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate# { |
| 49 | /// Create a new deflate extension either on client or server side. |
| 50 | pub fn newrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate]new().(mode: Moderust-analyzer cargo soketto 0.8.1 connection/Mode#) -> Selfrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate] { |
| 51 | let params = match mode { |
| 52 | Moderust-analyzer cargo soketto 0.8.1 connection/Mode#::Serverrust-analyzer cargo soketto 0.8.1 connection/Mode#Server# => Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 53 | Moderust-analyzer cargo soketto 0.8.1 connection/Mode#::Clientrust-analyzer cargo soketto 0.8.1 connection/Mode#Client# => { |
| 54 | let mut params = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 55 | params.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(SERVER_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_NO_CONTEXT_TAKEOVER.)); |
| 56 | params.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(CLIENT_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_NO_CONTEXT_TAKEOVER.)); |
| 57 | params.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(CLIENT_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_MAX_WINDOW_BITS.)); |
| 58 | params |
| 59 | } |
| 60 | }; |
| 61 | Deflaterust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate# { |
| 62 | moderust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#mode., |
| 63 | enabledrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#enabled.: false, |
| 64 | bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(), |
| 65 | paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params., |
| 66 | our_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#our_max_window_bits.: 15, |
| 67 | their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#their_max_window_bits.: 15, |
| 68 | await_last_fragmentrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#await_last_fragment.: false, |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /// Set the server's max. window bits. |
| 73 | /// |
| 74 | /// The value must be within 9 ..= 15. |
| 75 | /// The extension must be in client mode. |
| 76 | /// |
| 77 | /// By including this parameter, a client limits the LZ77 sliding window |
| 78 | /// size that the server will use to compress messages. A server accepts |
| 79 | /// by including the "server_max_window_bits" extension parameter in the |
| 80 | /// response with the same or smaller value as the offer. |
| 81 | pub fn set_max_server_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate]set_max_server_window_bits().(&mut self, max: u8) { |
| 82 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.moderust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#mode. == Moderust-analyzer cargo soketto 0.8.1 connection/Mode#::Clientrust-analyzer cargo soketto 0.8.1 connection/Mode#Client#, "setting max. server window bits requires client mode"); |
| 83 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(max >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). 8 && max <= 15, "max. server window bits have to be within 9 ..= 15"); |
| 84 | self.their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#their_max_window_bits. = max; // upper bound of the server's window |
| 85 | let mut p = Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(SERVER_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_MAX_WINDOW_BITS.); |
| 86 | p.set_valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]set_value().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(max.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 87 | self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(p) |
| 88 | } |
| 89 | |
| 90 | /// Set the client's max. window bits. |
| 91 | /// |
| 92 | /// The value must be within 9 ..= 15. |
| 93 | /// The extension must be in client mode. |
| 94 | /// |
| 95 | /// The parameter informs the server that even if it doesn't include the |
| 96 | /// "client_max_window_bits" extension parameter in the response with a |
| 97 | /// value greater than the one in the negotiation offer or if it doesn't |
| 98 | /// include the extension parameter at all, the client is not going to |
| 99 | /// use an LZ77 sliding window size greater than one given here. |
| 100 | /// The server may also respond with a smaller value which allows the client |
| 101 | /// to reduce its sliding window even more. |
| 102 | pub fn set_max_client_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate]set_max_client_window_bits().(&mut self, max: u8) { |
| 103 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.moderust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#mode. == Moderust-analyzer cargo soketto 0.8.1 connection/Mode#::Clientrust-analyzer cargo soketto 0.8.1 connection/Mode#Client#, "setting max. client window bits requires client mode"); |
| 104 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(max >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). 8 && max <= 15, "max. client window bits have to be within 9 ..= 15"); |
| 105 | self.our_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#our_max_window_bits. = max; // upper bound of the client's window |
| 106 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(p) = self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`IterMut<'a, T>`][Iterator]find().(|p| p.namerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]name().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().CLIENT_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_MAX_WINDOW_BITS.) { |
| 107 | p.set_valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]set_value().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(max.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 108 | } else { |
| 109 | let mut p = Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(CLIENT_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_MAX_WINDOW_BITS.); |
| 110 | p.set_valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]set_value().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(max.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 111 | self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(p) |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | fn set_their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate]set_their_max_window_bits().(&mut self, p: &Paramrust-analyzer cargo soketto 0.8.1 extension/Param#, expected: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), ()> { |
| 116 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v)) = p.valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]value().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<u8>()) { |
| 117 | if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().8 || v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().15 { |
| 118 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("invalid {}: {} (expected range: 8 ..= 15)", p.namerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]name().(), v); |
| 119 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(()); |
| 120 | } |
| 121 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(x) = expected { |
| 122 | if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().x { |
| 123 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("invalid {}: {} (expected: {} <= {})", p.namerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]name().(), v, v, x); |
| 124 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(()); |
| 125 | } |
| 126 | } |
| 127 | self.their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#their_max_window_bits. = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(9, v); |
| 128 | } |
| 129 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | impl Extensionrust-analyzer cargo soketto 0.8.1 extension/Extension# for Deflaterust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate# { |
| 134 | fn namerust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]name().(&self) -> &str { |
| 135 | "permessage-deflate" |
| 136 | } |
| 137 | |
| 138 | fn is_enabledrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]is_enabled().(&self) -> bool { |
| 139 | self.enabledrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#enabled. |
| 140 | } |
| 141 | |
| 142 | fn paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]params().(&self) -> &[Paramrust-analyzer cargo soketto 0.8.1 extension/Param#] { |
| 143 | &self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params. |
| 144 | } |
| 145 | |
| 146 | fn configurerust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]configure().(&mut self, params: &[Paramrust-analyzer cargo soketto 0.8.1 extension/Param#]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), BoxedErrorrust-analyzer cargo soketto 0.8.1 BoxedError#> { |
| 147 | match self.moderust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#mode. { |
| 148 | Moderust-analyzer cargo soketto 0.8.1 connection/Mode#::Serverrust-analyzer cargo soketto 0.8.1 connection/Mode#Server# => { |
| 149 | self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 150 | for p in params { |
| 151 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("configure server with: {}", p); |
| 152 | match p.namerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]name().() { |
| 153 | CLIENT_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_MAX_WINDOW_BITS. => { |
| 154 | if self.set_their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate]set_their_max_window_bits().(&p, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 155 | // we just accept the client's offer as is => no need to reply |
| 156 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 157 | } |
| 158 | } |
| 159 | SERVER_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_MAX_WINDOW_BITS. => { |
| 160 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v)) = p.valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]value().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<u8>()) { |
| 161 | // The RFC allows 8 to 15 bits, but due to zlib limitations we |
| 162 | // only support 9 to 15. |
| 163 | if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().9 || v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().15 { |
| 164 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("unacceptable server_max_window_bits: {}", v); |
| 165 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 166 | } |
| 167 | let mut x = Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(SERVER_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_MAX_WINDOW_BITS.); |
| 168 | x.set_valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]set_value().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(v.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())); |
| 169 | self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(x); |
| 170 | self.our_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#our_max_window_bits. = v; |
| 171 | } else { |
| 172 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("invalid server_max_window_bits: {:?}", p.valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]value().()); |
| 173 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 174 | } |
| 175 | } |
| 176 | CLIENT_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_NO_CONTEXT_TAKEOVER. => self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(CLIENT_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_NO_CONTEXT_TAKEOVER.)), |
| 177 | SERVER_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_NO_CONTEXT_TAKEOVER. => self.paramsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#params..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Paramrust-analyzer cargo soketto 0.8.1 extension/Param#::newrust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]new().(SERVER_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_NO_CONTEXT_TAKEOVER.)), |
| 178 | _ => { |
| 179 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("{}: unknown parameter: {}", self.namerust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]name().(), p.namerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]name().()); |
| 180 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | } |
| 185 | Moderust-analyzer cargo soketto 0.8.1 connection/Mode#::Clientrust-analyzer cargo soketto 0.8.1 connection/Mode#Client# => { |
| 186 | let mut server_no_context_takeover = false; |
| 187 | for p in params { |
| 188 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("configure client with: {}", p); |
| 189 | match p.namerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]name().() { |
| 190 | SERVER_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_NO_CONTEXT_TAKEOVER. => server_no_context_takeover = true, |
| 191 | CLIENT_NO_CONTEXT_TAKEOVERrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_NO_CONTEXT_TAKEOVER. => {} // must be supported |
| 192 | SERVER_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/SERVER_MAX_WINDOW_BITS. => { |
| 193 | let expected = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#their_max_window_bits.); |
| 194 | if self.set_their_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate]set_their_max_window_bits().(&p, expected).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 195 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 196 | } |
| 197 | } |
| 198 | CLIENT_MAX_WINDOW_BITSrust-analyzer cargo soketto 0.8.1 extension/deflate/CLIENT_MAX_WINDOW_BITS. => { |
| 199 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v)) = p.valuerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]value().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<u8>()) { |
| 200 | if v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]lt().8 || v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialOrd<Self>`]gt().15 { |
| 201 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("unacceptable client_max_window_bits: {}", v); |
| 202 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 203 | } |
| 204 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::{maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max()., minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().}; |
| 205 | // Due to zlib limitations we have to use 9 as a lower bound |
| 206 | // here, even if the server allowed us to go down to 8 bits. |
| 207 | self.our_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#our_max_window_bits. = minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/min().(self.our_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#our_max_window_bits., maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(9, v)); |
| 208 | } |
| 209 | } |
| 210 | _ => { |
| 211 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("{}: unknown parameter: {}", self.namerust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]name().(), p.namerust-analyzer cargo soketto 0.8.1 extension/impl#[`Param<'a>`]name().()); |
| 212 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().server_no_context_takeover { |
| 217 | logrust-analyzer cargo log 0.4.34 crate/::debugrust-analyzer cargo log 0.4.34 macros/debug!!("{}: server did not confirm no context takeover", self.namerust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]name().()); |
| 218 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | self.enabledrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#enabled. = true; |
| 223 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 224 | } |
| 225 | |
| 226 | fn reserved_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]reserved_bits().(&self) -> (bool, bool, bool) { |
| 227 | (true, false, false) |
| 228 | } |
| 229 | |
| 230 | fn decoderust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]decode().(&mut self, header: &mut Headerrust-analyzer cargo soketto 0.8.1 base/Header#, data: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), BoxedErrorrust-analyzer cargo soketto 0.8.1 BoxedError#> { |
| 231 | if data.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 232 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 233 | } |
| 234 | |
| 235 | match header.opcoderust-analyzer cargo soketto 0.8.1 base/impl#[Header]opcode().() { |
| 236 | OpCoderust-analyzer cargo soketto 0.8.1 base/OpCode#::Binaryrust-analyzer cargo soketto 0.8.1 base/OpCode#Binary# | OpCoderust-analyzer cargo soketto 0.8.1 base/OpCode#::Textrust-analyzer cargo soketto 0.8.1 base/OpCode#Text# if header.is_rsv1rust-analyzer cargo soketto 0.8.1 base/impl#[Header]is_rsv1().() => { |
| 237 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().header.is_finrust-analyzer cargo soketto 0.8.1 base/impl#[Header]is_fin().() { |
| 238 | self.await_last_fragmentrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#await_last_fragment. = true; |
| 239 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("deflate: not decoding {}; awaiting last fragment", header); |
| 240 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 241 | } |
| 242 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("deflate: decoding {}", header) |
| 243 | } |
| 244 | OpCoderust-analyzer cargo soketto 0.8.1 base/OpCode#::Continuerust-analyzer cargo soketto 0.8.1 base/OpCode#Continue# if header.is_finrust-analyzer cargo soketto 0.8.1 base/impl#[Header]is_fin().() && self.await_last_fragmentrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#await_last_fragment. => { |
| 245 | self.await_last_fragmentrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#await_last_fragment. = false; |
| 246 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("deflate: decoding {}", header) |
| 247 | } |
| 248 | _ => { |
| 249 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("deflate: not decoding {}", header); |
| 250 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | // Restore LEN and NLEN: |
| 255 | data.extend_from_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]extend_from_slice().(&[0, 0, 0xFF, 0xFF]); // cf. RFC 7692, 7.2.2 |
| 256 | |
| 257 | self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 258 | let mut decoder = DeflateDecoderrust-analyzer cargo flate2 1.1.9 deflate/write/DeflateDecoder#::newrust-analyzer cargo flate2 1.1.9 deflate/write/impl#[`DeflateDecoder<W>`]new().(&mut self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer.); |
| 259 | decoder.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(&data)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 260 | decoder.finishrust-analyzer cargo flate2 1.1.9 deflate/write/impl#[`DeflateDecoder<W>`]finish().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 261 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/swap().(data, &mut self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer.); |
| 262 | |
| 263 | header.set_rsv1rust-analyzer cargo soketto 0.8.1 base/impl#[Header]set_rsv1().(false); |
| 264 | header.set_payload_lenrust-analyzer cargo soketto 0.8.1 base/impl#[Header]set_payload_len().(data.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()); |
| 265 | |
| 266 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 267 | } |
| 268 | |
| 269 | fn encoderust-analyzer cargo soketto 0.8.1 extension/deflate/impl#[Deflate][Extension]encode().(&mut self, header: &mut Headerrust-analyzer cargo soketto 0.8.1 base/Header#, data: &mut Storagerust-analyzer cargo soketto 0.8.1 Storage#) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), BoxedErrorrust-analyzer cargo soketto 0.8.1 BoxedError#> { |
| 270 | if data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`&mut T`][`AsRef<U>`]as_ref().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 271 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 272 | } |
| 273 | |
| 274 | if let OpCoderust-analyzer cargo soketto 0.8.1 base/OpCode#::Binaryrust-analyzer cargo soketto 0.8.1 base/OpCode#Binary# | OpCoderust-analyzer cargo soketto 0.8.1 base/OpCode#::Textrust-analyzer cargo soketto 0.8.1 base/OpCode#Text# = header.opcoderust-analyzer cargo soketto 0.8.1 base/impl#[Header]opcode().() { |
| 275 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("deflate: encoding {}", header) |
| 276 | } else { |
| 277 | logrust-analyzer cargo log 0.4.34 crate/::tracerust-analyzer cargo log 0.4.34 macros/trace!!("deflate: not encoding {}", header); |
| 278 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 279 | } |
| 280 | |
| 281 | self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 282 | self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`&mut T`][`AsRef<U>`]as_ref().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 283 | |
| 284 | let mut encoder = Compressrust-analyzer cargo flate2 1.1.9 mem/Compress#::new_with_window_bitsrust-analyzer cargo flate2 1.1.9 mem/impl#[Compress]new_with_window_bits().(Compressionrust-analyzer cargo flate2 1.1.9 Compression#::fastrust-analyzer cargo flate2 1.1.9 impl#[Compression]fast().(), false, self.our_max_window_bitsrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#our_max_window_bits.); |
| 285 | |
| 286 | // Compress all input bytes. |
| 287 | while encoder.total_inrust-analyzer cargo flate2 1.1.9 mem/impl#[Compress]total_in().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialOrd<Self>`]lt().as_u64rust-analyzer cargo soketto 0.8.1 as_u64().(data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`&mut T`][`AsRef<U>`]as_ref().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) { |
| 288 | let i: usize = encoder.total_inrust-analyzer cargo flate2 1.1.9 mem/impl#[Compress]total_in().().try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 289 | match encoder.compress_vecrust-analyzer cargo flate2 1.1.9 mem/impl#[Compress]compress_vec().(&data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`&mut T`][`AsRef<U>`]as_ref().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., &mut self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer., FlushCompressrust-analyzer cargo flate2 1.1.9 mem/FlushCompress#::Nonerust-analyzer cargo flate2 1.1.9 mem/FlushCompress#None#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 290 | Statusrust-analyzer cargo flate2 1.1.9 mem/Status#::BufErrorrust-analyzer cargo flate2 1.1.9 mem/Status#BufError# => self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(4096), |
| 291 | Statusrust-analyzer cargo flate2 1.1.9 mem/Status#::Okrust-analyzer cargo flate2 1.1.9 mem/Status#Ok# => continue, |
| 292 | Statusrust-analyzer cargo flate2 1.1.9 mem/Status#::StreamEndrust-analyzer cargo flate2 1.1.9 mem/Status#StreamEnd# => break, |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | // We need to append an empty deflate block if not there yet (RFC 7692, 7.2.1). |
| 297 | while !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]ends_with().(&[0, 0, 0xFF, 0xFF]) { |
| 298 | self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(5); // Make sure there is room for the trailing end bytes. |
| 299 | match encoder.compress_vecrust-analyzer cargo flate2 1.1.9 mem/impl#[Compress]compress_vec().(&[], &mut self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer., FlushCompressrust-analyzer cargo flate2 1.1.9 mem/FlushCompress#::Syncrust-analyzer cargo flate2 1.1.9 mem/FlushCompress#Sync#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). { |
| 300 | Statusrust-analyzer cargo flate2 1.1.9 mem/Status#::Okrust-analyzer cargo flate2 1.1.9 mem/Status#Ok# => continue, |
| 301 | Statusrust-analyzer cargo flate2 1.1.9 mem/Status#::BufErrorrust-analyzer cargo flate2 1.1.9 mem/Status#BufError# => continue, // more capacity is reserved above |
| 302 | Statusrust-analyzer cargo flate2 1.1.9 mem/Status#::StreamEndrust-analyzer cargo flate2 1.1.9 mem/Status#StreamEnd# => break, |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | // If we still have not seen the empty deflate block appended, something is wrong. |
| 307 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]ends_with().(&[0, 0, 0xFF, 0xFF]) { |
| 308 | logrust-analyzer cargo log 0.4.34 crate/::errorrust-analyzer cargo log 0.4.34 macros/error!!("missing 00 00 FF FF"); |
| 309 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error]new().(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::ErrorKindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#::Otherrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/ErrorKind#Other#, "missing 00 00 FF FF").intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()); |
| 310 | } |
| 311 | |
| 312 | self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().4); // Remove 00 00 FF FF; cf. RFC 7692, 7.2.1 |
| 313 | |
| 314 | if let Storagerust-analyzer cargo soketto 0.8.1 Storage#::Ownedrust-analyzer cargo soketto 0.8.1 Storage#Owned#(d) = data { |
| 315 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/swap().(d, &mut self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer.) |
| 316 | } else { |
| 317 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().data = Storagerust-analyzer cargo soketto 0.8.1 Storage#::Ownedrust-analyzer cargo soketto 0.8.1 Storage#Owned#(memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/take().(&mut self.bufferrust-analyzer cargo soketto 0.8.1 extension/deflate/Deflate#buffer.)) |
| 318 | } |
| 319 | header.set_rsv1rust-analyzer cargo soketto 0.8.1 base/impl#[Header]set_rsv1().(true); |
| 320 | header.set_payload_lenrust-analyzer cargo soketto 0.8.1 base/impl#[Header]set_payload_len().(data.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[`&mut T`][`AsRef<U>`]as_ref().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 321 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 322 | } |
| 323 | } |