diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-12-18 18:59:05 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-12-18 18:59:05 -0500 |
commit | bb091da1e7e229d6b938ae99d40078610b13ac76 (patch) | |
tree | f413f518f3a4118e323358e55bc51628370e00f2 /src/lib | |
parent | 372df7a630afa4ffb0782287366b629916e0f728 (diff) | |
parent | 976c62e62a38c9f30c32ca742a43d59633a0e6ab (diff) | |
download | tor-bb091da1e7e229d6b938ae99d40078610b13ac76.tar.gz tor-bb091da1e7e229d6b938ae99d40078610b13ac76.zip |
Merge branch 'ticket28839_v2_squashed'
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/encoding/binascii.c | 12 | ||||
-rw-r--r-- | src/lib/encoding/binascii.h | 1 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/lib/encoding/binascii.c b/src/lib/encoding/binascii.c index e9140d9432..067db075ad 100644 --- a/src/lib/encoding/binascii.c +++ b/src/lib/encoding/binascii.c @@ -179,6 +179,18 @@ base64_encode_size(size_t srclen, int flags) return enclen; } +/** Return an upper bound on the number of bytes that might be needed to hold + * the data from decoding the base64 string <b>srclen</b>. This is only an + * upper bound, since some part of the base64 string might be padding or + * space. */ +size_t +base64_decode_maxsize(size_t srclen) +{ + tor_assert(srclen < INT_MAX / 3); + + return CEIL_DIV(srclen * 3, 4); +} + /** Internal table mapping 6 bit values to the Base64 alphabet. */ static const char base64_encode_table[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', diff --git a/src/lib/encoding/binascii.h b/src/lib/encoding/binascii.h index 23cbaa7070..c71ba65dfb 100644 --- a/src/lib/encoding/binascii.h +++ b/src/lib/encoding/binascii.h @@ -42,6 +42,7 @@ const char *hex_str(const char *from, size_t fromlen); #define BASE64_ENCODE_MULTILINE 1 size_t base64_encode_size(size_t srclen, int flags); +size_t base64_decode_maxsize(size_t srclen); 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); |