Class: ActionDispatch::Cookies::SignedCookieJar

Inherits:
Object
  • Object
show all
Includes:
ChainedCookieJars, SerializedCookieJars
Defined in:
lib/action_dispatch/middleware/cookies.rb

Overview

:nodoc:

Direct Known Subclasses

UpgradeLegacySignedCookieJar

Constant Summary

Constants included from SerializedCookieJars

ActionDispatch::Cookies::SerializedCookieJars::MARSHAL_SIGNATURE

Instance Method Summary collapse

Methods included from ChainedCookieJars

#encrypted, #permanent, #signed, #signed_or_encrypted

Constructor Details

#initialize(parent_jar, key_generator, options = {}) ⇒ SignedCookieJar

Returns a new instance of SignedCookieJar.



452
453
454
455
456
457
# File 'lib/action_dispatch/middleware/cookies.rb', line 452

def initialize(parent_jar, key_generator, options = {})
  @parent_jar = parent_jar
  @options = options
  secret = key_generator.generate_key(@options[:signed_cookie_salt])
  @verifier = ActiveSupport::MessageVerifier.new(secret, serializer: NullSerializer)
end

Instance Method Details

#[](name) ⇒ Object



459
460
461
462
463
# File 'lib/action_dispatch/middleware/cookies.rb', line 459

def [](name)
  if signed_message = @parent_jar[name]
    deserialize name, verify(signed_message)
  end
end

#[]=(name, options) ⇒ Object

Raises:



465
466
467
468
469
470
471
472
473
474
475
# File 'lib/action_dispatch/middleware/cookies.rb', line 465

def []=(name, options)
  if options.is_a?(Hash)
    options.symbolize_keys!
    options[:value] = @verifier.generate(serialize(name, options[:value]))
  else
    options = { :value => @verifier.generate(serialize(name, options)) }
  end

  raise CookieOverflow if options[:value].size > MAX_COOKIE_SIZE
  @parent_jar[name] = options
end