-
Jonathan Hefner authored
This commit adds a block form of `ActiveSupport::MessageEncryptors#rotate` and `ActiveSupport::MessageVerifiers#rotate`, which supports fine-grained per-salt rotation options. The block will receive a salt, and should return an appropriate options Hash. The block may also return `nil` to indicate that the rotation does not apply to the given salt. For example: ```ruby verifiers = ActiveSupport::MessageVerifiers.new { ... } verifiers.rotate(serializer: JSON, url_safe: true) verifiers.rotate do |salt| case salt when :foo { serializer: Marshal, url_safe: true } when :bar { serializer: Marshal, url_safe: false } end end # Uses `serializer: JSON, url_safe: true`. # Falls back to `serializer: Marshal, url_safe: true`. verifiers[:foo] # Uses `serializer: JSON, url_safe: true`. # Falls back to `serializer: Marshal, url_safe: false`. verifiers[:bar] # Uses `serializer: JSON, url_safe: true`. verifiers[:baz] ``` This can be particularly useful when migrating older configurations to a unified configuration.
Jonathan Hefner authoredThis commit adds a block form of `ActiveSupport::MessageEncryptors#rotate` and `ActiveSupport::MessageVerifiers#rotate`, which supports fine-grained per-salt rotation options. The block will receive a salt, and should return an appropriate options Hash. The block may also return `nil` to indicate that the rotation does not apply to the given salt. For example: ```ruby verifiers = ActiveSupport::MessageVerifiers.new { ... } verifiers.rotate(serializer: JSON, url_safe: true) verifiers.rotate do |salt| case salt when :foo { serializer: Marshal, url_safe: true } when :bar { serializer: Marshal, url_safe: false } end end # Uses `serializer: JSON, url_safe: true`. # Falls back to `serializer: Marshal, url_safe: true`. verifiers[:foo] # Uses `serializer: JSON, url_safe: true`. # Falls back to `serializer: Marshal, url_safe: false`. verifiers[:bar] # Uses `serializer: JSON, url_safe: true`. verifiers[:baz] ``` This can be particularly useful when migrating older configurations to a unified configuration.
Loading