Browse Source

Move util_format into a new libtor-encoding library

libtor-encoding is about various ways to transform data to and from
character sequences.
Nick Mathewson 5 years ago
parent
commit
235ddb15a0

+ 2 - 0
.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

+ 2 - 0
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 \

+ 0 - 2
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
 

+ 1 - 1
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>

+ 1 - 0
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

+ 1 - 0
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

+ 1 - 1
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"
 

+ 1 - 1
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"

+ 1 - 1
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

+ 1 - 1
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>

+ 1 - 1
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

+ 8 - 0
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

+ 7 - 4
src/common/util_format.c → 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>

+ 4 - 2
src/common/util_format.h → 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"
 

+ 16 - 0
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

+ 1 - 1
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>

+ 1 - 1
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

+ 1 - 1
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

+ 1 - 1
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"
 

+ 1 - 0
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");

+ 1 - 1
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"
 

+ 1 - 1
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
 

+ 1 - 1
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