Sha256: 3326bca46dab33385981dcc18480622e48c97758dad2e634c97c47f8878f5a86

Contents?: true

Size: 1.94 KB

Versions: 12

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require_relative 'firebug/version'
require_relative 'firebug/crypto'
require_relative 'firebug/serializer'
require_relative 'firebug/unserializer'
require_relative 'firebug/configuration'
require_relative 'action_dispatch/session/code_igniter_store'

module Firebug
  class << self
    attr_writer :configuration
  end

  # @return [Firebug::Configuration]
  def self.configuration
    @configuration ||= Configuration.new
  end

  # @yieldparam [Firebug::Configuration] config
  def self.configure
    yield configuration
  end

  # Serialize a ruby object into a PHP serialized string.
  #
  # @param [Object] value
  # @return [String]
  def self.serialize(value)
    Serializer.parse(value)
  end

  # Unserialize a PHP serialized string into a ruby object.
  #
  # @param [String] value
  # @return [Object]
  def self.unserialize(value)
    Unserializer.parse(value)
  end

  # Encrypt data the way CodeIgniter does.
  #
  # @param [Object] data
  # @param [String] key if `nil` use +Firebug::Configuration.key+
  def self.encrypt(data, key=nil)
    key = configuration.key if key.nil?
    Crypto.new(key).encrypt(data)
  end

  # Decrypt data encrypted using CodeIgniters encryption.
  #
  # @param [Object] data
  # @param [String] key if `nil` use +Firebug::Configuration.key+
  def self.decrypt(data, key=nil)
    key = configuration.key if key.nil?
    Crypto.new(key).decrypt(data)
  end

  # Serializes, encrypts, and base64 encodes the data.
  #
  # @param [Object] data
  # @return [String] a base64 encoded string
  def self.encrypt_cookie(data)
    Base64.strict_encode64(Firebug.encrypt(Firebug.serialize(data)))
  end

  # Decodes the base64 encoded string, decrypts, and unserializes.
  #
  # @param [String] data a base64 encoded encrypted string
  # @return [Object] the unserialized data
  def self.decrypt_cookie(data)
    return {} if data.nil?
    Firebug.unserialize(Firebug.decrypt(Base64.strict_decode64(data)))
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
firebug-0.1.10 lib/firebug.rb
firebug-0.1.9 lib/firebug.rb
firebug-0.1.8 lib/firebug.rb
firebug-0.1.7 lib/firebug.rb
firebug-0.1.6 lib/firebug.rb
firebug-0.1.5 lib/firebug.rb
firebug-0.1.4 lib/firebug.rb
firebug-0.1.3 lib/firebug.rb
firebug-0.1.2 lib/firebug.rb
firebug-0.1.1 lib/firebug.rb
firebug-0.1.0 lib/firebug.rb
firebug-0.0.7 lib/firebug.rb