lite-encryption 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8e6341e27bca450a794f52c1e212acceb3c0ba906283183090d9b74cba762727
4
+ data.tar.gz: 354c78a0d9ee5ad39ce6ed00fae615ee57978b3368f7403b58f551b8e51488f3
5
+ SHA512:
6
+ metadata.gz: b2147b276a2324dcb858ba53809f2ba8be89d2bdac581bdef7d67a852ed5c1dd8821d3131367d799bfa5411bd296f99f48d9120d771cbf3b374af429ab419b6c
7
+ data.tar.gz: 1d0829e71711850aaf6767c865c47ad136a017086493ff388703b5cb4c4200eb7524c812bd5ac1679e9aa953112fc4b69b65a6666ab17baee4efaf2e9f6a45ce
data/.fasterer.yml ADDED
@@ -0,0 +1,19 @@
1
+ speedups:
2
+ block_vs_symbol_to_proc: true
3
+ each_with_index_vs_while: false
4
+ fetch_with_argument_vs_block: true
5
+ for_loop_vs_each: true
6
+ getter_vs_attr_reader: true
7
+ gsub_vs_tr: true
8
+ hash_merge_bang_vs_hash_brackets: true
9
+ keys_each_vs_each_key: true
10
+ map_flatten_vs_flat_map: true
11
+ module_eval: true
12
+ proc_call_vs_yield: true
13
+ rescue_vs_respond_to: true
14
+ reverse_each_vs_reverse_each: true
15
+ select_first_vs_detect: true
16
+ select_last_vs_reverse_detect: true
17
+ setter_vs_attr_writer: true
18
+ shuffle_first_vs_sample: true
19
+ sort_vs_sort_by: true
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --backtrace
2
+ --color
3
+ --format progress
4
+ --order random
data/.rubocop.yml ADDED
@@ -0,0 +1,28 @@
1
+ require:
2
+ - rubocop-performance
3
+ - rubocop-rspec
4
+ AllCops:
5
+ TargetRubyVersion: 2.6
6
+ DisplayCopNames: true
7
+ DisplayStyleGuide: true
8
+ LineLength:
9
+ Max: 100
10
+ Layout/EmptyLinesAroundBlockBody:
11
+ Exclude:
12
+ - 'spec/**/**/*'
13
+ Layout/EmptyLinesAroundClassBody:
14
+ EnforcedStyle: empty_lines_except_namespace
15
+ Layout/EmptyLinesAroundModuleBody:
16
+ EnforcedStyle: empty_lines_except_namespace
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - 'spec/**/**/*'
20
+ - '*.gemspec'
21
+ Metrics/ModuleLength:
22
+ Enabled: false
23
+ RSpec/MultipleExpectations:
24
+ Enabled: false
25
+ Style/Documentation:
26
+ Enabled: false
27
+ Style/ExpandPathArguments:
28
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.5
6
+ - 2.6
7
+ - ruby-head
8
+ matrix:
9
+ fast_finish: true
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ before_install:
13
+ - gem update --system
14
+ - gem install bundler
15
+ install:
16
+ - bundle install --jobs=3 --retry=3
17
+ script:
18
+ - bundle exec rspec
19
+ - bundle exec rubocop
20
+ - bundle exec fasterer
21
+ notifications:
22
+ email: false
23
+ slack:
24
+ secure: Y66IyzeykhW/qjQsRee5n4ESEObpdjyLRZfhuBimH/Gn4r6hpB67Bl+d7MTNCNGACK4v9lkclpqBTxdELJA60b1DqpUKhOXM8BXYMrJq8ktiY4t+iqZUQEMzfYYQSMbC+YuozNxFaHc0Ngigh0Dx/giHR9uofmdl5fsAODnzX9KLFOdDzRfANjLw9WhCQ6l7VkyY9cbO4PirTYG3I+LRP45/l+SbwxtWYsLuAJ79UD4Jnm1FuPxUFwq5Iebqv6vTWLkLFM9GuI+uuZnGHyAaMxR55iKp24XR44VQ/s7vkgHhSTCWUIPHSEl5TrEGOUxu9ylmOwaG8fVa0zTRzhjbrTlZ3lAzpDqcqwc1X5ssuEVZCeKOetB+vHyYfcfHKe3Ye4v9AMiUxXXLRsC2WbUihL8uohEEy79KenrVQJBnFJHVU5kx/mbeDjgrzvaBeVtBfWcaMoNTGXHsEr752PD7z65Ui1lGpj1ECQhpbst1mbShi1iSRNe/2u7r7+OcAtNUjQLcrM0XwGWfp0G+sYHxD4r7mkONq+Pzr5VEc4UjMpATKuhJS3nhm0O6hCtwYADGfn5ea0uVeQfgNmW9uJstfviCH6+z4177rfY/Logxw3Ce/qN1b8UJJrlfFmgnTLzzqpBft5/dSsppUgWZ6axF44UXOOAbtZjjwGHfiIViAYM=
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [1.0.0] - 2019-08-24
10
+ ### Added
11
+ - Initial project version
@@ -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 j.gomez@drexed.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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in lite-encryption.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,141 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ lite-encryption (1.0.0)
5
+ activesupport
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionpack (6.0.0)
11
+ actionview (= 6.0.0)
12
+ activesupport (= 6.0.0)
13
+ rack (~> 2.0)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
+ actionview (6.0.0)
18
+ activesupport (= 6.0.0)
19
+ builder (~> 3.1)
20
+ erubi (~> 1.4)
21
+ rails-dom-testing (~> 2.0)
22
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
+ activemodel (6.0.0)
24
+ activesupport (= 6.0.0)
25
+ activerecord (6.0.0)
26
+ activemodel (= 6.0.0)
27
+ activesupport (= 6.0.0)
28
+ activesupport (6.0.0)
29
+ concurrent-ruby (~> 1.0, >= 1.0.2)
30
+ i18n (>= 0.7, < 2)
31
+ minitest (~> 5.1)
32
+ tzinfo (~> 1.1)
33
+ zeitwerk (~> 2.1, >= 2.1.8)
34
+ ast (2.4.0)
35
+ builder (3.2.3)
36
+ colorize (0.8.1)
37
+ concurrent-ruby (1.1.5)
38
+ crass (1.0.4)
39
+ database_cleaner (1.7.0)
40
+ diff-lcs (1.3)
41
+ erubi (1.8.0)
42
+ fasterer (0.6.0)
43
+ colorize (~> 0.7)
44
+ ruby_parser (>= 3.13.0)
45
+ generator_spec (0.9.4)
46
+ activesupport (>= 3.0.0)
47
+ railties (>= 3.0.0)
48
+ i18n (1.6.0)
49
+ concurrent-ruby (~> 1.0)
50
+ jaro_winkler (1.5.3)
51
+ loofah (2.2.3)
52
+ crass (~> 1.0.2)
53
+ nokogiri (>= 1.5.9)
54
+ method_source (0.9.2)
55
+ mini_portile2 (2.4.0)
56
+ minitest (5.11.3)
57
+ nokogiri (1.10.4)
58
+ mini_portile2 (~> 2.4.0)
59
+ parallel (1.17.0)
60
+ parser (2.6.3.0)
61
+ ast (~> 2.4.0)
62
+ rack (2.0.7)
63
+ rack-test (1.1.0)
64
+ rack (>= 1.0, < 3)
65
+ rails-dom-testing (2.0.3)
66
+ activesupport (>= 4.2.0)
67
+ nokogiri (>= 1.6)
68
+ rails-html-sanitizer (1.2.0)
69
+ loofah (~> 2.2, >= 2.2.2)
70
+ railties (6.0.0)
71
+ actionpack (= 6.0.0)
72
+ activesupport (= 6.0.0)
73
+ method_source
74
+ rake (>= 0.8.7)
75
+ thor (>= 0.20.3, < 2.0)
76
+ rainbow (3.0.0)
77
+ rake (12.3.3)
78
+ rspec (3.8.0)
79
+ rspec-core (~> 3.8.0)
80
+ rspec-expectations (~> 3.8.0)
81
+ rspec-mocks (~> 3.8.0)
82
+ rspec-core (3.8.2)
83
+ rspec-support (~> 3.8.0)
84
+ rspec-expectations (3.8.4)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.8.0)
87
+ rspec-mocks (3.8.1)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.8.0)
90
+ rspec-rails (3.8.2)
91
+ actionpack (>= 3.0)
92
+ activesupport (>= 3.0)
93
+ railties (>= 3.0)
94
+ rspec-core (~> 3.8.0)
95
+ rspec-expectations (~> 3.8.0)
96
+ rspec-mocks (~> 3.8.0)
97
+ rspec-support (~> 3.8.0)
98
+ rspec-support (3.8.2)
99
+ rubocop (0.74.0)
100
+ jaro_winkler (~> 1.5.1)
101
+ parallel (~> 1.10)
102
+ parser (>= 2.6)
103
+ rainbow (>= 2.2.2, < 4.0)
104
+ ruby-progressbar (~> 1.7)
105
+ unicode-display_width (>= 1.4.0, < 1.7)
106
+ rubocop-performance (1.4.1)
107
+ rubocop (>= 0.71.0)
108
+ rubocop-rspec (1.35.0)
109
+ rubocop (>= 0.60.0)
110
+ ruby-progressbar (1.10.1)
111
+ ruby_parser (3.13.1)
112
+ sexp_processor (~> 4.9)
113
+ sexp_processor (4.12.1)
114
+ sqlite3 (1.4.1)
115
+ thor (0.20.3)
116
+ thread_safe (0.3.6)
117
+ tzinfo (1.2.5)
118
+ thread_safe (~> 0.1)
119
+ unicode-display_width (1.6.0)
120
+ zeitwerk (2.1.9)
121
+
122
+ PLATFORMS
123
+ ruby
124
+
125
+ DEPENDENCIES
126
+ activerecord
127
+ bundler
128
+ database_cleaner
129
+ fasterer
130
+ generator_spec
131
+ lite-encryption!
132
+ rake
133
+ rspec
134
+ rspec-rails
135
+ rubocop
136
+ rubocop-performance
137
+ rubocop-rspec
138
+ sqlite3
139
+
140
+ BUNDLED WITH
141
+ 2.0.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Juan Gomez
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,113 @@
1
+ # Lite::Encryption
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/lite-encryption.svg)](http://badge.fury.io/rb/lite-encryption)
4
+ [![Build Status](https://travis-ci.org/drexed/lite-encryption.svg?branch=master)](https://travis-ci.org/drexed/lite-encryption)
5
+
6
+ Lite::Encryption is a ActiveSupport::MessageEncryptor wrapper library for encrypting and decrypting
7
+ PORO objects and model attributes.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'lite-encryption'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install lite-encryption
24
+
25
+ ## Table of Contents
26
+
27
+ * [Configurations](#configurations)
28
+ * [Message](#message)
29
+ * [Attribute](#attribute)
30
+
31
+ ## Configurations
32
+
33
+ `rails g lite:encryption:install` will generate the following file:
34
+ `../config/initalizers/lite_encryption.rb`
35
+
36
+ ```ruby
37
+ Lite::Encryption.configure do |config|
38
+ config.secret_key_base = nil
39
+ config.secret_key_salt = nil
40
+ end
41
+ ```
42
+
43
+ `secret_key_base` and `secret_key_salt` should be supplied via environment variables or a secret
44
+ management system.
45
+
46
+ To generate a `secret_key_base`, execute `bundle exec rails secret` in the terminal prompt.
47
+ To generate a `secret_key_salt`, execute the following command in the Rails console prompt:
48
+ ```ruby
49
+ SecureRandom.random_bytes(
50
+ ActiveSupport::MessageEncryptor.key_len
51
+ )
52
+ ```
53
+
54
+ ## Message
55
+
56
+ The message class is the wrapper class for `ActiveSupport::MessageEncryptor` so you can pass it
57
+ accepted options.
58
+
59
+ ```ruby
60
+ Lite::Encryption::Message.encrypt('decrypted_text', purpose: 'sec-pur')
61
+ Lite::Encryption::Message.decrypt('==encrypted_text')
62
+
63
+ # - or -
64
+
65
+ service = Lite::Encryption::Message.new
66
+
67
+ service.encrypt('decrypted_text', expires_in: 2.hours)
68
+ service.decrypt('==encrypted_text')
69
+ ```
70
+
71
+ ## Attribute
72
+
73
+ The attribute module provides a handy method for encrypting and decrypting attributes.
74
+ You must add an `encrypted_*[column_name]` attribute to your database table like
75
+ `encrypted_number`. You can then add code like the following for it to automatically
76
+ encrypt and decrypt your values.
77
+
78
+ ```ruby
79
+ class CreditCard < ActiveRecord::Base
80
+ extend Lite::Encryption::Attribute
81
+
82
+ attr_encrypt :number, :cvv, purpose: 'payment-menthod'
83
+
84
+ end
85
+ ```
86
+
87
+ You can then access attributes using the following:
88
+
89
+ ```ruby
90
+ credit_card = CreditCard.create(number: '1234')
91
+
92
+ credit_card.encrypted_number #=> '==encrypted_text'
93
+ credit_card.decrypted_number #=> '1234'
94
+ credit_card.number #=> '1234'
95
+ ```
96
+
97
+ ## Development
98
+
99
+ 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.
100
+
101
+ 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).
102
+
103
+ ## Contributing
104
+
105
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/lite-encryption. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
+
107
+ ## License
108
+
109
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
110
+
111
+ ## Code of Conduct
112
+
113
+ Everyone interacting in the Lite::Encryption project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lite-encryption/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/_config.yml ADDED
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-leap-day
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 'lite/encryption'
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/generators'
4
+
5
+ module Lite
6
+ module Encryption
7
+ class InstallGenerator < Rails::Generators::Base
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ def copy_initializer_file
12
+ copy_file('install.rb', 'config/initializers/lite_encryption.rb')
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Lite::Encryption.configure do |config|
4
+ config.secret_key_base = nil
5
+ config.secret_key_salt = nil
6
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[version configuration message attribute].each do |filename|
4
+ require "lite/encryption/#{filename}"
5
+ end
6
+
7
+ require 'generators/lite/encryption/install_generator'
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Encryption
5
+ module Attribute
6
+
7
+ # rubocop:disable Metrics/MethodLength
8
+ def attr_encrypt(*fields, **opts)
9
+ class_eval do
10
+ fields.each do |field|
11
+ define_method("#{field}=") do |value|
12
+ return if value.nil?
13
+
14
+ encrypted_value = Lite::Encryption::Message.encrypt(value, opts)
15
+ send("encrypted_#{field}=", encrypted_value)
16
+ end
17
+
18
+ define_method(field) do
19
+ encrypted_value = send("encrypted_#{field}")
20
+ return if encrypted_value.blank?
21
+
22
+ Lite::Encryption::Message.decrypt(encrypted_value, opts)
23
+ end
24
+
25
+ define_method("decrypted_#{field}") do
26
+ send(field)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ # rubocop:enable Metrics/MethodLength
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Encryption
5
+
6
+ class Configuration
7
+
8
+ attr_accessor :secret_key_base, :secret_key_salt
9
+
10
+ # rubocop:disable Metrics/LineLength
11
+ def initialize
12
+ @secret_key_base = 'b912e83c02b44122e31809a7435bc91e2e48c88742365aaccb07283eeb0379909e9aa09d64fc27cb5f20c3f072cd69aacd57518916799c00d41d94c06c916f5c'
13
+ @secret_key_salt = "\xD5\x8C\xB6\x14\xAC\xC7-&\xAEu\xDDj\x80/\xDF\x15\xD1\xB2\x13\x04\x85\b\x8F\xC6ZQ`Z\xC7\xD4q\xDE"
14
+ end
15
+ # rubocop:enable Metrics/LineLength
16
+
17
+ end
18
+
19
+ class << self
20
+
21
+ attr_writer :configuration
22
+
23
+ def configuration
24
+ @configuration ||= Configuration.new
25
+ end
26
+
27
+ def configure
28
+ yield(configuration)
29
+ end
30
+
31
+ def reset_configuration!
32
+ @configuration = Configuration.new
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w[key_generator message_encryptor message_verifier].each do |filename|
4
+ require "active_support/#{filename}"
5
+ end
6
+
7
+ module Lite
8
+ module Encryption
9
+ class Message
10
+
11
+ KEY ||= ActiveSupport::KeyGenerator.new(
12
+ Lite::Encryption.configuration.secret_key_base
13
+ ).generate_key(
14
+ Lite::Encryption.configuration.secret_key_salt,
15
+ ActiveSupport::MessageEncryptor.key_len
16
+ ).freeze
17
+
18
+ private_constant :KEY
19
+
20
+ class << self
21
+
22
+ %i[decrypt encrypt].each do |name|
23
+ define_method(name) do |value, opts = {}|
24
+ klass = new
25
+ klass.send(name, value, opts)
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ def decrypt(value, opts = {})
32
+ encryptor.decrypt_and_verify(value, opts)
33
+ end
34
+
35
+ def encrypt(value, opts = {})
36
+ encryptor.encrypt_and_sign(value, opts)
37
+ end
38
+
39
+ private
40
+
41
+ def encryptor
42
+ @encryptor ||= ActiveSupport::MessageEncryptor.new(KEY)
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Encryption
5
+
6
+ VERSION ||= '1.0.0'
7
+
8
+ end
9
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'lite/encryption/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'lite-encryption'
9
+ spec.version = Lite::Encryption::VERSION
10
+ spec.authors = ['Juan Gomez']
11
+ spec.email = %w[j.gomez@drexed.com]
12
+
13
+ # rubocop:disable Metrics/LineLength
14
+ spec.summary = 'ActiveSupport::MessageEncryptor encryption wrapper for PORO objects and ActiveModel attributes'
15
+ # rubocop:enable Metrics/LineLength
16
+ spec.homepage = 'http://drexed.github.io/lite-encryption'
17
+ spec.license = 'MIT'
18
+
19
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
20
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
21
+ if spec.respond_to?(:metadata)
22
+ spec.metadata.merge(
23
+ 'allowed_push_host' => 'https://rubygems.org',
24
+ 'changelog_uri' => 'https://github.com/drexed/lite-encryption/blob/master/CHANGELOG.md',
25
+ 'homepage_uri' => spec.homepage,
26
+ 'source_code_uri' => 'https://github.com/drexed/lite-encryption'
27
+ )
28
+ else
29
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
30
+ 'public gem pushes.'
31
+ end
32
+
33
+ # Specify which files should be added to the gem when it is released.
34
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
35
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
36
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
37
+ end
38
+ spec.bindir = 'exe'
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = %w[lib]
41
+
42
+ spec.add_runtime_dependency 'activesupport'
43
+
44
+ spec.add_development_dependency 'activerecord'
45
+ spec.add_development_dependency 'bundler'
46
+ spec.add_development_dependency 'database_cleaner'
47
+ spec.add_development_dependency 'fasterer'
48
+ spec.add_development_dependency 'generator_spec'
49
+ spec.add_development_dependency 'rake'
50
+ spec.add_development_dependency 'rspec'
51
+ spec.add_development_dependency 'rspec-rails'
52
+ spec.add_development_dependency 'rubocop'
53
+ spec.add_development_dependency 'rubocop-performance'
54
+ spec.add_development_dependency 'rubocop-rspec'
55
+ spec.add_development_dependency 'sqlite3'
56
+ end
metadata ADDED
@@ -0,0 +1,249 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lite-encryption
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Juan Gomez
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-08-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
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: bundler
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: database_cleaner
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: fasterer
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: generator_spec
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: rake
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
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec-rails
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: rubocop-performance
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: sqlite3
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ description:
196
+ email:
197
+ - j.gomez@drexed.com
198
+ executables: []
199
+ extensions: []
200
+ extra_rdoc_files: []
201
+ files:
202
+ - ".fasterer.yml"
203
+ - ".gitignore"
204
+ - ".rspec"
205
+ - ".rubocop.yml"
206
+ - ".travis.yml"
207
+ - CHANGELOG.md
208
+ - CODE_OF_CONDUCT.md
209
+ - Gemfile
210
+ - Gemfile.lock
211
+ - LICENSE.txt
212
+ - README.md
213
+ - Rakefile
214
+ - _config.yml
215
+ - bin/console
216
+ - bin/setup
217
+ - lib/generators/lite/encryption/install_generator.rb
218
+ - lib/generators/lite/encryption/templates/install.rb
219
+ - lib/lite/encryption.rb
220
+ - lib/lite/encryption/attribute.rb
221
+ - lib/lite/encryption/configuration.rb
222
+ - lib/lite/encryption/message.rb
223
+ - lib/lite/encryption/version.rb
224
+ - lite-encryption.gemspec
225
+ homepage: http://drexed.github.io/lite-encryption
226
+ licenses:
227
+ - MIT
228
+ metadata: {}
229
+ post_install_message:
230
+ rdoc_options: []
231
+ require_paths:
232
+ - lib
233
+ required_ruby_version: !ruby/object:Gem::Requirement
234
+ requirements:
235
+ - - ">="
236
+ - !ruby/object:Gem::Version
237
+ version: '0'
238
+ required_rubygems_version: !ruby/object:Gem::Requirement
239
+ requirements:
240
+ - - ">="
241
+ - !ruby/object:Gem::Version
242
+ version: '0'
243
+ requirements: []
244
+ rubygems_version: 3.0.4
245
+ signing_key:
246
+ specification_version: 4
247
+ summary: ActiveSupport::MessageEncryptor encryption wrapper for PORO objects and ActiveModel
248
+ attributes
249
+ test_files: []