[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Remove some functions which were unused except for their tests



commit a4e9d672924f027c3e66220a8f70427d42154fe2
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Sat Feb 23 23:38:43 2013 -0500

    Remove some functions which were unused except for their tests
---
 src/common/crypto.c    |   17 -----------
 src/common/crypto.h    |    1 -
 src/common/util.c      |   73 ------------------------------------------------
 src/common/util.h      |    2 -
 src/test/test_crypto.c |   16 ----------
 src/test/test_util.c   |   73 ------------------------------------------------
 6 files changed, 0 insertions(+), 182 deletions(-)

diff --git a/src/common/crypto.c b/src/common/crypto.c
index 84688ae..cfa11cb 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -1294,23 +1294,6 @@ crypto_pk_get_fingerprint(crypto_pk_t *pk, char *fp_out, int add_space)
   return 0;
 }
 
-/** Return true iff <b>s</b> is in the correct format for a fingerprint.
- */
-int
-crypto_pk_check_fingerprint_syntax(const char *s)
-{
-  int i;
-  for (i = 0; i < FINGERPRINT_LEN; ++i) {
-    if ((i%5) == 4) {
-      if (!TOR_ISSPACE(s[i])) return 0;
-    } else {
-      if (!TOR_ISXDIGIT(s[i])) return 0;
-    }
-  }
-  if (s[FINGERPRINT_LEN]) return 0;
-  return 1;
-}
-
 /* symmetric crypto */
 
 /** Return a pointer to the key set for the cipher in <b>env</b>.
diff --git a/src/common/crypto.h b/src/common/crypto.h
index 12fcfae..b783230 100644
--- a/src/common/crypto.h
+++ b/src/common/crypto.h
@@ -183,7 +183,6 @@ crypto_pk_t *crypto_pk_asn1_decode(const char *str, size_t len);
 int crypto_pk_get_digest(crypto_pk_t *pk, char *digest_out);
 int crypto_pk_get_all_digests(crypto_pk_t *pk, digests_t *digests_out);
 int crypto_pk_get_fingerprint(crypto_pk_t *pk, char *fp_out,int add_space);
-int crypto_pk_check_fingerprint_syntax(const char *s);
 
 /* symmetric crypto */
 const char *crypto_cipher_get_key(crypto_cipher_t *env);
diff --git a/src/common/util.c b/src/common/util.c
index ed9a1c9..17fb949 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1176,79 +1176,6 @@ escaped(const char *s)
   return escaped_val_;
 }
 
-/** Rudimentary string wrapping code: given a un-wrapped <b>string</b> (no
- * newlines!), break the string into newline-terminated lines of no more than
- * <b>width</b> characters long (not counting newline) and insert them into
- * <b>out</b> in order.  Precede the first line with prefix0, and subsequent
- * lines with prefixRest.
- */
-/* This uses a stupid greedy wrapping algorithm right now:
- *  - For each line:
- *    - Try to fit as much stuff as possible, but break on a space.
- *    - If the first "word" of the line will extend beyond the allowable
- *      width, break the word at the end of the width.
- */
-void
-wrap_string(smartlist_t *out, const char *string, size_t width,
-            const char *prefix0, const char *prefixRest)
-{
-  size_t p0Len, pRestLen, pCurLen;
-  const char *eos, *prefixCur;
-  tor_assert(out);
-  tor_assert(string);
-  tor_assert(width);
-  if (!prefix0)
-    prefix0 = "";
-  if (!prefixRest)
-    prefixRest = "";
-
-  p0Len = strlen(prefix0);
-  pRestLen = strlen(prefixRest);
-  tor_assert(width > p0Len && width > pRestLen);
-  eos = strchr(string, '\0');
-  tor_assert(eos);
-  pCurLen = p0Len;
-  prefixCur = prefix0;
-
-  while ((eos-string)+pCurLen > width) {
-    const char *eol = string + width - pCurLen;
-    while (eol > string && *eol != ' ')
-      --eol;
-    /* eol is now the last space that can fit, or the start of the string. */
-    if (eol > string) {
-      size_t line_len = (eol-string) + pCurLen + 2;
-      char *line = tor_malloc(line_len);
-      memcpy(line, prefixCur, pCurLen);
-      memcpy(line+pCurLen, string, eol-string);
-      line[line_len-2] = '\n';
-      line[line_len-1] = '\0';
-      smartlist_add(out, line);
-      string = eol + 1;
-    } else {
-      size_t line_len = width + 2;
-      char *line = tor_malloc(line_len);
-      memcpy(line, prefixCur, pCurLen);
-      memcpy(line+pCurLen, string, width - pCurLen);
-      line[line_len-2] = '\n';
-      line[line_len-1] = '\0';
-      smartlist_add(out, line);
-      string += width-pCurLen;
-    }
-    prefixCur = prefixRest;
-    pCurLen = pRestLen;
-  }
-
-  if (string < eos) {
-    size_t line_len = (eos-string) + pCurLen + 2;
-    char *line = tor_malloc(line_len);
-    memcpy(line, prefixCur, pCurLen);
-    memcpy(line+pCurLen, string, eos-string);
-    line[line_len-2] = '\n';
-    line[line_len-1] = '\0';
-    smartlist_add(out, line);
-  }
-}
-
 /* =====
  * Time
  * ===== */
diff --git a/src/common/util.h b/src/common/util.h
index d4c55bf..8206a6d 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -215,8 +215,6 @@ int tor_digest256_is_zero(const char *digest);
 char *esc_for_log(const char *string) ATTR_MALLOC;
 const char *escaped(const char *string);
 struct smartlist_t;
-void wrap_string(struct smartlist_t *out, const char *string, size_t width,
-                 const char *prefix0, const char *prefixRest);
 int tor_vsscanf(const char *buf, const char *pattern, va_list ap)
 #ifdef __GNUC__
   __attribute__((format(scanf, 2, 0)))
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index afb338a..c531c60 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -636,22 +636,6 @@ test_crypto_formats(void)
     tor_free(data2);
   }
 
-  /* Check fingerprint */
-  {
-    test_assert(crypto_pk_check_fingerprint_syntax(
-                "ABCD 1234 ABCD 5678 0000 ABCD 1234 ABCD 5678 0000"));
-    test_assert(!crypto_pk_check_fingerprint_syntax(
-                "ABCD 1234 ABCD 5678 0000 ABCD 1234 ABCD 5678 000"));
-    test_assert(!crypto_pk_check_fingerprint_syntax(
-                "ABCD 1234 ABCD 5678 0000 ABCD 1234 ABCD 5678 00000"));
-    test_assert(!crypto_pk_check_fingerprint_syntax(
-                "ABCD 1234 ABCD 5678 0000 ABCD1234 ABCD 5678 0000"));
-    test_assert(!crypto_pk_check_fingerprint_syntax(
-                "ABCD 1234 ABCD 5678 0000 ABCD1234 ABCD 5678 00000"));
-    test_assert(!crypto_pk_check_fingerprint_syntax(
-                "ACD 1234 ABCD 5678 0000 ABCD 1234 ABCD 5678 00000"));
-  }
-
  done:
   tor_free(data1);
   tor_free(data2);
diff --git a/src/test/test_util.c b/src/test/test_util.c
index c2cb444..7ab54e1 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -1054,79 +1054,6 @@ test_util_strmisc(void)
     test_assert(!tor_memstr(haystack, 7, "ababcade"));
   }
 
-  /* Test wrap_string */
-  {
-    smartlist_t *sl = smartlist_new();
-    wrap_string(sl,
-                "This is a test of string wrapping functionality: woot. "
-                    "a functionality? w00t w00t...!",
-                10, "", "");
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp,
-            "This is a\ntest of\nstring\nwrapping\nfunctional\nity: woot.\n"
-               "a\nfunctional\nity? w00t\nw00t...!\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_clear(sl);
-
-    wrap_string(sl, "This is a test of string wrapping functionality: woot.",
-                16, "### ", "# ");
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp,
-             "### This is a\n# test of string\n# wrapping\n# functionality:\n"
-             "# woot.\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_clear(sl);
-
-    wrap_string(sl, "A test of string wrapping...", 6, "### ", "# ");
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp,
-               "### A\n# test\n# of\n# stri\n# ng\n# wrap\n# ping\n# ...\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_clear(sl);
-
-    wrap_string(sl, "Wrapping test", 6, "#### ", "# ");
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp, "#### W\n# rapp\n# ing\n# test\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_clear(sl);
-
-    wrap_string(sl, "Small test", 6, "### ", "#### ");
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp, "### Sm\n#### a\n#### l\n#### l\n#### t\n#### e"
-                   "\n#### s\n#### t\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_clear(sl);
-
-    wrap_string(sl, "First null", 6, NULL, "> ");
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp, "First\n> null\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_clear(sl);
-
-    wrap_string(sl, "Second null", 6, "> ", NULL);
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp, "> Seco\nnd\nnull\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_clear(sl);
-
-    wrap_string(sl, "Both null", 6, NULL, NULL);
-    cp = smartlist_join_strings(sl, "", 0, NULL);
-    test_streq(cp, "Both\nnull\n");
-    tor_free(cp);
-    SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
-    smartlist_free(sl);
-
-    /* Can't test prefixes that have the same length as the line width, because
-       the function has an assert */
-  }
-
   /* Test hex_str */
   {
     char binary_data[68];



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits