}
}
+/** Return 1 if a given <b>method</b> is supported; otherwise 0. */
+int
+tor_compress_supports_method(compress_method_t method)
+{
+ switch (method) {
+ case GZIP_METHOD:
+ case ZLIB_METHOD:
+ return tor_zlib_method_supported();
+ case LZMA_METHOD:
+ return tor_lzma_method_supported();
+ case ZSTD_METHOD:
+ return tor_zstd_method_supported();
+ case NO_METHOD:
+ case UNKNOWN_METHOD:
+ default:
+ return 0;
+ }
+}
+
/** Return the approximate number of bytes allocated for all
* supported compression schemas. */
size_t
/** Enumeration of what kind of compression to use. Only ZLIB_METHOD and
* GZIP_METHOD is guaranteed to be supported by the compress/uncompress
- * functions here. */
+ * functions here. Call tor_compress_supports_method() to check if a given
+ * compression schema is supported by Tor. */
typedef enum {
NO_METHOD=0,
GZIP_METHOD=1,
int
tor_compress_is_compression_bomb(size_t size_in, size_t size_out);
+int
+tor_compress_supports_method(compress_method_t method);
+
size_t
tor_compress_get_total_allocation(void);
}
#endif // HAVE_LZMA.
+/** Return 1 if LZMA compression is supported; otherwise 0. */
+int
+tor_lzma_method_supported(void)
+{
+#ifdef HAVE_LZMA
+ return 1;
+#else
+ return 0;
+#endif
+}
+
/** Return a string representation of the version of the currently running
* version of liblzma. */
const char *
#ifndef TOR_COMPRESS_LZMA_H
#define TOR_COMPRESS_LZMA_H
+int
+tor_lzma_method_supported(void);
+
const char *
tor_lzma_get_version_str(void);
}
}
+/** Return 1 if zlib/gzip compression is supported; otherwise 0. */
+int
+tor_zlib_method_supported(void)
+{
+ /* We currently always support zlib/gzip, but we keep this function around in
+ * case we some day decide to deprecate zlib/gzip support.
+ */
+ return 1;
+}
+
/** Return a string representation of the version of the currently running
* version of zlib. */
const char *
#ifndef TOR_COMPRESS_ZLIB_H
#define TOR_COMPRESS_ZLIB_H
+int
+tor_zlib_method_supported(void);
+
const char *
tor_zlib_get_version_str(void);
/** Total number of bytes allocated for Zstandard state. */
static size_t total_zstd_allocation = 0;
+/** Return 1 if Zstandard compression is supported; otherwise 0. */
+int
+tor_zstd_method_supported(void)
+{
+#ifdef HAVE_ZSTD
+ return 1;
+#else
+ return 0;
+#endif
+}
+
/** Return a string representation of the version of the currently running
* version of libzstd. */
const char *
#ifndef TOR_COMPRESS_ZSTD_H
#define TOR_COMPRESS_ZSTD_H
+int
+tor_zstd_method_supported(void);
+
const char *
tor_zstd_get_version_str(void);
tor_compress_state_t *state = NULL;
(void)arg;
+ tt_assert(tor_compress_supports_method(GZIP_METHOD));
+ tt_assert(tor_compress_supports_method(ZLIB_METHOD));
+
buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ");
tt_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD);
tor_compress_state_t *state = NULL;
(void)arg;
+ tt_assert(tor_compress_supports_method(LZMA_METHOD));
+
buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ");
tt_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD);
tor_free(buf1);
#else
(void)arg;
+ tt_assert(! tor_compress_supports_method(LZMA_METHOD));
+
+ done:
+ ;
#endif // HAVE_LZMA.
}
tor_compress_state_t *state = NULL;
(void)arg;
+ tt_assert(tor_compress_supports_method(ZSTD_METHOD));
+
buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ");
tt_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD);
tor_free(buf1);
#else
(void)arg;
+ tt_assert(! tor_compress_supports_method(ZSTD_METHOD));
+
+ done:
+ ;
#endif // HAVE_ZSTD.
}