Class: Mail::Gpg::SignPart
- Inherits:
-
Part
- Object
- Part
- Mail::Gpg::SignPart
- Defined in:
- lib/mail/gpg/sign_part.rb
Class Method Summary collapse
-
.signature_valid?(plain_part, signature_part, options = {}) ⇒ Boolean
true if all signatures are valid.
-
.verify_signature(plain_part, signature_part, options = {}) ⇒ Object
will return [success(boolean), verify_result(as returned by gpgme)].
Instance Method Summary collapse
-
#initialize(cleartext_mail, options = {}) ⇒ SignPart
constructor
A new instance of SignPart.
Constructor Details
#initialize(cleartext_mail, options = {}) ⇒ SignPart
Returns a new instance of SignPart.
5 6 7 8 9 10 11 12 13 |
# File 'lib/mail/gpg/sign_part.rb', line 5 def initialize(cleartext_mail, = {}) signature = GpgmeHelper.sign(cleartext_mail.encoded, ) super() do body signature.to_s content_type "application/pgp-signature; name=\"signature.asc\"" content_disposition 'attachment; filename="signature.asc"' content_description 'OpenPGP digital signature' end end |
Class Method Details
.signature_valid?(plain_part, signature_part, options = {}) ⇒ Boolean
true if all signatures are valid
16 17 18 |
# File 'lib/mail/gpg/sign_part.rb', line 16 def self.signature_valid?(plain_part, signature_part, = {}) verify_signature(plain_part, signature_part, )[0] end |
.verify_signature(plain_part, signature_part, options = {}) ⇒ Object
will return [success(boolean), verify_result(as returned by gpgme)]
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/mail/gpg/sign_part.rb', line 21 def self.verify_signature(plain_part, signature_part, = {}) if !(signature_part.has_content_type? && ('application/pgp-signature' == signature_part.mime_type)) return false end # Work around the problem that plain_part.raw_source prefixes an # erronous CRLF, <https://github.com/mikel/mail/issues/702>. if ! plain_part.raw_source.empty? plaintext = [ plain_part.header.raw_source, "\r\n\r\n", plain_part.body.raw_source ].join else plaintext = plain_part.encoded end signature = signature_part.body.encoded GpgmeHelper.sign_verify(plaintext, signature, ) end |