From 5c3eeae3bda893bacca5a0aae5ad1bead21712aa Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Wed, 18 Dec 2013 00:23:35 -0500 Subject: [PATCH] Cache loaded encryption keys. I'm pretty sure that's a commit message that strikes fear in the hearts of cryptographers everywhere. --- 1pass.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/1pass.lua b/1pass.lua index c9e9e8e..788058a 100644 --- a/1pass.lua +++ b/1pass.lua @@ -57,7 +57,12 @@ local function load_json(fname) 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 @@ function loadKey(basedir, level, password) return nil end + keys[level] = decrypted return decrypted end end @@ -109,8 +115,7 @@ showHint(basedir) 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