summaryrefslogtreecommitdiff
path: root/src/common/crypto.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-02-15 23:39:14 +0000
committerNick Mathewson <nickm@torproject.org>2008-02-15 23:39:14 +0000
commit24e8e1fb36c3fa6319b00dff8b1db7feeb214905 (patch)
treeb9d908a734052bfd47c3107ae24e5b180b87220c /src/common/crypto.c
parentf5ed1f8469d28879a5efbf2a0ccad5766019bcbb (diff)
downloadtor-24e8e1fb36c3fa6319b00dff8b1db7feeb214905.tar.gz
tor-24e8e1fb36c3fa6319b00dff8b1db7feeb214905.zip
r14185@tombo: nickm | 2008-02-15 18:05:54 -0500
Replace the hefty tor_strpartition with a simple function to replace its only (trivial) use. svn:r13532
Diffstat (limited to 'src/common/crypto.c')
-rw-r--r--src/common/crypto.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index cd10e649c4..a00d07465d 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -999,6 +999,24 @@ crypto_pk_get_digest(crypto_pk_env_t *pk, char *digest_out)
return 0;
}
+/** Copy <b>in</b> to the <b>outlen</b>-byte buffer <b>out</b>, adding spaces
+ * every four spaces. */
+/* static */ void
+add_spaces_to_fp(char *out, size_t outlen, const char *in)
+{
+ int n = 0;
+ char *end = out+outlen;
+ while (*in && out<end) {
+ *out++ = *in++;
+ if (++n == 4 && *in && out<end) {
+ n = 0;
+ *out++ = ' ';
+ }
+ }
+ tor_assert(out<end);
+ *out = '\0';
+}
+
/** Given a private or public key <b>pk</b>, put a fingerprint of the
* public key into <b>fp_out</b> (must have at least FINGERPRINT_LEN+1 bytes of
* space). Return 0 on success, -1 on failure.
@@ -1019,8 +1037,7 @@ crypto_pk_get_fingerprint(crypto_pk_env_t *pk, char *fp_out, int add_space)
}
base16_encode(hexdigest,sizeof(hexdigest),digest,DIGEST_LEN);
if (add_space) {
- if (tor_strpartition(fp_out, FINGERPRINT_LEN+1, hexdigest, " ", 4)<0)
- return -1;
+ add_spaces_to_fp(fp_out, FINGERPRINT_LEN+1, hexdigest);
} else {
strncpy(fp_out, hexdigest, HEX_DIGEST_LEN+1);
}