Cache loaded encryption keys.
I'm pretty sure that's a commit message that strikes fear in the hearts of
cryptographers everywhere.
--- 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