lockbox 0.3.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6ba8d72d01b0dd6f8562bfb0980f9131e3670378299de01762cfefb6dd808857
4
- data.tar.gz: ace013580f48bb9c0950f2393726ff8a05923e626babdc9102a89bc6bd5c5043
3
+ metadata.gz: 775a12c813fb58a8e3a7f799d85af74d8a461b8cb6578beb672919dd1a4030f2
4
+ data.tar.gz: 41ab60ea29776ade74d0300ce4f933a0dc10e8f07c20bf48c2e604cab0aa4c13
5
5
  SHA512:
6
- metadata.gz: 29c1efa284ef09cb81e30bbc26b0f53a29793412e5f6983dd47af8a2b4258c56449cfd9f3410218b354abf56f655cbde33e60f6f5b2ef03037c32cfa258685f2
7
- data.tar.gz: a8d52b8a2a650bfe6c792c68b89dade741913081f10cda760dd76ccf74bbf5c6ac282b87fd02380eb4eff2899caba591fec1a95e325819f7688baa7cedfc081f
6
+ metadata.gz: 1208cd3e38d59425f09db7d2830b7f69809d6ae601b2b59d232001325d1721fad3087683eb44690d8ad672cd2c9c8adc22cae283ed1f56c31d906d3ed4bcaee2
7
+ data.tar.gz: 02e1faac0de9a9d8fcf168e01474792b5c9275fab7006f7e6fd4668dcae22a0b5e716bd983324104b66b4dd4ef55aede488f341f04bd7039a085ffb798f0b35d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.3.1 (2019-12-26)
2
+
3
+ - Fixed encoding for `encrypt_io` and `decrypt_io` in Ruby 2.7
4
+ - Fixed deprecation warnings in Ruby 2.7
5
+
1
6
  ## 0.3.0 (2019-12-22)
2
7
 
3
8
  - Added support for custom types
data/lib/lockbox.rb CHANGED
@@ -20,10 +20,13 @@ require "lockbox/railtie" if defined?(Rails)
20
20
  if defined?(ActiveSupport)
21
21
  ActiveSupport.on_load(:active_record) do
22
22
  extend Lockbox::Model
23
+ extend Lockbox::Model::Attached
23
24
  end
24
25
 
25
26
  ActiveSupport.on_load(:mongoid) do
26
27
  Mongoid::Document::ClassMethods.include(Lockbox::Model)
28
+ # TODO remove in 0.4.0
29
+ Mongoid::Document::ClassMethods.include(Lockbox::Model::Attached)
27
30
  end
28
31
  end
29
32
 
@@ -79,7 +82,6 @@ module Lockbox
79
82
  str.unpack("H*").first
80
83
  end
81
84
 
82
- # legacy
83
85
  def self.new(**options)
84
86
  Encryptor.new(**options)
85
87
  end
@@ -5,8 +5,8 @@ module Lockbox
5
5
  previous_versions = options.delete(:previous_versions)
6
6
 
7
7
  @boxes =
8
- [Box.new(options)] +
9
- Array(previous_versions).map { |v| Box.new({key: options[:key]}.merge(v)) }
8
+ [Box.new(**options)] +
9
+ Array(previous_versions).map { |v| Box.new(key: options[:key], **v) }
10
10
  end
11
11
 
12
12
  def encrypt(message, **options)
@@ -74,6 +74,7 @@ module Lockbox
74
74
  File.basename(source.path)
75
75
  end
76
76
  target.content_type = source.content_type if source.respond_to?(:content_type)
77
+ target.set_encoding(source.external_encoding) if source.respond_to?(:external_encoding)
77
78
  end
78
79
 
79
80
  # legacy for attr_encrypted
data/lib/lockbox/model.rb CHANGED
@@ -1,36 +1,5 @@
1
1
  module Lockbox
2
2
  module Model
3
- def attached_encrypted(attribute, **options)
4
- warn "[lockbox] DEPRECATION WARNING: Use encrypts_attached instead"
5
- encrypts_attached(attribute, **options)
6
- end
7
-
8
- def encrypts_attached(*attributes, **options)
9
- attributes.each do |name|
10
- name = name.to_sym
11
-
12
- class_eval do
13
- @lockbox_attachments ||= {}
14
-
15
- if @lockbox_attachments.empty?
16
- def self.lockbox_attachments
17
- parent_attachments =
18
- if superclass.respond_to?(:lockbox_attachments)
19
- superclass.lockbox_attachments
20
- else
21
- {}
22
- end
23
-
24
- parent_attachments.merge(@lockbox_attachments || {})
25
- end
26
- end
27
-
28
- raise "Duplicate encrypted attachment: #{name}" if lockbox_attachments[name]
29
- @lockbox_attachments[name] = options
30
- end
31
- end
32
- end
33
-
34
3
  def encrypts(*attributes, **options)
35
4
  # support objects
36
5
  # case options[:type]
@@ -271,6 +240,7 @@ module Lockbox
271
240
  table = activerecord ? table_name : collection_name.to_s
272
241
 
273
242
  unless message.nil?
243
+ # TODO use attribute type class in 0.4.0
274
244
  case options[:type]
275
245
  when :boolean
276
246
  message = ActiveRecord::Type::Boolean.new.serialize(message)
@@ -327,6 +297,7 @@ module Lockbox
327
297
  end
328
298
 
329
299
  unless message.nil?
300
+ # TODO use attribute type class in 0.4.0
330
301
  case options[:type]
331
302
  when :boolean
332
303
  message = message == "t"
@@ -363,5 +334,39 @@ module Lockbox
363
334
  end
364
335
  end
365
336
  end
337
+
338
+ module Attached
339
+ def encrypts_attached(*attributes, **options)
340
+ attributes.each do |name|
341
+ name = name.to_sym
342
+
343
+ class_eval do
344
+ @lockbox_attachments ||= {}
345
+
346
+ if @lockbox_attachments.empty?
347
+ def self.lockbox_attachments
348
+ parent_attachments =
349
+ if superclass.respond_to?(:lockbox_attachments)
350
+ superclass.lockbox_attachments
351
+ else
352
+ {}
353
+ end
354
+
355
+ parent_attachments.merge(@lockbox_attachments || {})
356
+ end
357
+ end
358
+
359
+ raise "Duplicate encrypted attachment: #{name}" if lockbox_attachments[name]
360
+ @lockbox_attachments[name] = options
361
+ end
362
+ end
363
+ end
364
+
365
+ # TODO remove in future version
366
+ def attached_encrypted(attribute, **options)
367
+ warn "[lockbox] DEPRECATION WARNING: Use encrypts_attached instead"
368
+ encrypts_attached(attribute, **options)
369
+ end
370
+ end
366
371
  end
367
372
  end
data/lib/lockbox/utils.rb CHANGED
@@ -14,7 +14,7 @@ module Lockbox
14
14
  options[:key] = Lockbox.attribute_key(table: table, attribute: attribute, master_key: options.delete(:master_key))
15
15
  end
16
16
 
17
- Lockbox.new(options)
17
+ Lockbox.new(**options)
18
18
  end
19
19
 
20
20
  def self.encrypted_options(record, name)
@@ -1,3 +1,3 @@
1
1
  module Lockbox
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-22 00:00:00.000000000 Z
11
+ date: 2019-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -220,7 +220,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  requirements: []
223
- rubygems_version: 3.0.3
223
+ rubygems_version: 3.1.2
224
224
  signing_key:
225
225
  specification_version: 4
226
226
  summary: Modern encryption for Rails