Sha256: 029e739a97f9095f62816796f80fd268378e3a6ad23d2721560ffb6289d22baa

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

require_relative 'detector'
require_relative 'base64_decoder'
require_relative 'decryptor'
require_relative '../input/handler'
module Sym
  module App
    module PrivateKey
      # This class figures out what is the private key that is
      # provided to be used.
      class Handler
        include Sym

        attr_accessor :opts, :input_handler, :password_cache
        attr_writer :key

        def initialize(opts, input_handler, password_cache)
          self.opts           = opts
          self.input_handler  = input_handler
          self.password_cache = password_cache
        end


        # @return [String] key Private key detected
        def key
          return @key if @key

          @key = begin
            Detector.new(opts, input_handler).key
          rescue Sym::Errors::Error => e
            if Sym::App::Args.new(opts).specify_key? && key.nil?
              raise e
            end
          end

          if @key && @key.length > 45
            @key = Decryptor.new(Base64Decoder.new(key).key, input_handler, password_cache).key
          end

          @key
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sym-2.3.0 lib/sym/app/private_key/handler.rb
sym-2.2.1 lib/sym/app/private_key/handler.rb
sym-2.2.0 lib/sym/app/private_key/handler.rb
sym-2.1.2 lib/sym/app/private_key/handler.rb
sym-2.1.1 lib/sym/app/private_key/handler.rb
sym-2.1.0 lib/sym/app/private_key/handler.rb
sym-2.0.3 lib/sym/app/private_key/handler.rb
sym-2.0.2 lib/sym/app/private_key/handler.rb
sym-2.0.1 lib/sym/app/private_key/handler.rb
sym-2.0.0 lib/sym/app/private_key/handler.rb