Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/tools/clu_base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
*/

#include <wolfclu/clu_error_codes.h>
#include <wolfclu/clu_header_main.h>
#include <wolfclu/clu_log.h>
#include <wolfclu/clu_optargs.h>
Expand Down Expand Up @@ -55,7 +56,7 @@ int wolfCLU_Base64Setup(int argc, char** argv)
int ret = WOLFCLU_SUCCESS;
int decode = 0;
int isPEM = 0;
word32 inputSz = 8000;
sword32 inputSz = 8000;
word32 outputSz = 0;
int option;
int longIndex = 1;
Expand Down Expand Up @@ -128,7 +129,7 @@ int wolfCLU_Base64Setup(int argc, char** argv)
}

if (ret == WOLFCLU_SUCCESS) {
inputSz = (word32)XFTELL(f);
inputSz = (sword32)XFTELL(f);
wolfSSL_BIO_reset(bioIn);
}
}
Expand All @@ -142,13 +143,18 @@ int wolfCLU_Base64Setup(int argc, char** argv)
else {
inputSz = wolfSSL_BIO_read(bioIn, input, inputSz);

if (inputSz < 0) {
wolfCLU_LogError("Could not read input.");
ret = WOLFCLU_FATAL_ERROR;
}
/* For decoding, check if input is in PEM format */
if (decode && inputSz > 11) {
else if (decode && inputSz > 11) {
/* Check if the input starts with a PEM header */
if (XMEMCMP(input, "-----BEGIN", 10) == 0) {
isPEM = 1;
}
}

}
}

Expand Down Expand Up @@ -199,7 +205,7 @@ int wolfCLU_Base64Setup(int argc, char** argv)
else {
/* For regular base64 decoding */
/* Calculate output size */
outputSz = (inputSz * 3) / 4 + 1;
outputSz = (inputSz / 4) * 3 + (inputSz % 4) * 3 / 4 + 1;
Comment thread
cconlon marked this conversation as resolved.

/* Allocate output buffer */
output = (byte*)XMALLOC(outputSz, HEAP_HINT,
Expand Down
Loading