lib/legion/transport/message.rb in legion-transport-1.1.0 vs lib/legion/transport/message.rb in legion-transport-1.1.1
- old
+ new
@@ -26,23 +26,29 @@
@options
end
def encode_message
message_payload = message
- message_payload = Legion::JSON.dump(message_payload) if message_payload.is_a? Hash
- @options[:content_encoding] = 'identity'
- return message_payload unless encrypt? && Legion::Settings[:crypt][:cs_encrypt_ready]
+ message_payload = Legion::JSON.dump(message_payload) unless message_payload.is_a? String
- @options[:content_encoding] = 'encrypted/cs'
- encrypt_message(message_payload)
+ if encrypt?
+ encrypted = Legion::Crypt.encrypt(message_payload)
+ headers[:iv] = encrypted[:iv]
+ @options[:content_encoding] = 'encrypted/cs'
+ return encrypted[:enciphered_message]
+ else
+ @options[:content_encoding] = 'identity'
+ end
+
+ message_payload
end
def encrypt_message(message, _type = 'cs')
Legion::Crypt.encrypt(message)
end
def encrypt?
- Legion::Settings[:transport][:messages][:encrypt]
+ Legion::Settings[:transport][:messages][:encrypt] && Legion::Settings[:crypt][:cs_encrypt_ready]
end
def exchange_name
lex = self.class.ancestors.first.to_s.split('::')[2].downcase
"Legion::Extensions::#{lex.capitalize}::Transport::Exchanges::#{lex.capitalize}"