module EnMail::Helpers::RFC3156

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

Public Instance Methods

sign_and_encrypt_combined(message) click to toggle source

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

# 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) click to toggle source

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

# File lib/enmail/helpers/rfc3156.rb, line 39
def sign_and_encrypt_encapsulated(message)
  sign(message)
  encrypt(message)
end

Protected Instance Methods

encryption_control_information() click to toggle source

As defined in RFC 3156

# File lib/enmail/helpers/rfc3156.rb, line 55
def encryption_control_information
  "Version: 1"
end
encryption_protocol() click to toggle source
# File lib/enmail/helpers/rfc3156.rb, line 50
def encryption_protocol
  "application/pgp-encrypted"
end
sign_protocol() click to toggle source
# File lib/enmail/helpers/rfc3156.rb, line 46
def sign_protocol
  "application/pgp-signature"
end