Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 71 lines (58 sloc) 2.343 kb
7757044 Aleksey Gureiev Added license headers to code
alg authored
1 # Version: OSDV Public License 1.2
ec3cb19 Aleksey Gureiev LIcense text correction
alg authored
2 # The contents of this file are subject to the OSDV Public License
7757044 Aleksey Gureiev Added license headers to code
alg authored
3 # Version 1.2 (the "License"); you may not use this file except in
4 # compliance with the License. You may obtain a copy of the License at
ec3cb19 Aleksey Gureiev LIcense text correction
alg authored
5 # The contents of this file are subject to the OSDV Public Licensewww.osdv.org/license/
7757044 Aleksey Gureiev Added license headers to code
alg authored
6 # Software distributed under the License is distributed on an "AS IS"
7 # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
8 # See the License for the specific language governing rights and limitations
9 # under the License.
10 #
11 # The Original Code is:
12 # TTV UOCAVA Ballot Portal.
13 # The Initial Developer of the Original Code is:
14 # Open Source Digital Voting Foundation.
15 # Portions created by Open Source Digital Voting Foundation are Copyright (C) 2010.
16 # All Rights Reserved.
17 #
18 # Contributors: Paul Stenbjorn, Aleksey Gureiev, Robin Bahr,
19 # Thomas Gaskin, Sean Durham, John Sebes.
20
f71de62 Aleksey Gureiev Reverted back to Rails 2.3.8
alg authored
21 module Paperclip
22 class Encrypt < Processor
23 def initialize(file, options = {}, attachment = nil)
24 super
25
3f6bb58 Aleksey Gureiev Encrypting ballots upon saving
alg authored
26 @file = file
27 @recipient = options[:geometry]
28 @attachment = attachment
29 @current_format = File.extname(@file.path)
30 @basename = File.basename(@file.path, @current_format)
f71de62 Aleksey Gureiev Reverted back to Rails 2.3.8
alg authored
31 end
32
33 def make
3f6bb58 Aleksey Gureiev Encrypting ballots upon saving
alg authored
34 src = @file
35 dst = Tempfile.new([@basename, 'gpg'].compact.join("."))
36 dst.binmode
37
08b848f Aleksey Gureiev Updated encryption
alg authored
38 raise PaperclipError, "GPG recipient wasn't set" if @recipient.blank?
39
6b2d428 Aleksey Gureiev Better error handling for encryption
alg authored
40 begin
41 run("rm", "-f \"#{File.expand_path(dst.path)}\"")
df86ae9 Aleksey Gureiev Unconditionally encrypting
alg authored
42 run("gpg", "--trust-model always -o \"#{File.expand_path(dst.path)}\" -e -r \"#{@recipient}\" \"#{File.expand_path(src.path)}\"")
6b2d428 Aleksey Gureiev Better error handling for encryption
alg authored
43 rescue PaperclipCommandLineError
44 raise PaperclipError, "couldn't be encrypted. Please try again later."
45 end
46
3f6bb58 Aleksey Gureiev Encrypting ballots upon saving
alg authored
47 dst
f71de62 Aleksey Gureiev Reverted back to Rails 2.3.8
alg authored
48 end
6b2d428 Aleksey Gureiev Better error handling for encryption
alg authored
49
50 def run(cmd, params = "", expected_outcodes = 0)
51 command = %Q<#{%Q[#{cmd} #{params}].gsub(/\s+/, " ")}>
52 command = "#{command} 2>&1"
53
54 Paperclip.log(command)
55
56 output = `#{command}`
57 unless [expected_outcodes].flatten.include?($?.exitstatus)
58 Paperclip.log output
59 raise PaperclipCommandLineError, "Error while running #{cmd}"
60 end
61
62 output
63 end
64
65 def bit_bucket #:nodoc:
66 File.exists?("/dev/null") ? "/dev/null" : "NUL"
67 end
68
f71de62 Aleksey Gureiev Reverted back to Rails 2.3.8
alg authored
69 end
70 end
Something went wrong with that request. Please try again.