End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
OpenSSL.secure_compare
OpenSSL.secure_compare(string, string) → boolean
ext/openssl/lib/openssl.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/ext/openssl/lib/openssl.rb, line 32
def self.secure_compare(a, b)
hashed_a = OpenSSL::Digest.digest('SHA256', a)
hashed_b = OpenSSL::Digest.digest('SHA256', b)
OpenSSL.fixed_length_secure_compare(hashed_a, hashed_b) && a == b
end
Constant time memory comparison. Inputs are hashed using SHA-256 to mask the length of the secret. Returns true if the strings are identical, false otherwise.