Sha256: 70d2891f2babfc51e5976b901b21f74c2e1530cb38c736af3d1910d88c18029f

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 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
        attr_writer :key

        def initialize(opts, input_handler)
          self.opts          = opts
          self.input_handler = input_handler
        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).key? && key.nil?
              raise e
            end
          end

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

          @key
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shhh-1.5.4 lib/shhh/app/private_key/handler.rb
shhh-1.4.1 lib/shhh/app/private_key/handler.rb
shhh-1.4.0 lib/shhh/app/private_key/handler.rb