suricata
util-base64.c File Reference
#include "util-base64.h"
#include "util-debug.h"
#include "util-validate.h"
#include "util-unittest.h"
Include dependency graph for util-base64.c:

Go to the source code of this file.

Macros

#define BASE64_TABLE_MAX   122
 
#define TEST_RFC2045(src, fin_str, dest_size, exp_decoded, exp_consumed, ecode)
 
#define TEST_RFC4648(src, fin_str, dest_size, exp_decoded, exp_consumed, ecode)
 

Functions

bool IsBase64Alphabet (uint8_t encoded_byte)
 Checks if the given char in a byte array is Base64 alphabet. More...
 
Base64Ecode DecodeBase64 (uint8_t *dest, uint32_t dest_size, const uint8_t *src, uint32_t len, uint32_t *consumed_bytes, uint32_t *decoded_bytes, Base64Mode mode)
 Decodes a base64-encoded string buffer into an ascii-encoded byte buffer. More...
 
void Base64RegisterTests (void)
 

Detailed Description

Macro Definition Documentation

◆ BASE64_TABLE_MAX

#define BASE64_TABLE_MAX   122

Definition at line 31 of file util-base64.c.

◆ TEST_RFC2045

#define TEST_RFC2045 (   src,
  fin_str,
  dest_size,
  exp_decoded,
  exp_consumed,
  ecode 
)
Value:
{ \
uint32_t consumed_bytes = 0, num_decoded = 0; \
uint8_t dst[dest_size]; \
Base64Ecode code = DecodeBase64(dst, dest_size, (const uint8_t *)src, strlen(src), \
&consumed_bytes, &num_decoded, BASE64_MODE_RFC2045); \
FAIL_IF(code != ecode); \
FAIL_IF(memcmp(dst, fin_str, strlen(fin_str)) != 0); \
FAIL_IF(num_decoded != exp_decoded); \
FAIL_IF(consumed_bytes != exp_consumed); \
}

Definition at line 302 of file util-base64.c.

◆ TEST_RFC4648

#define TEST_RFC4648 (   src,
  fin_str,
  dest_size,
  exp_decoded,
  exp_consumed,
  ecode 
)
Value:
{ \
uint32_t consumed_bytes = 0, num_decoded = 0; \
uint8_t dst[dest_size]; \
Base64Ecode code = DecodeBase64(dst, dest_size, (const uint8_t *)src, strlen(src), \
&consumed_bytes, &num_decoded, BASE64_MODE_RFC4648); \
FAIL_IF(code != ecode); \
FAIL_IF(memcmp(dst, fin_str, strlen(fin_str)) != 0); \
FAIL_IF(num_decoded != exp_decoded); \
FAIL_IF(consumed_bytes != exp_consumed); \
}

Definition at line 314 of file util-base64.c.

Function Documentation

◆ Base64RegisterTests()

void Base64RegisterTests ( void  )

Definition at line 495 of file util-base64.c.

References UtRegisterTest().

Here is the call graph for this function:

◆ DecodeBase64()

Base64Ecode DecodeBase64 ( uint8_t *  dest,
uint32_t  dest_size,
const uint8_t *  src,
uint32_t  len,
uint32_t *  consumed_bytes,
uint32_t *  decoded_bytes,
Base64Mode  mode 
)

Decodes a base64-encoded string buffer into an ascii-encoded byte buffer.

Parameters
destThe destination byte buffer
dest_sizeThe destination byte buffer size
srcThe source string
lenThe length of the source string
consumed_bytesThe bytes that were actually processed/consumed
decoded_bytesThe bytes that were decoded
modeThe mode in which decoding should happen
Returns
Error code indicating success or failures with parsing

Definition at line 276 of file util-base64.c.

References BASE64_ECODE_OK, and BASE64_MODE_RFC4648.

Referenced by DetectBase64DecodeDoMatch().

Here is the caller graph for this function:

◆ IsBase64Alphabet()

bool IsBase64Alphabet ( uint8_t  encoded_byte)

Checks if the given char in a byte array is Base64 alphabet.

Parameters
Charthat needs to be checked
Returns
True if the char was Base64 alphabet, False otherwise

Definition at line 74 of file util-base64.c.

BASE64_MODE_RFC2045
@ BASE64_MODE_RFC2045
Definition: util-base64.h:51
BASE64_MODE_RFC4648
@ BASE64_MODE_RFC4648
Definition: util-base64.h:68
src
uint16_t src
Definition: app-layer-dnp3.h:5
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
DecodeBase64
Base64Ecode DecodeBase64(uint8_t *dest, uint32_t dest_size, const uint8_t *src, uint32_t len, uint32_t *consumed_bytes, uint32_t *decoded_bytes, Base64Mode mode)
Decodes a base64-encoded string buffer into an ascii-encoded byte buffer.
Definition: util-base64.c:276