has_encrypted_field 0.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of has_encrypted_field might be problematic. Click here for more details.

checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23d488d714406773218720e4c8246bc3f05dcaaa5508d0e90568c0b89ede1aa1
4
+ data.tar.gz: 934f3d1c0cac53e6ceeada1c5fb22f0e832775a1082710e1640ba35faaaf8b03
5
+ SHA512:
6
+ metadata.gz: 86746990ecfcb5b22a371ac25ccd3c05e9f4750ed38c4b5443804f74627c51c22d1c5c0de4fa04a179964056bd891322b8dbd0f069356fd68d99b07624f708af
7
+ data.tar.gz: ef6380d0b5502eba551831e29ce2a80cd9cdbc9cf13462c2b2b98ad279b6e976fda48e36acf5cc3ccdc892526a5a044e4f9b5efc891caaaa8a443b5285b2b9df
@@ -0,0 +1,24 @@
1
+ ---
2
+ name: Bug report
3
+ about: Report an unexpected issue and help us improve
4
+ title: ''
5
+ labels: bug
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Actual behavior**
24
+ A clear and concise description of what you actually happened.
@@ -0,0 +1,19 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: feature request
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **What problem are you trying to solve? Please describe.**
11
+ A clear and concise description of what the problem is.
12
+
13
+ Ex. I'm always frustrated when [...], I'd like to able to [...]
14
+
15
+ **Describe the solution you'd like**
16
+ A clear and concise description of what you want to happen.
17
+
18
+ **Describe alternatives you've considered**
19
+ A clear and concise description of any alternative solutions or features you've considered.
@@ -0,0 +1,10 @@
1
+ ### What are you trying to accomplish with this PR?
2
+
3
+ <!--
4
+ Explain what you are implementing.
5
+
6
+ Provide information that will be helpful for reviewing
7
+ this pull request. For example, what is the use case
8
+ for these changes?
9
+ -->
10
+
@@ -0,0 +1,33 @@
1
+ name: Ruby
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ matrix:
10
+ rails_version: [5.2.4, 6.0.2.1]
11
+ ruby_version: [2.5, 2.6, 2.7]
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Cache
16
+ uses: actions/cache@v1.1.2
17
+ with:
18
+ path: vendor/bundle
19
+ key: ${{ matrix.ruby_version }}_${{ matrix.rails_version }}
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1.20.0
22
+ with:
23
+ ruby-version: ${{ matrix.ruby_version }}
24
+ - name: Build and test with Rake
25
+ run: |
26
+ sudo apt-get install libsqlite3-dev
27
+ rm Gemfile.lock
28
+ gem install bundler
29
+ bundle install --path vendor/bundle --jobs 4 --retry 3
30
+ bundle exec rake
31
+ bundle exec rubocop
32
+ env:
33
+ RAILS_VERSION: ${{ matrix.rails_version }}
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .ruby-version
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
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ gem "minitest", "~> 5.0"
7
+ gem "rails", (ENV["RAILS_VERSION"] || ">= 5.0.0")
8
+ gem "rake", "~> 12.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,174 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ has_encrypted_field (0.3.0)
5
+ activerecord (>= 5.0.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actioncable (6.0.2.1)
11
+ actionpack (= 6.0.2.1)
12
+ nio4r (~> 2.0)
13
+ websocket-driver (>= 0.6.1)
14
+ actionmailbox (6.0.2.1)
15
+ actionpack (= 6.0.2.1)
16
+ activejob (= 6.0.2.1)
17
+ activerecord (= 6.0.2.1)
18
+ activestorage (= 6.0.2.1)
19
+ activesupport (= 6.0.2.1)
20
+ mail (>= 2.7.1)
21
+ actionmailer (6.0.2.1)
22
+ actionpack (= 6.0.2.1)
23
+ actionview (= 6.0.2.1)
24
+ activejob (= 6.0.2.1)
25
+ mail (~> 2.5, >= 2.5.4)
26
+ rails-dom-testing (~> 2.0)
27
+ actionpack (6.0.2.1)
28
+ actionview (= 6.0.2.1)
29
+ activesupport (= 6.0.2.1)
30
+ rack (~> 2.0, >= 2.0.8)
31
+ rack-test (>= 0.6.3)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
+ actiontext (6.0.2.1)
35
+ actionpack (= 6.0.2.1)
36
+ activerecord (= 6.0.2.1)
37
+ activestorage (= 6.0.2.1)
38
+ activesupport (= 6.0.2.1)
39
+ nokogiri (>= 1.8.5)
40
+ actionview (6.0.2.1)
41
+ activesupport (= 6.0.2.1)
42
+ builder (~> 3.1)
43
+ erubi (~> 1.4)
44
+ rails-dom-testing (~> 2.0)
45
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
+ activejob (6.0.2.1)
47
+ activesupport (= 6.0.2.1)
48
+ globalid (>= 0.3.6)
49
+ activemodel (6.0.2.1)
50
+ activesupport (= 6.0.2.1)
51
+ activerecord (6.0.2.1)
52
+ activemodel (= 6.0.2.1)
53
+ activesupport (= 6.0.2.1)
54
+ activestorage (6.0.2.1)
55
+ actionpack (= 6.0.2.1)
56
+ activejob (= 6.0.2.1)
57
+ activerecord (= 6.0.2.1)
58
+ marcel (~> 0.3.1)
59
+ activesupport (6.0.2.1)
60
+ concurrent-ruby (~> 1.0, >= 1.0.2)
61
+ i18n (>= 0.7, < 2)
62
+ minitest (~> 5.1)
63
+ tzinfo (~> 1.1)
64
+ zeitwerk (~> 2.2)
65
+ ast (2.4.0)
66
+ builder (3.2.4)
67
+ byebug (11.1.1)
68
+ concurrent-ruby (1.1.6)
69
+ crass (1.0.6)
70
+ erubi (1.9.0)
71
+ globalid (0.4.2)
72
+ activesupport (>= 4.2.0)
73
+ i18n (1.8.2)
74
+ concurrent-ruby (~> 1.0)
75
+ jaro_winkler (1.5.4)
76
+ loofah (2.4.0)
77
+ crass (~> 1.0.2)
78
+ nokogiri (>= 1.5.9)
79
+ mail (2.7.1)
80
+ mini_mime (>= 0.1.1)
81
+ marcel (0.3.3)
82
+ mimemagic (~> 0.3.2)
83
+ method_source (0.9.2)
84
+ mimemagic (0.3.4)
85
+ mini_mime (1.0.2)
86
+ mini_portile2 (2.4.0)
87
+ minitest (5.14.0)
88
+ mocha (1.11.2)
89
+ nio4r (2.5.2)
90
+ nokogiri (1.10.9)
91
+ mini_portile2 (~> 2.4.0)
92
+ parallel (1.19.1)
93
+ parser (2.7.0.4)
94
+ ast (~> 2.4.0)
95
+ rack (2.2.2)
96
+ rack-test (1.1.0)
97
+ rack (>= 1.0, < 3)
98
+ rails (6.0.2.1)
99
+ actioncable (= 6.0.2.1)
100
+ actionmailbox (= 6.0.2.1)
101
+ actionmailer (= 6.0.2.1)
102
+ actionpack (= 6.0.2.1)
103
+ actiontext (= 6.0.2.1)
104
+ actionview (= 6.0.2.1)
105
+ activejob (= 6.0.2.1)
106
+ activemodel (= 6.0.2.1)
107
+ activerecord (= 6.0.2.1)
108
+ activestorage (= 6.0.2.1)
109
+ activesupport (= 6.0.2.1)
110
+ bundler (>= 1.3.0)
111
+ railties (= 6.0.2.1)
112
+ sprockets-rails (>= 2.0.0)
113
+ rails-dom-testing (2.0.3)
114
+ activesupport (>= 4.2.0)
115
+ nokogiri (>= 1.6)
116
+ rails-html-sanitizer (1.3.0)
117
+ loofah (~> 2.3)
118
+ railties (6.0.2.1)
119
+ actionpack (= 6.0.2.1)
120
+ activesupport (= 6.0.2.1)
121
+ method_source
122
+ rake (>= 0.8.7)
123
+ thor (>= 0.20.3, < 2.0)
124
+ rainbow (3.0.0)
125
+ rake (12.3.3)
126
+ rexml (3.2.4)
127
+ rubocop (0.80.1)
128
+ jaro_winkler (~> 1.5.1)
129
+ parallel (~> 1.10)
130
+ parser (>= 2.7.0.1)
131
+ rainbow (>= 2.2.2, < 4.0)
132
+ rexml
133
+ ruby-progressbar (~> 1.7)
134
+ unicode-display_width (>= 1.4.0, < 1.7)
135
+ rubocop-minitest (0.6.2)
136
+ rubocop (>= 0.74)
137
+ rubocop-performance (1.5.2)
138
+ rubocop (>= 0.71.0)
139
+ ruby-progressbar (1.10.1)
140
+ sprockets (4.0.0)
141
+ concurrent-ruby (~> 1.0)
142
+ rack (> 1, < 3)
143
+ sprockets-rails (3.2.1)
144
+ actionpack (>= 4.0)
145
+ activesupport (>= 4.0)
146
+ sprockets (>= 3.0.0)
147
+ sqlite3 (1.4.2)
148
+ thor (1.0.1)
149
+ thread_safe (0.3.6)
150
+ tzinfo (1.2.6)
151
+ thread_safe (~> 0.1)
152
+ unicode-display_width (1.6.1)
153
+ websocket-driver (0.7.1)
154
+ websocket-extensions (>= 0.1.0)
155
+ websocket-extensions (0.1.4)
156
+ zeitwerk (2.3.0)
157
+
158
+ PLATFORMS
159
+ ruby
160
+
161
+ DEPENDENCIES
162
+ byebug
163
+ has_encrypted_field!
164
+ minitest (~> 5.0)
165
+ mocha
166
+ rails (>= 5.0.0)
167
+ rake (~> 12.0)
168
+ rubocop
169
+ rubocop-minitest
170
+ rubocop-performance
171
+ sqlite3
172
+
173
+ BUNDLED WITH
174
+ 2.1.4
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,62 @@
1
+ [![Build Status](https://github.com/vinistock/has_encrypted_field/workflows/Ruby/badge.svg?branch=master)](https://github.com/vinistock/has_encrypted_field/actions) [![Gem Version](https://badge.fury.io/rb/has_encrypted_field.svg)](https://badge.fury.io/rb/has_encrypted_field)
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
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "has_encrypted_field"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+ ## Usage
22
+
23
+ Include the `HasEncryptedField` module inside the desired models and declare fields.
24
+
25
+ ```ruby
26
+ class User < ApplicationRecord
27
+ include HasEncryptedField
28
+
29
+ has_encrypted_field :email
30
+ end
31
+
32
+ # The writer encrypts
33
+ user = User.create!(email: "user@example.com")
34
+ p user
35
+ => #<User id: 1, email: "eXhzeEJ1ejRvOVE2VGFiU0V6Y0NPMWJybjd6a005c1F3RGh0R3...">
36
+
37
+ # The reader decrypts
38
+ p user.decrypted_email
39
+ => "user@example.com"
40
+
41
+ # Pluck decrypted fields
42
+ p User.pluck_decrypted(:email)
43
+ => ["user@example.com"]
44
+
45
+ # Pluck including encrypted and regular fields
46
+ p User.pluck_decrypted(:id, :email)
47
+ => [[1, "user@example.com"]]
48
+ ```
49
+
50
+ ### Available configuration and defaults
51
+
52
+ ```ruby
53
+ HasEncryptedField.configure do |config|
54
+ config.secret_key = ENV["RAILS_MASTER_KEY"] || contents of master.key
55
+ end
56
+ ```
57
+
58
+ ### Warning
59
+
60
+ Remember that using this gem to save encrypted fields to the database will always require the original master key in order to decrypt data.
61
+
62
+ It will not be possible to recover data encrypted if the original master key is lost.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "has_encrypted_field"
6
+
7
+ require "irb"
8
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
@@ -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,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HasEncryptedField
4
+ VERSION = "0.3.0"
5
+ 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,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_encrypted_field
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Vinicius Stock
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-03-19 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
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
119
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
120
+ - ".github/PULL_REQUEST_TEMPLATE/pull_request_template.md"
121
+ - ".github/workflows/ruby.yml"
122
+ - ".gitignore"
123
+ - ".rubocop.yml"
124
+ - CHANGELOG.md
125
+ - CONTRIBUTING.md
126
+ - Gemfile
127
+ - Gemfile.lock
128
+ - LICENSE.txt
129
+ - README.md
130
+ - Rakefile
131
+ - bin/console
132
+ - bin/setup
133
+ - has_encrypted_field.gemspec
134
+ - lib/has_encrypted_field.rb
135
+ - lib/has_encrypted_field/accessors.rb
136
+ - lib/has_encrypted_field/configuration.rb
137
+ - lib/has_encrypted_field/query_methods.rb
138
+ - lib/has_encrypted_field/version.rb
139
+ homepage: https://github.com/vinistock/has_encrypted_field
140
+ licenses:
141
+ - MIT
142
+ metadata:
143
+ homepage_uri: https://github.com/vinistock/has_encrypted_field
144
+ source_code_uri: https://github.com/vinistock/has_encrypted_field
145
+ changelog_uri: https://github.com/vinistock/has_encrypted_field/blob/master/CHANGELOG.md
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 2.3.0
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.1.2
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: Encrypted attributes for Rails models.
165
+ test_files: []