一个 ActiveModel::Type::Value,用于加密/解密文本字符串。
这是连接加密系统与模型类中 encrypts 声明的核心部分。每当您将一个属性声明为已加密时,它都会为该属性配置一个 EncryptedAttributeType。
方法
包含的模块
Attributes
| [R] | cast_type | |
| [R] | scheme |
类公共方法
new(scheme:, cast_type: ActiveModel::Type::String.new, previous_type: false, default: nil) 链接
选项¶ ↑
-
:scheme- 一个Scheme,包含此属性的加密属性。 -
:cast_type- 用于序列化(加密前)和反序列化(解密后)的类型。默认为ActiveModel::Type::String。
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 23 def initialize(scheme:, cast_type: ActiveModel::Type::String.new, previous_type: false, default: nil) super() @scheme = scheme @cast_type = cast_type @previous_type = previous_type @default = default end
实例公共方法
cast(value) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 31 def cast(value) cast_type.cast(value) end
changed_in_place?(raw_old_value, new_value) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 51 def changed_in_place?(raw_old_value, new_value) old_value = raw_old_value.nil? ? nil : deserialize(raw_old_value) old_value != new_value end
deserialize(value) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 35 def deserialize(value) cast_type.deserialize decrypt(value) end
encrypted?(value) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 47 def encrypted?(value) with_context { encryptor.encrypted? value } end
serialize(value) 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 39 def serialize(value) if serialize_with_oldest? serialize_with_oldest(value) else serialize_with_current(value) end end
support_unencrypted_data?() 链接
来源: 显示 | 在 GitHub 上
# File activerecord/lib/active_record/encryption/encrypted_attribute_type.rb, line 61 def support_unencrypted_data? scheme.support_unencrypted_data? && !previous_type? end