File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed
activesupport/lib/active_support Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -29,23 +29,28 @@ module ActiveSupport
29
29
# end
30
30
class SecureCompareRotator
31
31
include SecurityUtils
32
- prepend Messages ::Rotator
33
32
34
33
InvalidMatch = Class . new ( StandardError )
35
34
36
- def initialize ( value , ** _options )
35
+ def initialize ( value , on_rotation : nil )
37
36
@value = value
37
+ @rotate_values = [ ]
38
+ @on_rotation = on_rotation
38
39
end
39
40
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
44
43
end
45
44
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
49
53
end
54
+ end
50
55
end
51
56
end
You can’t perform that action at this time.
0 commit comments