symmetric-encryption 3.6.0 → 3.7.0
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/README.md +8 -649
- data/lib/_test_empty +0 -0
- data/lib/symmetric_encryption/cipher.rb +13 -13
- data/lib/symmetric_encryption/exception.rb +15 -0
- data/lib/symmetric_encryption/extensions/mongo_mapper/plugins/encrypted_key.rb +1 -1
- data/lib/symmetric_encryption/extensions/mongoid/encrypted.rb +1 -1
- data/lib/symmetric_encryption/generator.rb +23 -31
- data/lib/symmetric_encryption/railties/symmetric_encryption.rake +1 -1
- data/lib/symmetric_encryption/reader.rb +7 -5
- data/lib/symmetric_encryption/symmetric_encryption.rb +14 -14
- data/lib/symmetric_encryption/version.rb +1 -1
- data/lib/symmetric_encryption/writer.rb +4 -4
- data/lib/symmetric_encryption.rb +1 -0
- data/test/active_record_test.rb +12 -9
- data/test/cipher_test.rb +3 -3
- data/test/mongo_mapper_test.rb +445 -442
- data/test/mongoid_test.rb +11 -4
- data/test/reader_test.rb +16 -10
- data/test/symmetric_encryption_test.rb +15 -2
- data/test/test_db.sqlite3 +0 -0
- data/test/test_helper.rb +8 -6
- data/test/writer_test.rb +2 -2
- metadata +6 -4
@@ -85,18 +85,18 @@ module SymmetricEncryption
|
|
85
85
|
# Recommended: true
|
86
86
|
#
|
87
87
|
def initialize(params={})
|
88
|
-
|
89
|
-
@key =
|
90
|
-
@iv =
|
91
|
-
@cipher_name =
|
92
|
-
@version =
|
93
|
-
@always_add_header =
|
94
|
-
@encoding = (
|
95
|
-
|
96
|
-
raise "Missing mandatory parameter :key" unless @key
|
97
|
-
raise "Invalid Encoding: #{@encoding}" unless ENCODINGS.include?(@encoding)
|
98
|
-
raise "Cipher version has a valid
|
99
|
-
|
88
|
+
params = params.dup
|
89
|
+
@key = params.delete(:key)
|
90
|
+
@iv = params.delete(:iv)
|
91
|
+
@cipher_name = params.delete(:cipher_name) || params.delete(:cipher) || 'aes-256-cbc'
|
92
|
+
@version = params.delete(:version)
|
93
|
+
@always_add_header = params.delete(:always_add_header) || false
|
94
|
+
@encoding = (params.delete(:encoding) || :base64).to_sym
|
95
|
+
|
96
|
+
raise(ArgumentError, "Missing mandatory parameter :key") unless @key
|
97
|
+
raise(ArgumentError, "Invalid Encoding: #{@encoding}") unless ENCODINGS.include?(@encoding)
|
98
|
+
raise(ArgumentError, "Cipher version has a valid range of 0 to 255. #{@version} is too high, or negative") if (@version.to_i > 255) || (@version.to_i < 0)
|
99
|
+
raise(ArgumentError, "SymmetricEncryption::Cipher Invalid options #{params.inspect}") if params.size > 0
|
100
100
|
end
|
101
101
|
|
102
102
|
# Encrypt and then encode a string
|
@@ -286,7 +286,7 @@ module SymmetricEncryption
|
|
286
286
|
# otherwise to decrypt the data following the header
|
287
287
|
version = flags & 0b0000_0000_1111_1111
|
288
288
|
decryption_cipher = SymmetricEncryption.cipher(version)
|
289
|
-
raise "Cipher with version:#{version.inspect} not found in any of the configured SymmetricEncryption ciphers" unless decryption_cipher
|
289
|
+
raise(SymmetricEncryption::CipherError, "Cipher with version:#{version.inspect} not found in any of the configured SymmetricEncryption ciphers") unless decryption_cipher
|
290
290
|
iv, key, cipher_name = nil
|
291
291
|
|
292
292
|
if include_iv
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SymmetricEncryption
|
2
|
+
|
3
|
+
# Exceptions created by SymmetricEncryption
|
4
|
+
class Error < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
# Exceptions when working with Ciphers
|
8
|
+
class CipherError < Error
|
9
|
+
end
|
10
|
+
|
11
|
+
# Exceptions when trying to use the keys before they have been configured
|
12
|
+
class ConfigError < Error
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -112,7 +112,7 @@ module MongoMapper
|
|
112
112
|
encrypted_key_name = options.delete(:encrypt_as) || "encrypted_#{key_name}"
|
113
113
|
options[:type] = COERCION_MAP[type] unless [:yaml, :json].include?(options[:type])
|
114
114
|
|
115
|
-
raise "Invalid type: #{type.inspect}. Valid types: #{COERCION_MAP.keys.join(',')}" unless options[:type]
|
115
|
+
raise(ArgumentError, "Invalid type: #{type.inspect}. Valid types: #{COERCION_MAP.keys.join(',')}") unless options[:type]
|
116
116
|
|
117
117
|
SymmetricEncryption::Generator.generate_decrypted_accessors(self, key_name, encrypted_key_name, options)
|
118
118
|
|
@@ -99,7 +99,7 @@ Mongoid::Fields.option :encrypted do |model, field, options|
|
|
99
99
|
end
|
100
100
|
|
101
101
|
if decrypted_field_name.nil?
|
102
|
-
raise "SymmetricEncryption for Mongoid. Encryption enabled for field #{encrypted_field_name}. It must either start with 'encrypted_' or the option :decrypt_as must be supplied"
|
102
|
+
raise(ArgumentError, "SymmetricEncryption for Mongoid. Encryption enabled for field #{encrypted_field_name}. It must either start with 'encrypted_' or the option :decrypt_as must be supplied")
|
103
103
|
end
|
104
104
|
|
105
105
|
SymmetricEncryption::Generator.generate_decrypted_accessors(model, decrypted_field_name, encrypted_field_name, options)
|
@@ -3,21 +3,13 @@ module SymmetricEncryption
|
|
3
3
|
# Common internal method for generating accessors for decrypted accessors
|
4
4
|
# Primarily used by extensions
|
5
5
|
def self.generate_decrypted_accessors(model, decrypted_name, encrypted_name, options)
|
6
|
+
options = options.dup
|
7
|
+
random_iv = options.delete(:random_iv) || false
|
8
|
+
compress = options.delete(:compress) || false
|
9
|
+
type = options.delete(:type) || :string
|
6
10
|
|
7
|
-
|
8
|
-
|
9
|
-
type = options.delete(:type) || :string
|
10
|
-
|
11
|
-
# For backward compatibility
|
12
|
-
if options.delete(:marshal) == true
|
13
|
-
warn("The :marshal option has been deprecated in favor of :type. For example: attr_encrypted name, type: :yaml")
|
14
|
-
raise "Marshal is depreacted and cannot be used in conjunction with :type, just use :type. For #{params.inspect}" if type != :string
|
15
|
-
type = :yaml
|
16
|
-
end
|
17
|
-
|
18
|
-
options.each {|option| warn "Ignoring unknown option #{option.inspect} supplied when encrypting #{decrypted_name} with #{params.inspect}"}
|
19
|
-
|
20
|
-
raise "Invalid type: #{type.inspect}. Valid types: #{SymmetricEncryption::COERCION_TYPES.inspect}" unless SymmetricEncryption::COERCION_TYPES.include?(type)
|
11
|
+
raise(ArgumentError, "SymmetricEncryption Invalid options #{options.inspect} when encrypting '#{decrypted_name}'") if options.size > 0
|
12
|
+
raise(ArgumentError, "Invalid type: #{type.inspect}. Valid types: #{SymmetricEncryption::COERCION_TYPES.inspect}") unless SymmetricEncryption::COERCION_TYPES.include?(type)
|
21
13
|
|
22
14
|
if model.const_defined?(:EncryptedAttributes, _search_ancestors = false)
|
23
15
|
mod = model.const_get(:EncryptedAttributes)
|
@@ -28,25 +20,25 @@ module SymmetricEncryption
|
|
28
20
|
|
29
21
|
# Generate getter and setter methods
|
30
22
|
mod.module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
23
|
+
# Set the un-encrypted field
|
24
|
+
# Also updates the encrypted field with the encrypted value
|
25
|
+
# Freeze the decrypted field value so that it is not modified directly
|
26
|
+
def #{decrypted_name}=(value)
|
27
|
+
v = SymmetricEncryption::coerce(value, :#{type})
|
28
|
+
self.#{encrypted_name} = @stored_#{encrypted_name} = ::SymmetricEncryption.encrypt(v,#{random_iv},#{compress},:#{type})
|
29
|
+
@#{decrypted_name} = v.freeze
|
30
|
+
end
|
39
31
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
32
|
+
# Returns the decrypted value for the encrypted field
|
33
|
+
# The decrypted value is cached and is only decrypted if the encrypted value has changed
|
34
|
+
# If this method is not called, then the encrypted value is never decrypted
|
35
|
+
def #{decrypted_name}
|
36
|
+
if @stored_#{encrypted_name} != self.#{encrypted_name}
|
37
|
+
@#{decrypted_name} = ::SymmetricEncryption.decrypt(self.#{encrypted_name},version=nil,:#{type}).freeze
|
38
|
+
@stored_#{encrypted_name} = self.#{encrypted_name}
|
39
|
+
end
|
40
|
+
@#{decrypted_name}
|
47
41
|
end
|
48
|
-
@#{decrypted_name}
|
49
|
-
end
|
50
42
|
|
51
43
|
EOS
|
52
44
|
end
|
@@ -11,7 +11,7 @@ namespace :symmetric_encryption do
|
|
11
11
|
begin
|
12
12
|
require 'highline'
|
13
13
|
rescue LoadError
|
14
|
-
raise "Please install gem highline before using the command line task to encrypt an entered string.\n gem install \"highline\""
|
14
|
+
raise(SymmetricEncryption::ConfigError, "Please install gem highline before using the command line task to encrypt an entered string.\n gem install \"highline\"")
|
15
15
|
end
|
16
16
|
password1 = nil
|
17
17
|
password2 = 0
|
@@ -77,7 +77,7 @@ module SymmetricEncryption
|
|
77
77
|
# csv.close if csv
|
78
78
|
# end
|
79
79
|
def self.open(filename_or_stream, options={}, &block)
|
80
|
-
raise
|
80
|
+
raise(ArgumentError, 'options must be a hash') unless options.respond_to?(:each_pair)
|
81
81
|
mode = options.fetch(:mode, 'rb')
|
82
82
|
compress = options.fetch(:compress, false)
|
83
83
|
ios = filename_or_stream.is_a?(String) ? ::File.open(filename_or_stream, mode) : filename_or_stream
|
@@ -115,7 +115,7 @@ module SymmetricEncryption
|
|
115
115
|
@version = options[:version]
|
116
116
|
@header_present = false
|
117
117
|
|
118
|
-
raise
|
118
|
+
raise(ArgumentError, 'Buffer size cannot be smaller than 128') unless @buffer_size >= 128
|
119
119
|
|
120
120
|
read_header
|
121
121
|
end
|
@@ -180,12 +180,14 @@ module SymmetricEncryption
|
|
180
180
|
data = nil
|
181
181
|
if length
|
182
182
|
return '' if length == 0
|
183
|
-
return nil if
|
183
|
+
return nil if eof?
|
184
184
|
# Read length bytes
|
185
185
|
while (@read_buffer.length < length) && !@ios.eof?
|
186
186
|
read_block
|
187
187
|
end
|
188
|
-
if @read_buffer.length
|
188
|
+
if @read_buffer.length == 0
|
189
|
+
data = nil
|
190
|
+
elsif @read_buffer.length > length
|
189
191
|
data = @read_buffer.slice!(0..length-1)
|
190
192
|
else
|
191
193
|
data = @read_buffer
|
@@ -301,7 +303,7 @@ module SymmetricEncryption
|
|
301
303
|
rewind
|
302
304
|
offset = size + amount
|
303
305
|
else
|
304
|
-
raise "unknown whence:#{whence} supplied to seek()"
|
306
|
+
raise(ArgumentError, "unknown whence:#{whence} supplied to seek()")
|
305
307
|
end
|
306
308
|
read(offset) if offset > 0
|
307
309
|
0
|
@@ -38,7 +38,7 @@ module SymmetricEncryption
|
|
38
38
|
# cipher: 'aes-128-cbc'
|
39
39
|
# )
|
40
40
|
def self.cipher=(cipher)
|
41
|
-
raise
|
41
|
+
raise(ArgumentError, 'Cipher must respond to :encrypt and :decrypt') unless cipher.nil? || (cipher.respond_to?(:encrypt) && cipher.respond_to?(:decrypt))
|
42
42
|
@@cipher = cipher
|
43
43
|
end
|
44
44
|
|
@@ -47,7 +47,7 @@ module SymmetricEncryption
|
|
47
47
|
# Returns the primary cipher if no match was found and version == 0
|
48
48
|
# Returns nil if no match was found and version != 0
|
49
49
|
def self.cipher(version = nil)
|
50
|
-
raise
|
50
|
+
raise(SymmetricEncryption::ConfigError, 'Call SymmetricEncryption.load! or SymmetricEncryption.cipher= prior to encrypting or decrypting data') unless @@cipher
|
51
51
|
return @@cipher if version.nil? || (@@cipher.version == version)
|
52
52
|
secondary_ciphers.find {|c| c.version == version} || (@@cipher if version == 0)
|
53
53
|
end
|
@@ -59,9 +59,9 @@ module SymmetricEncryption
|
|
59
59
|
|
60
60
|
# Set the Secondary Symmetric Ciphers Array to be used
|
61
61
|
def self.secondary_ciphers=(secondary_ciphers)
|
62
|
-
raise "secondary_ciphers must be a collection" unless secondary_ciphers.respond_to? :each
|
62
|
+
raise(ArgumentError, "secondary_ciphers must be a collection") unless secondary_ciphers.respond_to? :each
|
63
63
|
secondary_ciphers.each do |cipher|
|
64
|
-
raise "secondary_ciphers can only consist of SymmetricEncryption::Ciphers" unless cipher.respond_to?(:encrypt) && cipher.respond_to?(:decrypt)
|
64
|
+
raise(ArgumentError, "secondary_ciphers can only consist of SymmetricEncryption::Ciphers") unless cipher.respond_to?(:encrypt) && cipher.respond_to?(:decrypt)
|
65
65
|
end
|
66
66
|
@@secondary_ciphers = secondary_ciphers
|
67
67
|
end
|
@@ -106,7 +106,7 @@ module SymmetricEncryption
|
|
106
106
|
# the incorrect key. Clearly the data returned is garbage, but it still
|
107
107
|
# successfully returns a string of data
|
108
108
|
def self.decrypt(encrypted_and_encoded_string, version=nil, type=:string)
|
109
|
-
raise
|
109
|
+
raise(SymmetricEncryption::ConfigError, 'Call SymmetricEncryption.load! or SymmetricEncryption.cipher= prior to encrypting or decrypting data') unless @@cipher
|
110
110
|
return encrypted_and_encoded_string if encrypted_and_encoded_string.nil? || (encrypted_and_encoded_string == '')
|
111
111
|
|
112
112
|
str = encrypted_and_encoded_string.to_s
|
@@ -176,7 +176,7 @@ module SymmetricEncryption
|
|
176
176
|
# the coercible gem is available in the path.
|
177
177
|
# Default: :string
|
178
178
|
def self.encrypt(str, random_iv=false, compress=false, type=:string)
|
179
|
-
raise
|
179
|
+
raise(SymmetricEncryption::ConfigError, 'Call SymmetricEncryption.load! or SymmetricEncryption.cipher= prior to encrypting or decrypting data') unless @@cipher
|
180
180
|
|
181
181
|
# Encrypt and then encode the supplied string
|
182
182
|
@@cipher.encrypt(coerce_to_string(str, type), random_iv, compress)
|
@@ -194,10 +194,10 @@ module SymmetricEncryption
|
|
194
194
|
# WARNING: It is possible to decrypt data using the wrong key, so the value
|
195
195
|
# returned should not be relied upon
|
196
196
|
def self.try_decrypt(str)
|
197
|
-
raise
|
197
|
+
raise(SymmetricEncryption::ConfigError, 'Call SymmetricEncryption.load! or SymmetricEncryption.cipher= prior to encrypting or decrypting data') unless @@cipher
|
198
198
|
begin
|
199
199
|
decrypt(str)
|
200
|
-
rescue OpenSSL::Cipher::CipherError
|
200
|
+
rescue OpenSSL::Cipher::CipherError, SymmetricEncryption::CipherError
|
201
201
|
nil
|
202
202
|
end
|
203
203
|
end
|
@@ -210,7 +210,7 @@ module SymmetricEncryption
|
|
210
210
|
# symmetric encryption header. In some cases data decrypted using the
|
211
211
|
# wrong key will decrypt and return garbage
|
212
212
|
def self.encrypted?(encrypted_data)
|
213
|
-
raise
|
213
|
+
raise(SymmetricEncryption::ConfigError, 'Call SymmetricEncryption.load! or SymmetricEncryption.cipher= prior to encrypting or decrypting data') unless @@cipher
|
214
214
|
|
215
215
|
# For now have to decrypt it fully
|
216
216
|
result = try_decrypt(encrypted_data)
|
@@ -276,7 +276,7 @@ module SymmetricEncryption
|
|
276
276
|
|
277
277
|
# RSA key to decrypt key files
|
278
278
|
private_rsa_key = config.delete('private_rsa_key')
|
279
|
-
raise "The configuration file must contain a 'private_rsa_key' parameter to generate symmetric keys" unless private_rsa_key
|
279
|
+
raise(SymmetricEncryption::ConfigError, "The configuration file must contain a 'private_rsa_key' parameter to generate symmetric keys") unless private_rsa_key
|
280
280
|
rsa_key = OpenSSL::PKey::RSA.new(private_rsa_key)
|
281
281
|
|
282
282
|
# Check if config file contains 1 or multiple ciphers
|
@@ -411,7 +411,7 @@ module SymmetricEncryption
|
|
411
411
|
|
412
412
|
# Load Encrypted Symmetric keys
|
413
413
|
if key_filename = config.delete(:key_filename)
|
414
|
-
raise "Missing mandatory config parameter :private_rsa_key when :key_filename is supplied" unless rsa
|
414
|
+
raise(SymmetricEncryption::ConfigError, "Missing mandatory config parameter :private_rsa_key when :key_filename is supplied") unless rsa
|
415
415
|
encrypted_key = begin
|
416
416
|
File.open(key_filename, 'rb'){|f| f.read}
|
417
417
|
rescue Errno::ENOENT
|
@@ -423,7 +423,7 @@ module SymmetricEncryption
|
|
423
423
|
end
|
424
424
|
|
425
425
|
if iv_filename = config.delete(:iv_filename)
|
426
|
-
raise "Missing mandatory config parameter :private_rsa_key when :iv_filename is supplied" unless rsa
|
426
|
+
raise(SymmetricEncryption::ConfigError, "Missing mandatory config parameter :private_rsa_key when :iv_filename is supplied") unless rsa
|
427
427
|
encrypted_iv = begin
|
428
428
|
File.open(iv_filename, 'rb'){|f| f.read} if iv_filename
|
429
429
|
rescue Errno::ENOENT
|
@@ -435,7 +435,7 @@ module SymmetricEncryption
|
|
435
435
|
end
|
436
436
|
|
437
437
|
if encrypted_key = config.delete(:encrypted_key)
|
438
|
-
raise "Missing mandatory config parameter :private_rsa_key when :encrypted_key is supplied" unless rsa
|
438
|
+
raise(SymmetricEncryption::ConfigError, "Missing mandatory config parameter :private_rsa_key when :encrypted_key is supplied") unless rsa
|
439
439
|
# Decode value first using encoding specified
|
440
440
|
encrypted_key = ::Base64.decode64(encrypted_key)
|
441
441
|
if !encrypted_key || encrypted_key.empty?
|
@@ -447,7 +447,7 @@ module SymmetricEncryption
|
|
447
447
|
end
|
448
448
|
|
449
449
|
if encrypted_iv = config.delete(:encrypted_iv)
|
450
|
-
raise "Missing mandatory config parameter :private_rsa_key when :encrypted_iv is supplied" unless rsa
|
450
|
+
raise(SymmetricEncryption::ConfigError, "Missing mandatory config parameter :private_rsa_key when :encrypted_iv is supplied") unless rsa
|
451
451
|
# Decode value first using encoding specified
|
452
452
|
encrypted_iv = ::Base64.decode64(encrypted_iv)
|
453
453
|
if !encrypted_key || encrypted_key.empty?
|
@@ -99,7 +99,7 @@ module SymmetricEncryption
|
|
99
99
|
# csv.close if csv
|
100
100
|
# end
|
101
101
|
def self.open(filename_or_stream, options={}, &block)
|
102
|
-
raise
|
102
|
+
raise(ArgumentError, 'options must be a hash') unless options.respond_to?(:each_pair)
|
103
103
|
mode = options.fetch(:mode, 'wb')
|
104
104
|
compress = options.fetch(:compress, false)
|
105
105
|
ios = filename_or_stream.is_a?(String) ? ::File.open(filename_or_stream, mode) : filename_or_stream
|
@@ -119,19 +119,19 @@ module SymmetricEncryption
|
|
119
119
|
header = options.fetch(:header, true)
|
120
120
|
random_key = options.fetch(:random_key, true)
|
121
121
|
random_iv = options.fetch(:random_iv, random_key)
|
122
|
-
raise
|
122
|
+
raise(ArgumentError, 'When :random_key is true, :random_iv must also be true') if random_key && !random_iv
|
123
123
|
# Compress is only used at this point for setting the flag in the header
|
124
124
|
compress = options.fetch(:compress, false)
|
125
125
|
version = options[:version]
|
126
126
|
cipher_name = options[:cipher_name]
|
127
|
-
raise
|
127
|
+
raise(ArgumentError, 'Cannot supply a :cipher_name unless both :random_key and :random_iv are true') if cipher_name && !random_key && !random_iv
|
128
128
|
|
129
129
|
# Force header if compressed or using random iv, key
|
130
130
|
header = true if compress || random_key || random_iv
|
131
131
|
|
132
132
|
# Cipher to encrypt the random_key, or the entire file
|
133
133
|
cipher = SymmetricEncryption.cipher(version)
|
134
|
-
raise "Cipher with version:#{version} not found in any of the configured SymmetricEncryption ciphers" unless cipher
|
134
|
+
raise(SymmetricEncryption::CipherError, "Cipher with version:#{version} not found in any of the configured SymmetricEncryption ciphers") unless cipher
|
135
135
|
|
136
136
|
@stream_cipher = ::OpenSSL::Cipher.new(cipher_name || cipher.cipher_name)
|
137
137
|
@stream_cipher.encrypt
|
data/lib/symmetric_encryption.rb
CHANGED
@@ -6,6 +6,7 @@ require 'coercible'
|
|
6
6
|
require 'symmetric_encryption/version'
|
7
7
|
require 'symmetric_encryption/cipher'
|
8
8
|
require 'symmetric_encryption/symmetric_encryption'
|
9
|
+
require 'symmetric_encryption/exception'
|
9
10
|
|
10
11
|
module SymmetricEncryption
|
11
12
|
autoload :Reader, 'symmetric_encryption/reader'
|
data/test/active_record_test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
ActiveRecord::Base.logger = SemanticLogger[ActiveRecord]
|
4
4
|
ActiveRecord::Base.configurations = YAML::load(ERB.new(IO.read('test/config/database.yml')).result)
|
5
|
-
ActiveRecord::Base.establish_connection(
|
5
|
+
ActiveRecord::Base.establish_connection(:test)
|
6
6
|
|
7
7
|
ActiveRecord::Schema.define version: 0 do
|
8
8
|
create_table :users, force: true do |t|
|
@@ -13,6 +13,7 @@ ActiveRecord::Schema.define version: 0 do
|
|
13
13
|
t.text :encrypted_data_yaml
|
14
14
|
t.text :encrypted_data_json
|
15
15
|
t.string :name
|
16
|
+
t.string :encrypted_unsupported_option
|
16
17
|
|
17
18
|
t.string :encrypted_integer_value
|
18
19
|
t.string :encrypted_float_value
|
@@ -67,7 +68,7 @@ User.establish_connection(cfg)
|
|
67
68
|
#
|
68
69
|
# Unit Test for attr_encrypted extensions in ActiveRecord
|
69
70
|
#
|
70
|
-
class ActiveRecordTest < Test
|
71
|
+
class ActiveRecordTest < Minitest::Test
|
71
72
|
context 'ActiveRecord' do
|
72
73
|
INTEGER_VALUE = 12
|
73
74
|
FLOAT_VALUE = 88.12345
|
@@ -163,13 +164,15 @@ class ActiveRecordTest < Test::Unit::TestCase
|
|
163
164
|
end
|
164
165
|
|
165
166
|
should 'allow lookups using unencrypted or encrypted column name' do
|
166
|
-
|
167
|
+
if ActiveRecord::VERSION::STRING.to_f < 4.1
|
168
|
+
@user.save!
|
167
169
|
|
168
|
-
|
169
|
-
|
170
|
-
|
170
|
+
inq = User.find_by_bank_account_number(@bank_account_number)
|
171
|
+
assert_equal @bank_account_number, inq.bank_account_number
|
172
|
+
assert_equal @bank_account_number_encrypted, inq.encrypted_bank_account_number
|
171
173
|
|
172
|
-
|
174
|
+
@user.delete
|
175
|
+
end
|
173
176
|
end
|
174
177
|
|
175
178
|
should 'all paths should lead to the same result' do
|
@@ -471,4 +474,4 @@ class ActiveRecordTest < Test::Unit::TestCase
|
|
471
474
|
end
|
472
475
|
end
|
473
476
|
end
|
474
|
-
end
|
477
|
+
end
|
data/test/cipher_test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
|
1
|
+
require_relative 'test_helper'
|
2
2
|
|
3
3
|
# Unit Test for SymmetricEncryption::Cipher
|
4
4
|
#
|
5
|
-
class CipherTest < Test
|
5
|
+
class CipherTest < Minitest::Test
|
6
6
|
context 'standalone' do
|
7
7
|
|
8
8
|
should "allow setting the cipher_name" do
|
@@ -36,7 +36,7 @@ class CipherTest < Test::Unit::TestCase
|
|
36
36
|
iv: '1234567890ABCDEF',
|
37
37
|
encoding: :none
|
38
38
|
)
|
39
|
-
|
39
|
+
assert_raises OpenSSL::Cipher::CipherError do
|
40
40
|
cipher.decrypt('bad data')
|
41
41
|
end
|
42
42
|
end
|