Class: ActionDispatch::Cookies::SignedCookieJar

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

Overview

:nodoc:

Direct Known Subclasses

UpgradeLegacySignedCookieJar

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.



378
379
380
381
382
383
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 378

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)
end

Instance Method Details

#[](name) ⇒ Object



385
386
387
388
389
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 385

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

#[]=(name, options) ⇒ Object

Raises:



391
392
393
394
395
396
397
398
399
400
401
# File 'actionpack/lib/action_dispatch/middleware/cookies.rb', line 391

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

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