summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/tfa/cli.rb5
-rw-r--r--lib/tfa/storage.rb6
-rw-r--r--lib/tfa/totp_command.rb8
-rw-r--r--lib/tfa/version.rb2
4 files changed, 15 insertions, 6 deletions
diff --git a/lib/tfa/cli.rb b/lib/tfa/cli.rb
index 107f202..03feeeb 100644
--- a/lib/tfa/cli.rb
+++ b/lib/tfa/cli.rb
@@ -12,6 +12,11 @@ module TFA
"Added #{name}"
end
+ desc "destroy NAME", "remove the secret associated with the name"
+ def destroy(name)
+ storage.delete(name)
+ end
+
desc "show NAME", "shows the secret for the given key"
def show(name = nil)
name ? storage.secret_for(name) : storage.all
diff --git a/lib/tfa/storage.rb b/lib/tfa/storage.rb
index 1424315..5eb0a3a 100644
--- a/lib/tfa/storage.rb
+++ b/lib/tfa/storage.rb
@@ -30,6 +30,12 @@ module TFA
end
end
+ def delete(key)
+ @storage.transaction do
+ @storage.delete(key)
+ end
+ end
+
private
def open_readonly
diff --git a/lib/tfa/totp_command.rb b/lib/tfa/totp_command.rb
index 8dd0125..14bc064 100644
--- a/lib/tfa/totp_command.rb
+++ b/lib/tfa/totp_command.rb
@@ -12,11 +12,9 @@ module TFA
private
def password_for(secret)
- begin
- ::ROTP::TOTP.new(secret).now
- rescue
- "???"
- end
+ ::ROTP::TOTP.new(secret).now
+ rescue ROTP::Base32::Base32Error
+ "INVALID SECRET"
end
def all_passwords
diff --git a/lib/tfa/version.rb b/lib/tfa/version.rb
index 411ea83..ffd9203 100644
--- a/lib/tfa/version.rb
+++ b/lib/tfa/version.rb
@@ -1,3 +1,3 @@
module TFA
- VERSION = "0.0.11"
+ VERSION = "0.0.12".freeze
end