diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2015-09-06 17:49:12 +0200 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2015-09-08 20:27:04 +0200 |
commit | 94b313db8d672a57ad5deb63203e334fe1184b84 (patch) | |
tree | 5b5f8dd8295f5c4a6f93bdc3e82ee1402cb6dd72 /actionpack | |
parent | b807ac7a7a195df663bbc9dfba87d397936b50f0 (diff) | |
download | rails-94b313db8d672a57ad5deb63203e334fe1184b84.tar.gz rails-94b313db8d672a57ad5deb63203e334fe1184b84.tar.bz2 rails-94b313db8d672a57ad5deb63203e334fe1184b84.zip |
Add commit in the EncryptedCookieJar
Gets rid of the option parsing and makes what the encryptor does stand out.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/cookies.rb | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/cookies.rb b/actionpack/lib/action_dispatch/middleware/cookies.rb index bbfd46e891..d863d84a1c 100644 --- a/actionpack/lib/action_dispatch/middleware/cookies.rb +++ b/actionpack/lib/action_dispatch/middleware/cookies.rb @@ -541,12 +541,11 @@ module ActionDispatch end end - class EncryptedCookieJar #:nodoc: - include ChainedCookieJars + class EncryptedCookieJar < AbstractCookieJar # :nodoc: include SerializedCookieJars def initialize(parent_jar) - @parent_jar = parent_jar + super if ActiveSupport::LegacyKeyGenerator === key_generator raise "You didn't set secrets.secret_key_base, which is required for this cookie jar. " + @@ -566,22 +565,13 @@ module ActionDispatch end end - # Encrypts and sets the cookie named +name+. The second argument may be the cookie's - # value or a hash of options as documented above. - def []=(name, options) - if options.is_a?(Hash) - options.symbolize_keys! - else - options = { :value => options } - end - - options[:value] = @encryptor.encrypt_and_sign(serialize(options[:value])) + private + def commit(options) + options[:value] = @encryptor.encrypt_and_sign(serialize(options[:value])) - raise CookieOverflow if options[:value].bytesize > MAX_COOKIE_SIZE - @parent_jar[name] = options - end + raise CookieOverflow if options[:value].bytesize > MAX_COOKIE_SIZE + end - private def decrypt_and_verify(encrypted_message) @encryptor.decrypt_and_verify(encrypted_message) rescue ActiveSupport::MessageVerifier::InvalidSignature, ActiveSupport::MessageEncryptor::InvalidMessage |