Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't define label when define MyApp.Encrypted.Binary #49

Closed
allanegidio opened this issue Dec 18, 2023 · 1 comment
Closed

can't define label when define MyApp.Encrypted.Binary #49

allanegidio opened this issue Dec 18, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@allanegidio
Copy link

Hello.

I'm trying to implement the same thing that we have during config MyApp.Vault.

For example:
I can have more than one cipher:
Keyword.put(config, :ciphers, [ default: {Cloak.Ciphers.AES.GCM, tag: "AES.GCM.V1", key: decode_env!("MY_KEY")}, two_factor_auth: {Cloak.Ciphers.AES.GCM, tag: "AES.GCM.V1", key: decode_env!("MY_SEC_KEY")} ])

If I use MyApp.Vault.encrypt("test", :two_factor_auth) I can choose which ciphers I want to use.
Unfortunately, I couldn't do the same thing during config a field on my Ecto Schema.

field(:two_factor_token, MyApp.Encrypted.Binary, label: :two_factor_auth)

There is this possibility? To choose which cipher my field should use?

@danielberkompas danielberkompas added the bug Something isn't working label Apr 6, 2024
@danielberkompas
Copy link
Owner

danielberkompas commented Apr 6, 2024

@allanegidio To do this, you'd need to define the :label in the field definition:

defmodule MyApp.Encrypted.TwoFactorBinary do
  use Cloak.Ecto.Binary, vault: MyApp.Vault, label: :two_factor_auth
end

Then use it in your field definition in your schema:

field(:two_factor_token, MyApp.Encrypted.TwoFactorBinary)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants