Module: Roqs::Wrapper::ClassMethods

Includes:
TR::CondUtils
Defined in:
lib/roqs/wrapper.rb

Instance Method Summary collapse

Instance Method Details

#detect_osObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/roqs/wrapper.rb', line 17

def detect_os
  plat = RUBY_PLATFORM
  if plat =~ /linux/
    :linux
  elsif plat =~ /darwin/
    :macos
  elsif plat =~ /mingw/
    :windows
  else
    raise WrapperError, "Unknown platform detected. [#{plat}]"
  end
end

#load_arch_lib(os) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/roqs/wrapper.rb', line 30

def load_arch_lib(os) 
  plat = RUBY_PLATFORM
  pplat = plat.split('-')[0]
  logger.debug "OS architecture is #{pplat}"
  usrDrvDir = ENV['ROQS_LIBOQS_DIR']
  if not_empty?(usrDrvDir)
    logger.debug "Load liboqs shared library from user provided root : #{File.join(usrDrvDir, pplat)}" 
    drvDir = File.join(usrDrvDir,pplat)
  else
    logger.debug "Load liboqs shared library from Roqs internal root : #{File.join(File.dirname(__FILE__),"..","..","native","#{os}",pplat)}" 
    drvDir = File.join(File.dirname(__FILE__),"..","..","native","#{os}",pplat)
  end

  if File.exist?(drvDir)
    Dir.glob(File.join(drvDir,"liboqs*")) do |f|
      logger.debug "Loading liboqs at : #{f}"
      dlload f
    end
  else
    errMsg = []
    errMsg << "Shared library of liboqs (https://github.com/open-quantum-safe/liboqs) could not be found at '#{drvDir}'"
    errMsg << "You might need to compile for your platform."
    errMsg << "Simply follow the steps beflow:"
    errMsg << "1. Clone the repository at https://github.com/open-quantum-safe/liboqs"
    errMsg << "   > clone https://github.com/open-quantum-safe/liboqs liboqs"
    errMsg << "2. Make sure all pre-requisites are installed as documented here : https://github.com/open-quantum-safe/liboqs#quickstart"
    errMsg << "3. Run the following commands: "
    errMsg << "   > cd liboqs && mkdir build && cd build"
    errMsg << "   > cmake -GNinja .. -DBUILD_SHARED_LIBS=ON"
    errMsg << "   > ninja"
    errMsg << "4. Shared library shall be built under lib dir."
    errMsg << "5. Copy the shared library into '#{drvDir}' and you should be good to go"
    errMsg << "   Note: System shall read env variable 'ROQS_LIBOQS_DIR' to decide where to load the liboqs dynamic library from."
    errMsg << "         If no value is given, system shall load from default path : #{File.join(File.dirname(__FILE__),"..","..","native","#{os}",pplat)}"
    raise WrapperError, errMsg.join("\n")
  end
end

#load_oqs_libObject



11
12
13
14
15
# File 'lib/roqs/wrapper.rb', line 11

def load_oqs_lib
  os = detect_os
  logger.debug "Found OS #{os}"
  load_arch_lib(os)          
end

#loggerObject



68
69
70
# File 'lib/roqs/wrapper.rb', line 68

def logger
  Roqs.logger(:roqs_wrapper)
end