active_record_encryption 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc2770632c4ba57ce5f3b807e9fe4e45ef18e959176ae907635e65a0de4f686d
4
- data.tar.gz: 7f98301e66f31aaa043cd5c3a2ab58e655d7da9023bd8fd1d6a310b938b642e6
3
+ metadata.gz: a44b6801eaa2a8f03073d3fb608ecf2ef1c307fafefed5e4b264c058d4b7d206
4
+ data.tar.gz: 27c5bb1d838a8599785518feecd5fad117b64846bc8d83153ab5e7e85288b202
5
5
  SHA512:
6
- metadata.gz: 5884f04a7b4e6fab65ce2044502b5387c172917442c4d29715bd368c75cdecd9b49bb6862c8493bd7668bd3780c431d036fbd8dfac5a2cd9d6a12e33e2453790
7
- data.tar.gz: 6f1c82c9b173fe8d6cdb19cf6a71e6dc9ef8be793028b27a5e230b0f885554c700f105f2354b1c74d905d49384afcb44480f3f9f5254c15867e0a8200ade8c0c
6
+ metadata.gz: cab1fcaf58a388284e677a3953702248b286b1b55691ffcfad66a1a3072a37aee6a974f0bf150b6a5293ecdf107451dfa0a79c8379f29320a7f96f35136529b4
7
+ data.tar.gz: 570e91b04e305d02c1c830c8a2433db9dce4605767e49a130cc9fa71adcaeb3f6a22627e8cc8989147d62d786fded62d4d1fd3fa45bc8c4ed6bf113d5daa5719
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 1.0.0
2
+
3
+ - EOL Ruby and Rails no longer supported #29
4
+ - Requires Ruby 3.0.0 or newer.
5
+ - Requires Rails 6.1.0 or newer.
6
+ - Support rails 7.0.0 #25
7
+ - Support rails 7.1.0 #31
8
+ - Migrate CI from travis.ci to GitHub Action. #27
9
+ - In Rails 7.0, `ActiveRecordEncryption` do not change encoding for backward compatibility.
10
+
1
11
  ## 0.3.0
2
12
 
3
13
  - Support rails 6.1.0 #22
data/README.md CHANGED
@@ -118,9 +118,8 @@ end
118
118
 
119
119
  ```bash
120
120
  bundle exec appraisal install
121
- bundle exec appraisal 5.0-stable rspec
122
- bundle exec appraisal 5.1-stable rspec
123
- bundle exec appraisal 5.2-stable rspec
121
+ bundle exec appraisal 6.1-stable rspec
122
+ bundle exec appraisal 7.0-stable rspec
124
123
  ```
125
124
 
126
125
  ## Contributing
@@ -18,12 +18,27 @@ module ActiveRecordEncryption
18
18
  'f'
19
19
  end
20
20
 
21
+ if ActiveRecord::VERSION::MAJOR >= 7
22
+ # Cast value to string
23
+ def type_cast(value)
24
+ return value.to_s if value.is_a?(Numeric)
25
+ super(value)
26
+ end
27
+ end
28
+
29
+ # @return [Symbol]
30
+ def default_timezone
31
+ ActiveRecord::Base.connection.default_timezone
32
+ end
33
+
21
34
  private
22
35
 
23
- # Cast value to string
24
- def _type_cast(value)
25
- return value.to_s if value.is_a?(Numeric)
26
- super(value)
36
+ if ActiveRecord::VERSION::MAJOR < 7
37
+ # Cast value to string
38
+ def _type_cast(value)
39
+ return value.to_s if value.is_a?(Numeric)
40
+ super(value)
41
+ end
27
42
  end
28
43
  end
29
44
  end
@@ -0,0 +1,30 @@
1
+ module ActiveRecordEncryption
2
+ class Type
3
+ class Binary < ActiveModel::Type::Binary
4
+ def cast(value)
5
+ return super if ActiveRecord::VERSION::STRING < '7.0.0'
6
+
7
+ if value.is_a?(Data)
8
+ value.to_s
9
+ else
10
+ value = cast_value(value) unless value.nil?
11
+ # NOTE: Don't convert string to binary for backward compatibility.
12
+ # value = value.b if ::String === value && value.encoding != Encoding::BINARY
13
+ value
14
+ end
15
+ end
16
+
17
+ def serialize(value)
18
+ return if value.nil?
19
+ Data.new(value)
20
+ end
21
+
22
+ class Data < ActiveModel::Type::Binary::Data
23
+ # NOTE: Don't convert string to binary for backward compatibility.
24
+ def initialize(value)
25
+ @value = value.to_s
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,23 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_record_encryption/serializer_with_cast'
4
-
5
3
  module ActiveRecordEncryption
6
4
  class Type < ActiveRecord::Type::Value
7
- using(ActiveRecordEncryption::SerializerWithCast)
8
-
9
5
  delegate :type, :cast, to: :subtype
10
6
  delegate :user_input_in_time_zone, to: :subtype # for ActiveRecord::AttributeMethods::TimeZoneConversion::TimeZoneConverter
11
7
 
12
8
  def initialize(
13
- subtype: default_value,
9
+ subtype: ActiveRecord::Type.default_value,
14
10
  encryption: ActiveRecordEncryption.default_encryption.clone,
15
11
  **options
16
12
  )
17
-
18
13
  # Lookup encryptor from options[:encryption]
19
14
  @encryptor = build_encryptor(encryption)
20
- @binary = ActiveRecord::Type.lookup(:binary)
15
+ @binary = ActiveRecord::Type.lookup(:encryption_binary)
21
16
 
22
17
  subtype = ActiveRecord::Type.lookup(subtype, **options) if subtype.is_a?(Symbol)
23
18
  @subtype = subtype
@@ -42,15 +37,6 @@ module ActiveRecordEncryption
42
37
 
43
38
  attr_reader :subtype, :binary, :encryptor
44
39
 
45
- # NOTE: `ActiveRecord::Type.default_value` is not defined in Rails 5.0
46
- def default_value
47
- if ActiveRecord.gem_version < Gem::Version.create('5.1.0')
48
- ActiveRecord::Type::Value.new
49
- else
50
- ActiveRecord::Type.default_value
51
- end
52
- end
53
-
54
40
  def build_encryptor(options)
55
41
  encryptor = options.delete(:encryptor)
56
42
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveRecordEncryption
4
- VERSION = '0.3.0'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -13,6 +13,7 @@ end
13
13
 
14
14
  ActiveSupport.on_load(:active_record) do
15
15
  require 'active_record_encryption/type'
16
+ require 'active_record_encryption/type/binary'
16
17
  require 'active_record_encryption/encryptor'
17
18
  require 'active_record_encryption/encrypted_attribute'
18
19
  require 'active_record_encryption/binary'
@@ -20,6 +21,7 @@ ActiveSupport.on_load(:active_record) do
20
21
 
21
22
  # Register `:encryption` type
22
23
  ActiveRecord::Type.register(:encryption, ActiveRecordEncryption::Type)
24
+ ActiveRecord::Type.register(:encryption_binary, ActiveRecordEncryption::Type::Binary)
23
25
 
24
26
  # Define `.encrypted_attribute`
25
27
  ActiveRecord::Base.include(ActiveRecordEncryption::EncryptedAttribute)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_record_encryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-29 00:00:00.000000000 Z
11
+ date: 2024-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '5.0'
19
+ version: '6.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '5.0'
26
+ version: '6.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: appraisal
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -187,8 +187,8 @@ files:
187
187
  - lib/active_record_encryption/encryptor/registry.rb
188
188
  - lib/active_record_encryption/exceptions.rb
189
189
  - lib/active_record_encryption/quoter.rb
190
- - lib/active_record_encryption/serializer_with_cast.rb
191
190
  - lib/active_record_encryption/type.rb
191
+ - lib/active_record_encryption/type/binary.rb
192
192
  - lib/active_record_encryption/version.rb
193
193
  homepage: https://github.com/alpaca-tc/active_record_encryption
194
194
  licenses:
@@ -202,14 +202,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
203
  - - ">="
204
204
  - !ruby/object:Gem::Version
205
- version: '0'
205
+ version: 3.1.0
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
208
  - - ">="
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
- rubygems_version: 3.1.4
212
+ rubygems_version: 3.5.18
213
213
  signing_key:
214
214
  specification_version: 4
215
215
  summary: Transparent ActiveRecord encryption
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module ActiveRecordEncryption
4
- module SerializerWithCast
5
- # Unfortunately, current Rails doesn't serialize value from user input with `#cast`.
6
- # IMO, it is expected that serialized value from user input should be equal same result.
7
- #
8
- # Example:
9
- # # Current
10
- # User.attribute(:id, :boolean)
11
- # User.where(id: 'string').to_sql #=> SELECT `users`.* FROM `users` WHERE `users`.`id` = 'string'
12
- # User.where(id: true).to_sql #=> SELECT `users`.* FROM `users` WHERE `users`.`id` = TRUE
13
- #
14
- # # Expected
15
- # User.attribute(:id, :boolean)
16
- # User.where(id: 'string').to_sql #=> SELECT `users`.* FROM `users` WHERE `users`.`id` = TRUE
17
- # User.where(id: true).to_sql #=> SELECT `users`.* FROM `users` WHERE `users`.`id` = TRUE
18
- if ActiveRecord.gem_version < Gem::Version.create('6.0')
19
- # https://github.com/rails/rails/commit/a741208f80dd33420a56486bd9ed2b0b9862234a
20
- refine ActiveModel::Type::Decimal do
21
- def serialize(value)
22
- cast(value)
23
- end
24
- end
25
-
26
- # https://github.com/rails/rails/commit/34cc301f03aea2e579d6687a9ea9782afc1089a0
27
- refine ActiveModel::Type::Boolean do
28
- def serialize(value)
29
- cast(value)
30
- end
31
- end
32
- end
33
-
34
- # Backport Rails5.2
35
- if ActiveRecord.gem_version < Gem::Version.create('5.2')
36
- refine ActiveModel::Type::DateTime do
37
- def serialize(value)
38
- super(cast(value))
39
- end
40
- end
41
- end
42
- end
43
- end