You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So before the application I am working with was using attr_encrypted when it was rails 6. It also called encrypted_attributes in places. I converted the decorators over to attribute as per the docs which does call into lib/symmetric_encryption/active_record/encrypted_attribute.rb as expected but nothing appears to be encrypted. Also I can set a type option for the attribute but it doesn't come through in the constructor for EncryptedAttribute. I have a validation on it and I get an error that the value is not encrypted with symmetric_encryption.
The error I get from validation is #<ActiveModel::Error attribute=encrypted_token_verification_key, type=must be a value encrypted using SymmetricEncryption.encrypt, options={}>
As you can see the database fields use the prefix encrypted_ from when this used the previous system. So I added methods to handle this.
def token_verification_key=(token_verification_key)
self.encrypted_token_verification_key = token_verification_key;
end
def token_verification_key
encrypted_token_verification_key
end
However I would like to do this by autogenerating the method for any model I need to in a concern for instance. We would like to avoid having to do a migration to change these columns in the database. So my questions are.
Why would this validation fail? Am I missing something?
How do I discover encrypted fields in a model so I can autogenerate these getters and setters when needed?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
So before the application I am working with was using
attr_encrypted
when it was rails 6. It also calledencrypted_attributes
in places. I converted the decorators over toattribute
as per the docs which does call intolib/symmetric_encryption/active_record/encrypted_attribute.rb
as expected but nothing appears to be encrypted. Also I can set atype
option for the attribute but it doesn't come through in the constructor forEncryptedAttribute
. I have a validation on it and I get an error that the value is not encrypted with symmetric_encryption.model:
The error I get from validation is
#<ActiveModel::Error attribute=encrypted_token_verification_key, type=must be a value encrypted using SymmetricEncryption.encrypt, options={}>
As you can see the database fields use the prefix
encrypted_
from when this used the previous system. So I added methods to handle this.However I would like to do this by autogenerating the method for any model I need to in a concern for instance. We would like to avoid having to do a migration to change these columns in the database. So my questions are.
Beta Was this translation helpful? Give feedback.
All reactions