diff --git a/lib/jwt/algos/ps.rb b/lib/jwt/algos/ps.rb index e0724741..864e7c2c 100644 --- a/lib/jwt/algos/ps.rb +++ b/lib/jwt/algos/ps.rb @@ -28,10 +28,14 @@ def verify(to_verify) end def require_openssl! - openssl_gem = Gem.loaded_specs['openssl'] - - unless openssl_gem && openssl_gem.version.release >= Gem::Version.new('2.1') - raise JWT::RequiredGemError, 'OpenSSL +2.1 is required to support RSASSA-PSS algorithms' + if Object.const_defined?('OpenSSL') + major, minor = OpenSSL::VERSION.split('.').first(2) + + unless major.to_i >= 2 && minor.to_i >= 1 + raise JWT::RequiredDependencyError, "You currently have OpenSSL #{OpenSSL::VERSION}. PS support requires >= 2.1" + end + else + raise JWT::RequiredDependencyError, 'PS signing requires OpenSSL +2.1' end end end diff --git a/lib/jwt/error.rb b/lib/jwt/error.rb index 0a72169f..bf63145b 100644 --- a/lib/jwt/error.rb +++ b/lib/jwt/error.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true module JWT - EncodeError = Class.new(StandardError) - DecodeError = Class.new(StandardError) - RequiredGemError = Class.new(StandardError) + EncodeError = Class.new(StandardError) + DecodeError = Class.new(StandardError) + RequiredDependencyError = Class.new(StandardError) VerificationError = Class.new(DecodeError) ExpiredSignature = Class.new(DecodeError)