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

[tor-commits] [tor/master] Add macros for baseXX encoding lengths



commit e7f40baade042ced7b7c211cee4b8e1cbf3e230f
Author: Taylor Yu <catalyst@xxxxxxxxxxxxxx>
Date:   Thu Apr 6 13:54:27 2017 -0400

    Add macros for baseXX encoding lengths
---
 src/common/util_format.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/common/util_format.h b/src/common/util_format.h
index 5fd82d6..c928052 100644
--- a/src/common/util_format.h
+++ b/src/common/util_format.h
@@ -10,6 +10,26 @@
 #include "testsupport.h"
 #include "torint.h"
 
+/** @{ */
+/** These macros don't check for overflow.  Use them only for constant inputs
+ * (like array declarations).  The *_LEN macros are the raw encoding lengths
+ * (without terminating NUL), while the *_BUFSIZE macros count the terminating
+ * NUL. */
+#define BASE64_LEN(n) (CEIL_DIV((n), 3) * 4)
+#define BASE32_LEN(n) (CEIL_DIV((n), 5) * 8)
+#define BASE16_LEN(n) ((n) * 2)
+
+#define BASE64_BUFSIZE(n) (BASE64_LEN(n) + 1)
+#define BASE32_BUFSIZE(n) (BASE32_LEN(n) + 1)
+#define BASE16_BUFSIZE(n) (BASE16_LEN(n) + 1)
+
+#define BASE64_NOPAD_LEN(n) (CEIL_DIV((n) * 4, 3)
+#define BASE32_NOPAD_LEN(n) (CEIL_DIV((n) * 8, 5)
+
+#define BASE64_NOPAD_BUFSIZE(n) (BASE64_NOPAD_LEN(n) + 1))
+#define BASE32_NOPAD_BUFSIZE(n) (BASE32_NOPAD_LEN(n) + 1))
+/** @} */
+
 #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,



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