attr_encrypted 1.4.0 → 3.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIDdDCCAlygAwIBAgIBATANBgkqhkiG9w0BAQUFADBAMRIwEAYDVQQDDAlzYWdo
3
+ YXVsb3IxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
4
+ bTAeFw0xNjAxMTEyMjQyMDFaFw0xNzAxMTAyMjQyMDFaMEAxEjAQBgNVBAMMCXNh
5
+ Z2hhdWxvcjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYD
6
+ Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx0xdQYk2GwCpQ1n/
7
+ n2mPVYHLYqU5TAn/82t5kbqBUWjbcj8tHAi41tJ19+fT/hH0dog8JHvho1zmOr71
8
+ ZIqreJQo60TqP6oE9a5HncUpjqbRp7tOmHo9E+mOW1yT4NiXqFf1YINExQKy2XND
9
+ WPQ+T50ZNUsGMfHFWB4NAymejRWXlOEY3bvKW0UHFeNmouP5he51TjoP8uCc9536
10
+ 4AIWVP/zzzjwrFtC7av7nRw4Y+gX2bQjrkK2k2JS0ejiGzKBIEMJejcI2B+t79zT
11
+ kUQq9SFwp2BrKSIy+4kh4CiF20RT/Hfc1MbvTxSIl/bbIxCYEOhmtHExHi0CoCWs
12
+ YCGCXQIDAQABo3kwdzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU
13
+ SCpVzSBvYbO6B3oT3n3RCZmurG8wHgYDVR0RBBcwFYETc2FnaGF1bG9yQGdtYWls
14
+ LmNvbTAeBgNVHRIEFzAVgRNzYWdoYXVsb3JAZ21haWwuY29tMA0GCSqGSIb3DQEB
15
+ BQUAA4IBAQAeiGdC3e0WiZpm0cF/b7JC6hJYXC9Yv9VsRAWD9ROsLjFKwOhmonnc
16
+ +l/QrmoTjMakYXBCai/Ca3L+k5eRrKilgyITILsmmFxK8sqPJXUw2Jmwk/dAky6x
17
+ hHKVZAofT1OrOOPJ2USoZyhR/VI8epLaD5wUmkVDNqtZWviW+dtRa55aPYjRw5Pj
18
+ wuj9nybhZr+BbEbmZE//2nbfkM4hCuMtxxxilPrJ22aYNmeWU0wsPpDyhPYxOUgU
19
+ ZjeLmnSDiwL6doiP5IiwALH/dcHU67ck3NGf6XyqNwQrrmtPY0mv1WVVL4Uh+vYE
20
+ kHoFzE2no0BfBg78Re8fY69P5yES5ncC
21
+ -----END CERTIFICATE-----
@@ -0,0 +1 @@
1
+ 845fc3cb09a19c3ac76192aba443788f92c880744617bca99b16fd31ce843e07
@@ -0,0 +1 @@
1
+ 81a065442258cc3702aab62c7b2307a48ed3e0deb803600d11a7480cce0db7c43fd9929acd2755081042f8989236553fd694b6cb62776bbfc53f9165a22cbca1
@@ -0,0 +1 @@
1
+ 33140af4b223177db7a19efb2fa38472a299a745b29ca1c5ba9d3fa947390b77
@@ -0,0 +1 @@
1
+ 0c467cab98b9b2eb331f9818323a90ae01392d6cb03cf1f32faccc954d0fc54be65f0fc7bf751b0fce57925eef1c9e2af90181bc40d81ad93e21d15a001c53c6
@@ -0,0 +1 @@
1
+ c1256b459336d4a2012a0d0c70ce5cd3dac46acb5e78da6f77f6f104cb1e8b7b
@@ -0,0 +1 @@
1
+ dca0c8a729974c0e26fde4cd4216c7d0f66d9eca9f6cf0ccca64999f5180a00bf7c05b630c1d420ec1673141a2923946e8bd28b12e711faf64a4cd42c7a3ac9e
@@ -6,21 +6,20 @@ if defined?(ActiveRecord::Base)
6
6
  base.class_eval do
7
7
 
8
8
  # https://github.com/attr-encrypted/attr_encrypted/issues/68
9
- def reload_with_attr_encrypted(*args, &block)
9
+ alias_method :reload_without_attr_encrypted, :reload
10
+ def reload(*args, &block)
10
11
  result = reload_without_attr_encrypted(*args, &block)
11
12
  self.class.encrypted_attributes.keys.each do |attribute_name|
12
13
  instance_variable_set("@#{attribute_name}", nil)
13
14
  end
14
15
  result
15
16
  end
16
- alias_method_chain :reload, :attr_encrypted
17
17
 
18
18
  attr_encrypted_options[:encode] = true
19
19
 
20
20
  class << self
21
- alias_method :attr_encryptor, :attr_encrypted
22
- alias_method_chain :method_missing, :attr_encrypted
23
- alias_method :undefine_attribute_methods, :reset_column_information if ::ActiveRecord::VERSION::STRING < "3"
21
+ alias_method :method_missing_without_attr_encrypted, :method_missing
22
+ alias_method :method_missing, :method_missing_with_attr_encrypted
24
23
  end
25
24
 
26
25
  def perform_attribute_assignment(method, new_attributes, *args)
@@ -31,17 +30,17 @@ if defined?(ActiveRecord::Base)
31
30
  end
32
31
  private :perform_attribute_assignment
33
32
 
34
- if ::ActiveRecord::VERSION::STRING < "3.0" || ::ActiveRecord::VERSION::STRING > "3.1"
35
- def assign_attributes_with_attr_encrypted(*args)
33
+ if ::ActiveRecord::VERSION::STRING > "3.1"
34
+ alias_method :assign_attributes_without_attr_encrypted, :assign_attributes
35
+ def assign_attributes(*args)
36
36
  perform_attribute_assignment :assign_attributes_without_attr_encrypted, *args
37
37
  end
38
- alias_method_chain :assign_attributes, :attr_encrypted
39
38
  end
40
39
 
41
- def attributes_with_attr_encrypted=(*args)
40
+ alias_method :attributes_without_attr_encrypted=, :attributes=
41
+ def attributes=(*args)
42
42
  perform_attribute_assignment :attributes_without_attr_encrypted=, *args
43
43
  end
44
- alias_method_chain :attributes=, :attr_encrypted
45
44
  end
46
45
  end
47
46
 
@@ -54,14 +53,32 @@ if defined?(ActiveRecord::Base)
54
53
  attr = attrs.pop
55
54
  options.merge! encrypted_attributes[attr]
56
55
 
57
- define_method("#{attr}_changed?") do
58
- send(attr) != decrypt(attr, send("#{options[:attribute]}_was"))
56
+ define_method("#{attr}_was") do
57
+ attribute_was(attr)
59
58
  end
60
59
 
61
- define_method("#{attr}_was") do
62
- decrypt(attr, send("#{options[:attribute]}_was")) if send("#{attr}_changed?")
60
+ if ::ActiveRecord::VERSION::STRING >= "4.1"
61
+ define_method("#{attr}_changed?") do |options = {}|
62
+ attribute_changed?(attr, options)
63
+ end
64
+ else
65
+ define_method("#{attr}_changed?") do
66
+ attribute_changed?(attr)
67
+ end
68
+ end
69
+
70
+ define_method("#{attr}_change") do
71
+ attribute_change(attr)
72
+ end
73
+
74
+ define_method("#{attr}_with_dirtiness=") do |value|
75
+ attribute_will_change!(attr) if value != __send__(attr)
76
+ __send__("#{attr}_without_dirtiness=", value)
63
77
  end
64
78
 
79
+ alias_method "#{attr}_without_dirtiness=", "#{attr}="
80
+ alias_method "#{attr}=", "#{attr}_with_dirtiness="
81
+
65
82
  alias_method "#{attr}_before_type_cast", attr
66
83
  end
67
84
 
@@ -69,10 +86,10 @@ if defined?(ActiveRecord::Base)
69
86
  # We add accessor methods of the db columns to the list of instance
70
87
  # methods returned to let ActiveRecord define the accessor methods
71
88
  # for the db columns
72
-
89
+
73
90
  # Use with_connection so the connection doesn't stay pinned to the thread.
74
91
  connected = ::ActiveRecord::Base.connection_pool.with_connection(&:active?) rescue false
75
-
92
+
76
93
  if connected && table_exists?
77
94
  columns_hash.keys.inject(super) {|instance_methods, column_name| instance_methods.concat [column_name.to_sym, :"#{column_name}="]}
78
95
  else
@@ -85,13 +102,13 @@ if defined?(ActiveRecord::Base)
85
102
  #
86
103
  # NOTE: This only works when the <tt>:key</tt> option is specified as a string (see the README)
87
104
  #
88
- # This is useful for encrypting fields like email addresses. Your user's email addresses
105
+ # This is useful for encrypting fields like email addresses. Your user's email addresses
89
106
  # are encrypted in the database, but you can still look up a user by email for logging in
90
107
  #
91
108
  # Example
92
109
  #
93
110
  # class User < ActiveRecord::Base
94
- # attr_encrypted :email, :key => 'secret key'
111
+ # attr_encrypted :email, key: 'secret key'
95
112
  # end
96
113
  #
97
114
  # User.find_by_email_and_password('test@example.com', 'testing')
@@ -101,8 +118,9 @@ if defined?(ActiveRecord::Base)
101
118
  if match = /^(find|scoped)_(all_by|by)_([_a-zA-Z]\w*)$/.match(method.to_s)
102
119
  attribute_names = match.captures.last.split('_and_')
103
120
  attribute_names.each_with_index do |attribute, index|
104
- if attr_encrypted?(attribute)
121
+ if attr_encrypted?(attribute) && encrypted_attributes[attribute.to_sym][:mode] == :single_iv_and_salt
105
122
  args[index] = send("encrypt_#{attribute}", args[index])
123
+ warn "DEPRECATION WARNING: This feature will be removed in the next major release."
106
124
  attribute_names[index] = encrypted_attributes[attribute.to_sym][:attribute]
107
125
  end
108
126
  end
@@ -114,5 +132,6 @@ if defined?(ActiveRecord::Base)
114
132
  end
115
133
  end
116
134
 
135
+ ActiveRecord::Base.extend AttrEncrypted
117
136
  ActiveRecord::Base.extend AttrEncrypted::Adapters::ActiveRecord
118
137
  end
@@ -11,6 +11,7 @@ if defined?(DataMapper)
11
11
 
12
12
  def included_with_attr_encrypted(base)
13
13
  included_without_attr_encrypted(base)
14
+ base.extend AttrEncrypted
14
15
  base.attr_encrypted_options[:encode] = true
15
16
  end
16
17
  end
@@ -9,5 +9,6 @@ if defined?(Sequel)
9
9
  end
10
10
  end
11
11
 
12
+ Sequel::Model.extend AttrEncrypted
12
13
  Sequel::Model.extend AttrEncrypted::Adapters::Sequel
13
14
  end
@@ -1,9 +1,9 @@
1
1
  module AttrEncrypted
2
2
  # Contains information about this gem's version
3
3
  module Version
4
- MAJOR = 1
5
- MINOR = 4
6
- PATCH = 0
4
+ MAJOR = 3
5
+ MINOR = 0
6
+ PATCH = 3
7
7
 
8
8
  # Returns a version string by joining <tt>MAJOR</tt>, <tt>MINOR</tt>, and <tt>PATCH</tt> with <tt>'.'</tt>
9
9
  #