diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-05-02 08:33:35 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-05-02 08:33:35 -0400 |
commit | 584ab1f29b05b6cd0c63c16668b1c260a957656b (patch) | |
tree | e25d2ada2d3e714808440284346403ad635ae32c /src/common | |
parent | 465448e659e6cbaecc1494b5cf270f556e104bd4 (diff) | |
parent | 3836d9481f81cc1617a9a48de2c2ca178f4804c8 (diff) | |
download | tor-584ab1f29b05b6cd0c63c16668b1c260a957656b.tar.gz tor-584ab1f29b05b6cd0c63c16668b1c260a957656b.zip |
Merge branch 'compress_none_v2_squashed'
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compress.c | 15 | ||||
-rw-r--r-- | src/common/compress_none.c | 53 | ||||
-rw-r--r-- | src/common/compress_none.h | 20 | ||||
-rw-r--r-- | src/common/include.am | 4 |
4 files changed, 89 insertions, 3 deletions
diff --git a/src/common/compress.c b/src/common/compress.c index 047f904cc7..6fe4569868 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; @@ -458,7 +464,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; } @@ -506,6 +514,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; } @@ -533,6 +543,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; } diff --git a/src/common/compress_none.c b/src/common/compress_none.c new file mode 100644 index 0000000000..b76e6010ec --- /dev/null +++ b/src/common/compress_none.c @@ -0,0 +1,53 @@ +/* Copyright (c) 2004, Roger Dingledine. + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file compress_lzma.c + * \brief Compression backend for identity compression. + * + * We actually define this backend so that we can treat the identity transform + * as another case of compression. + * + * This module should never be invoked directly. Use the compress module + * instead. + **/ + +#include "orconfig.h" + +#include "util.h" +#include "torlog.h" +#include "compress.h" +#include "compress_none.h" + +/** Transfer some bytes using the identity transformation. Read up to + * *<b>in_len</b> bytes from *<b>in</b>, and write up to *<b>out_len</b> bytes + * to *<b>out</b>, adjusting the values as we go. If <b>finish</b> is true, + * we've reached the end of the input. + * + * Return TOR_COMPRESS_DONE if we've finished the entire + * compression/decompression. + * Return TOR_COMPRESS_OK if we're processed everything from the input. + * Return TOR_COMPRESS_BUFFER_FULL if we're out of space on <b>out</b>. + * Return TOR_COMPRESS_ERROR if the stream is corrupt. + */ +tor_compress_output_t +tor_cnone_compress_process(char **out, size_t *out_len, + const char **in, size_t *in_len, + int finish) +{ + size_t n_to_copy = MIN(*in_len, *out_len); + + memcpy(*out, *in, n_to_copy); + *out += n_to_copy; + *in += n_to_copy; + *out_len -= n_to_copy; + *in_len -= n_to_copy; + if (*in_len == 0) { + return finish ? TOR_COMPRESS_DONE : TOR_COMPRESS_OK; + } else { + return TOR_COMPRESS_BUFFER_FULL; + } +} + diff --git a/src/common/compress_none.h b/src/common/compress_none.h new file mode 100644 index 0000000000..d1ebb4b625 --- /dev/null +++ b/src/common/compress_none.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2003, Roger Dingledine + * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson. + * Copyright (c) 2007-2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** + * \file compress_none.h + * \brief Header for compress_none.c + **/ + +#ifndef TOR_COMPRESS_NONE_H +#define TOR_COMPRESS_NONE_H + +tor_compress_output_t +tor_cnone_compress_process(char **out, size_t *out_len, + const char **in, size_t *in_len, + int finish); + +#endif // TOR_COMPRESS_NONE_H. + diff --git a/src/common/include.am b/src/common/include.am index e285ef5f86..51b7da65f5 100644 --- a/src/common/include.am +++ b/src/common/include.am @@ -107,6 +107,7 @@ LIBOR_CRYPTO_A_SRC = \ src/common/aes.c \ src/common/compress.c \ src/common/compress_lzma.c \ + src/common/compress_none.c \ src/common/compress_zlib.c \ src/common/compress_zstd.c \ src/common/crypto.c \ @@ -148,8 +149,9 @@ COMMONHEADERS = \ src/common/compat_openssl.h \ src/common/compat_threads.h \ src/common/compat_time.h \ - src/common/compress.h \ + src/common/compress.h \ src/common/compress_lzma.h \ + src/common/compress_none.h \ src/common/compress_zlib.h \ src/common/compress_zstd.h \ src/common/confline.h \ |