Class: Shhh::App::Commands::GenerateKey

Inherits:
Command
  • Object
show all
Includes:
Shhh
Defined in:
lib/shhh/app/commands/generate_key.rb

Constant Summary

Constants included from Shhh

VERSION

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Shhh::App::Commands::Command

Instance Method Details

#runObject


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/shhh/app/commands/generate_key.rb', line 11

def run
  retries         ||= 0
  new_private_key = self.class.create_private_key

  if opts[:password]
    new_private_key = encr_password(new_private_key,
                                    cli.input_handler.new_password)
  end

  clipboard_copy(new_private_key) if opts[:copy]

  if opts[:keychain] && Shhh::App.is_osx?
    Shhh::App::KeyChain.new(opts[:keychain]).add(new_private_key)
  end

  new_private_key
rescue Shhh::Errors::PasswordsDontMatch, Shhh::Errors::PasswordTooShort => e
  STDERR.puts e.message.bold
  retry if (retries += 1) < 3
end