pod4 0.10.1 → 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pod4/encrypting.rb +9 -4
- data/lib/pod4/version.rb +1 -1
- data/spec/common/model_plus_encrypting_spec.rb +33 -1
- data/spec/common/model_plus_typecasting_spec.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee46818707291111af50ad94a88168a026f9d2a
|
4
|
+
data.tar.gz: 9cae9859c19fbbd3784d8a43cb33d40a0effe7ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac96259ec5dad9ce2ad6b92d80e4b92987138ceba5d176dee3debfdc647699bd8dfa88858ecca0690384217fac34b6d8a175eae6da38ce1bccb4c2589dd48f47
|
7
|
+
data.tar.gz: 4fa5a9bbec0022d3da862b4b1a5d14b0298417fc0a3ef0e710a4f1db44c25f61cabb01110db83ead8f33a8ca4e9a1cfed434ffbf52ba94b948da30802a35309d
|
data/lib/pod4/encrypting.rb
CHANGED
@@ -142,7 +142,7 @@ module Pod4
|
|
142
142
|
end
|
143
143
|
|
144
144
|
self.class.encryption_columns.each do |col|
|
145
|
-
hash[col] = crypt(cipher, encryption_iv, hash[col]
|
145
|
+
hash[col] = crypt(cipher, :encrypt, encryption_iv, hash[col])
|
146
146
|
end
|
147
147
|
|
148
148
|
Octothorpe.new(hash)
|
@@ -157,7 +157,7 @@ module Pod4
|
|
157
157
|
iv = hash[self.class.encryption_iv_column] # not yet set on the model
|
158
158
|
|
159
159
|
self.class.encryption_columns.each do |col|
|
160
|
-
hash[col] = crypt(cipher, iv, hash[col])
|
160
|
+
hash[col] = crypt(cipher, :decrypt, iv, hash[col])
|
161
161
|
end
|
162
162
|
|
163
163
|
super Octothorpe.new(hash)
|
@@ -206,11 +206,16 @@ module Pod4
|
|
206
206
|
##
|
207
207
|
# Encrypt / decrypt
|
208
208
|
#
|
209
|
-
def crypt(cipher, iv, string)
|
209
|
+
def crypt(cipher, direction, iv, string)
|
210
210
|
return string if use_iv? and iv.nil?
|
211
|
+
return string if string.nil?
|
211
212
|
cipher.key = self.class.encryption_key
|
212
213
|
cipher.iv = iv if use_iv?
|
213
|
-
|
214
|
+
|
215
|
+
answer = ""
|
216
|
+
answer << cipher.update(string.to_s) unless direction == :encrypt && string.empty?
|
217
|
+
answer << cipher.final
|
218
|
+
answer
|
214
219
|
|
215
220
|
rescue OpenSSL::Cipher::CipherError
|
216
221
|
raise Pod4::Pod4Error, $!
|
data/lib/pod4/version.rb
CHANGED
@@ -18,7 +18,8 @@ describe "(Model with Encryption)" do
|
|
18
18
|
cipher.encrypt
|
19
19
|
cipher.key = key
|
20
20
|
cipher.iv = iv if iv
|
21
|
-
|
21
|
+
|
22
|
+
(plaintext.empty? ? "" : cipher.update(plaintext) ) + cipher.final
|
22
23
|
end
|
23
24
|
|
24
25
|
let(:encryption_key) { "dflkasdgklajndgnalkghlgasdgasdghaalsdg" }
|
@@ -302,6 +303,16 @@ describe "(Model with Encryption)" do
|
|
302
303
|
expect{ bad.map_to_interface }.to raise_exception Pod4::Pod4Error
|
303
304
|
end
|
304
305
|
|
306
|
+
it "doesn't freak out when asked to encrypt an empty column" do
|
307
|
+
bad = medical_model_class.new
|
308
|
+
bad.id = 998
|
309
|
+
bad.nhs_no = "12345"
|
310
|
+
bad.name = ""
|
311
|
+
bad.ailment = nil
|
312
|
+
|
313
|
+
expect{ bad.map_to_interface }.not_to raise_exception
|
314
|
+
end
|
315
|
+
|
305
316
|
context "when we don't have an IV column" do
|
306
317
|
|
307
318
|
it "encrypts only the encryptable columns for the interface" do
|
@@ -351,6 +362,15 @@ describe "(Model with Encryption)" do
|
|
351
362
|
expect( d.text ).to eq "sore toe"
|
352
363
|
end
|
353
364
|
|
365
|
+
it "successfully decrypts an empty column" do
|
366
|
+
d44.text = ""
|
367
|
+
d44.create
|
368
|
+
|
369
|
+
d = diary_model_class.new(44)
|
370
|
+
d.read
|
371
|
+
expect( d.text ).to eq ""
|
372
|
+
end
|
373
|
+
|
354
374
|
end
|
355
375
|
|
356
376
|
context "when we have an IV column" do
|
@@ -370,6 +390,18 @@ describe "(Model with Encryption)" do
|
|
370
390
|
expect( m.prescription ).to eq "suck thumb"
|
371
391
|
end
|
372
392
|
|
393
|
+
it "successfully decrypts an empty column" do
|
394
|
+
m40.ailment = ""
|
395
|
+
m40.prescription = nil
|
396
|
+
m40.create
|
397
|
+
|
398
|
+
m = medical_model_class.new(40)
|
399
|
+
m.read
|
400
|
+
expect( m.ailment ).to eq ""
|
401
|
+
expect( m.prescription ).to be_nil
|
402
|
+
end
|
403
|
+
|
404
|
+
|
373
405
|
end
|
374
406
|
|
375
407
|
end # of Model#map_to_model
|
@@ -31,7 +31,7 @@ describe "ProductModel" do
|
|
31
31
|
set_interface NullInterface.new( :id, :code, :band, :sales, :created, :yrstart,
|
32
32
|
:flag, :foo, :bar, [] )
|
33
33
|
|
34
|
-
def mycast(value, opts); end
|
34
|
+
def mycast(value, opts); "blarg" end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -316,7 +316,18 @@ describe "ProductModel" do
|
|
316
316
|
c.foo = "12345"
|
317
317
|
c.create
|
318
318
|
end
|
319
|
-
|
319
|
+
|
320
|
+
it "writes the return value from the use method to the interface" do
|
321
|
+
c = customer_model_class.new
|
322
|
+
c.id = 33
|
323
|
+
c.code = "baz"
|
324
|
+
c.foo = "12345"
|
325
|
+
c.create
|
326
|
+
|
327
|
+
record = customer_model_class.interface.read(33)
|
328
|
+
expect( record.>>.foo ).to eq "blarg"
|
329
|
+
end
|
330
|
+
|
320
331
|
end # of #map_to_interface"
|
321
332
|
|
322
333
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pod4
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.10.
|
4
|
+
version: 0.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jones
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: devnull
|