Class: EncryptedCookies::EncryptedCookieJar
- Inherits:
-
ActionDispatch::Cookies::CookieJar
- Object
- ActionDispatch::Cookies::CookieJar
- EncryptedCookies::EncryptedCookieJar
- Defined in:
- lib/encrypted-cookies/encrypted_cookie_jar.rb
Overview
:nodoc:
Constant Summary collapse
- MAX_COOKIE_SIZE =
Cookies can typically store 4096 bytes.
4096
- SECRET_MIN_LENGTH =
Characters
30
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(key, options) ⇒ Object
-
#initialize(parent_jar, secret) ⇒ EncryptedCookieJar
constructor
A new instance of EncryptedCookieJar.
- #method_missing(method, *arguments, &block) ⇒ Object
Constructor Details
#initialize(parent_jar, secret) ⇒ EncryptedCookieJar
Returns a new instance of EncryptedCookieJar.
6 7 8 9 10 |
# File 'lib/encrypted-cookies/encrypted_cookie_jar.rb', line 6 def initialize(parent_jar, secret) ensure_secret_secure(secret) @parent_jar = parent_jar @encrypter = ActiveSupport::MessageEncryptor.new(secret) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
34 35 36 |
# File 'lib/encrypted-cookies/encrypted_cookie_jar.rb', line 34 def method_missing(method, *arguments, &block) @parent_jar.send(method, *arguments, &block) end |
Instance Method Details
#[](name) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/encrypted-cookies/encrypted_cookie_jar.rb', line 12 def [](name) if = @parent_jar[name] @encrypter.decrypt() end rescue ActiveSupport::MessageVerifier::InvalidSignature nil rescue ActiveSupport::MessageEncryptor::InvalidMessage nil end |
#[]=(key, options) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/encrypted-cookies/encrypted_cookie_jar.rb', line 22 def []=(key, ) if .is_a?(Hash) .symbolize_keys! [:value] = @encrypter.encrypt([:value]) else = { :value => @encrypter.encrypt() } end raise CookieOverflow if [:value].size > MAX_COOKIE_SIZE @parent_jar[key] = end |