lockbox 0.6.6 → 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: 71efd55022975063c04c0a0588532e1bdd5167c7f2e6df5c8cf442362b4d52d6
4
- data.tar.gz: b823faa4b637c300367032b625972f7d41d0e3e12595921d7474140a955c64c7
3
+ metadata.gz: 767467c10e8b38cc53b822c604bc4d6189563a00b7a53a12181ac5d3de19e723
4
+ data.tar.gz: 56319f892b400761e11a96b9f0e05f3a5cf684c6b6f069e9f85cbbdd81299bef
5
5
  SHA512:
6
- metadata.gz: 0d7fd7b285c51ac3f80657ec8956d7cd4692481d33710be69dfa567da02dd2f38de7bef9e4b43962395d9241d7d8c452d01f156e2124d957f52ea9026c0ea14f
7
- data.tar.gz: 5d62ccbb565e9a3a6e76c1b6df617377bdcd1003289634cd16a2ba4b0e1d1a1ec72966c2a98dae27959e471fdf9ca77fd0755d25bd75ce6bd1e0cd7755819162
6
+ metadata.gz: 8e4550edc543add59495e42f0648b80c538ace8d326c12acbe5bad3bfb907f329d1ff63be86406bad83f8a2732b2938efa6ce6e20bce9b2d10406f173ee3e56b
7
+ data.tar.gz: 7087087f6307212b8b041c1703f4d08be578042295a4dcd91efdc1aaab17d1a4c8f2066969ae1837216d746ac3824f287f5fdcbb58afd8a12ce772bf7592d5b9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,21 @@
1
+ ## 1.0.0 (2022-06-11)
2
+
3
+ - Deprecated `encrypts` in favor of `has_encrypted` to avoid conflicting with Active Record encryption
4
+ - Deprecated `lockbox_encrypts` in favor of `has_encrypted`
5
+ - Fixed error with `pluck`
6
+ - Restored warning for attributes with `default` option
7
+ - Dropped support for Active Record < 5.2 and Ruby < 2.6
8
+
9
+ ## 0.6.8 (2022-01-25)
10
+
11
+ - Fixed issue with `encrypts` loading model schema early
12
+ - Removed warning for attributes with `default` option
13
+
14
+ ## 0.6.7 (2022-01-25)
15
+
16
+ - Added warning for attributes with `default` option
17
+ - Removed warning for Active Record 5.0 (still supported)
18
+
1
19
  ## 0.6.6 (2021-09-27)
2
20
 
3
21
  - Fixed `attribute?` method for `boolean` and `integer` types
@@ -25,6 +43,7 @@
25
43
  ## 0.6.1 (2020-12-03)
26
44
 
27
45
  - Added integration with Rails credentials
46
+ - Added warning for unsupported versions of Active Record
28
47
  - Fixed in place changes for Active Record 6.1
29
48
  - Fixed error with `content_type` method for CarrierWave < 2
30
49
 
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2018-2021 Andrew Kane
3
+ Copyright (c) 2018-2022 Andrew Kane
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -16,7 +16,7 @@ Learn [the principles behind it](https://ankane.org/modern-encryption-rails), [h
16
16
  Add this line to your application’s Gemfile:
17
17
 
18
18
  ```ruby
19
- gem 'lockbox'
19
+ gem "lockbox"
20
20
  ```
21
21
 
22
22
  ## Key Generation
@@ -72,7 +72,7 @@ Then follow the instructions below for the data you want to encrypt.
72
72
  Create a migration with:
73
73
 
74
74
  ```ruby
75
- class AddEmailCiphertextToUsers < ActiveRecord::Migration[6.1]
75
+ class AddEmailCiphertextToUsers < ActiveRecord::Migration[7.0]
76
76
  def change
77
77
  add_column :users, :email_ciphertext, :text
78
78
  end
@@ -83,7 +83,7 @@ Add to your model:
83
83
 
84
84
  ```ruby
85
85
  class User < ApplicationRecord
86
- encrypts :email
86
+ has_encrypted :email
87
87
  end
88
88
  ```
89
89
 
@@ -101,7 +101,7 @@ You can specify multiple fields in single line.
101
101
 
102
102
  ```ruby
103
103
  class User < ApplicationRecord
104
- encrypts :email, :phone, :city
104
+ has_encrypted :email, :phone, :city
105
105
  end
106
106
  ```
107
107
 
@@ -111,17 +111,17 @@ Fields are strings by default. Specify the type of a field with:
111
111
 
112
112
  ```ruby
113
113
  class User < ApplicationRecord
114
- encrypts :born_on, type: :date
115
- encrypts :signed_at, type: :datetime
116
- encrypts :opens_at, type: :time
117
- encrypts :active, type: :boolean
118
- encrypts :salary, type: :integer
119
- encrypts :latitude, type: :float
120
- encrypts :video, type: :binary
121
- encrypts :properties, type: :json
122
- encrypts :settings, type: :hash
123
- encrypts :messages, type: :array
124
- encrypts :ip, type: :inet
114
+ has_encrypted :birthday, type: :date
115
+ has_encrypted :signed_at, type: :datetime
116
+ has_encrypted :opens_at, type: :time
117
+ has_encrypted :active, type: :boolean
118
+ has_encrypted :salary, type: :integer
119
+ has_encrypted :latitude, type: :float
120
+ has_encrypted :video, type: :binary
121
+ has_encrypted :properties, type: :json
122
+ has_encrypted :settings, type: :hash
123
+ has_encrypted :messages, type: :array
124
+ has_encrypted :ip, type: :inet
125
125
  end
126
126
  ```
127
127
 
@@ -135,7 +135,7 @@ class User < ApplicationRecord
135
135
  store :settings, accessors: [:color, :homepage]
136
136
  attribute :configuration, CustomType.new
137
137
 
138
- encrypts :properties, :settings, :configuration
138
+ has_encrypted :properties, :settings, :configuration
139
139
  end
140
140
  ```
141
141
 
@@ -143,7 +143,7 @@ For [StoreModel](https://github.com/DmitryTsepelev/store_model), use:
143
143
 
144
144
  ```ruby
145
145
  class User < ApplicationRecord
146
- encrypts :configuration, type: Configuration.to_type
146
+ has_encrypted :configuration, type: Configuration.to_type
147
147
 
148
148
  after_initialize do
149
149
  self.configuration ||= {}
@@ -174,7 +174,7 @@ Add a new column for the ciphertext, then add to your model:
174
174
 
175
175
  ```ruby
176
176
  class User < ApplicationRecord
177
- encrypts :email, migrating: true
177
+ has_encrypted :email, migrating: true
178
178
  end
179
179
  ```
180
180
 
@@ -188,7 +188,7 @@ Then update the model to the desired state:
188
188
 
189
189
  ```ruby
190
190
  class User < ApplicationRecord
191
- encrypts :email
191
+ has_encrypted :email
192
192
 
193
193
  # remove this line after dropping email column
194
194
  self.ignored_columns = ["email"]
@@ -248,7 +248,7 @@ User.decrypt_email_ciphertext(user.email_ciphertext)
248
248
  Create a migration with:
249
249
 
250
250
  ```ruby
251
- class AddBodyCiphertextToRichTexts < ActiveRecord::Migration[6.1]
251
+ class AddBodyCiphertextToRichTexts < ActiveRecord::Migration[7.0]
252
252
  def change
253
253
  add_column :action_text_rich_texts, :body_ciphertext, :text
254
254
  end
@@ -287,7 +287,7 @@ Add to your model:
287
287
  class User
288
288
  field :email_ciphertext, type: String
289
289
 
290
- encrypts :email
290
+ has_encrypted :email
291
291
  end
292
292
  ```
293
293
 
@@ -336,6 +336,8 @@ def license
336
336
  end
337
337
  ```
338
338
 
339
+ Use `filename` to specify a filename or `disposition: "inline"` to show inline.
340
+
339
341
  #### Migrating Existing Files
340
342
 
341
343
  Lockbox makes it easy to encrypt existing files without downtime.
@@ -377,7 +379,7 @@ Encryption is applied to all versions after processing.
377
379
  You can mount the uploader [as normal](https://github.com/carrierwaveuploader/carrierwave#activerecord). With Active Record, this involves creating a migration:
378
380
 
379
381
  ```ruby
380
- class AddLicenseToUsers < ActiveRecord::Migration[6.1]
382
+ class AddLicenseToUsers < ActiveRecord::Migration[7.0]
381
383
  def change
382
384
  add_column :users, :license, :string
383
385
  end
@@ -401,6 +403,8 @@ def license
401
403
  end
402
404
  ```
403
405
 
406
+ Use `filename` to specify a filename or `disposition: "inline"` to show inline.
407
+
404
408
  #### Migrating Existing Files
405
409
 
406
410
  Encrypt existing files without downtime. Create a new encrypted uploader:
@@ -476,6 +480,8 @@ def license
476
480
  end
477
481
  ```
478
482
 
483
+ Use `filename` to specify a filename or `disposition: "inline"` to show inline.
484
+
479
485
  #### Non-Models
480
486
 
481
487
  Generate a key
@@ -566,7 +572,7 @@ Update your model:
566
572
 
567
573
  ```ruby
568
574
  class User < ApplicationRecord
569
- encrypts :email, previous_versions: [{master_key: previous_key}]
575
+ has_encrypted :email, previous_versions: [{master_key: previous_key}]
570
576
  end
571
577
  ```
572
578
 
@@ -702,24 +708,30 @@ Lockbox uses 256-bit keys.
702
708
 
703
709
  ### XSalsa20
704
710
 
705
- You can also use XSalsa20, which uses an extended nonce so you don’t have to worry about nonce collisions. First, [install Libsodium](https://github.com/crypto-rb/rbnacl/wiki/Installing-libsodium). For Homebrew, use:
711
+ You can also use XSalsa20, which uses an extended nonce so you don’t have to worry about nonce collisions. First, [install Libsodium](https://github.com/crypto-rb/rbnacl/wiki/Installing-libsodium). It comes preinstalled on [Heroku](https://devcenter.heroku.com/articles/stack-packages). For Homebrew, use:
706
712
 
707
713
  ```sh
708
714
  brew install libsodium
709
715
  ```
710
716
 
711
- And add to your Gemfile:
717
+ And for Ubuntu, use:
718
+
719
+ ```sh
720
+ sudo apt-get install libsodium23
721
+ ```
722
+
723
+ Then add to your Gemfile:
712
724
 
713
725
  ```ruby
714
- gem 'rbnacl'
726
+ gem "rbnacl"
715
727
  ```
716
728
 
717
- Then add to your model:
729
+ And add to your model:
718
730
 
719
731
 
720
732
  ```ruby
721
733
  class User < ApplicationRecord
722
- encrypts :email, algorithm: "xsalsa20"
734
+ has_encrypted :email, algorithm: "xsalsa20"
723
735
  end
724
736
  ```
725
737
 
@@ -731,72 +743,6 @@ Lockbox.default_options = {algorithm: "xsalsa20"}
731
743
 
732
744
  You can also pass an algorithm to `previous_versions` for key rotation.
733
745
 
734
- #### XSalsa20 Deployment
735
-
736
- ##### Heroku
737
-
738
- Heroku [comes with libsodium](https://devcenter.heroku.com/articles/stack-packages) preinstalled.
739
-
740
- ##### Ubuntu
741
-
742
- For Ubuntu 20.04 and 18.04, use:
743
-
744
- ```sh
745
- sudo apt-get install libsodium23
746
- ```
747
-
748
- For Ubuntu 16.04, use:
749
-
750
- ```sh
751
- sudo apt-get install libsodium18
752
- ```
753
-
754
- ##### GitHub Actions
755
-
756
- For Ubuntu 20.04 and 18.04, use:
757
-
758
- ```yml
759
- - name: Install Libsodium
760
- run: sudo apt-get update && sudo apt-get install libsodium23
761
- ```
762
-
763
- For Ubuntu 16.04, use:
764
-
765
- ```yml
766
- - name: Install Libsodium
767
- run: sudo apt-get update && sudo apt-get install libsodium18
768
- ```
769
-
770
- ##### Travis CI
771
-
772
- On Bionic, add to `.travis.yml`:
773
-
774
- ```yml
775
- addons:
776
- apt:
777
- packages:
778
- - libsodium23
779
- ```
780
-
781
- On Xenial, add to `.travis.yml`:
782
-
783
- ```yml
784
- addons:
785
- apt:
786
- packages:
787
- - libsodium18
788
- ```
789
-
790
- ##### CircleCI
791
-
792
- Add a step to `.circleci/config.yml`:
793
-
794
- ```yml
795
- - run:
796
- name: install Libsodium
797
- command: sudo apt-get install -y libsodium18
798
- ```
799
-
800
746
  ## Hybrid Cryptography
801
747
 
802
748
  [Hybrid cryptography](https://en.wikipedia.org/wiki/Hybrid_cryptosystem) allows servers to encrypt data without being able to decrypt it.
@@ -813,7 +759,7 @@ Store the keys with your other secrets. Then use:
813
759
 
814
760
  ```ruby
815
761
  class User < ApplicationRecord
816
- encrypts :email, algorithm: "hybrid", encryption_key: encryption_key, decryption_key: decryption_key
762
+ has_encrypted :email, algorithm: "hybrid", encryption_key: encryption_key, decryption_key: decryption_key
817
763
  end
818
764
  ```
819
765
 
@@ -843,7 +789,7 @@ To rename a table with encrypted columns/uploaders, use:
843
789
 
844
790
  ```ruby
845
791
  class User < ApplicationRecord
846
- encrypts :email, key_table: "original_table"
792
+ has_encrypted :email, key_table: "original_table"
847
793
  end
848
794
  ```
849
795
 
@@ -851,7 +797,7 @@ To rename an encrypted column itself, use:
851
797
 
852
798
  ```ruby
853
799
  class User < ApplicationRecord
854
- encrypts :email, key_attribute: "original_column"
800
+ has_encrypted :email, key_attribute: "original_column"
855
801
  end
856
802
  ```
857
803
 
@@ -861,7 +807,7 @@ To set a key for an individual field/uploader, use a string:
861
807
 
862
808
  ```ruby
863
809
  class User < ApplicationRecord
864
- encrypts :email, key: ENV["USER_EMAIL_ENCRYPTION_KEY"]
810
+ has_encrypted :email, key: ENV["USER_EMAIL_ENCRYPTION_KEY"]
865
811
  end
866
812
  ```
867
813
 
@@ -869,7 +815,7 @@ Or a proc:
869
815
 
870
816
  ```ruby
871
817
  class User < ApplicationRecord
872
- encrypts :email, key: -> { code }
818
+ has_encrypted :email, key: -> { code }
873
819
  end
874
820
  ```
875
821
 
@@ -879,7 +825,7 @@ To use a different key for each record, use a symbol:
879
825
 
880
826
  ```ruby
881
827
  class User < ApplicationRecord
882
- encrypts :email, key: :some_method
828
+ has_encrypted :email, key: :some_method
883
829
  end
884
830
  ```
885
831
 
@@ -887,7 +833,7 @@ Or a proc:
887
833
 
888
834
  ```ruby
889
835
  class User < ApplicationRecord
890
- encrypts :email, key: -> { some_method }
836
+ has_encrypted :email, key: -> { some_method }
891
837
  end
892
838
  ```
893
839
 
@@ -899,7 +845,7 @@ For Active Record and Mongoid, use:
899
845
 
900
846
  ```ruby
901
847
  class User < ApplicationRecord
902
- encrypts :email, key: :kms_key
848
+ has_encrypted :email, key: :kms_key
903
849
  end
904
850
  ```
905
851
 
@@ -987,7 +933,7 @@ lockbox.decrypt(ciphertext, associated_data: "othercontext") # fails
987
933
  You can use `binary` columns for the ciphertext instead of `text` columns.
988
934
 
989
935
  ```ruby
990
- class AddEmailCiphertextToUsers < ActiveRecord::Migration[6.1]
936
+ class AddEmailCiphertextToUsers < ActiveRecord::Migration[7.0]
991
937
  def change
992
938
  add_column :users, :email_ciphertext, :binary
993
939
  end
@@ -998,7 +944,7 @@ Disable Base64 encoding to save space.
998
944
 
999
945
  ```ruby
1000
946
  class User < ApplicationRecord
1001
- encrypts :email, encode: false
947
+ has_encrypted :email, encode: false
1002
948
  end
1003
949
  ```
1004
950
 
@@ -1032,7 +978,7 @@ end
1032
978
  Create a migration with:
1033
979
 
1034
980
  ```ruby
1035
- class MigrateToLockbox < ActiveRecord::Migration[6.1]
981
+ class MigrateToLockbox < ActiveRecord::Migration[7.0]
1036
982
  def change
1037
983
  add_column :users, :name_ciphertext, :text
1038
984
  add_column :users, :email_ciphertext, :text
@@ -1040,11 +986,11 @@ class MigrateToLockbox < ActiveRecord::Migration[6.1]
1040
986
  end
1041
987
  ```
1042
988
 
1043
- And add `encrypts` to your model with the `migrating` option:
989
+ And add `has_encrypted` to your model with the `migrating` option:
1044
990
 
1045
991
  ```ruby
1046
992
  class User < ApplicationRecord
1047
- encrypts :name, :email, migrating: true
993
+ has_encrypted :name, :email, migrating: true
1048
994
  end
1049
995
  ```
1050
996
 
@@ -1058,14 +1004,14 @@ Once all records are migrated, remove the `migrating` option and the previous mo
1058
1004
 
1059
1005
  ```ruby
1060
1006
  class User < ApplicationRecord
1061
- encrypts :name, :email
1007
+ has_encrypted :name, :email
1062
1008
  end
1063
1009
  ```
1064
1010
 
1065
1011
  Then remove the previous gem from your Gemfile and drop its columns.
1066
1012
 
1067
1013
  ```ruby
1068
- class RemovePreviousEncryptedColumns < ActiveRecord::Migration[6.1]
1014
+ class RemovePreviousEncryptedColumns < ActiveRecord::Migration[7.0]
1069
1015
  def change
1070
1016
  remove_column :users, :encrypted_name, :text
1071
1017
  remove_column :users, :encrypted_name_iv, :text
@@ -1077,6 +1023,16 @@ end
1077
1023
 
1078
1024
  ## Upgrading
1079
1025
 
1026
+ ### 1.0.0
1027
+
1028
+ `encrypts` is now deprecated in favor of `has_encrypted` to avoid conflicting with Active Record encryption.
1029
+
1030
+ ```ruby
1031
+ class User < ApplicationRecord
1032
+ has_encrypted :email
1033
+ end
1034
+ ```
1035
+
1080
1036
  ### 0.6.0
1081
1037
 
1082
1038
  0.6.0 adds `encrypted: true` to Active Storage metadata for new files. This field is informational, but if you prefer to add it to existing files, use:
@@ -3,7 +3,12 @@ module Lockbox
3
3
  def pluck(*column_names)
4
4
  return super unless model.respond_to?(:lockbox_attributes)
5
5
 
6
- lockbox_columns = column_names.map.with_index { |c, i| [model.lockbox_attributes[c.to_sym], i] }.select { |la, _i| la && !la[:migrating] }
6
+ lockbox_columns = column_names.map.with_index do |c, i|
7
+ next unless c.respond_to?(:to_sym)
8
+ [model.lockbox_attributes[c.to_sym], i]
9
+ end.select do |la, _i|
10
+ la && !la[:migrating]
11
+ end
7
12
 
8
13
  return super unless lockbox_columns.any?
9
14
 
@@ -106,10 +106,9 @@ module Lockbox
106
106
  end
107
107
 
108
108
  if CarrierWave::VERSION.to_i > 2
109
- raise "CarrierWave version (#{CarrierWave::VERSION}) not supported in this version of Lockbox (#{Lockbox::VERSION})"
109
+ raise Lockbox::Error, "CarrierWave #{CarrierWave::VERSION} not supported in this version of Lockbox"
110
110
  elsif CarrierWave::VERSION.to_i < 1
111
- # TODO raise error in 0.7.0
112
- warn "CarrierWave version (#{CarrierWave::VERSION}) not supported in this version of Lockbox (#{Lockbox::VERSION})"
111
+ raise Lockbox::Error, "CarrierWave #{CarrierWave::VERSION} not supported"
113
112
  end
114
113
 
115
114
  CarrierWave::Uploader::Base.extend(Lockbox::CarrierWaveExtensions)
data/lib/lockbox/model.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Lockbox
2
2
  module Model
3
- def lockbox_encrypts(*attributes, **options)
3
+ def has_encrypted(*attributes, **options)
4
4
  # support objects
5
5
  # case options[:type]
6
6
  # when Date
@@ -241,6 +241,23 @@ module Lockbox
241
241
  @lockbox_attributes[original_name] = options
242
242
 
243
243
  if activerecord
244
+ # warn on default attributes
245
+ if attributes_to_define_after_schema_loads.key?(name.to_s)
246
+ opt = attributes_to_define_after_schema_loads[name.to_s][1]
247
+
248
+ has_default =
249
+ if ActiveRecord::VERSION::MAJOR >= 7
250
+ # not ideal, since NO_DEFAULT_PROVIDED is private
251
+ opt != ActiveRecord::Attributes::ClassMethods.const_get(:NO_DEFAULT_PROVIDED)
252
+ else
253
+ opt.is_a?(Hash) && opt.key?(:default)
254
+ end
255
+
256
+ if has_default
257
+ warn "[lockbox] WARNING: attributes with `:default` option are not supported. Use `after_initialize` instead."
258
+ end
259
+ end
260
+
244
261
  # preference:
245
262
  # 1. type option
246
263
  # 2. existing virtual attribute
@@ -303,11 +320,9 @@ module Lockbox
303
320
  send("restore_#{encrypted_attribute}!")
304
321
  end
305
322
 
306
- if ActiveRecord::VERSION::STRING >= "5.1"
307
- define_method("#{name}_in_database") do
308
- send(name) # writes attribute when not already set
309
- super()
310
- end
323
+ define_method("#{name}_in_database") do
324
+ send(name) # writes attribute when not already set
325
+ super()
311
326
  end
312
327
 
313
328
  define_method("#{name}?") do
@@ -443,7 +458,6 @@ module Lockbox
443
458
  table = activerecord ? table_name : collection_name.to_s
444
459
 
445
460
  unless message.nil?
446
- # TODO use attribute type class in 0.7.0
447
461
  case options[:type]
448
462
  when :boolean
449
463
  message = ActiveRecord::Type::Boolean.new.serialize(message)
@@ -506,7 +520,6 @@ module Lockbox
506
520
  end
507
521
 
508
522
  unless message.nil?
509
- # TODO use attribute type class in 0.7.0
510
523
  case options[:type]
511
524
  when :boolean
512
525
  message = message == "t"
@@ -564,6 +577,11 @@ module Lockbox
564
577
  end
565
578
  end
566
579
 
580
+ def lockbox_encrypts(*attributes, **options)
581
+ ActiveSupport::Deprecation.warn("`#{__callee__}` is deprecated in favor of `has_encrypted`")
582
+ has_encrypted(*attributes, **options)
583
+ end
584
+
567
585
  module Attached
568
586
  def encrypts_attached(*attributes, **options)
569
587
  attributes.each do |name|
@@ -1,3 +1,3 @@
1
1
  module Lockbox
2
- VERSION = "0.6.6"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/lockbox.rb CHANGED
@@ -16,36 +16,6 @@ require "lockbox/padding"
16
16
  require "lockbox/utils"
17
17
  require "lockbox/version"
18
18
 
19
- # integrations
20
- require "lockbox/carrier_wave_extensions" if defined?(CarrierWave)
21
- require "lockbox/railtie" if defined?(Rails)
22
-
23
- if defined?(ActiveSupport::LogSubscriber)
24
- require "lockbox/log_subscriber"
25
- Lockbox::LogSubscriber.attach_to :lockbox
26
- end
27
-
28
- if defined?(ActiveSupport.on_load)
29
- ActiveSupport.on_load(:active_record) do
30
- # TODO raise error in 0.7.0
31
- if ActiveRecord::VERSION::STRING.to_f <= 5.0
32
- warn "Active Record version (#{ActiveRecord::VERSION::STRING}) not supported in this version of Lockbox (#{Lockbox::VERSION})"
33
- end
34
-
35
- extend Lockbox::Model
36
- extend Lockbox::Model::Attached
37
- # alias_method is private in Ruby < 2.5
38
- singleton_class.send(:alias_method, :encrypts, :lockbox_encrypts) if ActiveRecord::VERSION::MAJOR < 7
39
- ActiveRecord::Relation.prepend Lockbox::Calculations
40
- end
41
-
42
- ActiveSupport.on_load(:mongoid) do
43
- Mongoid::Document::ClassMethods.include(Lockbox::Model)
44
- # alias_method is private in Ruby < 2.5
45
- Mongoid::Document::ClassMethods.send(:alias_method, :encrypts, :lockbox_encrypts)
46
- end
47
- end
48
-
49
19
  module Lockbox
50
20
  class Error < StandardError; end
51
21
  class DecryptionError < Error; end
@@ -110,7 +80,39 @@ module Lockbox
110
80
 
111
81
  def self.encrypts_action_text_body(**options)
112
82
  ActiveSupport.on_load(:action_text_rich_text) do
113
- ActionText::RichText.lockbox_encrypts :body, **options
83
+ ActionText::RichText.has_encrypted :body, **options
114
84
  end
115
85
  end
116
86
  end
87
+
88
+ # integrations
89
+ require "lockbox/carrier_wave_extensions" if defined?(CarrierWave)
90
+ require "lockbox/railtie" if defined?(Rails)
91
+
92
+ if defined?(ActiveSupport::LogSubscriber)
93
+ require "lockbox/log_subscriber"
94
+ Lockbox::LogSubscriber.attach_to :lockbox
95
+ end
96
+
97
+ if defined?(ActiveSupport.on_load)
98
+ ActiveSupport.on_load(:active_record) do
99
+ ar_version = ActiveRecord::VERSION::STRING.to_f
100
+ if ar_version < 5.2
101
+ if ar_version >= 5
102
+ raise Lockbox::Error, "Active Record #{ActiveRecord::VERSION::STRING} requires Lockbox < 0.7"
103
+ else
104
+ raise Lockbox::Error, "Active Record #{ActiveRecord::VERSION::STRING} not supported"
105
+ end
106
+ end
107
+
108
+ extend Lockbox::Model
109
+ extend Lockbox::Model::Attached
110
+ singleton_class.alias_method(:encrypts, :lockbox_encrypts) if ActiveRecord::VERSION::MAJOR < 7
111
+ ActiveRecord::Relation.prepend Lockbox::Calculations
112
+ end
113
+
114
+ ActiveSupport.on_load(:mongoid) do
115
+ Mongoid::Document::ClassMethods.include(Lockbox::Model)
116
+ Mongoid::Document::ClassMethods.alias_method(:encrypts, :lockbox_encrypts)
117
+ end
118
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lockbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-28 00:00:00.000000000 Z
11
+ date: 2022-06-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -51,14 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2.4'
54
+ version: '2.6'
55
55
  required_rubygems_version: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.2.22
61
+ rubygems_version: 3.3.7
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Modern encryption for Ruby and Rails