class SymmetricEncryption::ActiveRecord::EncryptedAttribute

Attributes

compress[R]
encrypted_type[R]
random_iv[R]

Public Class Methods

new(random_iv: true, compress: false, type: :string) click to toggle source
# File lib/symmetric_encryption/active_record/encrypted_attribute.rb, line 4
def initialize(random_iv: true, compress: false, type: :string)
  @random_iv      = random_iv
  @compress       = compress
  @encrypted_type = type
end

Public Instance Methods

deserialize(value) click to toggle source
# File lib/symmetric_encryption/active_record/encrypted_attribute.rb, line 10
def deserialize(value)
  return if value.nil?

  SymmetricEncryption.decrypt(value, type: encrypted_type)
end
serialize(value) click to toggle source
# File lib/symmetric_encryption/active_record/encrypted_attribute.rb, line 16
def serialize(value)
  return if value.nil?

  SymmetricEncryption.encrypt(
    value,
    type:      encrypted_type,
    compress:  compress,
    random_iv: random_iv
  )
end

Private Instance Methods

cast_value(value) click to toggle source

Symmetric Encryption uses coercible gem to handle casting

# File lib/symmetric_encryption/active_record/encrypted_attribute.rb, line 30
def cast_value(value)
  value
end