yumapro  20.10-10
YumaPro SDK
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

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:

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

Here is the caller graph for this function:

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 call graph for this function:

Here is the caller graph for this function:

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:

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:

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
pblobpointer to BLOB to fill in; must be at least bsize * 2 + 1 bytes in length
bsizebinary object size
Return values
pblobis filled in, and zero-terminated
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
pbuffpointer to buffer to fill in; must be at least bsize+1 bytes in length
bsizebinary object size
Return values
pbuffis filled in
uint32 bobhash ( REGISTER const uint8 *  k,
REGISTER uint32  length,
REGISTER uint32  initval 
)

Calculate a 32-bit BOB hash value.

  [Jenk97]   B. Jenkins, "Algorithm Alley", Dr. Dobb's Journal,
               September 1997.
               http://burtleburtle.net/bob/hash/doobs.html.
  Copied From:
    Sampling and Filtering Techniques for IP Packet Selection
    RFC 5475
    Returns a 32-bit value.  Every bit of the key affects every bit
    of the return value.  Every 1-bit and 2-bit delta achieves
    avalanche. About 6*len+35 instructions.
    The best hash table sizes are powers of 2.  There is no need to
    do mod a prime (mod is sooo slow!).  If you need less than 32
    bits, use a bitmask.  For example, if you need only 10 bits, do
    h = (h & hashmask(10));
    In which case, the hash table should have hashsize(10) elements.
    If you are hashing n strings (uint8 **)k, do it like this:
    for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
    By Bob Jenkins, 1996.  bob_j.nosp@m.enki.nosp@m.ns@bu.nosp@m.rtle.nosp@m.burtl.nosp@m.e.ne.nosp@m.t.  You may
    use this code any way you wish, private, educational, or
    commercial.  It's free.
    See http://burtleburtle.net/bob/hash/evahash.html
    Use for hash table lookup, or anything where one collision in
    2^^32 is acceptable.  Do NOT use for cryptographic purposes.
 
@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