1pass.c
changeset 56 a573346e6f7b
parent 46 fe4f59680246
--- a/1pass.c	Sun Jun 18 01:57:23 2017 -0400
+++ b/1pass.c	Sun Jun 18 19:40:30 2017 -0400
@@ -18,6 +18,7 @@
 #include "md5.h"
 #include "sha256.h"
 #include "keyhook.h"
+#include "otp.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdk.h>
@@ -364,6 +365,15 @@
 } // decryptBase64UsingKey
 
 
+static int decryptTopt(lua_State *L)
+{
+    const char *base32_secret = luaL_checkstring(L, 1);
+    char otpstr[16];
+    const int rc = totp(base32_secret, otpstr, sizeof (otpstr));
+    return retvalString(L, (rc == -1) ? NULL : otpstr);
+} // decryptTopt
+
+
 static void calcSha256(const BYTE *buf, const size_t len, BYTE *hash)
 {
     SHA256_CTX sha256;
@@ -766,6 +776,7 @@
     // Set up initial C functions, etc we want to expose to Lua code...
     luaSetCFunc(luaState, decryptUsingPBKDF2, "decryptUsingPBKDF2");
     luaSetCFunc(luaState, decryptBase64UsingKey, "decryptBase64UsingKey");
+    luaSetCFunc(luaState, decryptTopt, "decryptTopt");
     luaSetCFunc(luaState, giveControlToGui, "giveControlToGui");
     luaSetCFunc(luaState, runGuiPasswordPrompt, "runGuiPasswordPrompt");
     luaSetCFunc(luaState, copyToClipboard, "copyToClipboard");