@@ -11,7 +11,7 @@ module Encryption
11
11
# It interacts with a KeyProvider for getting the keys, and delegate to
12
12
# ActiveRecord::Encryption::Cipher the actual encryption algorithm.
13
13
class Encryptor
14
- # The compressor to use for compressing the payload
14
+ # The compressor to use for compressing the payload.
15
15
attr_reader :compressor
16
16
17
17
# === Options
@@ -20,22 +20,22 @@ class Encryptor
20
20
# Defaults to +true+.
21
21
# * <tt>:compressor</tt> - The compressor to use.
22
22
# 1. If compressor is provided, it will be used.
23
- # 2. If not, it will use +ActiveRecord::Encryption.config.compressor+ which default value is +Zlib+.
23
+ # 2. If not, it will use +ActiveRecord::Encryption.config.compressor+, which default value is +Zlib+.
24
24
# If you want to use a custom compressor, it must respond to +deflate+ and +inflate+.
25
25
def initialize ( compress : true , compressor : nil )
26
26
@compress = compress
27
27
@compressor = compressor || ActiveRecord ::Encryption . config . compressor
28
28
end
29
29
30
- # Encrypts +clean_text+ and returns the encrypted result
30
+ # Encrypts +clean_text+ and returns the encrypted result.
31
31
#
32
32
# Internally, it will:
33
33
#
34
- # 1. Create a new ActiveRecord::Encryption::Message
35
- # 2. Compress and encrypt +clean_text+ as the message payload
34
+ # 1. Create a new ActiveRecord::Encryption::Message.
35
+ # 2. Compress and encrypt +clean_text+ as the message payload.
36
36
# 3. Serialize it with +ActiveRecord::Encryption.message_serializer+ (+ActiveRecord::Encryption::SafeMarshal+
37
- # by default)
38
- # 4. Encode the result with Base 64
37
+ # by default).
38
+ # 4. Encode the result with Base64.
39
39
#
40
40
# === Options
41
41
#
@@ -45,25 +45,25 @@ def initialize(compress: true, compressor: nil)
45
45
#
46
46
# [:cipher_options]
47
47
# Cipher-specific options that will be passed to the Cipher configured in
48
- # +ActiveRecord::Encryption.cipher+
48
+ # +ActiveRecord::Encryption.cipher+.
49
49
def encrypt ( clear_text , key_provider : default_key_provider , cipher_options : { } )
50
50
clear_text = force_encoding_if_needed ( clear_text ) if cipher_options [ :deterministic ]
51
51
52
52
validate_payload_type ( clear_text )
53
53
serialize_message build_encrypted_message ( clear_text , key_provider : key_provider , cipher_options : cipher_options )
54
54
end
55
55
56
- # Decrypts an +encrypted_text+ and returns the result as clean text
56
+ # Decrypts an +encrypted_text+ and returns the result as clean text.
57
57
#
58
58
# === Options
59
59
#
60
60
# [:key_provider]
61
61
# Key provider to use for the encryption operation. It will default to
62
- # +ActiveRecord::Encryption.key_provider+ when not provided
62
+ # +ActiveRecord::Encryption.key_provider+ when not provided.
63
63
#
64
64
# [:cipher_options]
65
65
# Cipher-specific options that will be passed to the Cipher configured in
66
- # +ActiveRecord::Encryption.cipher+
66
+ # +ActiveRecord::Encryption.cipher+.
67
67
def decrypt ( encrypted_text , key_provider : default_key_provider , cipher_options : { } )
68
68
message = deserialize_message ( encrypted_text )
69
69
keys = key_provider . decryption_keys ( message )
@@ -73,7 +73,7 @@ def decrypt(encrypted_text, key_provider: default_key_provider, cipher_options:
73
73
raise Errors ::Decryption
74
74
end
75
75
76
- # Returns whether the text is encrypted or not
76
+ # Returns whether the text is encrypted or not.
77
77
def encrypted? ( text )
78
78
deserialize_message ( text )
79
79
true
0 commit comments