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

Function b64pad

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

-------------------------------------------------------------------------*\ * Encodes the Base64 last 1 or 2 bytes and adds padding '=' * Result, if any, is appended to buffer. * Returns 0. \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

285* Returns 0.
286\*-------------------------------------------------------------------------*/
287static size_t b64pad(const UC *input, size_t size,
288 luaL_Buffer *buffer)
289{
290 unsigned long value = 0;
291 UC code[4] = {'=', '=', '=', '='};
292 switch (size) {
293 case 1:
294 value = input[0] << 4;
295 code[1] = b64base[value & 0x3f]; value >>= 6;
296 code[0] = b64base[value];
297 luaL_addlstring(buffer, (char *) code, 4);
298 break;
299 case 2:
300 value = input[0]; value <<= 8;
301 value |= input[1]; value <<= 2;
302 code[2] = b64base[value & 0x3f]; value >>= 6;
303 code[1] = b64base[value & 0x3f]; value >>= 6;
304 code[0] = b64base[value];
305 luaL_addlstring(buffer, (char *) code, 4);
306 break;
307 default:
308 break;
309 }
310 return 0;
311}
312
313/*-------------------------------------------------------------------------*\
314* Acumulates bytes in input buffer until 4 bytes are available.

Callers 1

mime_global_b64Function · 0.85

Calls 1

luaL_addlstringFunction · 0.85

Tested by

no test coverage detected