lite-encryption 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bee1adb5f59f9936b73b6df036b6e483d59e05d6bb17d805cde12913bd6ed667
4
- data.tar.gz: fc5e30962a65fa42361987c04c15bd23f8f895632723c13c355c1e06eae67c96
3
+ metadata.gz: cdda189309ae7d6af8fac9257314a5e57ffb942f6f9443a3d25dc13bf96d4ffe
4
+ data.tar.gz: ab1701787569d474a5d9107bc13522b71ea6339cf2d8542e3089356098d0321d
5
5
  SHA512:
6
- metadata.gz: abfd6cb379a4dd97e8f297d2678a96ce821aec36b04cea2885abf36b5ee504ed269fc82603592ad2c2d38678235cca6744c666ac8f86613f8f5d9d1d2c6fe51c
7
- data.tar.gz: a750806459a5fbccd5f4480fe46f44e3a8463d468f6cb8ca57549edb3720ca2d493e6165975319f7bd9068b099d79ccbdfab541cac2c62bc398792fec591a1a0
6
+ metadata.gz: 5017b7033e5d2939ce0fb02a534b7dcaf4c4cd2a069b9a6b0cca29a4838757d84d8a9f376f9ffc62d127b941c5082beb59cf5819a6a88f27ff7fef34fc3b2076
7
+ data.tar.gz: 65acf87b0fe976d86e9e9399e53cef33d1fca10f799d9f41819e8d4a89ee3f20939247b003248ed020b92111ac232b22c4b6cafa0525d6bf5cb22042c7424343
data/.rubocop.yml CHANGED
@@ -6,6 +6,8 @@ AllCops:
6
6
  NewCops: enable
7
7
  DisplayCopNames: true
8
8
  DisplayStyleGuide: true
9
+ Gemspec/RequiredRubyVersion:
10
+ Enabled: false
9
11
  Layout/EmptyLinesAroundAttributeAccessor:
10
12
  Enabled: true
11
13
  Layout/EmptyLinesAroundBlockBody:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.0] - 2021-04-12
10
+ ### Added
11
+ - Added deterministic encryption
12
+ ### Changed
13
+ - Update configuration methods
14
+
9
15
  ## [1.0.1] - 2020-07-03
10
16
  ### Added
11
17
  - Added Ruby 2.7 support
data/Gemfile.lock CHANGED
@@ -1,63 +1,70 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-encryption (1.0.2)
4
+ lite-encryption (1.1.0)
5
5
  activesupport
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actionpack (6.0.3.2)
11
- actionview (= 6.0.3.2)
12
- activesupport (= 6.0.3.2)
13
- rack (~> 2.0, >= 2.0.8)
10
+ actionpack (6.1.3.1)
11
+ actionview (= 6.1.3.1)
12
+ activesupport (= 6.1.3.1)
13
+ rack (~> 2.0, >= 2.0.9)
14
14
  rack-test (>= 0.6.3)
15
15
  rails-dom-testing (~> 2.0)
16
16
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
17
- actionview (6.0.3.2)
18
- activesupport (= 6.0.3.2)
17
+ actionview (6.1.3.1)
18
+ activesupport (= 6.1.3.1)
19
19
  builder (~> 3.1)
20
20
  erubi (~> 1.4)
21
21
  rails-dom-testing (~> 2.0)
22
22
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
- activemodel (6.0.3.2)
24
- activesupport (= 6.0.3.2)
25
- activerecord (6.0.3.2)
26
- activemodel (= 6.0.3.2)
27
- activesupport (= 6.0.3.2)
28
- activesupport (6.0.3.2)
23
+ activemodel (6.1.3.1)
24
+ activesupport (= 6.1.3.1)
25
+ activerecord (6.1.3.1)
26
+ activemodel (= 6.1.3.1)
27
+ activesupport (= 6.1.3.1)
28
+ activesupport (6.1.3.1)
29
29
  concurrent-ruby (~> 1.0, >= 1.0.2)
30
- i18n (>= 0.7, < 2)
31
- minitest (~> 5.1)
32
- tzinfo (~> 1.1)
33
- zeitwerk (~> 2.2, >= 2.2.2)
34
- ast (2.4.1)
30
+ i18n (>= 1.6, < 2)
31
+ minitest (>= 5.1)
32
+ tzinfo (~> 2.0)
33
+ zeitwerk (~> 2.3)
34
+ ast (2.4.2)
35
35
  builder (3.2.4)
36
36
  colorize (0.8.1)
37
- concurrent-ruby (1.1.6)
37
+ concurrent-ruby (1.1.8)
38
38
  crass (1.0.6)
39
- database_cleaner (1.8.5)
39
+ database_cleaner (2.0.1)
40
+ database_cleaner-active_record (~> 2.0.0)
41
+ database_cleaner-active_record (2.0.0)
42
+ activerecord (>= 5.a)
43
+ database_cleaner-core (~> 2.0.0)
44
+ database_cleaner-core (2.0.1)
40
45
  diff-lcs (1.4.4)
41
- erubi (1.9.0)
42
- fasterer (0.8.3)
46
+ erubi (1.10.0)
47
+ fasterer (0.9.0)
43
48
  colorize (~> 0.7)
44
49
  ruby_parser (>= 3.14.1)
45
50
  generator_spec (0.9.4)
46
51
  activesupport (>= 3.0.0)
47
52
  railties (>= 3.0.0)
48
- i18n (1.8.3)
53
+ i18n (1.8.10)
49
54
  concurrent-ruby (~> 1.0)
50
- loofah (2.6.0)
55
+ loofah (2.9.1)
51
56
  crass (~> 1.0.2)
52
57
  nokogiri (>= 1.5.9)
53
58
  method_source (1.0.0)
54
- mini_portile2 (2.4.0)
55
- minitest (5.14.1)
56
- nokogiri (1.10.9)
57
- mini_portile2 (~> 2.4.0)
58
- parallel (1.19.2)
59
- parser (2.7.1.4)
59
+ mini_portile2 (2.5.0)
60
+ minitest (5.14.4)
61
+ nokogiri (1.11.3)
62
+ mini_portile2 (~> 2.5.0)
63
+ racc (~> 1.4)
64
+ parallel (1.20.1)
65
+ parser (3.0.1.0)
60
66
  ast (~> 2.4.1)
67
+ racc (1.5.2)
61
68
  rack (2.2.3)
62
69
  rack-test (1.1.0)
63
70
  rack (>= 1.0, < 3)
@@ -66,63 +73,66 @@ GEM
66
73
  nokogiri (>= 1.6)
67
74
  rails-html-sanitizer (1.3.0)
68
75
  loofah (~> 2.3)
69
- railties (6.0.3.2)
70
- actionpack (= 6.0.3.2)
71
- activesupport (= 6.0.3.2)
76
+ railties (6.1.3.1)
77
+ actionpack (= 6.1.3.1)
78
+ activesupport (= 6.1.3.1)
72
79
  method_source
73
80
  rake (>= 0.8.7)
74
- thor (>= 0.20.3, < 2.0)
81
+ thor (~> 1.0)
75
82
  rainbow (3.0.0)
76
- rake (13.0.1)
77
- regexp_parser (1.7.1)
78
- rexml (3.2.4)
79
- rspec (3.9.0)
80
- rspec-core (~> 3.9.0)
81
- rspec-expectations (~> 3.9.0)
82
- rspec-mocks (~> 3.9.0)
83
- rspec-core (3.9.2)
84
- rspec-support (~> 3.9.3)
85
- rspec-expectations (3.9.2)
83
+ rake (13.0.3)
84
+ regexp_parser (2.1.1)
85
+ rexml (3.2.5)
86
+ rspec (3.10.0)
87
+ rspec-core (~> 3.10.0)
88
+ rspec-expectations (~> 3.10.0)
89
+ rspec-mocks (~> 3.10.0)
90
+ rspec-core (3.10.1)
91
+ rspec-support (~> 3.10.0)
92
+ rspec-expectations (3.10.1)
86
93
  diff-lcs (>= 1.2.0, < 2.0)
87
- rspec-support (~> 3.9.0)
88
- rspec-mocks (3.9.1)
94
+ rspec-support (~> 3.10.0)
95
+ rspec-mocks (3.10.2)
89
96
  diff-lcs (>= 1.2.0, < 2.0)
90
- rspec-support (~> 3.9.0)
91
- rspec-rails (4.0.1)
92
- actionpack (>= 4.2)
93
- activesupport (>= 4.2)
94
- railties (>= 4.2)
95
- rspec-core (~> 3.9)
96
- rspec-expectations (~> 3.9)
97
- rspec-mocks (~> 3.9)
98
- rspec-support (~> 3.9)
99
- rspec-support (3.9.3)
100
- rubocop (0.86.0)
97
+ rspec-support (~> 3.10.0)
98
+ rspec-rails (5.0.1)
99
+ actionpack (>= 5.2)
100
+ activesupport (>= 5.2)
101
+ railties (>= 5.2)
102
+ rspec-core (~> 3.10)
103
+ rspec-expectations (~> 3.10)
104
+ rspec-mocks (~> 3.10)
105
+ rspec-support (~> 3.10)
106
+ rspec-support (3.10.2)
107
+ rubocop (1.12.1)
101
108
  parallel (~> 1.10)
102
- parser (>= 2.7.0.1)
109
+ parser (>= 3.0.0.0)
103
110
  rainbow (>= 2.2.2, < 4.0)
104
- regexp_parser (>= 1.7)
111
+ regexp_parser (>= 1.8, < 3.0)
105
112
  rexml
106
- rubocop-ast (>= 0.0.3, < 1.0)
113
+ rubocop-ast (>= 1.2.0, < 2.0)
107
114
  ruby-progressbar (~> 1.7)
108
- unicode-display_width (>= 1.4.0, < 2.0)
109
- rubocop-ast (0.1.0)
110
- parser (>= 2.7.0.1)
111
- rubocop-performance (1.6.1)
112
- rubocop (>= 0.71.0)
113
- rubocop-rspec (1.41.0)
114
- rubocop (>= 0.68.1)
115
- ruby-progressbar (1.10.1)
116
- ruby_parser (3.14.2)
115
+ unicode-display_width (>= 1.4.0, < 3.0)
116
+ rubocop-ast (1.4.1)
117
+ parser (>= 2.7.1.5)
118
+ rubocop-performance (1.10.2)
119
+ rubocop (>= 0.90.0, < 2.0)
120
+ rubocop-ast (>= 0.4.0)
121
+ rubocop-rake (0.5.1)
122
+ rubocop
123
+ rubocop-rspec (2.2.0)
124
+ rubocop (~> 1.0)
125
+ rubocop-ast (>= 1.1.0)
126
+ ruby-progressbar (1.11.0)
127
+ ruby_parser (3.15.1)
117
128
  sexp_processor (~> 4.9)
118
- sexp_processor (4.15.0)
129
+ sexp_processor (4.15.2)
119
130
  sqlite3 (1.4.2)
120
- thor (1.0.1)
121
- thread_safe (0.3.6)
122
- tzinfo (1.2.7)
123
- thread_safe (~> 0.1)
124
- unicode-display_width (1.7.0)
125
- zeitwerk (2.3.1)
131
+ thor (1.1.0)
132
+ tzinfo (2.0.4)
133
+ concurrent-ruby (~> 1.0)
134
+ unicode-display_width (2.0.0)
135
+ zeitwerk (2.4.2)
126
136
 
127
137
  PLATFORMS
128
138
  ruby
@@ -139,8 +149,9 @@ DEPENDENCIES
139
149
  rspec-rails
140
150
  rubocop
141
151
  rubocop-performance
152
+ rubocop-rake
142
153
  rubocop-rspec
143
154
  sqlite3
144
155
 
145
156
  BUNDLED WITH
146
- 2.1.4
157
+ 2.2.16
data/README.md CHANGED
@@ -3,8 +3,8 @@
3
3
  [![Gem Version](https://badge.fury.io/rb/lite-encryption.svg)](http://badge.fury.io/rb/lite-encryption)
4
4
  [![Build Status](https://travis-ci.org/drexed/lite-encryption.svg?branch=master)](https://travis-ci.org/drexed/lite-encryption)
5
5
 
6
- Lite::Encryption is a ActiveSupport::MessageEncryptor wrapper library for encrypting and decrypting
7
- PORO objects and model attributes.
6
+ Lite::Encryption is a ActiveSupport::MessageEncryptor and OpenSSL::Cipher::Cipher wrapper libraries
7
+ for encrypting and decrypting PORO object values and model attributes.
8
8
 
9
9
  ## Installation
10
10
 
@@ -26,6 +26,7 @@ Or install it yourself as:
26
26
 
27
27
  * [Configurations](#configurations)
28
28
  * [Key](#key)
29
+ * [Schemes](#schemes)
29
30
  * [Message](#message)
30
31
  * [Attribute](#attribute)
31
32
 
@@ -36,24 +37,47 @@ Or install it yourself as:
36
37
 
37
38
  ```ruby
38
39
  Lite::Encryption.configure do |config|
39
- config.secret_key_base = ENV['SECRET_KEY_BASE']
40
- config.secret_key_salt = ENV['SECRET_KEY_SALT']
40
+ config.encryption_iv = ENV['ENCRYPTION_IV']
41
+ config.encryption_key = ENV['ENCRYPTION_KEY']
42
+ config.encryption_salt = ENV['ENCRYPTION_SALT']
41
43
  end
42
44
  ```
43
45
 
44
46
  ## Key
45
47
 
46
- Use the following to generate a base and salt key.
48
+ Use the following to generate encryption values that you can then add to your
49
+ credentials or ENV variables.
47
50
 
48
51
  ```ruby
49
- Lite::Encryption::Key.generate_base #=> "b912e83c02b44122e31809a7435bc91e2e48c88742365aaccb07283eeb0379909e9aa09d64fc27cb5f20c3f072cd69aacd57518916799c00d41d94c06c916f5c"
50
- Lite::Encryption::Key.generate_salt #=> "\xD5\x8C\xB6\x14\xAC\xC7-&\xAEu\xDDj\x80/\xDF\x15\xD1\xB2\x13\x04\x85\b\x8F\xC6ZQ`Z\xC7\xD4q\xDE"
52
+ Lite::Encryption::Key.generate_iv #=> "\x9C\x9F5<\xA5\x9B\x97\x97\xE2\x1DQ\x05"
53
+ Lite::Encryption::Key.generate_key #=> "y\x0Eo\xC1Gll\x05Qv\x11[\xE1vN8<\xAFxU_\xCB\xD7\x02)0\xC1#\x99\xDD4N"
54
+ Lite::Encryption::Key.generate_password #=> "289b4997f758b31693d3315679d9fa7c"
55
+ Lite::Encryption::Key.generate_salt #=> "\xD2\xBA\x9B\x81@e\x99\x8BN\a7\xC2\x95)f\x97k\xC9EM\xE0x\xFBO\x9BERBD\x85%n"
56
+ ```
57
+
58
+ ## Schemes
59
+
60
+ The non-deterministic message class is the wrapper class for `ActiveSupport::MessageEncryptor` so
61
+ you can pass it accepted options.
62
+
63
+ The deterministic message class is the wrapper class for `OpenSSL::Cipher::Cipher` so
64
+ you can pass it accepted options.
65
+
66
+ ```ruby
67
+ Lite::Encryption::Schemes::NonDeterministic.encrypt('decrypted_text', purpose: 'sec-pur')
68
+ Lite::Encryption::Schemes::NonDeterministic.decrypt('==encrypted_text')
69
+
70
+ # - or -
71
+
72
+ service = Lite::Encryption::Deterministic.new
73
+
74
+ service.encrypt('decrypted_text')
75
+ service.decrypt('==encrypted_text')
51
76
  ```
52
77
 
53
78
  ## Message
54
79
 
55
- The message class is the wrapper class for `ActiveSupport::MessageEncryptor` so you can pass it
56
- accepted options.
80
+ The message class is the wrapper class for both schemes so you can pass it accepted options.
57
81
 
58
82
  ```ruby
59
83
  Lite::Encryption::Message.encrypt('decrypted_text', purpose: 'sec-pur')
@@ -65,6 +89,18 @@ service = Lite::Encryption::Message.new
65
89
 
66
90
  service.encrypt('decrypted_text', expires_in: 2.hours)
67
91
  service.decrypt('==encrypted_text')
92
+
93
+ # - or -
94
+
95
+ Lite::Encryption::Message.encrypt('decrypted_text', deterministic: true)
96
+ Lite::Encryption::Message.decrypt('==encrypted_text', deterministic: true)
97
+
98
+ # - or -
99
+
100
+ service = Lite::Encryption::Message.new
101
+
102
+ service.encrypt('decrypted_text', deterministic: true)
103
+ service.decrypt('==encrypted_text', deterministic: true)
68
104
  ```
69
105
 
70
106
  ## Attribute
@@ -78,6 +114,7 @@ encrypt and decrypt your values.
78
114
  class CreditCard < ActiveRecord::Base
79
115
  extend Lite::Encryption::Attribute
80
116
 
117
+ attr_encrypt :name, deterministic: true
81
118
  attr_encrypt :number, :cvv, purpose: 'payment-menthod'
82
119
 
83
120
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Lite::Encryption.configure do |config|
4
- config.secret_key_base = ENV['SECRET_KEY_BASE']
5
- config.secret_key_salt = ENV['SECRET_KEY_SALT']
4
+ config.encryption_iv = ENV['ENCRYPTION_IV']
5
+ config.encryption_key = ENV['ENCRYPTION_KEY']
6
+ config.encryption_salt = ENV['ENCRYPTION_SALT']
6
7
  end
@@ -1,6 +1,22 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- %w[version key configuration message attribute].each do |filename|
3
+ %w[key_generator message_encryptor message_verifier].each do |filename|
4
+ require "active_support/#{filename}"
5
+ end
6
+
7
+ require 'lite/encryption/version'
8
+
9
+ %w[key configuration].each do |filename|
10
+ require "lite/encryption/#{filename}"
11
+ end
12
+
13
+ require 'lite/encryption/helpers/class_methods'
14
+
15
+ %w[deterministic non_deterministic].each do |filename|
16
+ require "lite/encryption/schemes/#{filename}"
17
+ end
18
+
19
+ %w[message attribute].each do |filename|
4
20
  require "lite/encryption/#{filename}"
5
21
  end
6
22
 
@@ -5,11 +5,12 @@ module Lite
5
5
 
6
6
  class Configuration
7
7
 
8
- attr_accessor :secret_key_base, :secret_key_salt
8
+ attr_accessor :encryption_iv, :encryption_key, :encryption_salt
9
9
 
10
10
  def initialize
11
- @secret_key_base = Lite::Encryption::Key.generate_base
12
- @secret_key_salt = Lite::Encryption::Key.generate_salt
11
+ @encryption_iv = Lite::Encryption::Key.generate_iv
12
+ @encryption_key = Lite::Encryption::Key.generate_key
13
+ @encryption_salt = Lite::Encryption::Key.generate_salt
13
14
  end
14
15
 
15
16
  end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Encryption
5
+ module Helpers
6
+ module ClassMethods
7
+
8
+ %i[decrypt encrypt].each do |name|
9
+ define_method(name) do |value, opts = {}|
10
+ klass = new
11
+ klass.send(name, value, opts)
12
+ end
13
+ end
14
+
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,22 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/message_encryptor'
4
3
  require 'securerandom'
5
4
 
6
5
  module Lite
7
6
  module Encryption
8
7
  class Key
9
8
 
10
- LENGTH ||= ActiveSupport::MessageEncryptor.key_len
9
+ CIPHER = OpenSSL::Cipher.new('aes-256-gcm').freeze
10
+ LENGTHS = {
11
+ iv: CIPHER.iv_len,
12
+ key: CIPHER.key_len,
13
+ password: 16,
14
+ salt: CIPHER.key_len
15
+ }.freeze
11
16
 
12
17
  class << self
13
18
 
14
- def generate_base
15
- SecureRandom.hex(LENGTH * 2)
19
+ def generate_iv
20
+ SecureRandom.random_bytes(LENGTHS[:iv])
21
+ end
22
+
23
+ def generate_key
24
+ generator = ActiveSupport::KeyGenerator.new(generate_password)
25
+ generator.generate_key(generate_salt, LENGTHS[:key])
26
+ end
27
+
28
+ def generate_password
29
+ SecureRandom.hex(LENGTHS[:password])
16
30
  end
17
31
 
18
32
  def generate_salt
19
- SecureRandom.random_bytes(LENGTH)
33
+ SecureRandom.random_bytes(LENGTHS[:salt])
20
34
  end
21
35
 
22
36
  end
@@ -1,45 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- %w[key_generator message_encryptor message_verifier].each do |filename|
4
- require "active_support/#{filename}"
5
- end
6
-
7
3
  module Lite
8
4
  module Encryption
9
5
  class Message
10
6
 
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
7
+ extend Lite::Encryption::Helpers::ClassMethods
30
8
 
31
9
  def decrypt(value, opts = {})
32
- encryptor.decrypt_and_verify(value, **opts)
10
+ scheme = scheme_by_option(opts)
11
+ scheme.decrypt(value, **opts)
33
12
  end
34
13
 
35
14
  def encrypt(value, opts = {})
36
- encryptor.encrypt_and_sign(value, **opts)
15
+ scheme = scheme_by_option(opts)
16
+ scheme.encrypt(value, **opts)
37
17
  end
38
18
 
39
19
  private
40
20
 
41
- def encryptor
42
- @encryptor ||= ActiveSupport::MessageEncryptor.new(KEY)
21
+ def deterministic_scheme
22
+ @deterministic_scheme ||= Lite::Encryption::Schemes::Deterministic.new
23
+ end
24
+
25
+ def non_deterministic_scheme
26
+ @non_deterministic_scheme ||= Lite::Encryption::Schemes::NonDeterministic.new
27
+ end
28
+
29
+ def scheme_by_option(options)
30
+ options.delete(:deterministic) ? deterministic_scheme : non_deterministic_scheme
43
31
  end
44
32
 
45
33
  end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Encryption
5
+ module Schemes
6
+ class Deterministic
7
+
8
+ extend Lite::Encryption::Helpers::ClassMethods
9
+
10
+ def decrypt(value, _opts = {})
11
+ decoded_value = Base64.strict_decode64(value)
12
+ crypt(:decrypt, decoded_value)
13
+ end
14
+
15
+ def encrypt(value, _opts = {})
16
+ encoded_value = crypt(:encrypt, value)
17
+ Base64.strict_encode64(encoded_value)
18
+ end
19
+
20
+ private
21
+
22
+ def cipher
23
+ @cipher ||= Lite::Encryption::Key::CIPHER.dup
24
+ end
25
+
26
+ def crypt(cipher_method, value)
27
+ cipher.send(cipher_method)
28
+ cipher.key = Lite::Encryption.configuration.encryption_salt
29
+ cipher.iv = Lite::Encryption.configuration.encryption_iv
30
+ cipher.update(value)
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lite
4
+ module Encryption
5
+ module Schemes
6
+ class NonDeterministic
7
+
8
+ extend Lite::Encryption::Helpers::ClassMethods
9
+
10
+ def decrypt(value, opts = {})
11
+ cipher.decrypt_and_verify(value, **opts)
12
+ end
13
+
14
+ def encrypt(value, opts = {})
15
+ cipher.encrypt_and_sign(value, **opts)
16
+ end
17
+
18
+ private
19
+
20
+ def cipher
21
+ @cipher ||= ActiveSupport::MessageEncryptor.new(
22
+ Lite::Encryption.configuration.encryption_key,
23
+ cipher: Lite::Encryption::Key::CIPHER.name
24
+ )
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Encryption
5
5
 
6
- VERSION ||= '1.0.2'
6
+ VERSION = '1.1.0'
7
7
 
8
8
  end
9
9
  end
@@ -51,6 +51,7 @@ Gem::Specification.new do |spec|
51
51
  spec.add_development_dependency 'rspec-rails'
52
52
  spec.add_development_dependency 'rubocop'
53
53
  spec.add_development_dependency 'rubocop-performance'
54
+ spec.add_development_dependency 'rubocop-rake'
54
55
  spec.add_development_dependency 'rubocop-rspec'
55
56
  spec.add_development_dependency 'sqlite3'
56
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lite-encryption
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juan Gomez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-03 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -164,6 +164,20 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: rubocop-rake
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'
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rubocop-rspec
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -219,8 +233,11 @@ files:
219
233
  - lib/lite/encryption.rb
220
234
  - lib/lite/encryption/attribute.rb
221
235
  - lib/lite/encryption/configuration.rb
236
+ - lib/lite/encryption/helpers/class_methods.rb
222
237
  - lib/lite/encryption/key.rb
223
238
  - lib/lite/encryption/message.rb
239
+ - lib/lite/encryption/schemes/deterministic.rb
240
+ - lib/lite/encryption/schemes/non_deterministic.rb
224
241
  - lib/lite/encryption/version.rb
225
242
  - lite-encryption.gemspec
226
243
  homepage: http://drexed.github.io/lite-encryption
@@ -242,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
242
259
  - !ruby/object:Gem::Version
243
260
  version: '0'
244
261
  requirements: []
245
- rubygems_version: 3.1.4
262
+ rubygems_version: 3.2.16
246
263
  signing_key:
247
264
  specification_version: 4
248
265
  summary: ActiveSupport::MessageEncryptor encryption wrapper for PORO objects and ActiveModel