Skip to content

Commit 2322e4d

Browse files
committed
Fix: work-around JRuby 9.2 autoload behavior
to be able to install jruby-openssl >= 0.12 on JRuby 9.2 while the default gem (shipped with JRuby) is < 0.12 GH-248
1 parent 478aee9 commit 2322e4d

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

lib/jopenssl/load.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,48 @@
3434
if RUBY_VERSION > '2.3'
3535
load 'jopenssl/_compat23.rb'
3636
end
37+
38+
# NOTE: content bellow should live in *lib/openssl.rb* but due RubyGems/Bundler
39+
# `autoload :OpenSSL` this will cause issues if an older version (0.11) is the
40+
# default gem under JRuby 9.2 (which on auto-load does not trigger a dynamic
41+
# require - this is only fixed in JRuby 9.3)
42+
43+
module OpenSSL
44+
autoload :Config, 'openssl/config' unless const_defined?(:Config, false)
45+
autoload :PKCS12, 'openssl/pkcs12'
46+
end
47+
48+
=begin
49+
= Info
50+
'OpenSSL for Ruby 2' project
51+
Copyright (C) 2002 Michal Rokos <[email protected]>
52+
All rights reserved.
53+
54+
= Licence
55+
This program is licensed under the same licence as Ruby.
56+
(See the file 'LICENCE'.)
57+
=end
58+
59+
require_relative 'openssl/bn'
60+
require_relative 'openssl/pkey'
61+
require_relative 'openssl/cipher'
62+
#require_relative 'openssl/config' if OpenSSL.const_defined?(:Config, false)
63+
require_relative 'openssl/digest'
64+
require_relative 'openssl/hmac'
65+
require_relative 'openssl/x509'
66+
require_relative 'openssl/ssl'
67+
require_relative 'openssl/pkcs5'
68+
69+
module OpenSSL
70+
# call-seq:
71+
# OpenSSL.secure_compare(string, string) -> boolean
72+
#
73+
# Constant time memory comparison. Inputs are hashed using SHA-256 to mask
74+
# the length of the secret. Returns +true+ if the strings are identical,
75+
# +false+ otherwise.
76+
def self.secure_compare(a, b)
77+
hashed_a = OpenSSL::Digest.digest('SHA256', a)
78+
hashed_b = OpenSSL::Digest.digest('SHA256', b)
79+
OpenSSL.fixed_length_secure_compare(hashed_a, hashed_b) && a == b
80+
end
81+
end

lib/openssl.rb

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,3 @@
11
# frozen_string_literal: true
22

33
require 'jopenssl/load'
4-
5-
module OpenSSL
6-
autoload :Config, 'openssl/config' unless const_defined?(:Config, false)
7-
autoload :PKCS12, 'openssl/pkcs12'
8-
end
9-
10-
=begin
11-
= Info
12-
'OpenSSL for Ruby 2' project
13-
Copyright (C) 2002 Michal Rokos <[email protected]>
14-
All rights reserved.
15-
16-
= Licence
17-
This program is licensed under the same licence as Ruby.
18-
(See the file 'LICENCE'.)
19-
=end
20-
21-
require_relative 'openssl/bn'
22-
require_relative 'openssl/pkey'
23-
require_relative 'openssl/cipher'
24-
#require_relative 'openssl/config' if OpenSSL.const_defined?(:Config, false)
25-
require_relative 'openssl/digest'
26-
require_relative 'openssl/hmac'
27-
require_relative 'openssl/x509'
28-
require_relative 'openssl/ssl'
29-
require_relative 'openssl/pkcs5'
30-
31-
module OpenSSL
32-
# call-seq:
33-
# OpenSSL.secure_compare(string, string) -> boolean
34-
#
35-
# Constant time memory comparison. Inputs are hashed using SHA-256 to mask
36-
# the length of the secret. Returns +true+ if the strings are identical,
37-
# +false+ otherwise.
38-
def self.secure_compare(a, b)
39-
hashed_a = OpenSSL::Digest.digest('SHA256', a)
40-
hashed_b = OpenSSL::Digest.digest('SHA256', b)
41-
OpenSSL.fixed_length_secure_compare(hashed_a, hashed_b) && a == b
42-
end
43-
end

0 commit comments

Comments
 (0)