Class: ActionDispatch::Session::EncryptedCookieStore

Inherits:
CookieStore
  • Object
show all
Defined in:
lib/encrypted_cookie_store.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ EncryptedCookieStore

Returns a new instance of EncryptedCookieStore.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/encrypted_cookie_store.rb', line 16

def initialize(app, options = {})
  @logger = options.delete(:logger)
  @digest = options.delete(:digest) || 'SHA1'

  @compress = options[:compress]
  @compress = true if @compress.nil?

  @secret = options.delete(:secret)
  @secret = @secret.call if @secret.respond_to?(:call)
  @secret.freeze
  @encryption_key = unhex(@secret).freeze
  ensure_encryption_key_secure

  @data_cipher = OpenSSL::Cipher::Cipher.new(EncryptedCookieStore.data_cipher_type)
  options[:refresh_interval] ||= 5.minutes

  super(app, options)
end

Class Attribute Details

.data_cipher_typeObject

Returns the value of attribute data_cipher_type.



12
13
14
# File 'lib/encrypted_cookie_store.rb', line 12

def data_cipher_type
  @data_cipher_type
end

Instance Method Details

overrides method in ActionDispatch::Session::CookieStore



49
50
51
# File 'lib/encrypted_cookie_store.rb', line 49

def cookie_jar(request)
  request.cookie_jar
end

#fetch_header(env, key, &block) ⇒ Object



40
41
42
# File 'lib/encrypted_cookie_store.rb', line 40

def fetch_header(req, key, &block)
  req.fetch_header(key, &block)
end

#get_header(env, key) ⇒ Object



36
37
38
# File 'lib/encrypted_cookie_store.rb', line 36

def get_header(req, key)
  req.get_header(key)
end

#load_session(req) ⇒ Object

overrides method in Rack::Session::Cookie



77
78
79
80
81
82
# File 'lib/encrypted_cookie_store.rb', line 77

def load_session(req)
  if time = timestamp(req)
    fetch_header(req, 'encrypted_cookie_store.session_refreshed_at') { |k| set_header(req, k, Time.at(time).utc) }
  end
  super
end

#set_header(env, key, value) ⇒ Object



44
45
46
# File 'lib/encrypted_cookie_store.rb', line 44

def set_header(req, key, value)
  req.set_header(key, value)
end