pub struct SecureCompressor { /* private fields */ }Expand description
Secure byte-level compressor with integrated bomb protection.
Wraps a CompressionBombDetector to ensure decompressed output never exceeds configured
size and ratio limits, regardless of which codec is active.
§Examples
use pjson_rs::compression::secure::{SecureCompressor, ByteCodec};
let compressor = SecureCompressor::with_default_security(ByteCodec::None);
let compressed = compressor.compress(b"hello world").unwrap();
let decompressed = compressor.decompress_protected(&compressed).unwrap();
assert_eq!(decompressed, b"hello world");Implementations§
Source§impl SecureCompressor
impl SecureCompressor
Sourcepub fn new(detector: CompressionBombDetector, codec: ByteCodec) -> Self
pub fn new(detector: CompressionBombDetector, codec: ByteCodec) -> Self
Create a new secure compressor with the given detector and codec.
Sourcepub fn with_default_security(codec: ByteCodec) -> Self
pub fn with_default_security(codec: ByteCodec) -> Self
Create with default security settings and the given codec.
Sourcepub fn with_quality(
detector: CompressionBombDetector,
codec: ByteCodec,
quality: CompressionQuality,
) -> Self
pub fn with_quality( detector: CompressionBombDetector, codec: ByteCodec, quality: CompressionQuality, ) -> Self
Create with explicit quality setting.
Sourcepub fn compress(&self, data: &[u8]) -> Result<SecureCompressedData>
pub fn compress(&self, data: &[u8]) -> Result<SecureCompressedData>
Compress data using the configured codec.
Validates the input size against max_compressed_size before encoding.
Sourcepub fn decompress_protected(
&self,
compressed: &SecureCompressedData,
) -> Result<Vec<u8>>
pub fn decompress_protected( &self, compressed: &SecureCompressedData, ) -> Result<Vec<u8>>
Decompress compressed using the codec recorded in compressed.codec.
Decoder output is streamed through CompressionBombProtector — decompression aborts
early if size or ratio limits are exceeded.
Sourcepub fn decompress_nested(
&self,
compressed: &SecureCompressedData,
depth: usize,
) -> Result<Vec<u8>>
pub fn decompress_nested( &self, compressed: &SecureCompressedData, depth: usize, ) -> Result<Vec<u8>>
Decompress nested/chained compression with depth tracking.
Equivalent to decompress_protected but additionally enforces
max_compression_depth via CompressionBombDetector::protect_nested_reader.
Auto Trait Implementations§
impl Freeze for SecureCompressor
impl RefUnwindSafe for SecureCompressor
impl Send for SecureCompressor
impl Sync for SecureCompressor
impl Unpin for SecureCompressor
impl UnsafeUnpin for SecureCompressor
impl UnwindSafe for SecureCompressor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more