]> git.cworth.org Git - sup/blobdiff - lib/sup/crypto.rb
Merge branch 'hook-local-vars'
[sup] / lib / sup / crypto.rb
index 8ec277b862603fb23d94a60d3fa19fd60ee0fd0f..772b8b696c4f4f41682fe2e51f4656bc66603254 100644 (file)
@@ -13,17 +13,15 @@ class CryptoManager
 
   def initialize
     @mutex = Mutex.new
-    self.class.i_am_the_instance self
 
     bin = `which gpg`.chomp
-
     @cmd =
       case bin
       when /\S/
-        Redwood::log "crypto: detected gpg binary in #{bin}"
+        debug "crypto: detected gpg binary in #{bin}"
         "#{bin} --quiet --batch --no-verbose --logger-fd 1 --use-agent"
       else
-        Redwood::log "crypto: no gpg binary detected"
+        debug "crypto: no gpg binary detected"
         nil
       end
   end
@@ -116,27 +114,24 @@ class CryptoManager
     output = run_gpg "--decrypt #{payload_fn.path}"
 
     if $?.success?
-      decrypted_payload, sig_lines =
-        if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
-          [$1, $2]
+      decrypted_payload, sig_lines = if output =~ /\A(.*?)((^gpg: .*$)+)\Z/m
+        [$1, $2]
+      else
+        [output, nil]
+      end
+
+      sig = if sig_lines # encrypted & signed
+        if sig_lines =~ /^gpg: (Good signature from .*$)/
+          Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
         else
-          [output, nil]
-        end
-      
-      sig = 
-        if sig_lines # encrypted & signed
-          if sig_lines =~ /^gpg: (Good signature from .*$)/
-            Chunk::CryptoNotice.new :valid, $1, sig_lines.split("\n")
-          else
-            Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
-          end
+          Chunk::CryptoNotice.new :invalid, $1, sig_lines.split("\n")
         end
+      end
 
       notice = Chunk::CryptoNotice.new :valid, "This message has been decrypted for display"
-      [RMail::Parser.read(decrypted_payload), sig, notice]
+      [notice, sig, RMail::Parser.read(decrypted_payload)]
     else
-      notice = Chunk::CryptoNotice.new :invalid, "This message could not be decrypted", output.split("\n")
-      [nil, nil, notice]
+      Chunk::CryptoNotice.new :invalid, "This message could not be decrypted", output.split("\n")
     end
   end
 
@@ -145,7 +140,7 @@ private
   def unknown_status lines=[]
     Chunk::CryptoNotice.new :unknown, "Unable to determine validity of cryptographic signature", lines
   end
-  
+
   def cant_find_binary
     ["Can't find gpg binary in path."]
   end
@@ -158,9 +153,7 @@ private
 
   def run_gpg args
     cmd = "#{@cmd} #{args} 2> /dev/null"
-    #Redwood::log "crypto: running: #{cmd}"
     output = `#{cmd}`
-    #Redwood::log "crypto: output: #{output.inspect}" unless $?.success?
     output
   end
 end