mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-17 08:30:04 +00:00
add import gpg file
This commit is contained in:
parent
0878155bcf
commit
0bf8d4e4ba
3 changed files with 15 additions and 7 deletions
4
bin/mpw
4
bin/mpw
|
@ -66,7 +66,7 @@ OptionParser.new do |opts|
|
|||
options[:export] = true
|
||||
end
|
||||
|
||||
opts.on('-f', '--file', I18n.t('option.file')) do |file|
|
||||
opts.on('-f', '--file FILE', I18n.t('option.file')) do |file|
|
||||
options[:file] = file
|
||||
end
|
||||
|
||||
|
@ -163,7 +163,7 @@ elsif not options[:add].nil? and options[:key].nil?
|
|||
|
||||
# Add a new public key in wallet
|
||||
elsif not options[:add].nil? and not options[:key].nil?
|
||||
cli.add_key(options[:key])
|
||||
cli.add_key(options[:key], options[:file])
|
||||
|
||||
# Delete a public key in wallet
|
||||
elsif not options[:delete].nil? and not options[:key].nil?
|
||||
|
|
|
@ -138,8 +138,15 @@ class MPW
|
|||
|
||||
# Add a public key
|
||||
# args: key -> new public key
|
||||
def add_key(key)
|
||||
data = GPGME::Key.export(key, armor: true).read
|
||||
# file -> public gpg file to import
|
||||
def add_key(key, file=nil)
|
||||
if not file.nil? and File.exists?(file)
|
||||
data = File.open(file).read
|
||||
GPGME::Key.import(data, armor: true)
|
||||
puts GPGME::Key.find(key)[0].trust
|
||||
else
|
||||
data = GPGME::Key.export(key, armor: true).read
|
||||
end
|
||||
|
||||
if data.to_s.empty?
|
||||
raise I18n.t('error.export_key')
|
||||
|
@ -298,7 +305,7 @@ class MPW
|
|||
private
|
||||
def encrypt(data)
|
||||
recipients = []
|
||||
crypto = GPGME::Crypto.new(armor: true)
|
||||
crypto = GPGME::Crypto.new(armor: true, always_trust: true)
|
||||
|
||||
@keys.each_key do |key|
|
||||
recipients.push(key)
|
||||
|
|
|
@ -188,8 +188,9 @@ class Cli
|
|||
|
||||
# Add a new public key
|
||||
# args: key -> the key name to add
|
||||
def add_key(key)
|
||||
@mpw.add_key(key)
|
||||
# file -> gpg public file to import
|
||||
def add_key(key, file=nil)
|
||||
@mpw.add_key(key, file)
|
||||
@mpw.write_data
|
||||
|
||||
puts "#{I18n.t('key.add.valid')}".green
|
||||
|
|
Loading…
Add table
Reference in a new issue