@@ -41,14 +41,14 @@ static const uint8_t base64DecTable[128] = {
4141 0xFF , 0xFF , 0x1A , 0x1B , 0x1C , 0x1D , 0x1E , 0x1F , 0x20 , 0x21 , 0x22 , 0x23 , 0x24 , 0x25 , 0x26 , 0x27 , 0x28 , 0x29 , 0x2A ,
4242 0x2B , 0x2C , 0x2D , 0x2E , 0x2F , 0x30 , 0x31 , 0x32 , 0x33 , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
4343
44-
4544#define ERROR_INVALID_PARAMETER 21
4645#define ERROR_INVALID_LENGTH 22
4746#define ERROR_INVALID_CHARACTER 23
4847#define NO_ERROR 0
4948
5049// local copy of function from base64.c
51- int32_t base64Decode (const char_t * input , size_t inputLen , void * output , uint16_t decoded_buffer_size , size_t * outputLen )
50+ int32_t base64Decode (const char_t * input , size_t inputLen , void * output , uint16_t decoded_buffer_size ,
51+ size_t * outputLen )
5252{
5353 int32_t error ;
5454 uint32_t value ;
@@ -70,17 +70,18 @@ int32_t base64Decode(const char_t *input, size_t inputLen, void *output, uint16_
7070
7171 // Check expected output buffer size is large enough for decoded input
7272 uint16_t outputLen_expected = 0 ;
73- uint8_t padding = 0 ;
74- if (inputLen >= 1 && input [inputLen - 1 ] == '=' )
73+ uint8_t padding = 0 ;
74+ if (inputLen >= 1 && input [inputLen - 1 ] == '=' )
7575 padding ++ ;
76- if (inputLen >= 2 && input [inputLen - 2 ] == '=' )
76+ if (inputLen >= 2 && input [inputLen - 2 ] == '=' )
7777 padding ++ ;
7878 outputLen_expected = ((inputLen * 3 ) / 4 ) - padding ;
7979
8080 // Special debug prints for UT
8181 printf ("InputLen: %ld\n \
8282 Expected Dec Buf Length: %d\n \
83- Passed In Dec Length: %d\n" , inputLen , outputLen_expected , decoded_buffer_size );
83+ Passed In Dec Length: %d\n" ,
84+ inputLen , outputLen_expected , decoded_buffer_size );
8485
8586 if (decoded_buffer_size < outputLen_expected )
8687 return ERROR_INVALID_LENGTH ;
@@ -194,26 +195,28 @@ int32_t base64Decode(const char_t *input, size_t inputLen, void *output, uint16_
194195
195196UTEST (CRYPTO_B64 , OVERSIZE_DECODE )
196197{
197- int32_t status = CRYPTO_LIB_ERROR ;
198+ int32_t status = CRYPTO_LIB_ERROR ;
198199
199200 // Success Case, This_one_is_just_the_right_size (len = 31)
200- char * ciphertext_base64 = "VGhpc19vbmVfaXNfanVzdF90aGVfcmlnaHRfc2l6ZQ==" ;
201- uint8_t len_data_out = 15 ;
201+ char * ciphertext_base64 = "VGhpc19vbmVfaXNfanVzdF90aGVfcmlnaHRfc2l6ZQ==" ;
202+ uint8_t len_data_out = 15 ;
202203 uint16_t decoded_buffer_size = (len_data_out )* 2 + 1 ; // 31
203204 uint8_t * ciphertext_decoded = malloc (decoded_buffer_size );
204205 size_t ciphertext_decoded_len = 0 ;
205- status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size , & ciphertext_decoded_len );
206+ status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size ,
207+ & ciphertext_decoded_len );
206208 printf ("Status: %d\n\n" , status );
207209 free (ciphertext_decoded );
208210 ASSERT_EQ (CRYPTO_LIB_SUCCESS , status );
209211
210212 // Success Case, This_one_allocates_too_much (len = 27)
211- ciphertext_base64 = "VGhpc19vbmVfYWxsb2NhdGVzX3Rvb19tdWNo" ;
212- len_data_out = 15 ;
213+ ciphertext_base64 = "VGhpc19vbmVfYWxsb2NhdGVzX3Rvb19tdWNo" ;
214+ len_data_out = 15 ;
213215 decoded_buffer_size = (len_data_out )* 2 + 1 ; // 31
214216 ciphertext_decoded = malloc (decoded_buffer_size );
215217 ciphertext_decoded_len = 0 ;
216- status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size , & ciphertext_decoded_len );
218+ status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size ,
219+ & ciphertext_decoded_len );
217220 printf ("Status: %d\n\n" , status );
218221 free (ciphertext_decoded );
219222 ASSERT_EQ (CRYPTO_LIB_SUCCESS , status );
@@ -224,7 +227,8 @@ UTEST(CRYPTO_B64, OVERSIZE_DECODE)
224227 decoded_buffer_size = (len_data_out )* 2 + 1 ;
225228 ciphertext_decoded = malloc (decoded_buffer_size );
226229 ciphertext_decoded_len = 0 ;
227- status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size , & ciphertext_decoded_len );
230+ status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size ,
231+ & ciphertext_decoded_len );
228232 printf ("Status: %d\n\n" , status );
229233 free (ciphertext_decoded );
230234 ASSERT_EQ (ERROR_INVALID_LENGTH , status );
@@ -235,7 +239,8 @@ UTEST(CRYPTO_B64, OVERSIZE_DECODE)
235239 decoded_buffer_size = (len_data_out )* 2 + 1 ;
236240 ciphertext_decoded = malloc (decoded_buffer_size );
237241 ciphertext_decoded_len = 0 ;
238- status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size , & ciphertext_decoded_len );
242+ status = base64Decode (ciphertext_base64 , strlen (ciphertext_base64 ), ciphertext_decoded , decoded_buffer_size ,
243+ & ciphertext_decoded_len );
239244 printf ("Status: %d\n\n" , status );
240245 free (ciphertext_decoded );
241246 ASSERT_EQ (ERROR_INVALID_LENGTH , status );
0 commit comments