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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0eac3b38bb9d7a211846dbec145dd7b65bad9d72
4
- data.tar.gz: 695e58e58810319cde7778e366990b4225c75768
3
+ metadata.gz: bebe9201328a264bc331e557bfb7b29eda6f8cec
4
+ data.tar.gz: f429009d3af1a7a09e8a3a4e45f21211994491c8
5
5
  SHA512:
6
- metadata.gz: 792805bc915d2e8e9b77cce29631760ef34f5bb60ec48184ab0c7beda4f3387be5e9cbc36572c6cc66af3662a1bf5f5cc03103bd3881bd07bcf5ee8f4d9ec056
7
- data.tar.gz: 6ce70f3a8c2c6e2bf2a38ca626f29f920028f658b1bd15a0ed8c3a7654f9d6d19291757c36eb86c36705d23d96179e6d7d5761199183fffade60ab6e28a3fb85
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
 
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module CryptKeeper
2
- VERSION = "0.16.1"
2
+ VERSION = "0.17.0"
3
3
  end
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.16.1
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-04-25 00:00:00.000000000 Z
11
+ date: 2014-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord