commit 151b12c7230872218a2b6c76084b7af1ede74152
parent db6b9cbe3c8276cad9a477419cb1fd4321541a9b
Author: Antoine A <>
Date: Wed, 11 Mar 2026 12:14:25 +0100
common: replace libdeflater with zlib-rs
Diffstat:
5 files changed, 28 insertions(+), 28 deletions(-)
diff --git a/Cargo.toml b/Cargo.toml
@@ -55,7 +55,6 @@ http-client = { path = "common/http-client" }
hyper = { version = "1.8.1", features = ["client", "http1", "http2"] }
anyhow = "1"
http-body-util = "0.1.2"
-libdeflater = "1.22.0"
base64 = "0.22"
owo-colors = "4.2.3"
aws-lc-rs = "1.15"
diff --git a/common/taler-api/Cargo.toml b/common/taler-api/Cargo.toml
@@ -12,7 +12,7 @@ listenfd = "1.0.0"
dashmap = "6.1"
base64.workspace = true
http-body-util.workspace = true
-libdeflater.workspace = true
+zlib-rs = "0.6.3"
tokio = { workspace = true, features = ["signal"] }
serde.workspace = true
tracing.workspace = true
diff --git a/common/taler-api/src/json.rs b/common/taler-api/src/json.rs
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2025 Taler Systems SA
+ Copyright (C) 2025, 2026 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -22,6 +22,7 @@ use axum::{
use http_body_util::BodyExt as _;
use serde::de::DeserializeOwned;
use taler_common::error_code::ErrorCode;
+use zlib_rs::{InflateConfig, ReturnCode};
use crate::{
constants::MAX_BODY_LENGTH,
@@ -114,23 +115,24 @@ where
};
let bytes = if compressed {
- let mut buf = vec![0; MAX_BODY_LENGTH];
- match libdeflater::Decompressor::new().zlib_decompress(&bytes, &mut buf) {
- Ok(it) => Bytes::copy_from_slice(&buf[..it]),
- Err(it) => match it {
- libdeflater::DecompressionError::BadData => {
- return Err(failure(
- ErrorCode::GENERIC_COMPRESSION_INVALID,
- "Failed to decompress body: invalid compression",
- ));
- }
- libdeflater::DecompressionError::InsufficientSpace => {
- return Err(failure(
- ErrorCode::GENERIC_UPLOAD_EXCEEDS_LIMIT,
- format!("Decompressed body is suspiciously big > {MAX_BODY_LENGTH}B"),
- ));
- }
- },
+ let mut buf = [0; MAX_BODY_LENGTH];
+ let (decompressed, code) =
+ zlib_rs::decompress_slice(&mut buf, &bytes, InflateConfig::default());
+ dbg!(code);
+ match code {
+ ReturnCode::Ok => Bytes::copy_from_slice(decompressed),
+ ReturnCode::BufError => {
+ return Err(failure(
+ ErrorCode::GENERIC_UPLOAD_EXCEEDS_LIMIT,
+ format!("Decompressed body is suspiciously big > {MAX_BODY_LENGTH}B"),
+ ));
+ }
+ _ => {
+ return Err(failure(
+ ErrorCode::GENERIC_COMPRESSION_INVALID,
+ "Failed to decompress body: invalid compression",
+ ));
+ }
}
} else {
bytes
diff --git a/common/taler-test-utils/Cargo.toml b/common/taler-test-utils/Cargo.toml
@@ -9,6 +9,7 @@ license-file.workspace = true
[dependencies]
tower = "0.5"
+flate2 = { version = "1.0", features = ["zlib-rs"], default-features = false }
axum.workspace = true
tokio.workspace = true
serde_json.workspace = true
@@ -21,4 +22,3 @@ tracing-subscriber.workspace = true
sqlx.workspace = true
http-body-util.workspace = true
url.workspace = true
-libdeflater.workspace = true
diff --git a/common/taler-test-utils/src/server.rs b/common/taler-test-utils/src/server.rs
@@ -1,6 +1,6 @@
/*
This file is part of TALER
- Copyright (C) 2025 Taler Systems SA
+ Copyright (C) 2025, 2026 Taler Systems SA
TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License as published by the Free Software
@@ -14,7 +14,7 @@
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
*/
-use std::{fmt::Debug, pin::Pin};
+use std::{fmt::Debug, io::Write, pin::Pin};
use axum::{
Router,
@@ -25,8 +25,8 @@ use axum::{
header::{self, AsHeaderName, IntoHeaderName},
},
};
+use flate2::{Compression, write::ZlibEncoder};
use http_body_util::BodyExt as _;
-use libdeflater::CompressionLvl;
use serde::{Deserialize, Serialize, de::DeserializeOwned};
use taler_common::{api_common::ErrorDetail, error_code::ErrorCode};
use tower::ServiceExt as _;
@@ -89,10 +89,9 @@ impl TestRequest {
pub fn deflate(mut self) -> Self {
let body = self.body.unwrap();
- let mut compressor = libdeflater::Compressor::new(CompressionLvl::fastest());
- let mut compressed = vec![0; compressor.zlib_compress_bound(body.len())];
- let nb = compressor.zlib_compress(&body, &mut compressed).unwrap();
- compressed.truncate(nb);
+ let mut encoder = ZlibEncoder::new(Vec::new(), Compression::fast());
+ encoder.write_all(&body).unwrap();
+ let compressed = encoder.finish().unwrap();
self.body = Some(compressed);
self.headers.insert(
header::CONTENT_ENCODING,