diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-11-12 23:13:01 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-11-12 23:13:01 -0800 |
commit | f4b44763fa6802543f7d1590719e5aed21e120cd (patch) | |
tree | 45fb389740f7a83f2d0de373d6b3d5253dc226f5 /examples | |
parent | 504ab0d4a4c402a90824aaf3c84ef21707e08ad5 (diff) | |
download | upr-f4b44763fa6802543f7d1590719e5aed21e120cd.tar.gz |
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
Diffstat (limited to 'examples')
-rw-r--r-- | examples/rails_app-2.3.4/config/initializers/ruby_19_compat.rb | 28 |
1 files changed, 7 insertions, 21 deletions
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] == "." |