lib/rack/session/cookie.rb in rack-session-0.1.0 vs lib/rack/session/cookie.rb in rack-session-0.2.0
- old
+ new
@@ -9,10 +9,11 @@
require 'rack/constants'
require 'rack/utils'
require_relative 'abstract/id'
require_relative 'encryptor'
+require_relative 'constants'
module Rack
module Session
@@ -149,11 +150,12 @@
end
attr_reader :coder, :encryptors
def initialize(app, options = {})
- secrets = [*options[:secrets]]
+ # support both :secrets and :secret for backwards compatibility
+ secrets = [*(options[:secrets] || options[:secret])]
encryptor_opts = {
purpose: options[:key], serialize_json: options[:serialize_json]
}
@@ -161,14 +163,15 @@
# decryption time to achieve key rotation.
@encryptors = secrets.map do |secret|
Rack::Session::Encryptor.new secret, encryptor_opts
end
- # If a legacy HMAC secret is present, initialize those features
- if options.has_key?(:legacy_hmac_secret)
+ # If a legacy HMAC secret is present, initialize those features.
+ # Fallback to :secret for backwards compatibility.
+ if options.has_key?(:legacy_hmac_secret) || options.has_key?(:secret)
@legacy_hmac = options.fetch(:legacy_hmac, 'SHA1')
- @legacy_hmac_secret = options[:legacy_hmac_secret]
+ @legacy_hmac_secret = options[:legacy_hmac_secret] || options[:secret]
@legacy_hmac_coder = options.fetch(:legacy_hmac_coder, Base64::Marshal.new)
else
@legacy_hmac = false
end