Sha256: e03195be71ea416a5eb2d3249f3f2469a8f4e2adaf468fff3f2db71e561f7c09

Contents?: true

Size: 993 Bytes

Versions: 7

Compression:

Stored size: 993 Bytes

Contents

require 'sym/app/commands/base_command'

module Sym
  module App
    module Commands
      class PasswordProtectKey < BaseCommand

        required_options %i(key interactive), :password
        incompatible_options %i(examples help version bash_support)
        try_after :generate_key, :encrypt, :decrypt

        def execute
          retries ||= 0
          raise Sym::Errors::NoPrivateKeyFound.new("Unable to resolve private key from argument '#{opts[:key]}'") if self.key.nil?

          the_key = self.key

          if opts[:password]
             encrypted_key, password = encrypt_with_password(the_key)
             add_password_to_the_cache(encrypted_key, password)
             the_key = encrypted_key
           end

          add_to_keychain_if_needed(the_key)

          the_key
        rescue Sym::Errors::PasswordsDontMatch, Sym::Errors::PasswordTooShort => e
          stderr.puts e.message.bold
          retry if (retries += 1) < 3
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sym-2.8.5 lib/sym/app/commands/password_protect_key.rb
sym-2.8.4 lib/sym/app/commands/password_protect_key.rb
sym-2.8.2 lib/sym/app/commands/password_protect_key.rb
sym-2.8.1 lib/sym/app/commands/password_protect_key.rb
sym-2.8.0 lib/sym/app/commands/password_protect_key.rb
sym-2.7.0 lib/sym/app/commands/password_protect_key.rb
sym-2.6.3 lib/sym/app/commands/password_protect_key.rb