Module: RSpec::PGPMatchers::GPGMatcherHelper Private

Extended by:
Forwardable
Defined in:
lib/rspec/pgp_matchers/gpg_matcher_helper.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

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

Instance Method Summary collapse

Instance Method Details

#detect_recipients(stderr_str) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



29
30
31
32
33
34
35
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
21
22
23
24
25
26
27
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



37
38
39
40
41
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
46
47
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



51
52
53
54
55
56
57
# 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