diff --git a/Gemfile b/Gemfile index 4c20fef..984e9bc 100644 --- a/Gemfile +++ b/Gemfile @@ -14,7 +14,7 @@ gem 'ffi' group :development do gem 'rake' - gem 'rspec' + gem 'rspec', '~> 2.99.0' gem 'jruby-openssl', :platforms => :jruby end diff --git a/krypt.gemspec b/krypt.gemspec index 77757d6..e2bb68c 100644 --- a/krypt.gemspec +++ b/krypt.gemspec @@ -1,5 +1,5 @@ -lib = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) +$:.unshift File.expand_path('../lib', __FILE__) + require 'krypt/version' Gem::Specification.new do |s| diff --git a/lib/krypt/provider.rb b/lib/krypt/provider.rb index 7def12e..93fa93c 100644 --- a/lib/krypt/provider.rb +++ b/lib/krypt/provider.rb @@ -1,8 +1,26 @@ require_relative 'provider/provider' +## +# If JRuby is configured with native API access disabled, requiring the FFI +# provider will result in a LoadError. The FFI provider is not required at +# runtime as there is always a default (Java-based) provider. +# + +def java? + !! (RUBY_PLATFORM =~ /java/) +end + +def native_disabled? + require 'jruby' + !JRuby.runtime.instance_config.native_enabled +end + begin require_relative 'provider/ffi' rescue LoadError => e - # cf. https://github.com/krypt/krypt/issues/47 - warn "FFI provider could not be loaded. Error message: #{e}" + if java? && native_disabled? + # Do not use the FFI provider with JRuby and native API access disabled + else + raise e + end end diff --git a/lib/krypt/version.rb b/lib/krypt/version.rb index 895abc7..65f8128 100644 --- a/lib/krypt/version.rb +++ b/lib/krypt/version.rb @@ -1,3 +1,3 @@ module Krypt - VERSION = "0.0.2.rc1" + VERSION = "0.0.2" end