3434if RUBY_VERSION > '2.3'
3535 load 'jopenssl/_compat23.rb'
3636end
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
0 commit comments