From ad5ac39d8d1a8b8f6f0fe077e20bac914ddc624b Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 6 Aug 2015 08:57:13 +0200 Subject: Add LuaSecureRandom --- src/script/lua_api/l_noise.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/script/lua_api/l_noise.h') diff --git a/src/script/lua_api/l_noise.h b/src/script/lua_api/l_noise.h index e958c5a23..492eb7550 100644 --- a/src/script/lua_api/l_noise.h +++ b/src/script/lua_api/l_noise.h @@ -160,4 +160,37 @@ public: static void Register(lua_State *L); }; + +/* + LuaSecureRandom +*/ +class LuaSecureRandom : public ModApiBase { +private: + static const size_t RAND_BUF_SIZE = 2048; + static const char className[]; + static const luaL_reg methods[]; + + u32 m_rand_idx; + char m_rand_buf[RAND_BUF_SIZE]; + + // Exported functions + + // garbage collector + static int gc_object(lua_State *L); + + // next_bytes(self, count) -> get count many bytes + static int l_next_bytes(lua_State *L); + +public: + bool fillRandBuf(); + + // LuaSecureRandom() + // Creates an LuaSecureRandom and leaves it on top of stack + static int create_object(lua_State *L); + + static LuaSecureRandom *checkobject(lua_State *L, int narg); + + static void Register(lua_State *L); +}; + #endif /* L_NOISE_H_ */ -- cgit v1.2.3