From f4b44763fa6802543f7d1590719e5aed21e120cd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 12 Nov 2009 23:13:01 -0800 Subject: example/rails_app-2.3.4: limit compat 1.9 to only 1.9 Not 1.8.7, too, since 1.8.7 strings respond to :bytesize each_byte iterators and j.next seem to make 1.8.7 unhappy --- .../config/initializers/ruby_19_compat.rb | 28 ++++++---------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'examples/rails_app-2.3.4/config') diff --git a/examples/rails_app-2.3.4/config/initializers/ruby_19_compat.rb b/examples/rails_app-2.3.4/config/initializers/ruby_19_compat.rb index 82987f4..2cfab6c 100644 --- a/examples/rails_app-2.3.4/config/initializers/ruby_19_compat.rb +++ b/examples/rails_app-2.3.4/config/initializers/ruby_19_compat.rb @@ -12,29 +12,15 @@ module ActiveSupport # constant-time comparison algorithm to prevent timing attacks def secure_compare(a, b) - if a.respond_to?(:bytesize) - # > 1.8.6 friendly version - if a.bytesize == b.bytesize - result = 0 - j = b.each_byte - a.each_byte { |i| result |= i ^ j.next } - result == 0 - else - false - end + if a.bytesize == b.bytesize + result = 0 + j = b.each_byte + a.each_byte { |i| result |= i ^ j.next } + result == 0 else - # <= 1.8.6 friendly version - if a.size == b.size - result = 0 - for i in 0..(a.length - 1) - result |= a[i] ^ b[i] - end - result == 0 - else - false - end + false end end end -end if Rails::VERSION::STRING == "2.3.4" && String.method_defined?(:bytesize) +end if Rails::VERSION::STRING == "2.3.4" && "."[0] == "." -- cgit v1.2.3-24-ge0c7