summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormo khan <mokhan@users.noreply.github.com>2016-11-18 10:29:33 -0700
committerGitHub <noreply@github.com>2016-11-18 10:29:33 -0700
commit172e3dfb7ff0ebec111a8349daddd50ad86648aa (patch)
tree216abfe1666126bda23cc2b27e5222c4e8f0ec9e /lib
parent6301ea64a649212838a449e7f11af91f72bd5263 (diff)
parent32938166ecb1d446101f0b312a3ba4635a010bdc (diff)
Merge pull request #6 from mokhan/GH-3v0.0.12
Add a command to remove a secret.
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