has_encrypted_field 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 +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +22 -0
- data/CHANGELOG.md +13 -0
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +181 -0
- data/LICENSE.txt +21 -0
- data/README.md +54 -0
- data/Rakefile +12 -0
- data/bin/console +8 -0
- data/bin/setup +6 -0
- data/has_encrypted_field.gemspec +37 -0
- data/lib/has_encrypted_field/accessors.rb +27 -0
- data/lib/has_encrypted_field/configuration.rb +27 -0
- data/lib/has_encrypted_field/query_methods.rb +36 -0
- data/lib/has_encrypted_field/version.rb +5 -0
- data/lib/has_encrypted_field.rb +35 -0
- metadata +161 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e23d1535da69e8fac005471ada8f582d0ca33f156fc13b0cc6849ee57dfa004b
|
4
|
+
data.tar.gz: 417ad4a021cbd01588ae6edf5b9d188b1d0efec26035032eb4dea33bb411e258
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 541ede4b27721ab52d547c6c15cbc8b8bb6303555340d22b62c80ed548e2e3f14a30dff87010b0300ff45bf38620b0e38f1aa4415c890774d7b5290f030ec038
|
7
|
+
data.tar.gz: f99e886a4af47c81693a6149ebc4d4a651aff7fe76cce780a409f5561080e9101fff46f6493bf43dcd4d9b3d0b970f2bc0bb01060b3ede061f28678038834725
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-minitest
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
Exclude:
|
7
|
+
- coverage/**/*
|
8
|
+
- vendor/bundle/**/*
|
9
|
+
Layout/LineLength:
|
10
|
+
Max: 140
|
11
|
+
Style/GuardClause:
|
12
|
+
Enabled: false
|
13
|
+
Style/StringLiterals:
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
Style/StringLiteralsInInterpolation:
|
16
|
+
Enabled: false
|
17
|
+
Style/HashEachMethods:
|
18
|
+
Enabled: true
|
19
|
+
Style/HashTransformKeys:
|
20
|
+
Enabled: true
|
21
|
+
Style/HashTransformValues:
|
22
|
+
Enabled: true
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
## 0.3.0 ##
|
2
|
+
|
3
|
+
* Make it possible to pluck regular fields among encrypted ones ([@vinistock])
|
4
|
+
|
5
|
+
## 0.2.0 ##
|
6
|
+
|
7
|
+
* Add pluck_decrypted ([@vinistock])
|
8
|
+
* Stop overriding original reader and create decrypted_attr instead ([@vinistock])
|
9
|
+
* Fix reading secret via masterk.key ([@vinistock])
|
10
|
+
|
11
|
+
## 0.1.0 ##
|
12
|
+
|
13
|
+
* Add has_encrypted_field ([@vinistock])
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
All contributions are greatly appreciated. Be it opening an issue proposing an improvement, submitting a pull request fixing a bug or any other assistance is helpful.
|
4
|
+
|
5
|
+
## Issues
|
6
|
+
|
7
|
+
If you have found a bug or have a suggestion, please make a brief search in the issues section to check if something similar has not been reported already.
|
8
|
+
|
9
|
+
**Bugs**
|
10
|
+
|
11
|
+
When describing bugs in the gem, please include steps for reproducing the issue. That makes it easier to identify the problem's source and solve it.
|
12
|
+
|
13
|
+
**Suggestions**
|
14
|
+
|
15
|
+
These are mostly pretty open, but try to be concise in your explanation of what is being suggested.
|
16
|
+
|
17
|
+
## Pull requests
|
18
|
+
|
19
|
+
If you're addressing an issue, please refer to it in your pull request's comment for tracking.
|
20
|
+
|
21
|
+
1. Fork it (https://github.com/vinistock/has_encrypted_field/fork)
|
22
|
+
2. Create your feature branch (git checkout -b my-feature)
|
23
|
+
3. Commit your changes (git commit -am 'Add my feature')
|
24
|
+
4. Push to the branch (git push origin my-feature)
|
25
|
+
5. Create a new Pull Request
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
has_encrypted_field (0.3.1)
|
5
|
+
activerecord (>= 5.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
actioncable (6.1.4.1)
|
11
|
+
actionpack (= 6.1.4.1)
|
12
|
+
activesupport (= 6.1.4.1)
|
13
|
+
nio4r (~> 2.0)
|
14
|
+
websocket-driver (>= 0.6.1)
|
15
|
+
actionmailbox (6.1.4.1)
|
16
|
+
actionpack (= 6.1.4.1)
|
17
|
+
activejob (= 6.1.4.1)
|
18
|
+
activerecord (= 6.1.4.1)
|
19
|
+
activestorage (= 6.1.4.1)
|
20
|
+
activesupport (= 6.1.4.1)
|
21
|
+
mail (>= 2.7.1)
|
22
|
+
actionmailer (6.1.4.1)
|
23
|
+
actionpack (= 6.1.4.1)
|
24
|
+
actionview (= 6.1.4.1)
|
25
|
+
activejob (= 6.1.4.1)
|
26
|
+
activesupport (= 6.1.4.1)
|
27
|
+
mail (~> 2.5, >= 2.5.4)
|
28
|
+
rails-dom-testing (~> 2.0)
|
29
|
+
actionpack (6.1.4.1)
|
30
|
+
actionview (= 6.1.4.1)
|
31
|
+
activesupport (= 6.1.4.1)
|
32
|
+
rack (~> 2.0, >= 2.0.9)
|
33
|
+
rack-test (>= 0.6.3)
|
34
|
+
rails-dom-testing (~> 2.0)
|
35
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
36
|
+
actiontext (6.1.4.1)
|
37
|
+
actionpack (= 6.1.4.1)
|
38
|
+
activerecord (= 6.1.4.1)
|
39
|
+
activestorage (= 6.1.4.1)
|
40
|
+
activesupport (= 6.1.4.1)
|
41
|
+
nokogiri (>= 1.8.5)
|
42
|
+
actionview (6.1.4.1)
|
43
|
+
activesupport (= 6.1.4.1)
|
44
|
+
builder (~> 3.1)
|
45
|
+
erubi (~> 1.4)
|
46
|
+
rails-dom-testing (~> 2.0)
|
47
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
48
|
+
activejob (6.1.4.1)
|
49
|
+
activesupport (= 6.1.4.1)
|
50
|
+
globalid (>= 0.3.6)
|
51
|
+
activemodel (6.1.4.1)
|
52
|
+
activesupport (= 6.1.4.1)
|
53
|
+
activerecord (6.1.4.1)
|
54
|
+
activemodel (= 6.1.4.1)
|
55
|
+
activesupport (= 6.1.4.1)
|
56
|
+
activestorage (6.1.4.1)
|
57
|
+
actionpack (= 6.1.4.1)
|
58
|
+
activejob (= 6.1.4.1)
|
59
|
+
activerecord (= 6.1.4.1)
|
60
|
+
activesupport (= 6.1.4.1)
|
61
|
+
marcel (~> 1.0.0)
|
62
|
+
mini_mime (>= 1.1.0)
|
63
|
+
activesupport (6.1.4.1)
|
64
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
65
|
+
i18n (>= 1.6, < 2)
|
66
|
+
minitest (>= 5.1)
|
67
|
+
tzinfo (~> 2.0)
|
68
|
+
zeitwerk (~> 2.3)
|
69
|
+
ast (2.4.2)
|
70
|
+
builder (3.2.4)
|
71
|
+
byebug (11.1.3)
|
72
|
+
concurrent-ruby (1.1.9)
|
73
|
+
crass (1.0.6)
|
74
|
+
erubi (1.10.0)
|
75
|
+
globalid (0.5.2)
|
76
|
+
activesupport (>= 5.0)
|
77
|
+
i18n (1.8.10)
|
78
|
+
concurrent-ruby (~> 1.0)
|
79
|
+
loofah (2.12.0)
|
80
|
+
crass (~> 1.0.2)
|
81
|
+
nokogiri (>= 1.5.9)
|
82
|
+
mail (2.7.1)
|
83
|
+
mini_mime (>= 0.1.1)
|
84
|
+
marcel (1.0.2)
|
85
|
+
method_source (1.0.0)
|
86
|
+
mini_mime (1.1.1)
|
87
|
+
mini_portile2 (2.6.1)
|
88
|
+
minitest (5.14.4)
|
89
|
+
mocha (1.13.0)
|
90
|
+
nio4r (2.5.8)
|
91
|
+
nokogiri (1.12.4)
|
92
|
+
mini_portile2 (~> 2.6.1)
|
93
|
+
racc (~> 1.4)
|
94
|
+
parallel (1.21.0)
|
95
|
+
parser (3.0.2.0)
|
96
|
+
ast (~> 2.4.1)
|
97
|
+
racc (1.5.2)
|
98
|
+
rack (2.2.3)
|
99
|
+
rack-test (1.1.0)
|
100
|
+
rack (>= 1.0, < 3)
|
101
|
+
rails (6.1.4.1)
|
102
|
+
actioncable (= 6.1.4.1)
|
103
|
+
actionmailbox (= 6.1.4.1)
|
104
|
+
actionmailer (= 6.1.4.1)
|
105
|
+
actionpack (= 6.1.4.1)
|
106
|
+
actiontext (= 6.1.4.1)
|
107
|
+
actionview (= 6.1.4.1)
|
108
|
+
activejob (= 6.1.4.1)
|
109
|
+
activemodel (= 6.1.4.1)
|
110
|
+
activerecord (= 6.1.4.1)
|
111
|
+
activestorage (= 6.1.4.1)
|
112
|
+
activesupport (= 6.1.4.1)
|
113
|
+
bundler (>= 1.15.0)
|
114
|
+
railties (= 6.1.4.1)
|
115
|
+
sprockets-rails (>= 2.0.0)
|
116
|
+
rails-dom-testing (2.0.3)
|
117
|
+
activesupport (>= 4.2.0)
|
118
|
+
nokogiri (>= 1.6)
|
119
|
+
rails-html-sanitizer (1.4.2)
|
120
|
+
loofah (~> 2.3)
|
121
|
+
railties (6.1.4.1)
|
122
|
+
actionpack (= 6.1.4.1)
|
123
|
+
activesupport (= 6.1.4.1)
|
124
|
+
method_source
|
125
|
+
rake (>= 0.13)
|
126
|
+
thor (~> 1.0)
|
127
|
+
rainbow (3.0.0)
|
128
|
+
rake (12.3.3)
|
129
|
+
regexp_parser (2.1.1)
|
130
|
+
rexml (3.2.5)
|
131
|
+
rubocop (1.21.0)
|
132
|
+
parallel (~> 1.10)
|
133
|
+
parser (>= 3.0.0.0)
|
134
|
+
rainbow (>= 2.2.2, < 4.0)
|
135
|
+
regexp_parser (>= 1.8, < 3.0)
|
136
|
+
rexml
|
137
|
+
rubocop-ast (>= 1.9.1, < 2.0)
|
138
|
+
ruby-progressbar (~> 1.7)
|
139
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
140
|
+
rubocop-ast (1.11.0)
|
141
|
+
parser (>= 3.0.1.1)
|
142
|
+
rubocop-minitest (0.15.0)
|
143
|
+
rubocop (>= 0.90, < 2.0)
|
144
|
+
rubocop-performance (1.11.5)
|
145
|
+
rubocop (>= 1.7.0, < 2.0)
|
146
|
+
rubocop-ast (>= 0.4.0)
|
147
|
+
ruby-progressbar (1.11.0)
|
148
|
+
sprockets (4.0.2)
|
149
|
+
concurrent-ruby (~> 1.0)
|
150
|
+
rack (> 1, < 3)
|
151
|
+
sprockets-rails (3.2.2)
|
152
|
+
actionpack (>= 4.0)
|
153
|
+
activesupport (>= 4.0)
|
154
|
+
sprockets (>= 3.0.0)
|
155
|
+
sqlite3 (1.4.2)
|
156
|
+
thor (1.1.0)
|
157
|
+
tzinfo (2.0.4)
|
158
|
+
concurrent-ruby (~> 1.0)
|
159
|
+
unicode-display_width (2.1.0)
|
160
|
+
websocket-driver (0.7.5)
|
161
|
+
websocket-extensions (>= 0.1.0)
|
162
|
+
websocket-extensions (0.1.5)
|
163
|
+
zeitwerk (2.4.2)
|
164
|
+
|
165
|
+
PLATFORMS
|
166
|
+
ruby
|
167
|
+
|
168
|
+
DEPENDENCIES
|
169
|
+
byebug
|
170
|
+
has_encrypted_field!
|
171
|
+
minitest (~> 5.0)
|
172
|
+
mocha
|
173
|
+
rails (>= 5.0.0)
|
174
|
+
rake (~> 12.0)
|
175
|
+
rubocop
|
176
|
+
rubocop-minitest
|
177
|
+
rubocop-performance
|
178
|
+
sqlite3
|
179
|
+
|
180
|
+
BUNDLED WITH
|
181
|
+
2.2.27
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Vinicius Stock
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
This unfinished experiment is no longer active. It did not work and should not be used.
|
2
|
+
|
3
|
+
# HasEncryptedField
|
4
|
+
|
5
|
+
This gem provides support for encrypted attributes for models based on activerecord.
|
6
|
+
|
7
|
+
It will encrypt the desired values inside model instances and save encrypted values to the database.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Not published
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Include the `HasEncryptedField` module inside the desired models and declare fields.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
class User < ApplicationRecord
|
19
|
+
include HasEncryptedField
|
20
|
+
|
21
|
+
has_encrypted_field :email
|
22
|
+
end
|
23
|
+
|
24
|
+
# The writer encrypts
|
25
|
+
user = User.create!(email: "user@example.com")
|
26
|
+
p user
|
27
|
+
=> #<User id: 1, email: "eXhzeEJ1ejRvOVE2VGFiU0V6Y0NPMWJybjd6a005c1F3RGh0R3...">
|
28
|
+
|
29
|
+
# The reader decrypts
|
30
|
+
p user.decrypted_email
|
31
|
+
=> "user@example.com"
|
32
|
+
|
33
|
+
# Pluck decrypted fields
|
34
|
+
p User.pluck_decrypted(:email)
|
35
|
+
=> ["user@example.com"]
|
36
|
+
|
37
|
+
# Pluck including encrypted and regular fields
|
38
|
+
p User.pluck_decrypted(:id, :email)
|
39
|
+
=> [[1, "user@example.com"]]
|
40
|
+
```
|
41
|
+
|
42
|
+
### Available configuration and defaults
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
HasEncryptedField.configure do |config|
|
46
|
+
config.secret_key = ENV["RAILS_MASTER_KEY"] || contents of master.key
|
47
|
+
end
|
48
|
+
```
|
49
|
+
|
50
|
+
### Warning
|
51
|
+
|
52
|
+
Remember that using this gem to save encrypted fields to the database will always require the original master key in order to decrypt data.
|
53
|
+
|
54
|
+
It will not be possible to recover data encrypted if the original master key is lost.
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/has_encrypted_field/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "has_encrypted_field"
|
7
|
+
spec.version = HasEncryptedField::VERSION
|
8
|
+
spec.authors = ["Vinicius Stock"]
|
9
|
+
spec.email = ["vinicius.stock@shopify.com"]
|
10
|
+
|
11
|
+
spec.summary = "Encrypted attributes for Rails models."
|
12
|
+
spec.description = "Encrypted attributes for Rails models."
|
13
|
+
spec.homepage = "https://github.com/vinistock/has_encrypted_field"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/vinistock/has_encrypted_field"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/vinistock/has_encrypted_field/blob/master/CHANGELOG.md"
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_dependency "activerecord", ">= 5.0.0"
|
30
|
+
|
31
|
+
spec.add_development_dependency "byebug"
|
32
|
+
spec.add_development_dependency "mocha"
|
33
|
+
spec.add_development_dependency "rubocop"
|
34
|
+
spec.add_development_dependency "rubocop-minitest"
|
35
|
+
spec.add_development_dependency "rubocop-performance"
|
36
|
+
spec.add_development_dependency "sqlite3"
|
37
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HasEncryptedField # :nodoc:
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# ClassMethods
|
7
|
+
#
|
8
|
+
# These methods are added to classes that include
|
9
|
+
# the HasEncryptedField module.
|
10
|
+
module ClassMethods
|
11
|
+
# rubocop:disable Naming/PredicateName
|
12
|
+
def has_encrypted_field(attribute)
|
13
|
+
class_eval(<<~ACCESSORS, __FILE__, __LINE__ + 1)
|
14
|
+
def decrypted_#{attribute}
|
15
|
+
HasEncryptedField.encryptor.decrypt_and_verify(self[:#{attribute}])
|
16
|
+
end
|
17
|
+
|
18
|
+
def #{attribute}=(value)
|
19
|
+
self[:#{attribute}] = HasEncryptedField.encryptor.encrypt_and_sign(value)
|
20
|
+
end
|
21
|
+
ACCESSORS
|
22
|
+
|
23
|
+
HasEncryptedField.register(to_s, attribute)
|
24
|
+
end
|
25
|
+
# rubocop:enable Naming/PredicateName
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HasEncryptedField
|
4
|
+
# Configuration
|
5
|
+
#
|
6
|
+
# This class holds all initializer configuration
|
7
|
+
# for the gem.
|
8
|
+
class Configuration
|
9
|
+
attr_accessor :secret_key
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@secret_key = initialize_secret_key
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def initialize_secret_key
|
18
|
+
ENV["RAILS_MASTER_KEY"] || read_key_from_file
|
19
|
+
end
|
20
|
+
|
21
|
+
def read_key_from_file
|
22
|
+
path = Rails.root.join("config/master.key")
|
23
|
+
|
24
|
+
File.binread(path).strip
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HasEncryptedField # :nodoc:
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
# ClassMethods
|
7
|
+
#
|
8
|
+
# These methods are added to classes that include
|
9
|
+
# the HasEncryptedField module.
|
10
|
+
module ClassMethods
|
11
|
+
def pluck_decrypted(*attributes)
|
12
|
+
attributes.length == 1 ? decrypt_simple(attributes) : decrypt_nested(attributes)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def decrypt_nested(attributes)
|
18
|
+
encrypted_fields = HasEncryptedField.registered_fields[to_s]
|
19
|
+
|
20
|
+
pluck(*attributes).map! do |tuple|
|
21
|
+
tuple.map!.with_index do |attr, index|
|
22
|
+
if encrypted_fields.include?(attributes[index])
|
23
|
+
HasEncryptedField.encryptor.decrypt_and_verify(attr)
|
24
|
+
else
|
25
|
+
attr
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def decrypt_simple(attributes)
|
32
|
+
pluck(*attributes)
|
33
|
+
.map! { |attr| HasEncryptedField.encryptor.decrypt_and_verify(attr) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
require "active_support/message_encryptor"
|
5
|
+
require "has_encrypted_field/version"
|
6
|
+
require "has_encrypted_field/configuration"
|
7
|
+
require "has_encrypted_field/accessors"
|
8
|
+
require "has_encrypted_field/query_methods"
|
9
|
+
|
10
|
+
module HasEncryptedField # :nodoc:
|
11
|
+
class << self
|
12
|
+
attr_writer :configuration
|
13
|
+
|
14
|
+
def encryptor
|
15
|
+
@encryptor ||= ActiveSupport::MessageEncryptor.new(configuration.secret_key)
|
16
|
+
end
|
17
|
+
|
18
|
+
def configuration
|
19
|
+
@configuration ||= Configuration.new
|
20
|
+
end
|
21
|
+
|
22
|
+
def configure
|
23
|
+
yield(configuration)
|
24
|
+
end
|
25
|
+
|
26
|
+
def registered_fields
|
27
|
+
@registered_fields ||= {}
|
28
|
+
end
|
29
|
+
|
30
|
+
def register(class_name, field)
|
31
|
+
registered_fields[class_name] ||= []
|
32
|
+
registered_fields[class_name] << field
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: has_encrypted_field
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vinicius Stock
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: byebug
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: mocha
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-minitest
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sqlite3
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Encrypted attributes for Rails models.
|
112
|
+
email:
|
113
|
+
- vinicius.stock@shopify.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".gitignore"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- CHANGELOG.md
|
121
|
+
- CONTRIBUTING.md
|
122
|
+
- Gemfile
|
123
|
+
- Gemfile.lock
|
124
|
+
- LICENSE.txt
|
125
|
+
- README.md
|
126
|
+
- Rakefile
|
127
|
+
- bin/console
|
128
|
+
- bin/setup
|
129
|
+
- has_encrypted_field.gemspec
|
130
|
+
- lib/has_encrypted_field.rb
|
131
|
+
- lib/has_encrypted_field/accessors.rb
|
132
|
+
- lib/has_encrypted_field/configuration.rb
|
133
|
+
- lib/has_encrypted_field/query_methods.rb
|
134
|
+
- lib/has_encrypted_field/version.rb
|
135
|
+
homepage: https://github.com/vinistock/has_encrypted_field
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata:
|
139
|
+
homepage_uri: https://github.com/vinistock/has_encrypted_field
|
140
|
+
source_code_uri: https://github.com/vinistock/has_encrypted_field
|
141
|
+
changelog_uri: https://github.com/vinistock/has_encrypted_field/blob/master/CHANGELOG.md
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: 2.3.0
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubygems_version: 3.2.27
|
158
|
+
signing_key:
|
159
|
+
specification_version: 4
|
160
|
+
summary: Encrypted attributes for Rails models.
|
161
|
+
test_files: []
|