Class: Warden::CookieSession::EncryptedCookie
- Inherits:
-
Object
- Object
- Warden::CookieSession::EncryptedCookie
- Defined in:
- lib/warden/cookie_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(domain) ⇒ Object
- #get ⇒ Object
-
#initialize(store:, cookie:, secret:) ⇒ EncryptedCookie
constructor
A new instance of EncryptedCookie.
- #put(data, domain) ⇒ Object
Constructor Details
#initialize(store:, cookie:, secret:) ⇒ EncryptedCookie
Returns a new instance of EncryptedCookie.
5 6 7 8 9 10 11 12 |
# File 'lib/warden/cookie_session/encrypted_cookie.rb', line 5 def initialize(store:, cookie:, secret:) @store = store @cookie = @secret = secret raise ArgumentError.new('secret must be 32 bytes') if @secret.length != 32 @encryptor ||= ActiveSupport::MessageEncryptor.new(secret) end |
Instance Attribute Details
#cookie ⇒ Object (readonly)
Returns the value of attribute cookie.
3 4 5 |
# File 'lib/warden/cookie_session/encrypted_cookie.rb', line 3 def @cookie end |
#encryptor ⇒ Object (readonly)
Returns the value of attribute encryptor.
3 4 5 |
# File 'lib/warden/cookie_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/cookie_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/cookie_session/encrypted_cookie.rb', line 3 def store @store end |
Instance Method Details
#clear(domain) ⇒ Object
31 32 33 |
# File 'lib/warden/cookie_session/encrypted_cookie.rb', line 31 def clear(domain) store.delete(, domain: domain) end |
#get ⇒ Object
14 15 16 17 18 19 |
# File 'lib/warden/cookie_session/encrypted_cookie.rb', line 14 def get value = store[] return nil unless value JSON(encryptor.decrypt_and_verify(value)) end |
#put(data, domain) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/warden/cookie_session/encrypted_cookie.rb', line 21 def put(data, domain) store[] = { value: encryptor.encrypt_and_sign(data.to_json), domain: domain, secure: true, http_only: true, httponly: true } end |