crypt_keeper 0.16.1 → 0.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/crypt_keeper/model.rb +14 -0
- data/lib/crypt_keeper/version.rb +1 -1
- data/spec/model_spec.rb +21 -0
- 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: bebe9201328a264bc331e557bfb7b29eda6f8cec
|
4
|
+
data.tar.gz: f429009d3af1a7a09e8a3a4e45f21211994491c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16879b1ba1a690e850e5f1a26fb0d3f9db237b926acaf1dfdfab4d490da7723e2a7d079223d626a293916661ed1c63c29673a71a2d318482e99ecceb02b8c379
|
7
|
+
data.tar.gz: 52a28a7ba7a2a3ed75fc9194bc5d42cb1fff57249aab11681c0288b90f3babbe6e4340c05320ea07cbe62402fe252454c33b36361ed09a3758eb32ede731e680
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Build Status](https://secure.travis-ci.org/jmazzi/crypt_keeper.png?branch=master)](http://travis-ci.org/jmazzi/crypt_keeper)
|
1
|
+
[![Build Status](https://secure.travis-ci.org/jmazzi/crypt_keeper.png?branch=master)](http://travis-ci.org/jmazzi/crypt_keeper) [![Gem Version](https://badge.fury.io/rb/crypt_keeper.svg)](http://badge.fury.io/rb/crypt_keeper)
|
2
2
|
|
3
3
|
![CryptKeeper](http://i.imgur.com/qf0aD.jpg)
|
4
4
|
|
data/lib/crypt_keeper/model.rb
CHANGED
@@ -24,6 +24,13 @@ module CryptKeeper
|
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
|
+
# Private: Force string encodings if the option is set
|
28
|
+
def force_encodings_on_fields
|
29
|
+
crypt_keeper_fields.each do |field|
|
30
|
+
send(field).force_encoding(crypt_keeper_encoding) if send(field).respond_to?(:force_encoding)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
27
34
|
module ClassMethods
|
28
35
|
# Public: Setup fields for encryption
|
29
36
|
#
|
@@ -42,15 +49,22 @@ module CryptKeeper
|
|
42
49
|
class_attribute :crypt_keeper_fields
|
43
50
|
class_attribute :crypt_keeper_encryptor
|
44
51
|
class_attribute :crypt_keeper_options
|
52
|
+
class_attribute :crypt_keeper_encoding
|
45
53
|
|
46
54
|
self.crypt_keeper_options = args.extract_options!
|
47
55
|
self.crypt_keeper_encryptor = crypt_keeper_options.delete(:encryptor)
|
56
|
+
self.crypt_keeper_encoding = crypt_keeper_options.delete(:encoding)
|
48
57
|
self.crypt_keeper_fields = args
|
49
58
|
|
50
59
|
ensure_valid_encryptor!
|
51
60
|
|
52
61
|
before_save :enforce_column_types_callback
|
53
62
|
|
63
|
+
if self.crypt_keeper_encoding
|
64
|
+
after_find :force_encodings_on_fields
|
65
|
+
before_save :force_encodings_on_fields
|
66
|
+
end
|
67
|
+
|
54
68
|
crypt_keeper_fields.each do |field|
|
55
69
|
serialize field, encryptor_klass.new(crypt_keeper_options).
|
56
70
|
extend(::CryptKeeper::Helper::Serializer)
|
data/lib/crypt_keeper/version.rb
CHANGED
data/spec/model_spec.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
module CryptKeeper
|
@@ -91,5 +93,24 @@ module CryptKeeper
|
|
91
93
|
expect { SensitiveData.search_by_plaintext(:what, 'test1') }.to raise_error(/what is not a crypt_keeper field/)
|
92
94
|
end
|
93
95
|
end
|
96
|
+
|
97
|
+
context "Encodings" do
|
98
|
+
before do
|
99
|
+
SensitiveData.crypt_keeper :storage, key: 'tool', salt: 'salt', encryptor: :aes_new, encoding: 'utf-8'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "forces the encoding on decrypt" do
|
103
|
+
record = SensitiveData.create!(storage: 'Tromsø')
|
104
|
+
record.reload
|
105
|
+
expect(record.storage).to eql('Tromsø')
|
106
|
+
end
|
107
|
+
|
108
|
+
it "converts from other encodings" do
|
109
|
+
plaintext = "\xC2\xA92011 AACR".force_encoding('ASCII-8BIT')
|
110
|
+
record = SensitiveData.create!(storage: plaintext)
|
111
|
+
record.reload
|
112
|
+
expect(record.storage.encoding.name).to eql('UTF-8')
|
113
|
+
end
|
114
|
+
end
|
94
115
|
end
|
95
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crypt_keeper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Mazzi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|