Skip to content

Commit

Permalink
Revert "ruby 1.9 friendly secure_compare" because it breaks CI and Sa…
Browse files Browse the repository at this point in the history
…m Ruby's suite

This reverts commit 5de7539.
  • Loading branch information
wycats committed Sep 12, 2009
1 parent 7152a4e commit a8a336c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions activesupport/lib/active_support/message_verifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,24 @@ def generate(value)
end

private
if "foo".respond_to?(:bytesize)
if "foo".respond_to?(:force_encoding)
# constant-time comparison algorithm to prevent timing attacks
# > 1.8.6 friendly version
def secure_compare(a, b)
if a.bytesize == b.bytesize
a = a.force_encoding(Encoding::BINARY)
b = b.force_encoding(Encoding::BINARY)

if a.length == b.length
result = 0
j = b.each_byte
a.each_byte { |i| result |= i ^ j.next }
for i in 0..(a.length - 1)
result |= a[i].ord ^ b[i].ord
end
result == 0
else
false
end
end
else
# For <= 1.8.6
# For 1.8
def secure_compare(a, b)
if a.length == b.length
result = 0
Expand Down

0 comments on commit a8a336c

Please sign in to comment.