| 454 | } |
| 455 | |
| 456 | static int |
| 457 | ts_lua_base64_encode(lua_State *L) |
| 458 | { |
| 459 | u_char *src; |
| 460 | u_char *dst; |
| 461 | size_t slen; |
| 462 | size_t dlen; |
| 463 | |
| 464 | size_t length; |
| 465 | |
| 466 | if (lua_gettop(L) != 1) { |
| 467 | return luaL_error(L, "expecting one argument"); |
| 468 | } |
| 469 | |
| 470 | if (lua_isnil(L, 1)) { |
| 471 | src = (u_char *)""; |
| 472 | slen = 0; |
| 473 | } else { |
| 474 | src = (u_char *)luaL_checklstring(L, 1, &slen); |
| 475 | } |
| 476 | |
| 477 | dlen = TS_LUA_MAX_STR_LENGTH; |
| 478 | dst = static_cast<u_char *>(lua_newuserdata(L, dlen)); |
| 479 | |
| 480 | if (TS_SUCCESS == TSBase64Encode((const char *)src, slen, (char *)dst, dlen, &length)) { |
| 481 | lua_pushlstring(L, (char *)dst, length); |
| 482 | return 1; |
| 483 | } else { |
| 484 | return luaL_error(L, "base64 encoding error"); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | static int |
| 489 | ts_lua_base64_decode(lua_State *L) |
nothing calls this directly
no test coverage detected