aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/compat/gpg.rb
diff options
context:
space:
mode:
authorMike McQuaid2017-12-30 18:57:23 +0000
committerMike McQuaid2017-12-30 20:56:54 +0000
commitfaf2182495e770041274c59e3b9ac80b98326fae (patch)
treeb556a6c961e9c8cc0c482028a0e31bab3228f730 /Library/Homebrew/compat/gpg.rb
parent176ed97d4241ae673f8d7ef1daa43efa1695d06f (diff)
downloadbrew-faf2182495e770041274c59e3b9ac80b98326fae.tar.bz2
gpg: move to compat.
Diffstat (limited to 'Library/Homebrew/compat/gpg.rb')
-rw-r--r--Library/Homebrew/compat/gpg.rb49
1 files changed, 49 insertions, 0 deletions
diff --git a/Library/Homebrew/compat/gpg.rb b/Library/Homebrew/compat/gpg.rb
new file mode 100644
index 000000000..01880f71e
--- /dev/null
+++ b/Library/Homebrew/compat/gpg.rb
@@ -0,0 +1,49 @@
+require "utils"
+
+module Gpg
+ module_function
+
+ def executable
+ which "gpg"
+ end
+
+ def available?
+ File.executable?(executable.to_s)
+ end
+
+ def create_test_key(path)
+ odie "No GPG present to test against!" unless available?
+
+ (path/"batch.gpg").write <<~EOS
+ Key-Type: RSA
+ Key-Length: 2048
+ Subkey-Type: RSA
+ Subkey-Length: 2048
+ Name-Real: Testing
+ Name-Email: testing@foo.bar
+ Expire-Date: 1d
+ %no-protection
+ %commit
+ EOS
+ system executable, "--batch", "--gen-key", "batch.gpg"
+ end
+
+ def cleanup_test_processes!
+ odie "No GPG present to test against!" unless available?
+
+ gpgconf = Pathname.new(executable).parent/"gpgconf"
+
+ system gpgconf, "--kill", "gpg-agent"
+ system gpgconf, "--homedir", "keyrings/live", "--kill",
+ "gpg-agent"
+ end
+
+ def test(path)
+ create_test_key(path)
+ begin
+ yield
+ ensure
+ cleanup_test_processes!
+ end
+ end
+end