symmetric-encryption 3.2 → 3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/README.md +67 -11
- data/lib/symmetric_encryption.rb +7 -9
- data/lib/symmetric_encryption/extensions/active_record/base.rb +29 -11
- data/lib/symmetric_encryption/mongoid.rb +29 -7
- data/lib/symmetric_encryption/railties/symmetric_encryption.rake +5 -1
- data/lib/symmetric_encryption/symmetric_encryption.rb +94 -7
- data/lib/symmetric_encryption/version.rb +1 -1
- data/test/attr_encrypted_test.rb +315 -17
- data/test/cipher_test.rb +1 -10
- data/test/field_encrypted_test.rb +306 -19
- data/test/reader_test.rb +1 -10
- data/test/symmetric_encryption_test.rb +113 -10
- data/test/test_db.sqlite3 +0 -0
- data/test/test_helper.rb +19 -0
- data/test/writer_test.rb +1 -10
- metadata +28 -12
data/test/reader_test.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
-
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
2
|
require 'stringio'
|
5
|
-
require 'rubygems'
|
6
|
-
require 'test/unit'
|
7
|
-
require 'shoulda'
|
8
|
-
require 'symmetric-encryption'
|
9
|
-
|
10
|
-
# Load Symmetric Encryption keys
|
11
|
-
SymmetricEncryption.load!(File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
|
12
3
|
|
13
4
|
# Unit Test for SymmetricEncrypted::ReaderStream
|
14
5
|
#
|
@@ -1,13 +1,4 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
-
|
4
|
-
require 'rubygems'
|
5
|
-
require 'test/unit'
|
6
|
-
require 'shoulda'
|
7
|
-
require 'symmetric-encryption'
|
8
|
-
|
9
|
-
# Load Symmetric Encryption keys
|
10
|
-
SymmetricEncryption.load!(File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
11
2
|
|
12
3
|
# Unit Test for SymmetricEncryption
|
13
4
|
#
|
@@ -176,6 +167,118 @@ class SymmetricEncryptionTest < Test::Unit::TestCase
|
|
176
167
|
end
|
177
168
|
end
|
178
169
|
|
170
|
+
context "data types" do
|
171
|
+
context "string" do
|
172
|
+
setup do
|
173
|
+
@social_security_number = "987654321"
|
174
|
+
end
|
175
|
+
|
176
|
+
should "encrypt and decrypt value to and from a string" do
|
177
|
+
assert encrypted = SymmetricEncryption.encrypt(@social_security_number, random_iv=false, compress=false, type=:string)
|
178
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
179
|
+
assert_equal @social_security_number, SymmetricEncryption.decrypt(encrypted, version=nil, type=:string)
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context "integer" do
|
184
|
+
setup do
|
185
|
+
@age = 21
|
186
|
+
end
|
187
|
+
|
188
|
+
should "encrypt and decrypt value to and from an integer" do
|
189
|
+
assert encrypted = SymmetricEncryption.encrypt(@age, random_iv=false, compress=false, type=:integer)
|
190
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
191
|
+
assert_equal @age, SymmetricEncryption.decrypt(encrypted, version=nil, type=:integer)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
context "float" do
|
196
|
+
setup do
|
197
|
+
@miles = 2.5
|
198
|
+
end
|
199
|
+
|
200
|
+
should "encrypt and decrypt value to and from a float" do
|
201
|
+
assert encrypted = SymmetricEncryption.encrypt(@miles, random_iv=false, compress=false, type=:float)
|
202
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
203
|
+
assert_equal @miles, SymmetricEncryption.decrypt(encrypted, version=nil, type=:float)
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context "decimal" do
|
208
|
+
setup do
|
209
|
+
@account_balance = BigDecimal.new("12.58")
|
210
|
+
end
|
211
|
+
|
212
|
+
should "encrypt and decrypt value to and from a BigDecimal" do
|
213
|
+
assert encrypted = SymmetricEncryption.encrypt(@account_balance, random_iv=false, compress=false, type=:decimal)
|
214
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
215
|
+
assert_equal @account_balance, SymmetricEncryption.decrypt(encrypted, version=nil, type=:decimal)
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
context "datetime" do
|
220
|
+
setup do
|
221
|
+
@checked_in_at = DateTime.new(2001, 11, 26, 20, 55, 54, "-5")
|
222
|
+
end
|
223
|
+
|
224
|
+
should "encrypt and decrypt value to and from a DateTime" do
|
225
|
+
assert encrypted = SymmetricEncryption.encrypt(@checked_in_at, random_iv=false, compress=false, type=:datetime)
|
226
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
227
|
+
assert_equal @checked_in_at, SymmetricEncryption.decrypt(encrypted, version=nil, type=:datetime)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "time" do
|
232
|
+
setup do
|
233
|
+
@closing_time = Time.new(2013, 01, 01, 22, 30, 00, "-04:00")
|
234
|
+
end
|
235
|
+
|
236
|
+
should "encrypt and decrypt value to and from a Time" do
|
237
|
+
assert encrypted = SymmetricEncryption.encrypt(@closing_time, random_iv=false, compress=false, type=:time)
|
238
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
239
|
+
assert_equal @closing_time, SymmetricEncryption.decrypt(encrypted, version=nil, type=:time)
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
context "date" do
|
244
|
+
setup do
|
245
|
+
@birthdate = Date.new(1927, 04, 01)
|
246
|
+
end
|
247
|
+
|
248
|
+
should "encrypt and decrypt value to and from a Date" do
|
249
|
+
assert encrypted = SymmetricEncryption.encrypt(@birthdate, random_iv=false, compress=false, type=:date)
|
250
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
251
|
+
assert_equal @birthdate, SymmetricEncryption.decrypt(encrypted, version=nil, type=:date)
|
252
|
+
end
|
253
|
+
end
|
254
|
+
|
255
|
+
context "boolean" do
|
256
|
+
context "when true" do
|
257
|
+
setup do
|
258
|
+
@is_working = true
|
259
|
+
end
|
260
|
+
|
261
|
+
should "encrypt and decrypt a true value to and from a boolean" do
|
262
|
+
assert encrypted = SymmetricEncryption.encrypt(@is_working, random_iv=false, compress=false, type=:boolean)
|
263
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
264
|
+
assert_equal @is_working, SymmetricEncryption.decrypt(encrypted, version=nil, type=:boolean)
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context "when false" do
|
269
|
+
setup do
|
270
|
+
@is_broken = false
|
271
|
+
end
|
272
|
+
|
273
|
+
should "encrypt and decrypt a false value to and from a boolean" do
|
274
|
+
assert encrypted = SymmetricEncryption.encrypt(@is_broken, random_iv=false, compress=false, type=:boolean)
|
275
|
+
assert_equal true, SymmetricEncryption.encrypted?(encrypted)
|
276
|
+
assert_equal @is_broken, SymmetricEncryption.decrypt(encrypted, version=nil, type=:boolean)
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
179
282
|
end
|
180
283
|
|
181
284
|
end
|
data/test/test_db.sqlite3
CHANGED
Binary file
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Allow examples to be run in-place without requiring a gem install
|
2
|
+
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
require 'semantic_logger'
|
6
|
+
require 'erb'
|
7
|
+
require 'test/unit'
|
8
|
+
# Since we want both the AR and Mongoid extensions loaded we need to require them first
|
9
|
+
require 'active_record'
|
10
|
+
require 'mongoid'
|
11
|
+
require 'symmetric-encryption'
|
12
|
+
# Should redefines Proc#bind so must include after Rails
|
13
|
+
require 'shoulda'
|
14
|
+
|
15
|
+
SemanticLogger.add_appender('test.log') if SemanticLogger.appenders.size == 0
|
16
|
+
SemanticLogger.default_level = :trace
|
17
|
+
|
18
|
+
# Load Symmetric Encryption keys
|
19
|
+
SymmetricEncryption.load!(File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
|
data/test/writer_test.rb
CHANGED
@@ -1,14 +1,5 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
|
3
|
-
|
1
|
+
require File.dirname(__FILE__) + '/test_helper'
|
4
2
|
require 'stringio'
|
5
|
-
require 'rubygems'
|
6
|
-
require 'test/unit'
|
7
|
-
require 'shoulda'
|
8
|
-
require 'symmetric-encryption'
|
9
|
-
|
10
|
-
# Load Symmetric Encryption keys
|
11
|
-
SymmetricEncryption.load!(File.join(File.dirname(__FILE__), 'config', 'symmetric-encryption.yml'), 'test')
|
12
3
|
|
13
4
|
# Unit Test for Symmetric::EncryptedStream
|
14
5
|
#
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: symmetric-encryption
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '3.
|
4
|
+
version: '3.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Reid Morrison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
12
|
-
dependencies:
|
11
|
+
date: 2014-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: coercible
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.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: 1.0.0
|
13
27
|
description: SymmetricEncryption supports encrypting ActiveRecord data, Mongoid data,
|
14
28
|
passwords in configuration files, encrypting and decrypting of large files through
|
15
29
|
streaming
|
@@ -19,10 +33,15 @@ executables: []
|
|
19
33
|
extensions: []
|
20
34
|
extra_rdoc_files: []
|
21
35
|
files:
|
36
|
+
- LICENSE.txt
|
37
|
+
- README.md
|
38
|
+
- Rakefile
|
39
|
+
- examples/symmetric-encryption.yml
|
22
40
|
- lib/rails/generators/symmetric_encryption/config/config_generator.rb
|
23
41
|
- lib/rails/generators/symmetric_encryption/config/templates/symmetric-encryption.yml
|
24
42
|
- lib/rails/generators/symmetric_encryption/new_keys/new_keys_generator.rb
|
25
43
|
- lib/symmetric-encryption.rb
|
44
|
+
- lib/symmetric_encryption.rb
|
26
45
|
- lib/symmetric_encryption/cipher.rb
|
27
46
|
- lib/symmetric_encryption/extensions/active_record/base.rb
|
28
47
|
- lib/symmetric_encryption/mongoid.rb
|
@@ -33,11 +52,6 @@ files:
|
|
33
52
|
- lib/symmetric_encryption/symmetric_encryption.rb
|
34
53
|
- lib/symmetric_encryption/version.rb
|
35
54
|
- lib/symmetric_encryption/writer.rb
|
36
|
-
- lib/symmetric_encryption.rb
|
37
|
-
- examples/symmetric-encryption.yml
|
38
|
-
- LICENSE.txt
|
39
|
-
- Rakefile
|
40
|
-
- README.md
|
41
55
|
- test/attr_encrypted_test.rb
|
42
56
|
- test/cipher_test.rb
|
43
57
|
- test/config/database.yml
|
@@ -53,8 +67,9 @@ files:
|
|
53
67
|
- test/reader_test.rb
|
54
68
|
- test/symmetric_encryption_test.rb
|
55
69
|
- test/test_db.sqlite3
|
70
|
+
- test/test_helper.rb
|
56
71
|
- test/writer_test.rb
|
57
|
-
homepage: https://github.com/
|
72
|
+
homepage: https://github.com/reidmorrison/symmetric-encryption
|
58
73
|
licenses:
|
59
74
|
- Apache License V2.0
|
60
75
|
metadata: {}
|
@@ -64,17 +79,17 @@ require_paths:
|
|
64
79
|
- lib
|
65
80
|
required_ruby_version: !ruby/object:Gem::Requirement
|
66
81
|
requirements:
|
67
|
-
- -
|
82
|
+
- - ">="
|
68
83
|
- !ruby/object:Gem::Version
|
69
84
|
version: '0'
|
70
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
86
|
requirements:
|
72
|
-
- -
|
87
|
+
- - ">="
|
73
88
|
- !ruby/object:Gem::Version
|
74
89
|
version: '0'
|
75
90
|
requirements: []
|
76
91
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.0
|
92
|
+
rubygems_version: 2.2.0
|
78
93
|
signing_key:
|
79
94
|
specification_version: 4
|
80
95
|
summary: Symmetric Encryption for Ruby, and Ruby on Rails
|
@@ -94,4 +109,5 @@ test_files:
|
|
94
109
|
- test/reader_test.rb
|
95
110
|
- test/symmetric_encryption_test.rb
|
96
111
|
- test/test_db.sqlite3
|
112
|
+
- test/test_helper.rb
|
97
113
|
- test/writer_test.rb
|