def dump(obj, encrypt = nil)
      must_encrypt = encrypt || @encrypt
      serialize_format = if obj.respond_to?(:send_version) && can_handle_msgpack_result?(obj.send_version)
        @serializer.format
      else
        :json
      end
      encode_format = serialize_format == :json ? :pem : :der
      msg = @serializer.dump(obj, serialize_format)
      if must_encrypt
        certs = @store.get_target(obj)
        if certs
          msg = EncryptedDocument.new(msg, certs).encrypted_data(encode_format)
        else
          target = obj.target_for_encryption if obj.respond_to?(:target_for_encryption)
          ErrorTracker.log(self, "No certs available for object #{obj.class} being sent to #{target.inspect}") if target
        end
      end
      sig = Signature.new(msg, @cert, @key).data(encode_format)
      @serializer.dump({'id' => @identity, 'data' => msg, 'signature' => sig, 'encrypted' => !certs.nil?}, serialize_format)
    end
def dump(obj, encrypt = nil)
      must_encrypt = encrypt || @encrypt
      serialize_format = if obj.respond_to?(:send_version) && can_handle_msgpack_result?(obj.send_version)
        @serializer.format
      else
        :json
      end
      encode_format = serialize_format == :json ? :pem : :der
      msg = @serializer.dump(obj, serialize_format)
      if must_encrypt
        certs = @store.get_target(obj)
        if certs
          msg = EncryptedDocument.new(msg, certs).encrypted_data(encode_format)
        else
          target = obj.target_for_encryption if obj.respond_to?(:target_for_encryption)
          ErrorTracker.log(self, "No certs available for object #{obj.class} being sent to #{target.inspect}") if target
        end
      end
      sig = Signature.new(msg, @cert, @key).data(encode_format)
      @serializer.dump({'id' => @identity, 'data' => msg, 'signature' => sig, 'encrypted' => !certs.nil?}, serialize_format)
    end
Initialize serializer, must be called prior to using it

 === Parameters
 serializer(Serializer):: Object serializer
 identity(String):: Serialized identity associated with serialized messages
 store(Object):: Credentials store exposing certificates used for
   encryption (:get_target), signature validation (:get_signer), and
   certificate(s)/key(s) used for decryption (:get_receiver)
 encrypt(Boolean):: true if data should be signed and encrypted, otherwise
   just signed, true by default
 Serialize, sign, and encrypt message
 Sign and encrypt using X.509 certificate

 === Parameters
 obj(Object):: Object to be serialized and encrypted
 encrypt(Boolean|nil):: true if object should be signed and encrypted,
   false if just signed, nil means use class setting

 === Return
 (String):: MessagePack serialized and optionally encrypted object