Sha256: 6311a6c662def9641fb44277c133ac25c9fe960496a086e6ad8a345a9aec51ff

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'hashie/extensions/indifferent_access'
require 'hashie/extensions/method_access'
require 'openssl'

module InlineEncryption

  # known configuration variables
  # key - a String containing the private key, a filename pointing to the private key, or an OpenSSL::PKey::RSA
  class Config < Hash
    include Hashie::Extensions::IndifferentAccess
    include Hashie::Extensions::MethodAccess

    # checks required, currently only the 'key'
    # @raises [InlineEncryption::MissingRequiredVariableError] raise on a missing variable
    def check_required_variables
      raise MissingRequiredVariableError.new("missing variable: 'key'") unless self.has_key?(:key)
    end


    # @return [OpenSSL::PKey::RSA] the OpenSSL key instance
    def real_key
      case self[:key]
        when NilClass
          nil
        when String
          if File.exists?(self[:key])
            OpenSSL::PKey::RSA.new(File.read(self[:key]))
          else
            OpenSSL::PKey::RSA.new(self[:key])
          end
        when OpenSSL::PKey::RSA
          self[:key]
      end
    end
  end


end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
inline_encryption-0.0.6 lib/inline_encryption/config.rb