luckyframework/avram

Add attribute encryption

Aperta

#716 aperta il 3 ago 2021

 (5 commenti) (1 reazione) (0 assegnatari)Crystal (67 fork)auto 404
feature requesthacktoberfest

Metriche repository

Star
 (180 stelle)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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.

Guida contributor