mirror of https://github.com/rails/rails
Merge pull request #40429 from natematykiewicz/openssl_fixed_length_secure_compare
Speed up `ActiveSupport::SecurityUtils.fixed_length_secure_compare`
This commit is contained in:
commit
7eb855bfbc
|
@ -1,3 +1,8 @@
|
|||
* Speed up `ActiveSupport::SecurityUtils.fixed_length_secure_compare` by using
|
||||
`OpenSSL.fixed_length_secure_compare`, if available.
|
||||
|
||||
*Nate Matykiewicz*
|
||||
|
||||
* `ActiveSupport::Cache::MemCacheStore` now checks `ENV["MEMCACHE_SERVERS"]` before falling back to `"localhost:11211"` if configured without any addresses.
|
||||
|
||||
```ruby
|
||||
|
|
|
@ -6,6 +6,12 @@ module ActiveSupport
|
|||
#
|
||||
# The values compared should be of fixed length, such as strings
|
||||
# that have already been processed by HMAC. Raises in case of length mismatch.
|
||||
|
||||
if defined?(OpenSSL.fixed_length_secure_compare)
|
||||
def fixed_length_secure_compare(a, b)
|
||||
OpenSSL.fixed_length_secure_compare(a, b)
|
||||
end
|
||||
else
|
||||
def fixed_length_secure_compare(a, b)
|
||||
raise ArgumentError, "string length mismatch." unless a.bytesize == b.bytesize
|
||||
|
||||
|
@ -15,6 +21,7 @@ module ActiveSupport
|
|||
b.each_byte { |byte| res |= byte ^ l.shift }
|
||||
res == 0
|
||||
end
|
||||
end
|
||||
module_function :fixed_length_secure_compare
|
||||
|
||||
# Secure string comparison for strings of variable length.
|
||||
|
|
Loading…
Reference in New Issue