Class: Warden::SharedSession::EncryptedCookie
- Inherits:
-
Object
- Object
- Warden::SharedSession::EncryptedCookie
- Defined in:
- lib/warden/shared_session/encrypted_cookie.rb
Instance Attribute Summary collapse
-
#cookie ⇒ Object
readonly
Returns the value of attribute cookie.
-
#encryptor ⇒ Object
readonly
Returns the value of attribute encryptor.
-
#secret ⇒ Object
readonly
Returns the value of attribute secret.
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #clear ⇒ Object
- #get ⇒ Object
-
#initialize(store:, cookie:, secret:) ⇒ EncryptedCookie
constructor
A new instance of EncryptedCookie.
- #put(data) ⇒ Object
Constructor Details
#initialize(store:, cookie:, secret:) ⇒ EncryptedCookie
Returns a new instance of EncryptedCookie.
5 6 7 8 9 10 11 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 5 def initialize(store:, cookie:, secret:) @store = store @cookie = @secret = secret @encryptor ||= ActiveSupport::MessageEncryptor.new(secret) end |
Instance Attribute Details
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
3 4 5 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 3 def @cookie end |
#encryptor ⇒ Object (readonly)
Returns the value of attribute encryptor.
3 4 5 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 3 def encryptor @encryptor end |
#secret ⇒ Object (readonly)
Returns the value of attribute secret.
3 4 5 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 3 def secret @secret end |
#store ⇒ Object (readonly)
Returns the value of attribute store.
3 4 5 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 3 def store @store end |
Instance Method Details
#clear ⇒ Object
24 25 26 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 24 def clear store.delete() end |
#get ⇒ Object
13 14 15 16 17 18 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 13 def get value = store[] return nil unless value JSON(encryptor.decrypt_and_verify(value)) end |
#put(data) ⇒ Object
20 21 22 |
# File 'lib/warden/shared_session/encrypted_cookie.rb', line 20 def put(data) store[] = encryptor.encrypt_and_sign(data.to_json) end |