module RSpec::PGPMatchers::GPGMatcherHelper

A collection of utility methods to be included in matchers. Mostly for extracting information from GnuPG output.

@api private

Public Instance Methods

detect_recipients(stderr_str) click to toggle source
# File lib/rspec/pgp_matchers/gpg_matcher_helper.rb, line 29
def detect_recipients(stderr_str)
  rx = /encrypted with .*\n.*\<(?<email>[^>]+)\>/

  stderr_str.to_enum(:scan, rx).map do
    $~["email"]
  end
end
detect_signers(stderr_str) click to toggle source
# File lib/rspec/pgp_matchers/gpg_matcher_helper.rb, line 18
def detect_signers(stderr_str)
  rx = /(?<ok>Good|BAD) signature from .*\<(?<email>[^>]+)\>/

  stderr_str.to_enum(:scan, rx).map do
    {
      email: $~["email"],
      ok: ($~["ok"] == "Good"),
    }
  end
end
match_cleartext(cleartext) click to toggle source
# File lib/rspec/pgp_matchers/gpg_matcher_helper.rb, line 37
def match_cleartext(cleartext)
  if cleartext != expected_cleartext
    msg_mismatch(cleartext)
  end
end
match_recipients(recipients) click to toggle source
# File lib/rspec/pgp_matchers/gpg_matcher_helper.rb, line 43
def match_recipients(recipients)
  if expected_recipients.sort != recipients.sort
    msg_wrong_recipients(recipients)
  end
end
match_signature(signature) click to toggle source

Checks if signature is valid. If `expected_signer` is not `nil`, then it additionally checks if the signature was issued by expected signer.

# File lib/rspec/pgp_matchers/gpg_matcher_helper.rb, line 51
def match_signature(signature)
  if !signature[:ok]
    msg_mismatch(text)
  elsif expected_signer && signature[:email] != expected_signer
    msg_wrong_signer(signature[:email])
  end
end