commit 235ddb15a0f9fc322002ba39e8900634316dc333 Author: Nick Mathewson nickm@torproject.org Date: Wed Jun 27 15:59:07 2018 -0400
Move util_format into a new libtor-encoding library
libtor-encoding is about various ways to transform data to and from character sequences. --- .gitignore | 2 ++ Makefile.am | 2 ++ src/common/include.am | 2 -- src/common/util.c | 2 +- src/include.am | 1 + src/lib/crypt_ops/.may_include | 1 + src/lib/crypt_ops/crypto.c | 2 +- src/lib/crypt_ops/crypto_ed25519.c | 2 +- src/lib/crypt_ops/crypto_format.c | 2 +- src/lib/crypt_ops/crypto_rand.c | 2 +- src/lib/crypt_ops/crypto_rsa.c | 2 +- src/lib/encoding/.may_include | 8 ++++++++ src/{common/util_format.c => lib/encoding/binascii.c} | 11 +++++++---- src/{common/util_format.h => lib/encoding/binascii.h} | 6 ++++-- src/lib/encoding/include.am | 16 ++++++++++++++++ src/or/keypin.c | 2 +- src/or/or.h | 2 +- src/or/parsecommon.c | 2 +- src/or/shared_random_client.c | 2 +- src/rust/build.rs | 1 + src/test/test_crypto_openssl.c | 2 +- src/test/test_util_format.c | 2 +- src/tools/tor-gencert.c | 2 +- 23 files changed, 55 insertions(+), 21 deletions(-)
diff --git a/.gitignore b/.gitignore index 02e8bb77c..5198daf4f 100644 --- a/.gitignore +++ b/.gitignore @@ -171,6 +171,8 @@ uptime-*.json /src/lib/libtor-crypt-ops-testing.a /src/lib/libtor-ctime.a /src/lib/libtor-ctime-testing.a +/src/lib/libtor-encoding.a +/src/lib/libtor-encoding-testing.a /src/lib/libtor-err.a /src/lib/libtor-err-testing.a /src/lib/libtor-fdio.a diff --git a/Makefile.am b/Makefile.am index ef727e01f..c016310a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,6 +41,7 @@ endif TOR_UTIL_LIBS = \ src/common/libor.a \ src/lib/libtor-fs.a \ + src/lib/libtor-encoding.a \ src/lib/libtor-sandbox.a \ src/lib/libtor-container.a \ src/lib/libtor-net.a \ @@ -60,6 +61,7 @@ TOR_UTIL_LIBS = \ TOR_UTIL_TESTING_LIBS = \ src/common/libor-testing.a \ src/lib/libtor-fs-testing.a \ + src/lib/libtor-encoding-testing.a \ src/lib/libtor-sandbox-testing.a \ src/lib/libtor-container-testing.a \ src/lib/libtor-net-testing.a \ diff --git a/src/common/include.am b/src/common/include.am index c8be3658e..2360c7f77 100644 --- a/src/common/include.am +++ b/src/common/include.am @@ -39,7 +39,6 @@ LIBOR_A_SRC = \ src/common/confline.c \ src/common/memarea.c \ src/common/util.c \ - src/common/util_format.c \ src/common/util_process.c \ src/common/storagedir.c \ src/common/token_bucket.c \ @@ -88,7 +87,6 @@ COMMONHEADERS = \ src/common/timers.h \ src/common/token_bucket.h \ src/common/util.h \ - src/common/util_format.h \ src/common/util_process.h \ src/common/workqueue.h
diff --git a/src/common/util.c b/src/common/util.c index 497f54972..92742a814 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -24,7 +24,7 @@ #include "lib/sandbox/sandbox.h" #include "lib/err/backtrace.h" #include "common/util_process.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
#ifdef _WIN32 #include <io.h> diff --git a/src/include.am b/src/include.am index 62234d468..c83ec0d57 100644 --- a/src/include.am +++ b/src/include.am @@ -7,6 +7,7 @@ include src/lib/compress/include.am include src/lib/container/include.am include src/lib/crypt_ops/include.am include src/lib/defs/include.am +include src/lib/encoding/include.am include src/lib/fdio/include.am include src/lib/fs/include.am include src/lib/include.libdonna.am diff --git a/src/lib/crypt_ops/.may_include b/src/lib/crypt_ops/.may_include index d05e86f72..dad6d5fc6 100644 --- a/src/lib/crypt_ops/.may_include +++ b/src/lib/crypt_ops/.may_include @@ -4,6 +4,7 @@ lib/container/*.h lib/crypt_ops/*.h lib/ctime/*.h lib/defs/*.h +lib/encoding/*.h lib/malloc/*.h lib/err/*.h lib/intmath/*.h diff --git a/src/lib/crypt_ops/crypto.c b/src/lib/crypt_ops/crypto.c index 193580397..efd355928 100644 --- a/src/lib/crypt_ops/crypto.c +++ b/src/lib/crypt_ops/crypto.c @@ -67,7 +67,7 @@ ENABLE_GCC_WARNING(redundant-decls) #include "lib/crypt_ops/aes.h" #include "common/util.h" #include "common/compat.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
#include "keccak-tiny/keccak-tiny.h"
diff --git a/src/lib/crypt_ops/crypto_ed25519.c b/src/lib/crypt_ops/crypto_ed25519.c index 5655fbf50..b0e23e29c 100644 --- a/src/lib/crypt_ops/crypto_ed25519.c +++ b/src/lib/crypt_ops/crypto_ed25519.c @@ -29,7 +29,7 @@ #include "lib/crypt_ops/crypto_util.h" #include "lib/log/torlog.h" #include "common/util.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
#include "ed25519/ref10/ed25519_ref10.h" #include "ed25519/donna/ed25519_donna_tor.h" diff --git a/src/lib/crypt_ops/crypto_format.c b/src/lib/crypt_ops/crypto_format.c index 888c0794e..131aa449e 100644 --- a/src/lib/crypt_ops/crypto_format.c +++ b/src/lib/crypt_ops/crypto_format.c @@ -22,7 +22,7 @@ #include "lib/crypt_ops/crypto_util.h" #include "lib/string/util_string.h" #include "common/util.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h" #include "lib/log/torlog.h"
/** Write the <b>datalen</b> bytes from <b>data</b> to the file named diff --git a/src/lib/crypt_ops/crypto_rand.c b/src/lib/crypt_ops/crypto_rand.c index bf6a35ddb..247a50224 100644 --- a/src/lib/crypt_ops/crypto_rand.c +++ b/src/lib/crypt_ops/crypto_rand.c @@ -29,7 +29,7 @@ #include "lib/testsupport/testsupport.h" #include "lib/log/torlog.h" #include "common/util.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
DISABLE_GCC_WARNING(redundant-decls) #include <openssl/rand.h> diff --git a/src/lib/crypt_ops/crypto_rsa.c b/src/lib/crypt_ops/crypto_rsa.c index 3f2f8544f..a62c0018f 100644 --- a/src/lib/crypt_ops/crypto_rsa.c +++ b/src/lib/crypt_ops/crypto_rsa.c @@ -35,7 +35,7 @@ ENABLE_GCC_WARNING(redundant-decls)
#include "lib/log/torlog.h" #include "common/util.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
/** Declaration for crypto_pk_t structure. */ struct crypto_pk_t diff --git a/src/lib/encoding/.may_include b/src/lib/encoding/.may_include new file mode 100644 index 000000000..299e0fc4f --- /dev/null +++ b/src/lib/encoding/.may_include @@ -0,0 +1,8 @@ +orconfig.h +lib/cc/*.h +lib/encoding/*.h +lib/intmath/*.h +lib/log/*.h +lib/malloc/*.h +lib/string/*.h +lib/testsupport/*.h diff --git a/src/common/util_format.c b/src/lib/encoding/binascii.c similarity index 98% rename from src/common/util_format.c rename to src/lib/encoding/binascii.c index 04fd59d66..554b95016 100644 --- a/src/common/util_format.c +++ b/src/lib/encoding/binascii.c @@ -5,18 +5,21 @@ /* See LICENSE for licensing information */
/** - * \file util_format.c + * \file binascii.c * * \brief Miscellaneous functions for encoding and decoding various things * in base{16,32,64}. */
#include "orconfig.h" -#include <stddef.h> + +#include "lib/encoding/binascii.h" #include "lib/log/torlog.h" -#include "common/util.h" -#include "common/util_format.h" +#include "lib/log/util_bug.h" #include "lib/cc/torint.h" +#include "lib/string/compat_ctype.h" +#include "lib/intmath/muldiv.h" +#include "lib/malloc/util_malloc.h"
#include <stddef.h> #include <string.h> diff --git a/src/common/util_format.h b/src/lib/encoding/binascii.h similarity index 95% rename from src/common/util_format.h rename to src/lib/encoding/binascii.h index 713fd0d00..04310f4ed 100644 --- a/src/common/util_format.h +++ b/src/lib/encoding/binascii.h @@ -4,9 +4,11 @@ * Copyright (c) 2007-2018, The Tor Project, Inc. */ /* See LICENSE for licensing information */
-#ifndef TOR_UTIL_FORMAT_H -#define TOR_UTIL_FORMAT_H +#ifndef TOR_BINASCII_H +#define TOR_BINASCII_H
+#include "orconfig.h" +#include <stddef.h> #include "lib/testsupport/testsupport.h" #include "lib/cc/torint.h"
diff --git a/src/lib/encoding/include.am b/src/lib/encoding/include.am new file mode 100644 index 000000000..fcd9baf3d --- /dev/null +++ b/src/lib/encoding/include.am @@ -0,0 +1,16 @@ +noinst_LIBRARIES += src/lib/libtor-encoding.a + +if UNITTESTS_ENABLED +noinst_LIBRARIES += src/lib/libtor-encoding-testing.a +endif + +src_lib_libtor_encoding_a_SOURCES = \ + src/lib/encoding/binascii.c + +src_lib_libtor_encoding_testing_a_SOURCES = \ + $(src_lib_libtor_encoding_a_SOURCES) +src_lib_libtor_encoding_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS) +src_lib_libtor_encoding_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS) + +noinst_HEADERS += \ + src/lib/encoding/binascii.h diff --git a/src/or/keypin.c b/src/or/keypin.c index db267673f..8e1ef099a 100644 --- a/src/or/keypin.c +++ b/src/or/keypin.c @@ -22,7 +22,7 @@ #include "lib/log/torlog.h" #include "lib/fdio/fdio.h" #include "common/util.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
#ifdef HAVE_UNISTD_H #include <unistd.h> diff --git a/src/or/or.h b/src/or/or.h index a71cb6b00..df0e60c26 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -81,7 +81,7 @@ #include "lib/crypt_ops/crypto_ed25519.h" #include "tor_queue.h" #include "common/token_bucket.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h" #include "or/hs_circuitmap.h"
// These, more than other includes, are for keeping the other struct diff --git a/src/or/parsecommon.c b/src/or/parsecommon.c index 17a7c6a89..3b6e15b0f 100644 --- a/src/or/parsecommon.c +++ b/src/or/parsecommon.c @@ -8,7 +8,7 @@
#include "or/parsecommon.h" #include "lib/log/torlog.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h" #include "lib/container/smartlist.h"
#define MIN_ANNOTATION A_PURPOSE diff --git a/src/or/shared_random_client.c b/src/or/shared_random_client.c index f0b13a171..9a6c0f664 100644 --- a/src/or/shared_random_client.c +++ b/src/or/shared_random_client.c @@ -15,7 +15,7 @@ #include "or/voting_schedule.h" #include "or/networkstatus.h" #include "common/util.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
#include "or/networkstatus_st.h"
diff --git a/src/rust/build.rs b/src/rust/build.rs index 90f53bd23..36f847d2e 100644 --- a/src/rust/build.rs +++ b/src/rust/build.rs @@ -152,6 +152,7 @@ pub fn main() { cfg.component("tor-crypt-ops-testing"); cfg.component("or-testing"); cfg.component("tor-sandbox"); + cfg.component("tor-encoding-testing"); cfg.component("tor-net"); cfg.component("tor-log"); cfg.component("tor-lock"); diff --git a/src/test/test_crypto_openssl.c b/src/test/test_crypto_openssl.c index cc817ad70..a01de18a6 100644 --- a/src/test/test_crypto_openssl.c +++ b/src/test/test_crypto_openssl.c @@ -9,7 +9,7 @@
#include "lib/crypt_ops/crypto_rand.h" #include "common/util.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h" #include "common/compat.h" #include "test/test.h"
diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c index 931a184e7..44a00b9b7 100644 --- a/src/test/test_util_format.c +++ b/src/test/test_util_format.c @@ -8,7 +8,7 @@
#include "lib/crypt_ops/crypto_rand.h" #define UTIL_FORMAT_PRIVATE -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
#define NS_MODULE util_format
diff --git a/src/tools/tor-gencert.c b/src/tools/tor-gencert.c index f65a0e250..2fda1cd8f 100644 --- a/src/tools/tor-gencert.c +++ b/src/tools/tor-gencert.c @@ -42,7 +42,7 @@ ENABLE_GCC_WARNING(redundant-decls) #include "lib/crypt_ops/crypto_rand.h" #include "lib/crypt_ops/crypto_util.h" #include "lib/net/address.h" -#include "common/util_format.h" +#include "lib/encoding/binascii.h"
#define IDENTITY_KEY_BITS 3072 #define SIGNING_KEY_BITS 2048