|
@@ -44,80 +44,6 @@ static int crypto_sha1( lua_State* L )
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
-#ifdef LUA_USE_MODULES_ENCODER
|
|
|
-static int call_encoder( lua_State* L, const char *function ) {
|
|
|
- if (lua_gettop(L) != 1) {
|
|
|
- luaL_error(L, "%s must have one argument", function);
|
|
|
- }
|
|
|
- lua_getglobal(L, "encoder");
|
|
|
- luaL_checktype(L, -1, LUA_TTABLE);
|
|
|
- lua_getfield(L, -1, function);
|
|
|
- lua_insert(L, 1); //move function below the argument
|
|
|
- lua_pop(L, 1); //and dump the encoder rotable from stack.
|
|
|
- lua_call(L,1,1); // Normal call encoder.xxx(string)
|
|
|
- // (errors thrown back to caller)
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-static int crypto_base64_encode (lua_State* L) {
|
|
|
- platform_print_deprecation_note("crypto.toBase64", "in the next version");
|
|
|
- return call_encoder(L, "toBase64");
|
|
|
-}
|
|
|
-static int crypto_hex_encode (lua_State* L) {
|
|
|
- platform_print_deprecation_note("crypto.toHex", "in the next version");
|
|
|
- return call_encoder(L, "toHex");
|
|
|
-}
|
|
|
-#else
|
|
|
-static const char* bytes64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
-/**
|
|
|
- * encoded = crypto.toBase64(raw)
|
|
|
- *
|
|
|
- * Encodes raw binary string as base64 string.
|
|
|
- */
|
|
|
-static int crypto_base64_encode( lua_State* L )
|
|
|
-{
|
|
|
- int len, i;
|
|
|
- const char* msg = luaL_checklstring(L, 1, &len);
|
|
|
- luaL_Buffer out;
|
|
|
-
|
|
|
- platform_print_deprecation_note("crypto.toBase64", "in the next version");
|
|
|
-
|
|
|
- luaL_buffinit(L, &out);
|
|
|
- for (i = 0; i < len; i += 3) {
|
|
|
- int a = msg[i];
|
|
|
- int b = (i + 1 < len) ? msg[i + 1] : 0;
|
|
|
- int c = (i + 2 < len) ? msg[i + 2] : 0;
|
|
|
- luaL_addchar(&out, bytes64[a >> 2]);
|
|
|
- luaL_addchar(&out, bytes64[((a & 3) << 4) | (b >> 4)]);
|
|
|
- luaL_addchar(&out, (i + 1 < len) ? bytes64[((b & 15) << 2) | (c >> 6)] : 61);
|
|
|
- luaL_addchar(&out, (i + 2 < len) ? bytes64[(c & 63)] : 61);
|
|
|
- }
|
|
|
- luaL_pushresult(&out);
|
|
|
- return 1;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * encoded = crypto.toHex(raw)
|
|
|
- *
|
|
|
- * Encodes raw binary string as hex string.
|
|
|
- */
|
|
|
-static int crypto_hex_encode( lua_State* L)
|
|
|
-{
|
|
|
- int len, i;
|
|
|
- const char* msg = luaL_checklstring(L, 1, &len);
|
|
|
- luaL_Buffer out;
|
|
|
-
|
|
|
- platform_print_deprecation_note("crypto.toHex", "in the next version");
|
|
|
-
|
|
|
- luaL_buffinit(L, &out);
|
|
|
- for (i = 0; i < len; i++) {
|
|
|
- luaL_addchar(&out, crypto_hexbytes[msg[i] >> 4]);
|
|
|
- luaL_addchar(&out, crypto_hexbytes[msg[i] & 0xf]);
|
|
|
- }
|
|
|
- luaL_pushresult(&out);
|
|
|
- return 1;
|
|
|
-}
|
|
|
-#endif
|
|
|
/**
|
|
|
* masked = crypto.mask(message, mask)
|
|
|
*
|
|
@@ -147,7 +73,7 @@ static inline int bad_mem (lua_State *L) { return luaL_error (L, "insufficient
|
|
|
static inline int bad_file (lua_State *L) { return luaL_error (L, "file does not exist"); }
|
|
|
|
|
|
/* rawdigest = crypto.hash("MD5", str)
|
|
|
- * strdigest = crypto.toHex(rawdigest)
|
|
|
+ * strdigest = encoder.toHex(rawdigest)
|
|
|
*/
|
|
|
static int crypto_lhash (lua_State *L)
|
|
|
{
|
|
@@ -169,7 +95,7 @@ static int crypto_lhash (lua_State *L)
|
|
|
* sha = crypto.new_hash("MD5")
|
|
|
* sha.update("Data")
|
|
|
* sha.update("Data2")
|
|
|
- * strdigest = crypto.toHex(sha.finalize())
|
|
|
+ * strdigest = encoder.toHex(sha.finalize())
|
|
|
*/
|
|
|
|
|
|
#define WANT_HASH 0
|
|
@@ -279,7 +205,7 @@ static sint32_t vfs_read_wrap (int fd, void *ptr, size_t len)
|
|
|
}
|
|
|
|
|
|
/* rawdigest = crypto.hash("MD5", filename)
|
|
|
- * strdigest = crypto.toHex(rawdigest)
|
|
|
+ * strdigest = encoder.toHex(rawdigest)
|
|
|
*/
|
|
|
static int crypto_flhash (lua_State *L)
|
|
|
{
|
|
@@ -313,7 +239,7 @@ static int crypto_flhash (lua_State *L)
|
|
|
|
|
|
|
|
|
/* rawsignature = crypto.hmac("SHA1", str, key)
|
|
|
- * strsignature = crypto.toHex(rawsignature)
|
|
|
+ * strsignature = encoder.toHex(rawsignature)
|
|
|
*/
|
|
|
static int crypto_lhmac (lua_State *L)
|
|
|
{
|
|
@@ -400,8 +326,6 @@ LROT_END(crypto_hash_map, NULL, LROT_MASK_INDEX)
|
|
|
// Module function map
|
|
|
LROT_BEGIN(crypto, NULL, 0)
|
|
|
LROT_FUNCENTRY( sha1, crypto_sha1 )
|
|
|
- LROT_FUNCENTRY( toBase64, crypto_base64_encode )
|
|
|
- LROT_FUNCENTRY( toHex, crypto_hex_encode )
|
|
|
LROT_FUNCENTRY( mask, crypto_mask )
|
|
|
LROT_FUNCENTRY( hash, crypto_lhash )
|
|
|
LROT_FUNCENTRY( fhash, crypto_flhash )
|