blind_index 1.0.0 → 1.0.1

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: d2a4c6e35691fe1efa918f077afda9902109591f695a3f4043ae9eb6350ffb44
4
- data.tar.gz: dcbe4e3c535a2d36495370a7fa53078d6fd32979c8b7d07b7e29c3202e8fd393
3
+ metadata.gz: 93b1688db3ff1410b5e56fcf3fae01d76cfcb073df3647abb6582fffbb05d148
4
+ data.tar.gz: 3b0b3dff637c2eab2b7b4d5811b413166cd23503dec1d6081fb5bfee7533ce99
5
5
  SHA512:
6
- metadata.gz: 1c80bec06e019677e606d4da2c52d0aa529f5aeb56e1091a79a138ce40b73dedb3244fdabf073a96d249e9a876e6557d73e38bd48dfddfd5b1963e19ebb91c93
7
- data.tar.gz: e206e2619af60a2274f300eac56f1edf3a7f00822c8bdead7fa579252b81b7540d16832c083ed630f454c08049521b312c95f72c33e070706894a60f1c3f1eef
6
+ metadata.gz: fcae62db34e27e82885d6fb200b6d3549bc14d9c7c1ddedf9d59aa32a7f9691010aa641379318fbb20706823b258328013ba7eb3cc2b6e63242ae4addcdc7a0e
7
+ data.tar.gz: 45a07059d4d78d2a9f814db37d9a80fe37603e78603207b65f80a812bce6e18c818ebb0c3fc7e6b8439203eec4398a81a9db7b32bfaa7061865244841050ad2c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 1.0.1
2
+
3
+ - Added support for Mongoid
4
+
1
5
  ## 1.0.0
2
6
 
3
7
  - Added support for master key
data/README.md CHANGED
@@ -2,11 +2,9 @@
2
2
 
3
3
  Securely search encrypted database fields
4
4
 
5
- Works with [Lockbox](https://github.com/ankane/lockbox) and [attr_encrypted](https://github.com/attr-encrypted/attr_encrypted)
5
+ Works with [Lockbox](https://github.com/ankane/lockbox) ([full example](https://ankane.org/securing-user-emails-lockbox)) and [attr_encrypted](https://github.com/attr-encrypted/attr_encrypted) ([full example](https://ankane.org/securing-user-emails-in-rails))
6
6
 
7
- Here’s a [full example](https://ankane.org/securing-user-emails-in-rails) of how to use it
8
-
9
- Check out [this post](https://ankane.org/sensitive-data-rails) for more info on securing sensitive data with Rails
7
+ Learn more about [securing sensitive data in Rails](https://ankane.org/sensitive-data-rails)
10
8
 
11
9
  [![Build Status](https://travis-ci.org/ankane/blind_index.svg?branch=master)](https://travis-ci.org/ankane/blind_index)
12
10
 
@@ -34,11 +32,11 @@ On Windows, also add:
34
32
  gem 'argon2', git: 'https://github.com/technion/ruby-argon2.git', submodules: true
35
33
  ```
36
34
 
37
- Until `argon2 >= 2.0.1` is released.
35
+ Until `argon2 > 2.0.2` is released.
38
36
 
39
37
  ## Getting Started
40
38
 
41
- > Note: Your model should already be set up with Lockbox or attr_encrypted. The examples are for a `User` model with `encrypts :email` or `attr_encrypted :email`. See the [full example](https://ankane.org/securing-user-emails-in-rails) if needed.
39
+ > Note: Your model should already be set up with Lockbox or attr_encrypted. The examples are for a `User` model with `encrypts :email` or `attr_encrypted :email`. See the full examples for [Lockbox](https://ankane.org/securing-user-emails-lockbox) and [attr_encrypted](https://ankane.org/securing-user-emails-in-rails) if needed.
42
40
 
43
41
  First, generate a key
44
42
 
@@ -252,6 +250,16 @@ test_user:
252
250
 
253
251
  Be sure to include the `inspect` at the end or it won’t be encoded properly in YAML.
254
252
 
253
+ ## Mongoid
254
+
255
+ For Mongoid, use:
256
+
257
+ ```ruby
258
+ class User
259
+ field :email_bidx, type: String
260
+ end
261
+ ```
262
+
255
263
  ## Reference
256
264
 
257
265
  Set default options in an initializer with:
data/lib/blind_index.rb CHANGED
@@ -145,3 +145,13 @@ ActiveSupport.on_load(:active_record) do
145
145
  ActiveRecord::Validations::UniquenessValidator.prepend(BlindIndex::Extensions::UniquenessValidator)
146
146
  end
147
147
  end
148
+
149
+ if defined?(Mongoid)
150
+ # TODO find better ActiveModel hook
151
+ require "active_model/callbacks"
152
+ ActiveModel::Callbacks.include(BlindIndex::Model)
153
+
154
+ require "blind_index/mongoid"
155
+ Mongoid::Criteria.prepend(BlindIndex::Mongoid::Criteria)
156
+ Mongoid::Validatable::UniquenessValidator.prepend(BlindIndex::Mongoid::UniquenessValidator)
157
+ end
@@ -33,7 +33,7 @@ module BlindIndex
33
33
  class_method_name = :"generate_#{name}_bidx"
34
34
 
35
35
  key = options[:key]
36
- key ||= -> { BlindIndex.index_key(table: table_name, bidx_attribute: bidx_attribute, master_key: options[:master_key], encode: false) }
36
+ key ||= -> { BlindIndex.index_key(table: try(:table_name) || collection_name.to_s, bidx_attribute: bidx_attribute, master_key: options[:master_key], encode: false) }
37
37
 
38
38
  class_eval do
39
39
  @blind_indexes ||= {}
@@ -74,7 +74,15 @@ module BlindIndex
74
74
  end
75
75
 
76
76
  if callback
77
- before_validation method_name, if: -> { changes.key?(attribute.to_s) }
77
+ if defined?(ActiveRecord) && self < ActiveRecord::Base
78
+ # Active Record
79
+ # prevent deprecation warnings
80
+ before_validation method_name, if: -> { changes.key?(attribute.to_s) }
81
+ else
82
+ # Mongoid
83
+ # Lockbox only supports attribute_changed?
84
+ before_validation method_name, if: -> { send("#{attribute}_changed?") }
85
+ end
78
86
  end
79
87
 
80
88
  # use include so user can override
@@ -0,0 +1,51 @@
1
+ module BlindIndex
2
+ module Mongoid
3
+ module Criteria
4
+ private
5
+
6
+ def expr_query(criterion)
7
+ if criterion.is_a?(Hash) && klass.respond_to?(:blind_indexes)
8
+ criterion.keys.each do |key|
9
+ key_sym = (key.is_a?(::Mongoid::Criteria::Queryable::Key) ? key.name : key).to_sym
10
+
11
+ if (bi = klass.blind_indexes[key_sym])
12
+ value = criterion.delete(key)
13
+
14
+ bidx_key =
15
+ if key.is_a?(::Mongoid::Criteria::Queryable::Key)
16
+ ::Mongoid::Criteria::Queryable::Key.new(
17
+ bi[:bidx_attribute],
18
+ key.strategy,
19
+ key.operator,
20
+ key.expanded,
21
+ &key.block
22
+ )
23
+ else
24
+ bi[:bidx_attribute]
25
+ end
26
+
27
+ criterion[bidx_key] =
28
+ if value.is_a?(Array)
29
+ value.map { |v| BlindIndex.generate_bidx(v, bi) }
30
+ else
31
+ BlindIndex.generate_bidx(value, bi)
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ super(criterion)
38
+ end
39
+ end
40
+
41
+ module UniquenessValidator
42
+ def create_criteria(base, document, attribute, value)
43
+ if base.respond_to?(:blind_indexes) && (bi = base.blind_indexes[attribute])
44
+ value = BlindIndex.generate_bidx(value, bi)
45
+ attribute = bi[:bidx_attribute]
46
+ end
47
+ super(base, document, attribute, value)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,3 +1,3 @@
1
1
  module BlindIndex
2
- VERSION = "1.0.0"
2
+ VERSION = "1.0.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blind_index
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.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-07-08 00:00:00.000000000 Z
11
+ date: 2019-08-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -177,6 +177,7 @@ files:
177
177
  - lib/blind_index/extensions.rb
178
178
  - lib/blind_index/key_generator.rb
179
179
  - lib/blind_index/model.rb
180
+ - lib/blind_index/mongoid.rb
180
181
  - lib/blind_index/version.rb
181
182
  homepage: https://github.com/ankane/blind_index
182
183
  licenses: