Class: ActiveRecordStringEncryption::EncryptString
- Inherits:
-
ActiveRecord::Type::String
- Object
- ActiveRecord::Type::String
- ActiveRecordStringEncryption::EncryptString
- Defined in:
- lib/active_record_string_encryption/encrypt_string.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#deserialize(value) ⇒ Object
ActiveRecord calls ‘deserialize` to convert values stored database to Ruby objects.
-
#serialize(value) ⇒ Object
ActiveRecord calls ‘serialize` to convert Ruby objects to a format that can be understood by database.
Class Method Details
.key_len ⇒ Object
6 7 8 |
# File 'lib/active_record_string_encryption/encrypt_string.rb', line 6 def key_len ActiveSupport::MessageEncryptor.key_len(ActiveRecordStringEncryption.configuration.cipher_alg) end |
Instance Method Details
#deserialize(value) ⇒ Object
ActiveRecord calls ‘deserialize` to convert values stored database to Ruby objects
20 21 22 23 24 25 |
# File 'lib/active_record_string_encryption/encrypt_string.rb', line 20 def deserialize(value) # expects same behavior as ActiveRecord::Type::String other than decryption # https://github.com/rails/rails/blob/5-0-stable/activemodel/lib/active_model/type/value.rb#L21-L23 v = super(value) encryptor.decrypt_and_verify(v) if v.present? end |
#serialize(value) ⇒ Object
ActiveRecord calls ‘serialize` to convert Ruby objects to a format that can be understood by database
12 13 14 15 16 17 |
# File 'lib/active_record_string_encryption/encrypt_string.rb', line 12 def serialize(value) # expects same behavior as ActiveRecord::Type::String other than encryption # https://github.com/rails/rails/blob/5-0-stable/activemodel/lib/active_model/type/immutable_string.rb v = super(value) encryptor.encrypt_and_sign(v) if v.present? end |