Sha256: 00aa8111b5650d2e39e20a515166e63131f9e48ca0edae36e8e92a381a0dffdf

Contents?: true

Size: 886 Bytes

Versions: 1

Compression:

Stored size: 886 Bytes

Contents

require 'singleton'
require 'openssl'

module R509
  # a singleton class to store loaded OpenSSL Engines
  class Engine
    include Singleton

    def initialize
      @engines = {}
    end

    # @param hash Takes a hash with SO_PATH and ID
    # @return OpenSSL::Engine object
    def load(hash)
      if not hash.has_key?("SO_PATH") or not hash.has_key?("ID")
        raise ArgumentError, "You must supply a hash with both SO_PATH and ID"
      end
      if @engines.has_key?(hash["ID"])
        @engines[hash["ID"]]
      else
        OpenSSL::Engine.load
        @engines[hash["ID"]] = OpenSSL::Engine.by_id("dynamic") do |e|
          e.ctrl_cmd("SO_PATH",hash["SO_PATH"])
          e.ctrl_cmd("ID",hash["ID"])
          e.ctrl_cmd("LOAD")
        end
      end
    end

    # Takes an engine ID and returns the engine object
    def [](key)
      @engines[key]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
r509-0.9.2 lib/r509/engine.rb