Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 51 lines (39 sloc) 1.42 kb
f71de62 @alg Reverted back to Rails 2.3.8
alg authored
1 module Paperclip
2 class Encrypt < Processor
3 def initialize(file, options = {}, attachment = nil)
4 super
5
3f6bb58 @alg Encrypting ballots upon saving
alg authored
6 @file = file
7 @recipient = options[:geometry]
8 @attachment = attachment
9 @current_format = File.extname(@file.path)
10 @basename = File.basename(@file.path, @current_format)
f71de62 @alg Reverted back to Rails 2.3.8
alg authored
11 end
12
13 def make
3f6bb58 @alg Encrypting ballots upon saving
alg authored
14 src = @file
15 dst = Tempfile.new([@basename, 'gpg'].compact.join("."))
16 dst.binmode
17
08b848f @alg Updated encryption
alg authored
18 raise PaperclipError, "GPG recipient wasn't set" if @recipient.blank?
19
6b2d428 @alg Better error handling for encryption
alg authored
20 begin
21 run("rm", "-f \"#{File.expand_path(dst.path)}\"")
df86ae9 @alg Unconditionally encrypting
alg authored
22 run("gpg", "--trust-model always -o \"#{File.expand_path(dst.path)}\" -e -r \"#{@recipient}\" \"#{File.expand_path(src.path)}\"")
6b2d428 @alg Better error handling for encryption
alg authored
23 rescue PaperclipCommandLineError
24 raise PaperclipError, "couldn't be encrypted. Please try again later."
25 end
26
3f6bb58 @alg Encrypting ballots upon saving
alg authored
27 dst
f71de62 @alg Reverted back to Rails 2.3.8
alg authored
28 end
6b2d428 @alg Better error handling for encryption
alg authored
29
30 def run(cmd, params = "", expected_outcodes = 0)
31 command = %Q<#{%Q[#{cmd} #{params}].gsub(/\s+/, " ")}>
32 command = "#{command} 2>&1"
33
34 Paperclip.log(command)
35
36 output = `#{command}`
37 unless [expected_outcodes].flatten.include?($?.exitstatus)
38 Paperclip.log output
39 raise PaperclipCommandLineError, "Error while running #{cmd}"
40 end
41
42 output
43 end
44
45 def bit_bucket #:nodoc:
46 File.exists?("/dev/null") ? "/dev/null" : "NUL"
47 end
48
f71de62 @alg Reverted back to Rails 2.3.8
alg authored
49 end
50 end
Something went wrong with that request. Please try again.