Cache loaded encryption keys.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 18 Dec 2013 00:23:35 -0500
changeset 5 6f80cd157c13
parent 4 bf5593e5ddbb
child 6 b7f19e0599db
Cache loaded encryption keys.

I'm pretty sure that's a commit message that strikes fear in the hearts of
cryptographers everywhere.
1pass.lua
--- a/1pass.lua	Tue Dec 17 22:59:57 2013 -0500
+++ b/1pass.lua	Wed Dec 18 00:23:35 2013 -0500
@@ -57,7 +57,12 @@
 end
 
 
+local keys = {}
 function loadKey(basedir, level, password)
+    if keys[level] ~= nil then
+        return keys[level]
+    end
+
     local keysjson = load_json(basedir .. "/encryptionKeys.js");
     if (keysjson == nil) or (keysjson[level] == nil) then
         return nil
@@ -81,6 +86,7 @@
                 return nil
             end
 
+            keys[level] = decrypted
             return decrypted
         end
     end
@@ -109,8 +115,7 @@
 io.write("password: ")
 local password = io.read("*l")
 
-local sl5 = loadKey(basedir, "SL5", password)
-if sl5 == nil then
+if loadKey(basedir, "SL5", password) == nil then
     print("wrong password?\n")
     os.exit(1)
 end