class R509::Engine
a singleton class to store loaded OpenSSL
Engines
Public Class Methods
new()
click to toggle source
# File lib/r509/engine.rb, line 9 def initialize @engines = {} end
Public Instance Methods
[](key)
click to toggle source
Takes an engine ID and returns the engine object
# File lib/r509/engine.rb, line 25 def [](key) @engines[key] end
load(hash)
click to toggle source
@param hash Takes a hash with SO_PATH and ID @return OpenSSL::Engine object
# File lib/r509/engine.rb, line 15 def load(hash) validate_hash(hash) if @engines.key?(hash[:id]) @engines[hash[:id]] else init_engine(hash) end end
Private Instance Methods
init_engine(hash)
click to toggle source
# File lib/r509/engine.rb, line 31 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
validate_hash(hash)
click to toggle source
# File lib/r509/engine.rb, line 40 def validate_hash(hash) return unless !hash.respond_to?(:key?) || !hash.key?(:so_path) || !hash.key?(:id) raise ArgumentError, "You must supply a hash with both :so_path and :id" end