Added calculation for encoded output size based on input size. Calculated size is never more than a byte larger than the actual size.
This commit is contained in:
parent
3acc56055c
commit
8b73c4041b
1
external/libb64-1.2.1/include/b64/cencode.h
vendored
1
external/libb64-1.2.1/include/b64/cencode.h
vendored
|
@ -28,6 +28,7 @@ typedef struct
|
|||
|
||||
void base64_init_encodestate(base64_encodestate* state_in);
|
||||
|
||||
int base64_calc_buffer_length(int length_in, const base64_encodestate* state_in);
|
||||
|
||||
int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
|
||||
|
||||
|
|
13
external/libb64-1.2.1/src/cencode.c
vendored
13
external/libb64-1.2.1/src/cencode.c
vendored
|
@ -24,6 +24,19 @@ char base64_encode_value(char value_in)
|
|||
return encoding[(int)value_in];
|
||||
}
|
||||
|
||||
/*
|
||||
Output_size calculation from:
|
||||
http://stackoverflow.com/questions/1533113/calculate-the-size-to-a-base-64-encoded-message
|
||||
Never more than a byte larger than the actual encoded size.
|
||||
Guaranteed equal to or larger than the actual encoded size.
|
||||
*/
|
||||
int base64_calc_buffer_length(int length_in, const base64_encodestate* state_in)
|
||||
{
|
||||
const int blockend_newline = ((BASE64_ENC_NO_NEWLINE_TERM & state_in->flags) == 0);
|
||||
const int output_length = ((((length_in - 1) / 3) * 4) + 4);
|
||||
return output_length + blockend_newline + (output_length / CHARS_PER_LINE);
|
||||
}
|
||||
|
||||
int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in)
|
||||
{
|
||||
int stepcount = state_in->stepcount;
|
||||
|
|
Loading…
Reference in New Issue
Block a user