summaryrefslogtreecommitdiff
path: root/src/common/compress.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-04-27 10:00:41 -0400
committerNick Mathewson <nickm@torproject.org>2017-05-02 08:31:32 -0400
commit1bc21111d82579b6472357d43f07a85142b6614a (patch)
tree5a88e50435ae01a87947535267e9a0d80b25cb44 /src/common/compress.c
parent49deb1e1b810e348bfa9fb27a0f0ef54f3694cc9 (diff)
downloadtor-1bc21111d82579b6472357d43f07a85142b6614a.tar.gz
tor-1bc21111d82579b6472357d43f07a85142b6614a.zip
Treat the identity transformation as another kind of compression.
This will allow us to treat NO_METHOD as a real compression method, and to simplify code that currently does if (compressing) { compress } else { copy }
Diffstat (limited to 'src/common/compress.c')
-rw-r--r--src/common/compress.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/common/compress.c b/src/common/compress.c
index 9a24025db0..e1571c7bb2 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -24,6 +24,7 @@
#include "torlog.h"
#include "compress.h"
#include "compress_lzma.h"
+#include "compress_none.h"
#include "compress_zlib.h"
#include "compress_zstd.h"
@@ -67,8 +68,12 @@ guess_compress_size(int compress, compress_method_t method,
size_t in_len)
{
// ignore these for now.
- (void)method;
(void)compression_level;
+ if (method == NO_METHOD) {
+ /* Guess that we'll need an extra byte, to avoid a needless realloc
+ * for nul-termination */
+ return (in_len < SIZE_MAX) ? in_len + 1 : in_len;
+ }
/* Always guess a factor of 2. */
if (compress) {
@@ -279,6 +284,7 @@ tor_compress_supports_method(compress_method_t method)
case ZSTD_METHOD:
return tor_zstd_method_supported();
case NO_METHOD:
+ return 1;
case UNKNOWN_METHOD:
default:
return 0;
@@ -436,7 +442,9 @@ tor_compress_new(int compress, compress_method_t method,
state->u.zstd_state = zstd_state;
break;
}
- case NO_METHOD:
+ case NO_METHOD: {
+ break;
+ }
case UNKNOWN_METHOD:
goto err;
}
@@ -484,6 +492,8 @@ tor_compress_process(tor_compress_state_t *state,
out, out_len, in, in_len,
finish);
case NO_METHOD:
+ return tor_cnone_compress_process(out, out_len, in, in_len,
+ finish);
case UNKNOWN_METHOD:
goto err;
}
@@ -511,6 +521,7 @@ tor_compress_free(tor_compress_state_t *state)
tor_zstd_compress_free(state->u.zstd_state);
break;
case NO_METHOD:
+ break;
case UNKNOWN_METHOD:
break;
}