Skip to content

Commit

Permalink
Replaces usage of Gem#loaded_specs with Object#const_defined? to requ…
Browse files Browse the repository at this point in the history
…ire OpenSSL +2.1. Replaces RequiredGemError with RequiredDependencyError
  • Loading branch information
Oliver committed Sep 13, 2018
1 parent 1d16558 commit df315b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 8 additions & 4 deletions lib/jwt/algos/ps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions lib/jwt/error.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit df315b5

Please sign in to comment.