ssoper-acts_as_encryptable 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +5 -0
- data/acts_as_encryptable.gemspec +1 -1
- data/lib/acts_as_encryptable/base.rb +6 -6
- metadata +1 -1
data/Changelog
CHANGED
data/acts_as_encryptable.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module ActsAsEncryptable
|
2
2
|
module Base
|
3
3
|
WARNING_MSG = "\n \e[0m\e[1;36m[\e[37mActsAsEncryptable\e[36m] \e[1;31mUsing the provided sample keys in production mode is highly discouraged. Generate your own RSA keys using the provided crypto libraries.\e[0m\n\n"
|
4
|
-
MAX_CHUNK_SIZE =
|
4
|
+
MAX_CHUNK_SIZE = 115
|
5
5
|
ENCRYPTED_CHUNK_SIZE = 175
|
6
6
|
|
7
7
|
def self.included(base)
|
@@ -11,9 +11,8 @@ module ActsAsEncryptable
|
|
11
11
|
module ClassMethods
|
12
12
|
def acts_as_encryptable(*args)
|
13
13
|
self.class_eval do
|
14
|
-
has_many :encrypted_chunks, :as => :encryptable
|
15
14
|
before_save :encrypt!
|
16
|
-
|
15
|
+
|
17
16
|
sample_key_public = File.join(File.dirname(__FILE__), '/../../sample_keys/rsa_key.pub')
|
18
17
|
sample_key_private = File.join(File.dirname(__FILE__), '/../../sample_keys/rsa_key')
|
19
18
|
|
@@ -29,6 +28,8 @@ module ActsAsEncryptable
|
|
29
28
|
RAILS_DEFAULT_LOGGER.warn WARNING_MSG
|
30
29
|
end
|
31
30
|
|
31
|
+
args = args.first if args.first.is_a? Array
|
32
|
+
|
32
33
|
write_inheritable_attribute(:encrypted_fields, args.uniq)
|
33
34
|
class_inheritable_reader :encrypted_fields
|
34
35
|
|
@@ -51,13 +52,12 @@ module ActsAsEncryptable
|
|
51
52
|
def chunkize(str, chunk_size)
|
52
53
|
(0..((str.length/chunk_size.to_f).ceil - 1)).each do |x|
|
53
54
|
start, stop = x * chunk_size, (x + 1) * chunk_size
|
54
|
-
|
55
|
-
yield str[start..stop]
|
55
|
+
yield str[start,stop]
|
56
56
|
end
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
-
module InstanceMethods
|
60
|
+
module InstanceMethods
|
61
61
|
def encrypt!
|
62
62
|
yaml_data = self.class.encrypted_fields.inject({}) do |result, field|
|
63
63
|
result.merge!(field => instance_variable_get("@#{field}".to_sym))
|