/** * Decodes a BASE64 encoded data block. Returns True if string has been * successfully decoded, or False if it cannot be decoded (or memory * allocation fails). The len parameter is negative if the amount of * data is unknown in advance. */ STATIC Bool BASE64_DecodeFile2(File * in, size_t len, Buffer * out, const I8u * map) { Base64Decode decode; /* pre-allocate memory in the output buffer */ if (out && len > 0) { size_t nbytes = 3*len/4; if (len%4) nbytes++; if (!BUFFER_EnsureCapacity(out, BUFFER_Size(out) + nbytes, False)) { return False; } } /* initialize the context */ decode.in = in; decode.nread = 0; decode.out = out; if (map) { decode.decodeMap = map; decode.flags = 0; } else { decode.decodeMap = base64_decodeMap; decode.flags = FLAG_DETECT; } /* run the decoder */ return BASE64_InternalDecode(&decode); }
/** * Decodes a BASE32 encoded data block. Returns True if string has been * successfully decoded, or False if it cannot be decoded (or memory * allocation fails). The len parameter is negative if the amount of * data is unknown in advance. */ STATIC Bool BASE32_DecodeFile2(File * in,int len,Buffer * out,const I8u * map) { Base32Decode decode; /* pre-allocate maximum amount of memory for the output buffer */ if (out && len > 0) { int nbytes = ENCODE_CHUNK_SIZE*(len/DECODE_CHUNK_SIZE); switch (len % DECODE_CHUNK_SIZE) { case 0: case 1: break; case 2: case 3: nbytes++; /* NOBREAK */ case 4: nbytes++; /* NOBREAK */ case 5: case 6: nbytes++; /* NOBREAK */ case 7: nbytes++; break; } if (!BUFFER_EnsureCapacity(out, BUFFER_Size(out) + nbytes, False)) { return False; } } /* initialize the context */ decode.in = in; decode.nread = 0; decode.out = out; decode.decodeMap = map; decode.flags = 0; /* run the decoder */ return BASE32_InternalDecode(&decode); }