class Dotgpg
Public Class Methods
decrypt_without_validating_signatures(data)
click to toggle source
this is a quick workaroundfor situations where finding a dotgpg directory is difficult.
THIS WILL NOT VERIFY THE INPUT WAS SIGNED THIS WILL NOT VERIFY THE INPUT SIGNATURE IS VALID THIS WILL NOT VERIFY THE INPUT SIGNATURE IS TRUSTED
see Dir#decrypt
for the right way to read files.
# File lib/dotgpg.rb, line 107 def self.decrypt_without_validating_signatures(data) GPGME::Crypto.new.decrypt data, passphrase_callback: Dotgpg.method(:passfunc) end
editor()
click to toggle source
This method copied directly from Pry and is Copyright © 2013 John Mair (banisterfiend) github.com/pry/pry/blob/master/LICENSE
# File lib/dotgpg.rb, line 21 def self.editor configured = ENV["VISUAL"] || ENV["EDITOR"] || guess_editor configured = configured.dup case configured when /^mate/, /^subl/ configured << " -w" when /^[gm]vim/ configured << " --nofork" when /^jedit/ configured << " -wait" end configured end
guess_editor()
click to toggle source
# File lib/dotgpg.rb, line 36 def self.guess_editor %w(subl sublime-text sensible-editor editor mate nano vim vi open).detect do |editor| system("command -v #{editor} > /dev/null 2>&1") end end
interactive=(bool)
click to toggle source
# File lib/dotgpg.rb, line 56 def self.interactive=(bool) @interactive = bool if interactive? # get rid of stack trace on <ctrl-c> trap(:INT){ exit 2 } else trap(:INT, "DEFAULT") end end
interactive?()
click to toggle source
# File lib/dotgpg.rb, line 66 def self.interactive? !!@interactive end
passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd)
click to toggle source
# File lib/dotgpg.rb, line 85 def self.passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd) if interactive? && (!@passphrase || prev_was_bad != 0) uid_hint = $1 if uid_hint =~ /<(.*)>/ @passphrase = read_passphrase "GPG passphrase for #{uid_hint}: " elsif !@passphrase raise "You must set Dotgpg.password or Dotgpg.interactive" end io = IO.for_fd(fd, 'w') io.puts(@passphrase) io.flush end
passphrase=(passphrase)
click to toggle source
TODO: it'd be nice not to store the passphrase in plaintext in RAM.
# File lib/dotgpg.rb, line 72 def self.passphrase=(passphrase) @passphrase = passphrase end
read_input(prompt)
click to toggle source
# File lib/dotgpg.rb, line 42 def self.read_input(prompt) $stderr.print prompt $stderr.flush $stdin.readline.strip end
read_passphrase(prompt)
click to toggle source
# File lib/dotgpg.rb, line 48 def self.read_passphrase(prompt) `stty -echo` read_input prompt ensure $stderr.print "\n" `stty echo` end
warn(context, error)
click to toggle source
# File lib/dotgpg.rb, line 76 def self.warn(context, error) if interactive? $stderr.puts "#{context}: #{error.message}" else puts "raising warning" raise error end end