Module: RSpec::PGPMatchers::GPGRunner
- Defined in:
- lib/rspec/pgp_matchers/gpg_runner.rb
Overview
A helper module for executing GnuPG commands.
Class Method Summary collapse
-
.run_command(gpg_cmd) ⇒ Array
Executes arbitrary GnuPG command.
-
.run_decrypt(encrypted_string) ⇒ Array
Decrypts a message.
-
.run_verify(cleartext, signature_string) ⇒ Array
Verifies a signature.
Class Method Details
.run_command(gpg_cmd) ⇒ Array
Executes arbitrary GnuPG command.
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rspec/pgp_matchers/gpg_runner.rb', line 23 def run_command(gpg_cmd) env = { "LC_ALL" => "C" } # Gettext English locale gpg_executable = Shellwords.escape(RSpec::PGPMatchers.gpg_executable) homedir_path = Shellwords.escape(RSpec::PGPMatchers.homedir) Open3.capture3(env, <<~SH) #{gpg_executable} \ --homedir #{homedir_path} \ --no-permission-warning \ #{gpg_cmd} SH end |
.run_decrypt(encrypted_string) ⇒ Array
Decrypts a message.
42 43 44 45 46 47 48 |
# File 'lib/rspec/pgp_matchers/gpg_runner.rb', line 42 def run_decrypt(encrypted_string) enc_file = make_tempfile_containing(encrypted_string) cmd = gpg_decrypt_command(enc_file) run_command(cmd) ensure File.unlink(enc_file.path) end |
.run_verify(cleartext, signature_string) ⇒ Array
Verifies a signature.
56 57 58 59 60 61 62 63 |
# File 'lib/rspec/pgp_matchers/gpg_runner.rb', line 56 def run_verify(cleartext, signature_string) sig_file = make_tempfile_containing(signature_string) data_file = make_tempfile_containing(cleartext) cmd = gpg_verify_command(sig_file, data_file) run_command(cmd) ensure File.unlink(sig_file.path, data_file.path) end |