yumapro  24.10-2
YumaPro SDK
Loading...
Searching...
No Matches
Binary Data Utilities

Base64 utility functions for YANG. More...

Collaboration diagram for Binary Data Utilities:

Functions

status_t b64_encode (const unsigned char *inbuff, unsigned int inbufflen, unsigned char *outbuff, unsigned int outbufflen, unsigned int linesize, unsigned int *retlen)
 base64 encode a stream adding padding and line breaks as per spec. More...
 
status_t b64_decode (const uint8_t *inbuff, uint32_t inbufflen, uint8_t *outbuff, uint32_t outbufflen, uint32_t *retlen)
 Decode a base64 string. More...
 
uint32_t b64_get_decoded_str_len (const uint8_t *inbuff, size_t inputLen)
 Calculate the length of the buffer required to decode the base64 string. More...
 
uint32_t b64_get_encoded_str_len (uint32_t inbufflen, uint32_t linesize)
 Get the output buffer size required for encoding the string. More...
 
boolean b64_valid_base64 (const char *b64str)
 Check if a string match base64 encoding or not. More...
 
void blob2bin (const char *pblob, unsigned char *pbuff, uint32 bsize)
 Convert a mySQL BLOB to a binary string. More...
 
void bin2blob (const unsigned char *pbuff, char *pblob, uint32 bsize)
 Convert a binary string to to a mySQL BLOB. More...
 
uint32 bobhash (REGISTER const uint8 *k, REGISTER uint32 length, REGISTER uint32 initval)
 Calculate a 32-bit BOB hash value. More...
 

Detailed Description

Base64 utility functions for YANG.

bobhash function is used by the def_reg.c module to hash the registry entries.

The blob utilities are used by yangdump-pro.

The 'binary' data type is supported by these conversion functions.

The –format=sqldb option needs to convert blobs to text.

It is not used anywhere else.

Function Documentation

◆ b64_decode()

status_t b64_decode ( const uint8_t *  inbuff,
uint32_t  inbufflen,
uint8_t *  outbuff,
uint32_t  outbufflen,
uint32_t *  retlen 
)

Decode a base64 string.

This function decodes the supplied base 64 string. It has the following constraints:

   1 - The length of the supplied base64 string must be divisible by 4
       (any other length strings are NOT valid base 64)
   2 - If any non base64 characters are encountered the length of
       decoded string will be truncated.
   3 - CR and LF characters in the encoded string will be skipped.
Parameters
inbuffpointer to buffer of base64 chars
inbufflennumber of chars in inbuff
outbuffpointer to the output buffer to use
outbufflenthe length of outbuff.
retlenthe number of decoded bytes
Returns
NO_ERR if all OK ERR_BUFF_OVFL if outbuff not big enough
Here is the caller graph for this function:

◆ b64_encode()

status_t b64_encode ( const unsigned char *  inbuff,
unsigned int  inbufflen,
unsigned char *  outbuff,
unsigned int  outbufflen,
unsigned int  linesize,
unsigned int *  retlen 
)

base64 encode a stream adding padding and line breaks as per spec.

Parameters
inbuffpointer to buffer of binary chars
inbufflennumber of binary chars in inbuff
outbuffpointer to the output buffer to use.
outbufflenmax number of chars to write to outbuff
linesizethe output line length to use
retlenaddress of return length
Returns
NO_ERR if all OK, ERR_BUFF_OVFL if outbuff not big enough

◆ b64_get_decoded_str_len()

uint32_t b64_get_decoded_str_len ( const uint8_t *  inbuff,
size_t  inputLen 
)

Calculate the length of the buffer required to decode the base64 string.

Parameters
inbuffthe base64 string to decode.
inputLenthe length of inbuff.
Returns
the length of the required buffer.
Here is the caller graph for this function:

◆ b64_get_encoded_str_len()

uint32_t b64_get_encoded_str_len ( uint32_t  inbufflen,
uint32_t  linesize 
)

Get the output buffer size required for encoding the string.

Parameters
inbufflenthe size of the input buffer.
linesizethe length of each line
Returns
the size required for encoding the string.
Here is the caller graph for this function:

◆ b64_valid_base64()

boolean b64_valid_base64 ( const char *  b64str)

Check if a string match base64 encoding or not.

In base64 encoding, the character set is [A-Z,a-z,0-9,and + /], if the rest length is less than 4, pad with '=' character.

^([A-Za-z0-9+/]{4})* means the String start with 0 time or more base64 group

([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==) means the String must end of 3 forms in [A-Za-z0-9+/]{4} or [A-Za-z0-9+/]{3}= or [A-Za-z0-9+/]{2}==

If the String matches this pattern then it is a valid base64 string which can be decoded.

Parameters
b64strinput string to check
Returns
FALSE if the string does not match the pattern; TRUE if the sting is valid base64 string
Here is the caller graph for this function:

◆ bin2blob()

void bin2blob ( const unsigned char *  pbuff,
char *  pblob,
uint32  bsize 
)

Convert a binary string to to a mySQL BLOB.

Parameters
pbuffpointer to buffer to convert; must be at least bsize+1 bytes in length
[out]pblobpointer to BLOB to fill in; must be at least bsize * 2 + 1 bytes in length
pblob is filled in, and zero-terminated
bsizebinary object size

◆ blob2bin()

void blob2bin ( const char *  pblob,
unsigned char *  pbuff,
uint32  bsize 
)

Convert a mySQL BLOB to a binary string.

INPUTS:

Parameters
pblobpointer to BLOB to convert; must be of the same type as the binary object; this blob will be bsize * 2 + 1 bytes in length
[out]pbuffpointer to buffer to fill in; must be at least bsize+1 bytes in length; pbuff is filled in
bsizebinary object size

◆ bobhash()

uint32 bobhash ( REGISTER const uint8 *  k,
REGISTER uint32  length,
REGISTER uint32  initval 
)

Calculate a 32-bit BOB hash value.

@param k the key (the unaligned variable-length array of bytes)
@param len len the length of the key, counting by bytes
@param initval can be any 4-byte value
@return unsigned long has value