1 /* Copyright (c) 2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
7 * \file compress_none.c
8 * \brief Compression backend for identity compression.
10 * We actually define this backend so that we can treat the identity transform
11 * as another case of compression.
13 * This module should never be invoked directly. Use the compress module
19 #include "lib/log/log.h"
20 #include "lib/compress/compress.h"
21 #include "lib/compress/compress_none.h"
22 #include "lib/intmath/cmp.h"
26 /** Transfer some bytes using the identity transformation. Read up to
27 * *<b>in_len</b> bytes from *<b>in</b>, and write up to *<b>out_len</b> bytes
28 * to *<b>out</b>, adjusting the values as we go. If <b>finish</b> is true,
29 * we've reached the end of the input.
31 * Return TOR_COMPRESS_DONE if we've finished the entire
32 * compression/decompression.
33 * Return TOR_COMPRESS_OK if we're processed everything from the input.
34 * Return TOR_COMPRESS_BUFFER_FULL if we're out of space on <b>out</b>.
35 * Return TOR_COMPRESS_ERROR if the stream is corrupt.
38 tor_cnone_compress_process(char **out
, size_t *out_len
,
39 const char **in
, size_t *in_len
,
42 size_t n_to_copy
= MIN(*in_len
, *out_len
);
44 memcpy(*out
, *in
, n_to_copy
);
47 *out_len
-= n_to_copy
;
50 return finish
? TOR_COMPRESS_DONE
: TOR_COMPRESS_OK
;
52 return TOR_COMPRESS_BUFFER_FULL
;