From 22239c5db456805c4e214a36f24704360f1d7e79 Mon Sep 17 00:00:00 2001 From: nishiki Date: Sat, 7 May 2016 17:47:24 +0200 Subject: [PATCH] remove a pub key --- bin/mpw | 5 ++++- lib/mpw/mpw.rb | 8 +++++++- lib/mpw/ui/cli.rb | 14 +++++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/bin/mpw b/bin/mpw index 669a0f0..d74f20a 100755 --- a/bin/mpw +++ b/bin/mpw @@ -161,6 +161,10 @@ elsif not options[:add].nil? and options[:key].nil? elsif not options[:add].nil? and not options[:key].nil? cli.add_key(options[:key]) +# Delete a public key in wallet +elsif not options[:delete].nil? and not options[:key].nil? + cli.delete_key(options[:key]) + # Export elsif not options[:export].nil? cli.export(options[:export]) @@ -169,7 +173,6 @@ elsif not options[:export].nil? elsif not options[:import].nil? cli.import(options[:import]) -# Interactive mode end cli = nil diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index 9d9d14f..f5dc2a2 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -137,7 +137,7 @@ class MPW @passwords[id] = encrypt(password) end - # Add public key + # Add a public key # args: key -> new public key def add_key(key) data = GPGME::Key.export(key, armor: true).read @@ -149,6 +149,12 @@ class MPW @keys[key] = data end + # Delete a public key + # args: key -> public key to delete + def delete_key(key) + @keys.delete(key) + end + # TODO def check_config if false diff --git a/lib/mpw/ui/cli.rb b/lib/mpw/ui/cli.rb index 378c290..682747f 100644 --- a/lib/mpw/ui/cli.rb +++ b/lib/mpw/ui/cli.rb @@ -186,7 +186,8 @@ class Cli end end - # Add new public key + # Add a new public key + # args: key -> the key name to add def add_key(key) @mpw.add_key(key) @mpw.write_data @@ -196,6 +197,17 @@ class Cli puts "#{I18n.t('display.error')} #13: #{e}".red end + # Add new public key + # args: key -> the key name to delete + def delete_key(key) + @mpw.delete_key(key) + @mpw.write_data + + puts "#{I18n.t('key.delete.valid')}".green + rescue Exception => e + puts "#{I18n.t('display.error')} #15: #{e}".red + end + # Form to add a new item def add options = {}