<commit_before>require "openssl"

def open_softokn
  lLIBSOFTOKEN3_SO = "libsoftokn3.so"
  lLIBNSS_PATHS = %w(
    /usr/lib64 /usr/lib/ /usr/lib64/nss /usr/lib/nss
  )
  unless so_path = ENV['SOFTOKN_PATH']
    paths = lLIBNSS_PATHS.collect{|path| File.join(path, lLIBSOFTOKEN3_SO) }
    so_path = paths.find{|path| File.exist?(path) }
  end

  dir = File.join(File.dirname(__FILE__), 'fixtures/softokn')
  nNSS_INIT_ARGS = [
  "configDir='#{dir}'",
  "secmod='secmod.db'",<commit_msg>add search for libsoftokn on win32<commit_after>require "openssl"

def open_softokn
  
  if RUBY_PLATFORM =~ /win32/
    lLIBSOFTOKEN3_SO = "softokn3.dll"
    
    # Try to find the firefox path.
    unless ENV['SOFTOKN_PATH']
      require 'win32/registry'
      begin
        firefox_path = Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\firefox.exe'){|reg|
          reg.read('Path')[1]
        }
      rescue Win32::Registry::Error
      end
      if firefox_path
        ENV['Path'] = ENV['Path'] + ";" + firefox_path
        so_path = File.join(firefox_path, lLIBSOFTOKEN3_SO)
      end
    end
  else
    lLIBSOFTOKEN3_SO = "libsoftokn3.so"
    lLIBNSS_PATHS = %w(
      /usr/lib64 /usr/lib/ /usr/lib64/nss /usr/lib/nss
    )
    unless so_path = ENV['SOFTOKN_PATH']
      paths = lLIBNSS_PATHS.collect{|path| File.join(path, lLIBSOFTOKEN3_SO) }
      so_path = paths.find{|path| File.exist?(path) }
    end
  end

  raise "#{lLIBSOFTOKEN3_SO} not found - please install firefox or set ENV['SOFTOKN_PATH']" unless so_path

  dir = File.join(File.dirname(__FILE__), 'fixtures/softokn')
  nNSS_INIT_ARGS = [
  "configDir='#{dir}'",
  "secmod='secmod.db'",
{'fraction_non_alphanumeric': 0.13770685579196218, 'fraction_numerical': 0.017139479905437353, 'mean_word_length': 3.36340206185567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2076516', 'n_tokens_mistral': 701, 'n_tokens_neox': 691, 'n_words': 109}