mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 13:57:52 +00:00
add public key in wallet
This commit is contained in:
parent
27c4162aa9
commit
22676a8b79
3 changed files with 30 additions and 4 deletions
10
bin/mpw
10
bin/mpw
|
@ -92,6 +92,10 @@ OptionParser.new do |opts|
|
|||
options[:import] = file
|
||||
end
|
||||
|
||||
opts.on('-k', '--key KEY', I18n.t('option.import')) do |key|
|
||||
options[:key] = key
|
||||
end
|
||||
|
||||
opts.on('-N', '--no-sync', I18n.t('option.no_sync')) do
|
||||
options[:sync] = false
|
||||
end
|
||||
|
@ -150,9 +154,13 @@ elsif not options[:update].nil? and not options[:id].nil?
|
|||
cli.update(options[:id])
|
||||
|
||||
# Add a new item
|
||||
elsif not options[:add].nil?
|
||||
elsif not options[:add].nil? and options[:key].nil?
|
||||
cli.add
|
||||
|
||||
# Add a new public key in wallet
|
||||
elsif not options[:add].nil? and not options[:key].nil?
|
||||
cli.add_key(options[:key])
|
||||
|
||||
# Export
|
||||
elsif not options[:export].nil?
|
||||
cli.export(options[:export])
|
||||
|
|
|
@ -112,7 +112,7 @@ class MPW
|
|||
|
||||
@keys.each do |id, key|
|
||||
tar.add_file_simple("wallet/keys/#{id}.pub", 0400, key.length) do |io|
|
||||
io.write(password)
|
||||
io.write(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -131,6 +131,18 @@ class MPW
|
|||
@passwords[id] = encrypt(password)
|
||||
end
|
||||
|
||||
# Add public key
|
||||
# args: key -> new public key
|
||||
def add_key(key)
|
||||
data = GPGME::Key.export(key).read
|
||||
|
||||
if data.to_s.empty?
|
||||
raise I18n.t('error.export_key')
|
||||
end
|
||||
|
||||
@keys[key] = data
|
||||
end
|
||||
|
||||
# TODO
|
||||
def check_config
|
||||
if false
|
||||
|
@ -150,7 +162,6 @@ class MPW
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
# Search in some csv data
|
||||
# @args: options -> a hash with paramaters
|
||||
# @rtrn: a list with the resultat of the search
|
||||
|
|
|
@ -157,7 +157,6 @@ class Cli
|
|||
def get_wallet(wallet=nil)
|
||||
if wallet.to_s.empty?
|
||||
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
|
||||
puts wallets
|
||||
|
||||
case wallets.length
|
||||
when 0
|
||||
|
@ -186,6 +185,14 @@ class Cli
|
|||
end
|
||||
end
|
||||
|
||||
# Add new public key
|
||||
def add_key(key)
|
||||
@mpw.add_key(key)
|
||||
@mpw.write_data
|
||||
rescue Exception => e
|
||||
puts "#{I18n.t('display.error')} #13: #{e}".red
|
||||
end
|
||||
|
||||
# Form to add a new item
|
||||
def add
|
||||
options = {}
|
||||
|
|
Loading…
Reference in a new issue