Skip to content

Commit 63f7439

Browse files
Merge pull request rails#47322 from jonathanhefner/secure_compare_rotator-decouple-messages-rotator
Detach `Messages::Rotator` from `SecureCompareRotator`
2 parents bbffe63 + 9e5c7cf commit 63f7439

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

activesupport/lib/active_support/secure_compare_rotator.rb

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,28 @@ module ActiveSupport
2929
# end
3030
class SecureCompareRotator
3131
include SecurityUtils
32-
prepend Messages::Rotator
3332

3433
InvalidMatch = Class.new(StandardError)
3534

36-
def initialize(value, **_options)
35+
def initialize(value, on_rotation: nil)
3736
@value = value
37+
@rotate_values = []
38+
@on_rotation = on_rotation
3839
end
3940

40-
def secure_compare!(other_value, on_rotation: @on_rotation)
41-
secure_compare(@value, other_value) ||
42-
run_rotations(on_rotation) { |wrapper| wrapper.secure_compare!(other_value) } ||
43-
raise(InvalidMatch)
41+
def rotate(previous_value)
42+
@rotate_values << previous_value
4443
end
4544

46-
private
47-
def build_rotation(previous_value, **_options)
48-
self.class.new(previous_value)
45+
def secure_compare!(other_value, on_rotation: @on_rotation)
46+
if secure_compare(@value, other_value)
47+
true
48+
elsif @rotate_values.any? { |value| secure_compare(value, other_value) }
49+
on_rotation&.call
50+
true
51+
else
52+
raise InvalidMatch
4953
end
54+
end
5055
end
5156
end

0 commit comments

Comments
 (0)