Class: R509::Engine

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/r509/engine.rb

Overview

a singleton class to store loaded OpenSSL Engines

Instance Method Summary (collapse)

Constructor Details

- (Engine) initialize

A new instance of Engine



9
10
11
# File 'lib/r509/engine.rb', line 9

def initialize
  @engines = {}
end

Instance Method Details

- (Object) [](key)

Takes an engine ID and returns the engine object



32
33
34
# File 'lib/r509/engine.rb', line 32

def [](key)
  @engines[key]
end

- (Object) load(hash)

OpenSSL::Engine object

Parameters:

  • hash

    Takes a hash with SO_PATH and ID

Returns:

  • OpenSSL::Engine object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/r509/engine.rb', line 15

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