@@ -51,6 +51,63 @@ static int LUACALL wxLua_function_bulk_updates_thaw(lua_State *L)
5151}
5252%end
5353
54+ %override wxLua_function__verify_signature
55+ #include < botan/ed25519.h>
56+ #include < botan/hex.h>
57+ #include < botan/pubkey.h>
58+
59+ static int LUACALL wxLua_function__verify_signature (lua_State *L)
60+ {
61+ if (!(lua_isstring (L, 3 )))
62+ {
63+ wxlua_argerror (L, 3 , wxT (" a hex string" ));
64+ return 0 ;
65+ }
66+
67+ std::string pubkey_string (lua_tostring (L, 3 ), lua_strlen (L, 3 ));
68+
69+ if (!(lua_isstring (L, 2 )))
70+ {
71+ wxlua_argerror (L, 2 , wxT (" a binary string" ));
72+ return 0 ;
73+ }
74+
75+ const uint8_t *signature = (const uint8_t *)(lua_tostring (L, 2 ));
76+ size_t signature_len = lua_strlen (L, 2 );
77+
78+ if (!(lua_isstring (L, 1 )))
79+ {
80+ wxlua_argerror (L, 1 , wxT (" a binary string" ));
81+ return 0 ;
82+ }
83+
84+ const uint8_t *message = (const uint8_t *)(lua_tostring (L, 1 ));
85+ size_t message_len = lua_strlen (L, 1 );
86+
87+ uint8_t pubkey_bin[32 ];
88+ try {
89+ if (pubkey_string.length () != 64 || Botan::hex_decode (pubkey_bin, pubkey_string) != 32 )
90+ {
91+ luaL_error (L, " Invalid public key" );
92+ return 0 ;
93+ }
94+ }
95+ catch (const Botan::Exception &e)
96+ {
97+ luaL_error (L, " Invalid public key" );
98+ return 0 ;
99+ }
100+
101+ Botan::Ed25519_PublicKey pubkey (pubkey_bin, 32 );
102+
103+ Botan::PK_Verifier verifier (pubkey, " Pure" );
104+ bool ok = verifier.verify_message (message, message_len, signature, signature_len);
105+
106+ lua_pushboolean (L, ok);
107+ return 1 ;
108+ }
109+ %end
110+
54111%override wxLua_REHex_App_SetupHookRegistration_constructor
55112static int LUACALL wxLua_REHex_App_SetupHookRegistration_constructor (lua_State *L)
56113{
0 commit comments