aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/codec/base64/base64.h
diff options
context:
space:
mode:
authorEvgeny Pokhilko <[email protected]>2017-02-05 18:25:15 +1100
committerEvgeny Pokhilko <[email protected]>2017-02-06 00:26:56 +1100
commit8b9660ebced19b93afce347937772d3a74530e41 (patch)
treed604027b3c05b0b8c232d8e63643cb0267e1deb2 /src/lib/codec/base64/base64.h
parent8efc26812b3234acfdee099d6e343722f26bef24 (diff)
Remove function comments n*4/3 and n*3/4 in base64
The parameter comments were misleading because they did not take into account that input_length must be rounded up to a multiple of 3 and 4 for encode and decode respectively. Two new functions were added to calculate the correct maximum output length.
Diffstat (limited to 'src/lib/codec/base64/base64.h')
-rw-r--r--src/lib/codec/base64/base64.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/lib/codec/base64/base64.h b/src/lib/codec/base64/base64.h
index 0e78ea3c2..70d806ee8 100644
--- a/src/lib/codec/base64/base64.h
+++ b/src/lib/codec/base64/base64.h
@@ -15,7 +15,7 @@ namespace Botan {
/**
* Perform base64 encoding
-* @param output an array of at least input_length*4/3 bytes
+* @param output an array of at least base64_encode_max_output bytes
* @param input is some binary data
* @param input_length length of input in bytes
* @param input_consumed is an output parameter which says how many
@@ -54,7 +54,7 @@ std::string base64_encode(const std::vector<uint8_t, Alloc>& input)
/**
* Perform base64 decoding
-* @param output an array of at least input_length*3/4 bytes
+* @param output an array of at least base64_decode_max_output bytes
* @param input some base64 input
* @param input_length length of input in bytes
* @param input_consumed is an output parameter which says how many
@@ -76,7 +76,7 @@ size_t BOTAN_DLL base64_decode(uint8_t output[],
/**
* Perform base64 decoding
-* @param output an array of at least input_length*3/4 bytes
+* @param output an array of at least base64_decode_max_output bytes
* @param input some base64 input
* @param input_length length of input in bytes
* @param ignore_ws ignore whitespace on input; if false, throw an
@@ -90,7 +90,7 @@ size_t BOTAN_DLL base64_decode(uint8_t output[],
/**
* Perform base64 decoding
-* @param output an array of at least input_length/3*4 bytes
+* @param output an array of at least base64_decode_max_output bytes
* @param input some base64 input
* @param ignore_ws ignore whitespace on input; if false, throw an
exception if whitespace is encountered
@@ -122,6 +122,20 @@ secure_vector<uint8_t> BOTAN_DLL base64_decode(const char input[],
secure_vector<uint8_t> BOTAN_DLL base64_decode(const std::string& input,
bool ignore_ws = true);
+/**
+* Calculate the size of output buffer for base64_encode
+* @param input_length the length of input in bytes
+* @return the size of output buffer in bytes
+*/
+size_t BOTAN_DLL base64_encode_max_output(size_t input_length);
+
+/**
+* Calculate the size of output buffer for base64_decode
+* @param input_length the length of input in bytes
+* @return the size of output buffer in bytes
+*/
+size_t BOTAN_DLL base64_decode_max_output(size_t input_length);
+
}
#endif