active_record_encrypted_string 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +68 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.travis.yml +6 -0
- data/Appraisals +18 -0
- data/CHANGELOG.md +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +118 -0
- data/README.md +55 -0
- data/Rakefile +8 -0
- data/active_record_encrypted_string.gemspec +38 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/gemfiles/5_0_stable.gemfile +10 -0
- data/gemfiles/5_1_stable.gemfile +9 -0
- data/gemfiles/5_2_stable.gemfile +9 -0
- data/gemfiles/6_0_stable.gemfile +9 -0
- data/lib/active_record_encrypted_string.rb +23 -0
- data/lib/active_record_encrypted_string/configuration.rb +11 -0
- data/lib/active_record_encrypted_string/type.rb +46 -0
- data/lib/active_record_encrypted_string/version.rb +5 -0
- metadata +202 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 16c12340eda2ad6a628bba3c2e453644a10c5349d5cee8480f72db277adc7e1a
|
4
|
+
data.tar.gz: '051916ef47c8e2eda8c9876e4228bacd7158468cf19da289d4391cdbaa1046d9'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ba98ac182ebc1a15e1dea5276840dd14f7b9ab9ba947b96e8f90c177d601a3c5dc98508773e78e20cde778d2faeb24fcb8049b7bb910e1a24e54b579ec28fbe0
|
7
|
+
data.tar.gz: dba1ae39f9afad1a82c263728b62e24432dad543a7ef0723df02a6f66af74bef5b1d7b36200a392d112a74ea4634a5cab6e2f802da65e7974a4bbc4daad0ca0b
|
@@ -0,0 +1,68 @@
|
|
1
|
+
common: &common
|
2
|
+
working_directory: ~/workspace
|
3
|
+
parallelism: 1
|
4
|
+
resource_class: small
|
5
|
+
environment:
|
6
|
+
CI: 1
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.7.1
|
9
|
+
steps:
|
10
|
+
- checkout
|
11
|
+
|
12
|
+
- restore_cache:
|
13
|
+
keys:
|
14
|
+
- bundle-v1-{{ checksum "active_record_string_encryption.gemspec" }}
|
15
|
+
- bundle-v1-
|
16
|
+
|
17
|
+
- run:
|
18
|
+
name: Build gem dependencies
|
19
|
+
command: |
|
20
|
+
bundle lock
|
21
|
+
bundle config --local path '.bundle'
|
22
|
+
bundle check || bundle install --jobs 4
|
23
|
+
|
24
|
+
bundle exec appraisal ${RAILS_VERSION} bundle lock
|
25
|
+
bundle exec appraisal ${RAILS_VERSION} bundle install --jobs 4
|
26
|
+
bundle exec appraisal ${RAILS_VERSION} bundle clean
|
27
|
+
|
28
|
+
- save_cache:
|
29
|
+
key: bundle-v1-{{ checksum "active_record_string_encryption.gemspec" }}
|
30
|
+
paths:
|
31
|
+
- active_record_string_encryption/gemfiles/.bundle
|
32
|
+
|
33
|
+
- run:
|
34
|
+
name: Run tests
|
35
|
+
command: bundle exec appraisal ${RAILS_VERSION} rspec
|
36
|
+
|
37
|
+
|
38
|
+
version: 2.1
|
39
|
+
jobs:
|
40
|
+
build_and_test_rails_5_0:
|
41
|
+
<<: *common
|
42
|
+
environment:
|
43
|
+
RAILS_VERSION: 5_0_stable
|
44
|
+
|
45
|
+
build_and_test_rails_5_1:
|
46
|
+
<<: *common
|
47
|
+
environment:
|
48
|
+
RAILS_VERSION: 5_1_stable
|
49
|
+
|
50
|
+
build_and_test_rails_5_2:
|
51
|
+
<<: *common
|
52
|
+
environment:
|
53
|
+
RAILS_VERSION: 5_2_stable
|
54
|
+
|
55
|
+
build_and_test_rails_6_0:
|
56
|
+
<<: *common
|
57
|
+
environment:
|
58
|
+
RAILS_VERSION: 6_0_stable
|
59
|
+
|
60
|
+
|
61
|
+
workflows:
|
62
|
+
version: 2
|
63
|
+
build-and-test:
|
64
|
+
jobs:
|
65
|
+
- build_and_test_rails_5_0
|
66
|
+
- build_and_test_rails_5_1
|
67
|
+
- build_and_test_rails_5_2
|
68
|
+
- build_and_test_rails_6_0
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
appraise '5_0_stable' do
|
4
|
+
gem 'activerecord', '~> 5.0.0'
|
5
|
+
gem 'sqlite3', '~> 1.3.6'
|
6
|
+
end
|
7
|
+
|
8
|
+
appraise '5_1_stable' do
|
9
|
+
gem 'activerecord', '~> 5.1.0'
|
10
|
+
end
|
11
|
+
|
12
|
+
appraise '5_2_stable' do
|
13
|
+
gem 'activerecord', '~> 5.2.0'
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise '6_0_stable' do
|
17
|
+
gem 'activerecord', '~> 6.0.0'
|
18
|
+
end
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at 32205171+kamillle@users.noreply.github.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
active_record_encrypted_string (1.0.0)
|
5
|
+
activerecord (>= 5.0, < 7)
|
6
|
+
activesupport (< 7)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
abstract_type (0.0.7)
|
12
|
+
activemodel (6.0.3.1)
|
13
|
+
activesupport (= 6.0.3.1)
|
14
|
+
activerecord (6.0.3.1)
|
15
|
+
activemodel (= 6.0.3.1)
|
16
|
+
activesupport (= 6.0.3.1)
|
17
|
+
activesupport (6.0.3.1)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (>= 0.7, < 2)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
23
|
+
adamantium (0.2.0)
|
24
|
+
ice_nine (~> 0.11.0)
|
25
|
+
memoizable (~> 0.4.0)
|
26
|
+
appraisal (2.3.0)
|
27
|
+
bundler
|
28
|
+
rake
|
29
|
+
thor (>= 0.14.0)
|
30
|
+
ast (2.4.0)
|
31
|
+
binding_ninja (0.2.3)
|
32
|
+
coderay (1.1.3)
|
33
|
+
concord (0.1.5)
|
34
|
+
adamantium (~> 0.2.0)
|
35
|
+
equalizer (~> 0.0.9)
|
36
|
+
concurrent-ruby (1.1.6)
|
37
|
+
diff-lcs (1.3)
|
38
|
+
equalizer (0.0.11)
|
39
|
+
i18n (1.8.3)
|
40
|
+
concurrent-ruby (~> 1.0)
|
41
|
+
ice_nine (0.11.2)
|
42
|
+
memoizable (0.4.2)
|
43
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
44
|
+
minitest (5.14.1)
|
45
|
+
parallel (1.19.1)
|
46
|
+
parser (2.7.1.3)
|
47
|
+
ast (~> 2.4.0)
|
48
|
+
proc_to_ast (0.1.0)
|
49
|
+
coderay
|
50
|
+
parser
|
51
|
+
unparser
|
52
|
+
procto (0.0.3)
|
53
|
+
rainbow (3.0.0)
|
54
|
+
rake (12.3.3)
|
55
|
+
regexp_parser (1.7.1)
|
56
|
+
rexml (3.2.4)
|
57
|
+
rspec (3.9.0)
|
58
|
+
rspec-core (~> 3.9.0)
|
59
|
+
rspec-expectations (~> 3.9.0)
|
60
|
+
rspec-mocks (~> 3.9.0)
|
61
|
+
rspec-core (3.9.2)
|
62
|
+
rspec-support (~> 3.9.3)
|
63
|
+
rspec-expectations (3.9.2)
|
64
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
65
|
+
rspec-support (~> 3.9.0)
|
66
|
+
rspec-mocks (3.9.1)
|
67
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
68
|
+
rspec-support (~> 3.9.0)
|
69
|
+
rspec-parameterized (0.4.2)
|
70
|
+
binding_ninja (>= 0.2.3)
|
71
|
+
parser
|
72
|
+
proc_to_ast
|
73
|
+
rspec (>= 2.13, < 4)
|
74
|
+
unparser
|
75
|
+
rspec-support (3.9.3)
|
76
|
+
rubocop (0.85.1)
|
77
|
+
parallel (~> 1.10)
|
78
|
+
parser (>= 2.7.0.1)
|
79
|
+
rainbow (>= 2.2.2, < 4.0)
|
80
|
+
regexp_parser (>= 1.7)
|
81
|
+
rexml
|
82
|
+
rubocop-ast (>= 0.0.3)
|
83
|
+
ruby-progressbar (~> 1.7)
|
84
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
85
|
+
rubocop-ast (0.0.3)
|
86
|
+
parser (>= 2.7.0.1)
|
87
|
+
ruby-progressbar (1.10.1)
|
88
|
+
sqlite3 (1.4.2)
|
89
|
+
thor (1.0.1)
|
90
|
+
thread_safe (0.3.6)
|
91
|
+
tzinfo (1.2.7)
|
92
|
+
thread_safe (~> 0.1)
|
93
|
+
unicode-display_width (1.7.0)
|
94
|
+
unparser (0.4.7)
|
95
|
+
abstract_type (~> 0.0.7)
|
96
|
+
adamantium (~> 0.2.0)
|
97
|
+
concord (~> 0.1.5)
|
98
|
+
diff-lcs (~> 1.3)
|
99
|
+
equalizer (~> 0.0.9)
|
100
|
+
parser (>= 2.6.5)
|
101
|
+
procto (~> 0.0.2)
|
102
|
+
zeitwerk (2.3.0)
|
103
|
+
|
104
|
+
PLATFORMS
|
105
|
+
ruby
|
106
|
+
|
107
|
+
DEPENDENCIES
|
108
|
+
active_record_encrypted_string!
|
109
|
+
appraisal
|
110
|
+
bundler
|
111
|
+
rake
|
112
|
+
rspec
|
113
|
+
rspec-parameterized
|
114
|
+
rubocop
|
115
|
+
sqlite3
|
116
|
+
|
117
|
+
BUNDLED WITH
|
118
|
+
2.1.4
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# ActiveRecordEncryptedString
|
2
|
+
Generates encrypted_string type that transparently encrypt and decrypt string value to ActiveRecord.
|
3
|
+
|
4
|
+
Support ActiveRecord 5.0 and later.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'active_record_encrypted_string', '>= 1'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
```shell
|
17
|
+
bundle install
|
18
|
+
```
|
19
|
+
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Call ActiveRecord::Attribute API and specify `:encrypted_string` as type, then your database has encrypted value and application can get plain value.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class User < ActiveRecord::Base
|
27
|
+
attribute :name, :encrypted_string
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Must configure secret_key and salt for encryption and decryption. You can also configure algorithm, pass the value to `cipher_alg`. `cipher_alg` has default value `aes-256-gcm` so you do not need to configure if you want to use `aes-256-gcm`.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
# config/initializers/active_record_encrypted_string.rb
|
35
|
+
ActiveRecordEncryptedString.configure do |c|
|
36
|
+
c.secret_key = ENV['ENCRYPTION_SECRET_KEY'],
|
37
|
+
c.salt = ENV['ENCRYPTION_SALT'],
|
38
|
+
c.cipher_alg = 'aes-256-gcm'
|
39
|
+
end
|
40
|
+
```
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
|
+
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/active_record_encrypted_string. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/active_record_encrypted_string/blob/master/CODE_OF_CONDUCT.md).
|
51
|
+
|
52
|
+
|
53
|
+
## Code of Conduct
|
54
|
+
|
55
|
+
Everyone interacting in the ActiveRecordEncryptedString project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/active_record_encrypted_string/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/active_record_encrypted_string/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'active_record_encrypted_string'
|
7
|
+
spec.version = ActiveRecordEncryptedString::VERSION
|
8
|
+
spec.authors = ['kamillle']
|
9
|
+
spec.email = ['32205171+kamillle@users.noreply.github.com']
|
10
|
+
|
11
|
+
spec.summary = 'Generates encrypted_string type that transparently encrypt and decrypt string value to ActiveRecord.'
|
12
|
+
spec.description = 'Generates encrypted_string type that transparently encrypt and decrypt string value to ActiveRecord.'
|
13
|
+
spec.homepage = 'https://github.com/kamillle/active_record_encrypted_string'
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
15
|
+
|
16
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
17
|
+
spec.metadata['source_code_uri'] = 'https://github.com/kamillle/active_record_encrypted_string'
|
18
|
+
spec.metadata['changelog_uri'] = 'https://github.com/kamillle/active_record_encrypted_string/CHANGELOG.md'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
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', '< 7'
|
30
|
+
spec.add_dependency 'activesupport', '< 7'
|
31
|
+
spec.add_development_dependency 'appraisal'
|
32
|
+
spec.add_development_dependency 'bundler'
|
33
|
+
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'rspec'
|
35
|
+
spec.add_development_dependency 'rspec-parameterized'
|
36
|
+
spec.add_development_dependency 'rubocop'
|
37
|
+
spec.add_development_dependency 'sqlite3'
|
38
|
+
end
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'active_record_encrypted_string'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/lazy_load_hooks'
|
4
|
+
require 'active_record_encrypted_string/version'
|
5
|
+
require 'active_record_encrypted_string/configuration'
|
6
|
+
|
7
|
+
module ActiveRecordEncryptedString
|
8
|
+
class << self
|
9
|
+
def configure
|
10
|
+
yield(configuration)
|
11
|
+
end
|
12
|
+
|
13
|
+
def configuration
|
14
|
+
@configuration ||= Configuration.new
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
ActiveSupport.on_load(:active_record) do
|
20
|
+
require 'active_record_encrypted_string/type'
|
21
|
+
|
22
|
+
ActiveRecord::Type.register(:encrypted_string, ActiveRecordEncryptedString::Type)
|
23
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ActiveRecordEncryptedString
|
4
|
+
class Type < ActiveRecord::Type::String
|
5
|
+
class << self
|
6
|
+
def key_len
|
7
|
+
ActiveSupport::MessageEncryptor.key_len(ActiveRecordEncryptedString.configuration.cipher_alg)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
# ActiveRecord calls `serialize` to convert Ruby objects to a format that can be understood by database
|
12
|
+
def serialize(value)
|
13
|
+
# expects same behavior as ActiveRecord::Type::String other than encryption
|
14
|
+
# https://github.com/rails/rails/blob/5-0-stable/activemodel/lib/active_model/type/immutable_string.rb
|
15
|
+
v = super(value)
|
16
|
+
v.present? ? encryptor.encrypt_and_sign(v) : v
|
17
|
+
end
|
18
|
+
|
19
|
+
# ActiveRecord calls `deserialize` to convert values stored database to Ruby objects
|
20
|
+
def deserialize(value)
|
21
|
+
# expects same behavior as ActiveRecord::Type::String other than decryption
|
22
|
+
# https://github.com/rails/rails/blob/5-0-stable/activemodel/lib/active_model/type/value.rb#L21-L23
|
23
|
+
v = super(value)
|
24
|
+
v.present? ? encryptor.decrypt_and_verify(v) : v
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def encryptor
|
30
|
+
# TODO: rotate
|
31
|
+
ActiveSupport::MessageEncryptor.new(secret, cipher: ActiveRecordEncryptedString.configuration.cipher_alg)
|
32
|
+
end
|
33
|
+
|
34
|
+
def secret
|
35
|
+
ActiveSupport::KeyGenerator.new(secret_key).generate_key(salt, self.class.key_len)
|
36
|
+
end
|
37
|
+
|
38
|
+
def secret_key
|
39
|
+
ActiveRecordEncryptedString.configuration.secret_key
|
40
|
+
end
|
41
|
+
|
42
|
+
def salt
|
43
|
+
ActiveRecordEncryptedString.configuration.salt
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: active_record_encrypted_string
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kamillle
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-13 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'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '7'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '5.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '7'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activesupport
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "<"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '7'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: appraisal
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rake
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: rspec
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: rspec-parameterized
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
type: :development
|
111
|
+
prerelease: false
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: rubocop
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
type: :development
|
125
|
+
prerelease: false
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
- !ruby/object:Gem::Dependency
|
132
|
+
name: sqlite3
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
type: :development
|
139
|
+
prerelease: false
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
description: Generates encrypted_string type that transparently encrypt and decrypt
|
146
|
+
string value to ActiveRecord.
|
147
|
+
email:
|
148
|
+
- 32205171+kamillle@users.noreply.github.com
|
149
|
+
executables: []
|
150
|
+
extensions: []
|
151
|
+
extra_rdoc_files: []
|
152
|
+
files:
|
153
|
+
- ".circleci/config.yml"
|
154
|
+
- ".gitignore"
|
155
|
+
- ".rspec"
|
156
|
+
- ".rubocop.yml"
|
157
|
+
- ".travis.yml"
|
158
|
+
- Appraisals
|
159
|
+
- CHANGELOG.md
|
160
|
+
- CODE_OF_CONDUCT.md
|
161
|
+
- Gemfile
|
162
|
+
- Gemfile.lock
|
163
|
+
- README.md
|
164
|
+
- Rakefile
|
165
|
+
- active_record_encrypted_string.gemspec
|
166
|
+
- bin/console
|
167
|
+
- bin/setup
|
168
|
+
- gemfiles/5_0_stable.gemfile
|
169
|
+
- gemfiles/5_1_stable.gemfile
|
170
|
+
- gemfiles/5_2_stable.gemfile
|
171
|
+
- gemfiles/6_0_stable.gemfile
|
172
|
+
- lib/active_record_encrypted_string.rb
|
173
|
+
- lib/active_record_encrypted_string/configuration.rb
|
174
|
+
- lib/active_record_encrypted_string/type.rb
|
175
|
+
- lib/active_record_encrypted_string/version.rb
|
176
|
+
homepage: https://github.com/kamillle/active_record_encrypted_string
|
177
|
+
licenses: []
|
178
|
+
metadata:
|
179
|
+
homepage_uri: https://github.com/kamillle/active_record_encrypted_string
|
180
|
+
source_code_uri: https://github.com/kamillle/active_record_encrypted_string
|
181
|
+
changelog_uri: https://github.com/kamillle/active_record_encrypted_string/CHANGELOG.md
|
182
|
+
post_install_message:
|
183
|
+
rdoc_options: []
|
184
|
+
require_paths:
|
185
|
+
- lib
|
186
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
187
|
+
requirements:
|
188
|
+
- - ">="
|
189
|
+
- !ruby/object:Gem::Version
|
190
|
+
version: 2.3.0
|
191
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
|
+
requirements:
|
193
|
+
- - ">="
|
194
|
+
- !ruby/object:Gem::Version
|
195
|
+
version: '0'
|
196
|
+
requirements: []
|
197
|
+
rubygems_version: 3.1.2
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: Generates encrypted_string type that transparently encrypt and decrypt string
|
201
|
+
value to ActiveRecord.
|
202
|
+
test_files: []
|