Class: Phronomy::StateStore::Encryptor::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/state_store/encryptor/base.rb

Overview

Abstract base class for state encryption adapters.

Subclass and implement #encrypt and #decrypt to integrate any symmetric encryption scheme. Pass an instance to ActiveRecord via the +encryptor:+ argument.

Examples:

class MyEncryptor < Phronomy::StateStore::Encryptor::Base
  def encrypt(plaintext) = Base64.strict_encode64(plaintext.reverse)
  def decrypt(ciphertext) = Base64.strict_decode64(ciphertext).reverse
end

Direct Known Subclasses

ActiveSupport

Instance Method Summary collapse

Instance Method Details

#decrypt(ciphertext) ⇒ String

Decrypts a ciphertext string.

Parameters:

  • ciphertext (String)

    previously produced by #encrypt

Returns:

  • (String)

    the original plaintext

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/phronomy/state_store/encryptor/base.rb', line 28

def decrypt(ciphertext)
  raise NotImplementedError, "#{self.class}#decrypt is not implemented"
end

#encrypt(plaintext) ⇒ String

Encrypts a plaintext string.

Parameters:

  • plaintext (String)

    the JSON string produced by the state store

Returns:

  • (String)

    the encrypted ciphertext

Raises:

  • (NotImplementedError)


21
22
23
# File 'lib/phronomy/state_store/encryptor/base.rb', line 21

def encrypt(plaintext)
  raise NotImplementedError, "#{self.class}#encrypt is not implemented"
end