|
@@ -42,6 +42,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
#include "version.h"
|
|
|
#include "util/hex.h"
|
|
|
#include "util/sha1.h"
|
|
|
+#include "util/sha256.h"
|
|
|
#include "util/png.h"
|
|
|
#include <cstdio>
|
|
|
|
|
@@ -566,6 +567,27 @@ int ModApiUtil::l_sha1(lua_State *L)
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
+int ModApiUtil::l_sha256(lua_State *L)
|
|
|
+{
|
|
|
+ NO_MAP_LOCK_REQUIRED;
|
|
|
+
|
|
|
+ auto data = readParam<std::string_view>(L, 1);
|
|
|
+ bool hex = !lua_isboolean(L, 2) || !readParam<bool>(L, 2);
|
|
|
+
|
|
|
+ std::string data_sha256;
|
|
|
+ data_sha256.resize(SHA256_DIGEST_LENGTH);
|
|
|
+ SHA256(reinterpret_cast<const unsigned char*>(data.data()), data.size(),
|
|
|
+ reinterpret_cast<unsigned char *>(data_sha256.data()));
|
|
|
+
|
|
|
+ if (hex) {
|
|
|
+ lua_pushstring(L, hex_encode(data_sha256).c_str());
|
|
|
+ } else {
|
|
|
+ lua_pushlstring(L, data_sha256.data(), data_sha256.size());
|
|
|
+ }
|
|
|
+
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
// colorspec_to_colorstring(colorspec)
|
|
|
int ModApiUtil::l_colorspec_to_colorstring(lua_State *L)
|
|
|
{
|
|
@@ -690,6 +712,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
|
|
|
|
|
|
API_FCT(get_version);
|
|
|
API_FCT(sha1);
|
|
|
+ API_FCT(sha256);
|
|
|
API_FCT(colorspec_to_colorstring);
|
|
|
API_FCT(colorspec_to_bytes);
|
|
|
|
|
@@ -723,6 +746,7 @@ void ModApiUtil::InitializeClient(lua_State *L, int top)
|
|
|
|
|
|
API_FCT(get_version);
|
|
|
API_FCT(sha1);
|
|
|
+ API_FCT(sha256);
|
|
|
API_FCT(colorspec_to_colorstring);
|
|
|
API_FCT(colorspec_to_bytes);
|
|
|
|
|
@@ -766,6 +790,7 @@ void ModApiUtil::InitializeAsync(lua_State *L, int top)
|
|
|
|
|
|
API_FCT(get_version);
|
|
|
API_FCT(sha1);
|
|
|
+ API_FCT(sha256);
|
|
|
API_FCT(colorspec_to_colorstring);
|
|
|
API_FCT(colorspec_to_bytes);
|
|
|
|