Class: As2::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/as2/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, private_key, public_certificate) ⇒ Message

Returns a new instance of Message.



7
8
9
10
11
# File 'lib/as2/message.rb', line 7

def initialize(message, private_key, public_certificate)
  @original_message = message
  @private_key = private_key
  @public_certificate = public_certificate
end

Instance Attribute Details

#original_messageObject (readonly)

Returns the value of attribute original_message.



5
6
7
# File 'lib/as2/message.rb', line 5

def original_message
  @original_message
end

Instance Method Details

#attachmentObject

Return the attached file, use .filename and .body on the return value



27
28
29
30
31
32
33
# File 'lib/as2/message.rb', line 27

def attachment
  if mail.has_attachments?
    mail.attachments.find{|a| a.content_type == "application/edi-consent"}
  else
    mail
  end
end

#decrypted_messageObject



13
14
15
# File 'lib/as2/message.rb', line 13

def decrypted_message
  @decrypted_message ||= decrypt_smime(original_message)
end

#valid_signature?(partner_certificate) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
# File 'lib/as2/message.rb', line 17

def valid_signature?(partner_certificate)
  store = OpenSSL::X509::Store.new
  store.add_cert(partner_certificate)

  smime = Base64Helper.ensure_body_base64(decrypted_message)
  message = read_smime(smime)
  message.verify [partner_certificate], store
end