Sha256: 596443884f6e789e0e31416f6a0a75d089615a5dec9edba82fd695a31c15ce08

Contents?: true

Size: 690 Bytes

Versions: 3

Compression:

Stored size: 690 Bytes

Contents

class Warden::CookieSession::EncryptedCookie

  attr_reader :store, :cookie, :secret, :encryptor

  def initialize(store:, cookie:, secret:)
    @store = store
    @cookie = cookie
    @secret = secret
    raise ArgumentError.new('secret must be 32 bytes') if @secret.length != 32

    @encryptor ||= ActiveSupport::MessageEncryptor.new(secret)
  end

  def get
    value = store[cookie]
    return nil unless value

    JSON(encryptor.decrypt_and_verify(value))
  end

  def put(data, domain)
    c = {
      value:  encryptor.encrypt_and_sign(data.to_json),
      domain: domain
    }

    store[cookie] = c
  end

  def clear(domain)
    store.delete(cookie, domain: domain)
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
warden_cookie_session-0.1.2.19245 lib/warden/cookie_session/encrypted_cookie.rb
warden_cookie_session-0.1.2.19222 lib/warden/cookie_session/encrypted_cookie.rb
warden_cookie_session-0.1.1.19161 lib/warden/cookie_session/encrypted_cookie.rb