dragonfly-openssl 1.0.2 → 1.0.3
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.
@@ -5,7 +5,7 @@ module Dragonfly
|
|
5
5
|
def self.apply_configuration(app, opts = {})
|
6
6
|
app.configure do |c|
|
7
7
|
c.encoder.register(Encoder) do |e|
|
8
|
-
e.
|
8
|
+
e.key = opts[:key] if opts.has_key?(:key)
|
9
9
|
end
|
10
10
|
|
11
11
|
c.job :encrypt do |options|
|
@@ -2,25 +2,25 @@ module Dragonfly
|
|
2
2
|
module OpenSSL
|
3
3
|
class Encoder
|
4
4
|
include ::Dragonfly::Configurable
|
5
|
-
configurable_attr :
|
5
|
+
configurable_attr :key, nil
|
6
6
|
|
7
7
|
def encode(temp_object, format, options = {})
|
8
8
|
throw :unable_to_handle unless [:encrypt, :decrypt].include?(format)
|
9
|
-
throw :unable_to_handle
|
9
|
+
throw :unable_to_handle unless key
|
10
10
|
|
11
11
|
options[:meta] ||= {}
|
12
12
|
|
13
13
|
original_filename = temp_object.original_filename
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
temp_file = Tempfile.new(original_filename)
|
16
|
+
temp_file.binmode
|
17
|
+
temp_file.close
|
18
18
|
|
19
19
|
dec = (format == :decrypt) ? '-d ' : ''
|
20
20
|
|
21
|
-
%x{openssl enc -aes-256-cbc #{dec} -in "#{temp_object.path}" -out "#{
|
21
|
+
%x{openssl enc -aes-256-cbc #{dec} -in "#{temp_object.path}" -out "#{temp_file.path}" -pass pass:"#{key}"}
|
22
22
|
|
23
|
-
content = ::Dragonfly::TempObject.new(File.new(
|
23
|
+
content = ::Dragonfly::TempObject.new(File.new(temp_file.path))
|
24
24
|
meta = {
|
25
25
|
name: original_filename,
|
26
26
|
encrypted: (format != :decrypt)
|