Sha256: f2aea64850c8328b32e1d7ff213cfec1e70f751153b29381c50ee6e07d9e8ff0

Contents?: true

Size: 754 Bytes

Versions: 1

Compression:

Stored size: 754 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)
    store[cookie] = {
      value:     encryptor.encrypt_and_sign(data.to_json),
      domain:    domain,
      secure:    true,
      http_only: true,
      httponly:  true
    }
  end

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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
warden_cookie_session-0.1.2.19275 lib/warden/cookie_session/encrypted_cookie.rb