luckyframework/avram

Add attribute encryption

Open

#716 opened on Aug 3, 2021

View on GitHub
 (5 comments) (1 reaction) (0 assignees)Crystal (67 forks)auto 404
feature requesthacktoberfest

Repository metrics

Stars
 (180 stars)
PR merge metrics
 (PR metrics pending)

Description

The lucky_encrypted shard depends heavily on Lucky and Avram. I'm wondering if it wouldn't have a better place in Avram. It's tiny, literally just one file, and I strongly believe this type of functionality belongs there. Rails 7 will have it (https://github.com/rails/rails/pull/41659), so why not Lucky?

I'd propose to keep it simple and extend functionality when and if required. So starting with something like:

module Avram
  module Encrypted
    class String
      include Lucky::AllowedInTags
      ...

      module Lucky
        include Avram::Type
        ...
      end
    end
  end
end

Then usage would be:

class User < BaseModel
  table do
    column email : Encrypted::String
  end
end

That would leave the door open to add more encrypted types later on. Just like Andrew Kane's Lockbox gem allows:

class User < BaseModel
  table do
    column email : Encrypted::String
    column age : Encrypted::Int16
    column married_at : Encrypted::Time
    column settings : Encrypted::JSON
    ...
  end
end

I'd also use a dedicated encryption key for easier key rotation. And key rotation itself is something that we can implement later.

Contributor guide