Decode base64 encoded source from the supplied chain iterator to the end of the source. This function is provided because bese64 encoded matter is often found partway into a chain (see email processing). By use of this function a separate step of copying the partial chain is avoided
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | Base64Decode | (hzChain&,hzChain::Iter&,) |
Declared in file: hzCodec.h
Defined in file : hzCodec.cpp
Function Logic:
Function body:
hzEcode Base64Decode (hzChain& Decoded)hzChain::Iter& ci,
{
// Category: Codec
//
// Decode base64 encoded source from the supplied chain iterator to the end of the source.
//
// This function is provided because bese64 encoded matter is often found partway into a chain (see email processing). By use of
// this function a separate step of copying the partial chain is avoided
//
// Arguments: 1) Decoded Chain to contain result of decode operation
// 2) ci Chain iterator into encoded data
//
// Returns: E_FORMAT If the input chain contains unexpected sequences
// E_OK If the input was decoded
_hzfunc("Base64Decode(chIter)") ;
chIter zi ; // Iterator
int32_t val ; // Holds 24 bit value to be written as 3 bytes
int32_t a ; // Input 1st value
int32_t b ; // Input 2nd value
int32_t c ; // Input 3rd value
int32_t d ; // Input 4th value
Decoded.Clear() ;
// Loop through collecting sets of 4 chars and writing out sets of 3 chars
zi = ci ;
for (; !zi.eof() ;)
{
if (*zi == CHAR_CR) { zi++ ; continue ; }
if (*zi == CHAR_NL) { zi++ ; continue ; }
a = _get6bit(*zi) ; zi++ ;
b = _get6bit(*zi) ; zi++ ;
c = _get6bit(*zi) ; zi++ ;
d = _get6bit(*zi) ; zi++ ;
if (a == 101||b== 101||c== 101||d== 101)
return E_FORMAT ;
val = 0;
if (a < 100)val += (a << 18);
if (b < 100)val += (b << 12);
if (c < 100)val += (c << 6);
if (d < 100)val += d ;
a = (val & 0xff0000)>>16;
b = (val & 0xff00)>>8;
c = val & 0xff;
Decoded.AddByte(a) ;
if (b)
Decoded.AddByte(b) ;
if (c)
Decoded.AddByte(c) ;
}
return E_OK ;
}