module ResponseEncryption::EncryptAttributes

Public Class Methods

new(object, options) click to toggle source
Calls superclass method
# File lib/response_encryption/encrypt_attributes.rb, line 6
def initialize(object,  options)
  super(object, options)
  context = context_from(options)
  if ResponseEncryption.encrypted_attributes_strategy?
    raise(ActionController::ParameterMissing, 'You must to set the context for the resource/serializer') if context.blank?
    @encrypter = ResponseEncryption::SymmetricEncrypter.new(encoded_iv: context[:encoded_nonce], encoded_key: context[:encoded_symmetric_key])
    self.class.encrypt_attributes!(object)
  end
end

Public Instance Methods

cipher() click to toggle source
# File lib/response_encryption/encrypt_attributes.rb, line 33
def cipher
  ResponseEncryption.cipher
end
context_from(param) click to toggle source

Retrieve the context variable that will be send to the Serializer or Resource in order to pass some important variables. @param param [ Hash ] @return [ Hash ]

# File lib/response_encryption/encrypt_attributes.rb, line 20
def context_from(param)
  case ResponseEncryption.serializer_gem
  when :active_model_serializers
     raise "You must to set encoded_symmetric_key option in the context hash" if param[:context]&.slice(:encoded_symmetric_key).blank?
     param[:context]
  when :jsonapi_resources
    raise "You must to set encoded_symmetric_key option in the context hash" if param[:encoded_symmetric_key].blank?
    param
  when :none
    raise 'pending!!'
  end
end