luckyframework/avram

Add attribute encryption

Ouverte

#716 ouverte le 3 août 2021

 (5 commentaires) (1 réaction) (0 personne assignée)Crystal (67 forks)auto 404
feature requesthacktoberfest

Métriques du dépôt

Stars
 (180 étoiles)
Métriques de merge PR
 (Métriques PR en attente)

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.

Guide contributeur