summaryrefslogtreecommitdiff
path: root/src/common/util_format.h
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2015-07-31 11:21:34 -0400
committerNick Mathewson <nickm@torproject.org>2015-07-31 11:21:34 -0400
commit347fe449fe818f97e0f3ba29dd0a08ff6d39081e (patch)
tree9397c155e38a7e7084b91c55f1c57f576aa42b25 /src/common/util_format.h
parent8c83e8cec0e8d4c29577ae7c7b27637e5b91c99e (diff)
downloadtor-347fe449fe818f97e0f3ba29dd0a08ff6d39081e.tar.gz
tor-347fe449fe818f97e0f3ba29dd0a08ff6d39081e.zip
Move formatting functions around.
The base64 and base32 functions used to be in crypto.c; crypto_format.h had no header; some general-purpose functions were in crypto_curve25519.c. This patch makes a {crypto,util}_format.[ch], and puts more functions there. Small modules are beautiful!
Diffstat (limited to 'src/common/util_format.h')
-rw-r--r--src/common/util_format.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/common/util_format.h b/src/common/util_format.h
new file mode 100644
index 0000000000..3fb7e1ac16
--- /dev/null
+++ b/src/common/util_format.h
@@ -0,0 +1,33 @@
+/* Copyright (c) 2001, Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2015, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef TOR_UTIL_FORMAT_H
+#define TOR_UTIL_FORMAT_H
+
+#include "testsupport.h"
+#include "torint.h"
+
+#define BASE64_ENCODE_MULTILINE 1
+size_t base64_encode_size(size_t srclen, int flags);
+int base64_encode(char *dest, size_t destlen, const char *src, size_t srclen,
+ int flags);
+int base64_decode(char *dest, size_t destlen, const char *src, size_t srclen);
+int base64_encode_nopad(char *dest, size_t destlen,
+ const uint8_t *src, size_t srclen);
+int base64_decode_nopad(uint8_t *dest, size_t destlen,
+ const char *src, size_t srclen);
+
+/** Characters that can appear (case-insensitively) in a base32 encoding. */
+#define BASE32_CHARS "abcdefghijklmnopqrstuvwxyz234567"
+void base32_encode(char *dest, size_t destlen, const char *src, size_t srclen);
+int base32_decode(char *dest, size_t destlen, const char *src, size_t srclen);
+
+int hex_decode_digit(char c);
+void base16_encode(char *dest, size_t destlen, const char *src, size_t srclen);
+int base16_decode(char *dest, size_t destlen, const char *src, size_t srclen);
+
+#endif
+