Sha256: a24bac8384ae3f3bf471fd46506f5b52422f57f4648771a882e14867eba5da9e
Contents?: true
Size: 1.02 KB
Versions: 1
Compression:
Stored size: 1.02 KB
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) validate_hash(hash) if @engines.has_key?(hash[:id]) @engines[hash[:id]] else init_engine(hash) end end # Takes an engine ID and returns the engine object def [](key) @engines[key] end private def init_engine(hash) 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 def validate_hash(hash) if not hash.respond_to?(:has_key?) or 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 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
r509-0.10.0 | lib/r509/engine.rb |