Class: ActionDispatch::Cookies::EncryptedCookieJar
- Inherits:
-
Object
- Object
- ActionDispatch::Cookies::EncryptedCookieJar
- Includes:
- ChainedCookieJars, SerializedCookieJars
- Defined in:
- lib/action_dispatch/middleware/cookies.rb
Overview
:nodoc:
Direct Known Subclasses
Constant Summary
Constants included from SerializedCookieJars
SerializedCookieJars::MARSHAL_SIGNATURE
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, options) ⇒ Object
-
#initialize(parent_jar, key_generator, options = {}) ⇒ EncryptedCookieJar
constructor
A new instance of EncryptedCookieJar.
Methods included from ChainedCookieJars
#encrypted, #permanent, #signed, #signed_or_encrypted
Constructor Details
#initialize(parent_jar, key_generator, options = {}) ⇒ EncryptedCookieJar
Returns a new instance of EncryptedCookieJar.
503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/action_dispatch/middleware/cookies.rb', line 503 def initialize(parent_jar, key_generator, = {}) if ActiveSupport::LegacyKeyGenerator === key_generator raise "You didn't set secrets.secret_key_base, which is required for this cookie jar. " + "Read the upgrade documentation to learn more about this new config option." end @parent_jar = parent_jar @options = secret = key_generator.generate_key(@options[:encrypted_cookie_salt]) sign_secret = key_generator.generate_key(@options[:encrypted_signed_cookie_salt]) @encryptor = ActiveSupport::MessageEncryptor.new(secret, sign_secret, serializer: NullSerializer) end |
Instance Method Details
#[](name) ⇒ Object
516 517 518 519 520 |
# File 'lib/action_dispatch/middleware/cookies.rb', line 516 def [](name) if = @parent_jar[name] deserialize name, decrypt_and_verify() end end |
#[]=(name, options) ⇒ Object
522 523 524 525 526 527 528 529 530 531 532 533 |
# File 'lib/action_dispatch/middleware/cookies.rb', line 522 def []=(name, ) if .is_a?(Hash) .symbolize_keys! else = { :value => } end [:value] = @encryptor.encrypt_and_sign(serialize(name, [:value])) raise CookieOverflow if [:value].size > MAX_COOKIE_SIZE @parent_jar[name] = end |