ssh/algorithm/compression/
mod.rs1use super::Compress;
2use crate::SshResult;
3
4mod zlib;
5pub(crate) trait Compression: Send + Sync {
7 fn new() -> Self
8 where
9 Self: Sized;
10 fn compress(&mut self, buf: &[u8]) -> SshResult<Vec<u8>>;
16 fn decompress(&mut self, buf: &[u8]) -> SshResult<Vec<u8>>;
17}
18
19pub(crate) fn from(comp: &Compress) -> Box<dyn Compression> {
20 match comp {
21 Compress::None => Box::new(CompressNone::new()),
22 #[cfg(feature = "deprecated-zlib")]
23 Compress::Zlib => Box::new(zlib::CompressZlib::new()),
24 Compress::ZlibOpenSsh => Box::new(zlib::CompressZlib::new()),
25 }
26}
27
28#[derive(Default)]
29pub(crate) struct CompressNone {}
30
31impl Compression for CompressNone {
32 fn new() -> Self {
33 Self {}
34 }
35
36 fn compress(&mut self, buf: &[u8]) -> SshResult<Vec<u8>> {
37 Ok(buf.to_vec())
38 }
39
40 fn decompress(&mut self, buf: &[u8]) -> SshResult<Vec<u8>> {
41 Ok(buf.to_vec())
42 }
43}