Module: EnMail::Helpers::RFC3156

Includes:
RFC1847
Included in:
Adapters::GPGME, Adapters::RNP
Defined in:
lib/enmail/helpers/rfc3156.rb

Overview

Common interface for building adapters conforming to RFC 3156 “MIME Security with OpenPGP”, which is an implementation of RFC 1847 “Security Multiparts for MIME: Multipart/Signed and Multipart/Encrypted”.

See: tools.ietf.org/html/rfc3156

Instance Method Summary collapse

Methods included from RFC1847

#encrypt, #sign

Instance Method Details

#sign_and_encrypt_combined(message) ⇒ Object

The RFC 3156 explicitly allows for signing and encrypting data in a single OpenPGP message. See: tools.ietf.org/html/rfc3156#section-6.2

rubocop:disable Metrics/MethodLength



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/enmail/helpers/rfc3156.rb', line 19

def sign_and_encrypt_combined(message)
  source_part = body_to_part(message)
  restrict_encoding(source_part)
  signer = find_signer_for(message)
  recipients = find_recipients_for(message)
  encrypted =
    sign_and_encrypt_string(source_part.encoded, signer, recipients).to_s
  encrypted_part = build_encrypted_part(encrypted)
  control_part = build_encryption_control_part

  rewrite_body(
    message,
    content_type: multipart_encrypted_content_type,
    parts: [control_part, encrypted_part],
  )
end

#sign_and_encrypt_encapsulated(message) ⇒ Object

The RFC 3156 requires that the message is first signed, then encrypted. See: tools.ietf.org/html/rfc3156#section-6.1



39
40
41
42
# File 'lib/enmail/helpers/rfc3156.rb', line 39

def sign_and_encrypt_encapsulated(message)
  sign(message)
  encrypt(message)
end