MCPcopy Create free account
hub / github.com/Tencent/UnLua / b64decode

Function b64decode

Plugins/UnLuaExtensions/LuaSocket/Source/src/mime.cpp:318–341  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Acumulates bytes in input buffer until 4 bytes are available. * Translate the 4 bytes from Base64 form and append to buffer. * Returns new number of bytes in buffer. \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

316* Returns new number of bytes in buffer.
317\*-------------------------------------------------------------------------*/
318static size_t b64decode(UC c, UC *input, size_t size,
319 luaL_Buffer *buffer)
320{
321 /* ignore invalid characters */
322 if (b64unbase[c] > 64) return size;
323 input[size++] = c;
324 /* decode atom */
325 if (size == 4) {
326 UC decoded[3];
327 int valid, value = 0;
328 value = b64unbase[input[0]]; value <<= 6;
329 value |= b64unbase[input[1]]; value <<= 6;
330 value |= b64unbase[input[2]]; value <<= 6;
331 value |= b64unbase[input[3]];
332 decoded[2] = (UC) (value & 0xff); value >>= 8;
333 decoded[1] = (UC) (value & 0xff); value >>= 8;
334 decoded[0] = (UC) value;
335 /* take care of paddding */
336 valid = (input[2] == '=') ? 1 : (input[3] == '=') ? 2 : 3;
337 luaL_addlstring(buffer, (char *) decoded, valid);
338 return 0;
339 /* need more data */
340 } else return size;
341}
342
343/*-------------------------------------------------------------------------*\
344* Incrementally applies the Base64 transfer content encoding to a string

Callers 1

mime_global_unb64Function · 0.85

Calls 1

luaL_addlstringFunction · 0.85

Tested by

no test coverage detected