suricata
util-base64.c File Reference
#include "util-base64.h"
#include "util-debug.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

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 30 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, strlen(fin_str), (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 184 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, strlen(fin_str), (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 196 of file util-base64.c.

Function Documentation

◆ Base64RegisterTests()

void Base64RegisterTests ( void  )

Definition at line 363 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 94 of file util-base64.c.

References B64_BLOCK, BASE64_ECODE_OK, len, and padding.

Referenced by DetectBase64DecodeDoMatch().

Here is the caller graph for this function:
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
code
uint8_t code
Definition: decode-icmpv4.h:1
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:94