Sha256: 72173bdd2fc2666db766af544d4bd38bd6e4b62be14f8c35a33860bc5e7da844

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

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

        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 Shhh::Errors::Error => e
            if Shhh::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

1 entries across 1 versions & 1 rubygems

Version Path
shhh-1.7.0 lib/shhh/app/private_key/handler.rb