Class: Dotgpg
- Inherits:
-
Object
show all
- Defined in:
- lib/dotgpg.rb,
lib/dotgpg/cli.rb,
lib/dotgpg/dir.rb,
lib/dotgpg/key.rb
Defined Under Namespace
Classes: Cli, Dir, Failure, InvalidSignature, Key
Class Method Summary
collapse
Class Method Details
.editor ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# 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 ⇒ Object
36
37
38
39
40
|
# 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) ⇒ Object
56
57
58
59
60
61
62
63
64
|
# File 'lib/dotgpg.rb', line 56
def self.interactive=(bool)
@interactive = bool
if interactive?
trap(:INT){ exit 2 }
else
trap(:INT, "DEFAULT")
end
end
|
.interactive? ⇒ Boolean
66
67
68
|
# File 'lib/dotgpg.rb', line 66
def self.interactive?
!!@interactive
end
|
.passfunc(hook, uid_hint, passphrase_info, prev_was_bad, fd) ⇒ Object
85
86
87
88
89
90
91
92
93
94
95
96
|
# 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) ⇒ Object
TODO: it’d be nice not to store the passphrase in plaintext in RAM.
72
73
74
|
# File 'lib/dotgpg.rb', line 72
def self.passphrase=(passphrase)
@passphrase = passphrase
end
|
42
43
44
45
46
|
# File 'lib/dotgpg.rb', line 42
def self.read_input(prompt)
$stderr.print prompt
$stderr.flush
$stdin.readline.strip
end
|
.read_passphrase(prompt) ⇒ Object
48
49
50
51
52
53
54
|
# 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) ⇒ Object
76
77
78
79
80
81
82
83
|
# 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
|