Sha256: 64d37521c8173285fa0b026a6a5206ba60b22b2fb1e9dabfe2e543be4a8f493d

Contents?: true

Size: 1.13 KB

Versions: 18

Compression:

Stored size: 1.13 KB

Contents

require 'sym/app/private_key/base64_decoder'
require 'sym/app/private_key/decryptor'
require 'sym/app/private_key/detector'
require 'sym/app/input/handler'
require 'sym/app/args'
require 'sym/errors'
module Sym
  module App
    module PrivateKey
      # This class figures out what is the private key that is
      # provided to be used.
      class Handler < Struct.new(:opts, :input_handler, :password_cache)
        include Sym
        attr_accessor :key, :key_source

        def initialize(*args)
          super(*args)
          self.key, self.key_source = detect_key
        end

        private

        def detect_key
          begin
            reader = Detector.new(opts, input_handler, password_cache)
            key = reader.key
            key_source = reader.key_source
          rescue Sym::Errors::Error => e
            if Sym::App::Args.new(opts.to_h).specify_key? && key.nil?
              raise e
            end
          end
          key = Decryptor.new(Base64Decoder.new(key).key, input_handler, password_cache).key if key && key.length > 45
          return key ? [key, key_source] : [nil, nil]
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
sym-3.0.2 lib/sym/app/private_key/handler.rb
sym-3.0.1 lib/sym/app/private_key/handler.rb
sym-3.0.0 lib/sym/app/private_key/handler.rb
sym-2.10.0 lib/sym/app/private_key/handler.rb
sym-2.8.5 lib/sym/app/private_key/handler.rb
sym-2.8.4 lib/sym/app/private_key/handler.rb
sym-2.8.2 lib/sym/app/private_key/handler.rb
sym-2.8.1 lib/sym/app/private_key/handler.rb
sym-2.8.0 lib/sym/app/private_key/handler.rb
sym-2.7.0 lib/sym/app/private_key/handler.rb
sym-2.6.3 lib/sym/app/private_key/handler.rb
sym-2.6.2 lib/sym/app/private_key/handler.rb
sym-2.6.1 lib/sym/app/private_key/handler.rb
sym-2.6.0 lib/sym/app/private_key/handler.rb
sym-2.5.3 lib/sym/app/private_key/handler.rb
sym-2.5.1 lib/sym/app/private_key/handler.rb
sym-2.5.0 lib/sym/app/private_key/handler.rb
sym-2.4.3 lib/sym/app/private_key/handler.rb