/* decrypt.c generated by valac 0.56.19, the Vala compiler
 * generated from decrypt.vala, do not modify */

#include "omemo.h"
#include "libdino.h"
#include "xmpp-vala.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <gee.h>
#include <omemo/signal_protocol_types.h>
#include <omemo/signal_protocol.h>
#include <native/helper.h>
#include <omemo/protocol.h>
#include <omemo/curve.h>
#include "qlite.h"
#include <omemo/session_cipher.h>
#include <gio/gio.h>

#define DINO_PLUGINS_OMEMO_NS_URI "eu.siacs.conversations.axolotl"
#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

enum  {
	DINO_PLUGINS_OMEMO_OMEMO_DECRYPTOR_0_PROPERTY,
	DINO_PLUGINS_OMEMO_OMEMO_DECRYPTOR_OWN_DEVICE_ID_PROPERTY,
	DINO_PLUGINS_OMEMO_OMEMO_DECRYPTOR_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_omemo_decryptor_properties[DINO_PLUGINS_OMEMO_OMEMO_DECRYPTOR_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _qlite_database_unref0(var) ((var == NULL) ? NULL : (var = (qlite_database_unref (var), NULL)))
#define _dino_plugins_omemo_trust_manager_unref0(var) ((var == NULL) ? NULL : (var = (dino_plugins_omemo_trust_manager_unref (var), NULL)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _xmpp_xep_omemo_parsed_data_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_omemo_parsed_data_unref (var), NULL)))
#define _signal_buffer_free0(var) ((var == NULL) ? NULL : (var = (signal_buffer_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _omemo_context_unref0(var) ((var == NULL) ? NULL : (var = (omemo_context_unref (var), NULL)))
#define _qlite_statement_builder_unref0(var) ((var == NULL) ? NULL : (var = (qlite_statement_builder_unref (var), NULL)))
#define _qlite_row_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_unref (var), NULL)))
#define _qlite_row_iterator_unref0(var) ((var == NULL) ? NULL : (var = (qlite_row_iterator_unref (var), NULL)))
#define _signal_type_unref_vapi0(var) ((var == NULL) ? NULL : (var = (signal_type_unref_vapi (var), NULL)))
#define _signal_protocol_address_free0(var) ((var == NULL) ? NULL : (var = (signal_protocol_address_free (var), NULL)))
#define _session_cipher_free0(var) ((var == NULL) ? NULL : (var = (session_cipher_free (var), NULL)))
enum  {
	DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_0_PROPERTY,
	DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY,
	DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY,
	DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_decrypt_message_listener_properties[DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_NUM_PROPERTIES];
typedef struct _DinoPluginsOmemoDecryptMessageListenerRunData DinoPluginsOmemoDecryptMessageListenerRunData;

struct _DinoPluginsOmemoOmemoDecryptorPrivate {
	DinoEntitiesAccount* account;
	OmemoStore* store;
	DinoPluginsOmemoDatabase* db;
	DinoStreamInteractor* stream_interactor;
	DinoPluginsOmemoTrustManager* trust_manager;
};

struct _DinoPluginsOmemoDecryptMessageListenerPrivate {
	GeeHashMap* decryptors;
};

struct _DinoPluginsOmemoDecryptMessageListenerRunData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoPluginsOmemoDecryptMessageListener* self;
	DinoEntitiesMessage* message;
	XmppMessageStanza* stanza;
	DinoEntitiesConversation* conversation;
	gboolean result;
	GeeHashMap* _tmp0_;
	DinoEntitiesAccount* _tmp1_;
	DinoEntitiesAccount* _tmp2_;
	gpointer _tmp3_;
	DinoPluginsOmemoOmemoDecryptor* _tmp4_;
};

static gint DinoPluginsOmemoOmemoDecryptor_private_offset;
static gpointer dino_plugins_omemo_omemo_decryptor_parent_class = NULL;
static gint DinoPluginsOmemoDecryptMessageListener_private_offset;
static gpointer dino_plugins_omemo_decrypt_message_listener_parent_class = NULL;

static guchar* _vala_array_dup10 (guchar* self,
                           gssize length);
static const char* _omemo_error_code_to_string (int value);
static guint8* _vala_array_dup11 (guint8* self,
                           gssize length);
static gchar* dino_plugins_omemo_omemo_decryptor_arr_to_str (DinoPluginsOmemoOmemoDecryptor* self,
                                                      guint8* arr,
                                                      gint arr_length1);
static guint8* _vala_array_dup12 (guint8* self,
                           gssize length);
static guint8* dino_plugins_omemo_omemo_decryptor_real_decrypt_key (XmppXepOmemoOmemoDecryptor* base,
                                                             XmppXepOmemoParsedData* data,
                                                             XmppJid* from_jid,
                                                             gint* result_length1,
                                                             GError** error);
static guint8* _vala_array_dup13 (guint8* self,
                           gssize length);
static guint8* _vala_array_dup14 (guint8* self,
                           gssize length);
static gboolean dino_plugins_omemo_omemo_decryptor_update_db_for_prekey (DinoPluginsOmemoOmemoDecryptor* self,
                                                                  gint identity_id,
                                                                  const gchar* identity_key,
                                                                  XmppJid* from_jid,
                                                                  gint sid);
static guint8* _vala_array_dup15 (guint8* self,
                           gssize length);
static guint8* _vala_array_dup16 (guint8* self,
                           gssize length);
static guint8* _vala_array_dup17 (guint8* self,
                           gssize length);
static guint8* _vala_array_dup18 (guint8* self,
                           gssize length);
static gchar* dino_plugins_omemo_omemo_decryptor_real_decrypt (XmppXepOmemoOmemoDecryptor* base,
                                                        guint8* ciphertext,
                                                        gint ciphertext_length1,
                                                        guint8* key,
                                                        gint key_length1,
                                                        guint8* iv,
                                                        gint iv_length1,
                                                        GError** error);
static void dino_plugins_omemo_omemo_decryptor_finalize (GObject * obj);
static GType dino_plugins_omemo_omemo_decryptor_get_type_once (void);
static void _vala_dino_plugins_omemo_omemo_decryptor_get_property (GObject * object,
                                                            guint property_id,
                                                            GValue * value,
                                                            GParamSpec * pspec);
static void dino_plugins_omemo_decrypt_message_listener_real_run_data_free (gpointer _data);
static void dino_plugins_omemo_decrypt_message_listener_real_run (DinoMessageListener* base,
                                                           DinoEntitiesMessage* message,
                                                           XmppMessageStanza* stanza,
                                                           DinoEntitiesConversation* conversation,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_);
static gboolean dino_plugins_omemo_decrypt_message_listener_real_run_co (DinoPluginsOmemoDecryptMessageListenerRunData* _data_);
static void dino_plugins_omemo_decrypt_message_listener_finalize (GObject * obj);
static GType dino_plugins_omemo_decrypt_message_listener_get_type_once (void);
static void _vala_dino_plugins_omemo_decrypt_message_listener_get_property (GObject * object,
                                                                     guint property_id,
                                                                     GValue * value,
                                                                     GParamSpec * pspec);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static inline gpointer
dino_plugins_omemo_omemo_decryptor_get_instance_private (DinoPluginsOmemoOmemoDecryptor* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoOmemoDecryptor_private_offset);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static gpointer
_dino_plugins_omemo_trust_manager_ref0 (gpointer self)
{
	return self ? dino_plugins_omemo_trust_manager_ref (self) : NULL;
}

static gpointer
_qlite_database_ref0 (gpointer self)
{
	return self ? qlite_database_ref (self) : NULL;
}

DinoPluginsOmemoOmemoDecryptor*
dino_plugins_omemo_omemo_decryptor_construct (GType object_type,
                                              DinoEntitiesAccount* account,
                                              DinoStreamInteractor* stream_interactor,
                                              DinoPluginsOmemoTrustManager* trust_manager,
                                              DinoPluginsOmemoDatabase* db,
                                              OmemoStore* store)
{
	DinoPluginsOmemoOmemoDecryptor * self = NULL;
	DinoEntitiesAccount* _tmp0_;
	DinoStreamInteractor* _tmp1_;
	DinoPluginsOmemoTrustManager* _tmp2_;
	DinoPluginsOmemoDatabase* _tmp3_;
	OmemoStore* _tmp4_;
	g_return_val_if_fail (account != NULL, NULL);
	g_return_val_if_fail (stream_interactor != NULL, NULL);
	g_return_val_if_fail (trust_manager != NULL, NULL);
	g_return_val_if_fail (db != NULL, NULL);
	g_return_val_if_fail (store != NULL, NULL);
	self = (DinoPluginsOmemoOmemoDecryptor*) xmpp_xep_omemo_omemo_decryptor_construct (object_type);
	_tmp0_ = _g_object_ref0 (account);
	_g_object_unref0 (self->priv->account);
	self->priv->account = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream_interactor);
	_g_object_unref0 (self->priv->stream_interactor);
	self->priv->stream_interactor = _tmp1_;
	_tmp2_ = _dino_plugins_omemo_trust_manager_ref0 (trust_manager);
	_dino_plugins_omemo_trust_manager_unref0 (self->priv->trust_manager);
	self->priv->trust_manager = _tmp2_;
	_tmp3_ = _qlite_database_ref0 (db);
	_qlite_database_unref0 (self->priv->db);
	self->priv->db = _tmp3_;
	_tmp4_ = _g_object_ref0 (store);
	_g_object_unref0 (self->priv->store);
	self->priv->store = _tmp4_;
	return self;
}

DinoPluginsOmemoOmemoDecryptor*
dino_plugins_omemo_omemo_decryptor_new (DinoEntitiesAccount* account,
                                        DinoStreamInteractor* stream_interactor,
                                        DinoPluginsOmemoTrustManager* trust_manager,
                                        DinoPluginsOmemoDatabase* db,
                                        OmemoStore* store)
{
	return dino_plugins_omemo_omemo_decryptor_construct (DINO_PLUGINS_OMEMO_TYPE_OMEMO_DECRYPTOR, account, stream_interactor, trust_manager, db, store);
}

static guchar*
_vala_array_dup10 (guchar* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guchar));
	}
	return NULL;
}

static const char*
_omemo_error_code_to_string (int value)
{
	switch (value) {
		case SG_SUCCESS:
		return "SG_SUCCESS";
		case SG_ERR_NOMEM:
		return "SG_ERR_NOMEM";
		case SG_ERR_INVAL:
		return "SG_ERR_INVAL";
		case SG_ERR_UNKNOWN:
		return "SG_ERR_UNKNOWN";
		case SG_ERR_DUPLICATE_MESSAGE:
		return "SG_ERR_DUPLICATE_MESSAGE";
		case SG_ERR_INVALID_KEY:
		return "SG_ERR_INVALID_KEY";
		case SG_ERR_INVALID_KEY_ID:
		return "SG_ERR_INVALID_KEY_ID";
		case SG_ERR_INVALID_MAC:
		return "SG_ERR_INVALID_MAC";
		case SG_ERR_INVALID_MESSAGE:
		return "SG_ERR_INVALID_MESSAGE";
		case SG_ERR_INVALID_VERSION:
		return "SG_ERR_INVALID_VERSION";
		case SG_ERR_LEGACY_MESSAGE:
		return "SG_ERR_LEGACY_MESSAGE";
		case SG_ERR_NO_SESSION:
		return "SG_ERR_NO_SESSION";
		case SG_ERR_STALE_KEY_EXCHANGE:
		return "SG_ERR_STALE_KEY_EXCHANGE";
		case SG_ERR_UNTRUSTED_IDENTITY:
		return "SG_ERR_UNTRUSTED_IDENTITY";
		case SG_ERR_VRF_SIG_VERIF_FAILED:
		return "SG_ERR_VRF_SIG_VERIF_FAILED";
		case SG_ERR_INVALID_PROTO_BUF:
		return "SG_ERR_INVALID_PROTO_BUF";
		case SG_ERR_FP_VERSION_MISMATCH:
		return "SG_ERR_FP_VERSION_MISMATCH";
		case SG_ERR_FP_IDENT_MISMATCH:
		return "SG_ERR_FP_IDENT_MISMATCH";
	}
	return NULL;
}

static gint
signal_throw_gerror_by_code_ (gint code,
                              const gchar* message,
                              GError** error)
{
	gboolean _tmp0_ = FALSE;
	GError* _inner_error0_ = NULL;
	gint result;
	if (code < 0) {
		_tmp0_ = code > SG_ERR_MINIMUM;
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		const gchar* _tmp1_ = NULL;
		const gchar* _tmp2_;
		GError* _tmp3_;
		gint _tmp4_ = -1;
		_tmp1_ = message;
		if (_tmp1_ == NULL) {
			_tmp1_ = "libomemo-c error";
		}
		_tmp2_ = _omemo_error_code_to_string ((int) code);
		_tmp3_ = g_error_new ((GQuark) -1, code, "%s: %s", _tmp1_, _tmp2_);
		_inner_error0_ = _tmp3_;
		g_propagate_error (error, _inner_error0_);
		return _tmp4_;
	}
	result = code;
	return result;
}

static guint8*
signal_buffer_get_data (signal_buffer* self,
                        gint* result_length1)
{
	guint8* result;
	gint x = 0;
	guint8* res = NULL;
	guint8* _tmp0_;
	gint res_length1;
	gint _res_size_;
	guint8* _tmp1_;
	gint _tmp1__length1;
	g_return_val_if_fail (self != NULL, NULL);
	x = (gint) signal_buffer_len (self);
	_tmp0_ = signal_buffer_data (self);
	res = _tmp0_;
	res_length1 = -1;
	_res_size_ = res_length1;
	res_length1 = x;
	_tmp1_ = res;
	_tmp1__length1 = res_length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static guint8*
_vala_array_dup11 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
signal_vala_decrypt_ (gint cipher,
                      guint8* key,
                      gint key_length1,
                      guint8* iv,
                      gint iv_length1,
                      guint8* ciphertext,
                      gint ciphertext_length1,
                      gint* result_length1,
                      GError** error)
{
	signal_buffer* buf = NULL;
	signal_buffer* _tmp0_ = NULL;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	gint _tmp3_ = 0;
	guint8* _tmp4_;
	gint _tmp4__length1;
	guint8* _tmp5_;
	gint _tmp5__length1;
	guint8* _tmp6_;
	gint _tmp6__length1;
	GError* _inner_error0_ = NULL;
	guint8* result;
	_tmp1_ = signal_vala_decrypt (&_tmp0_, cipher, key, (gint) key_length1, iv, (gint) iv_length1, ciphertext, (gint) ciphertext_length1, NULL);
	_signal_buffer_free0 (buf);
	buf = _tmp0_;
	signal_throw_gerror_by_code_ (_tmp1_, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_signal_buffer_free0 (buf);
		return NULL;
	}
	_tmp2_ = signal_buffer_get_data (buf, &_tmp3_);
	_tmp2__length1 = _tmp3_;
	_tmp4_ = _tmp2_;
	_tmp4__length1 = _tmp2__length1;
	_tmp5_ = (_tmp4_ != NULL) ? _vala_array_dup11 (_tmp4_, _tmp4__length1) : _tmp4_;
	_tmp5__length1 = _tmp4__length1;
	_tmp6_ = _tmp5_;
	_tmp6__length1 = _tmp5__length1;
	if (result_length1) {
		*result_length1 = _tmp6__length1;
	}
	result = _tmp6_;
	_signal_buffer_free0 (buf);
	return result;
}

gboolean
dino_plugins_omemo_omemo_decryptor_decrypt_message (DinoPluginsOmemoOmemoDecryptor* self,
                                                    DinoEntitiesMessage* message,
                                                    XmppMessageStanza* stanza,
                                                    DinoEntitiesConversation* conversation)
{
	XmppStanzaNode* encrypted_node = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	gboolean _tmp2_ = FALSE;
	gboolean _tmp3_ = FALSE;
	XmppStanzaNode* _tmp4_;
	gint identity_id = 0;
	DinoPluginsOmemoDatabase* _tmp10_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp11_;
	DinoPluginsOmemoDatabaseIdentityTable* _tmp12_;
	DinoEntitiesAccount* _tmp13_;
	DinoEntitiesAccount* _tmp14_;
	gint _tmp15_;
	gint _tmp16_;
	DinoPluginsOmemoMessageFlag* flag = NULL;
	DinoPluginsOmemoMessageFlag* _tmp17_;
	DinoPluginsOmemoMessageFlag* _tmp18_;
	XmppXepOmemoParsedData* data = NULL;
	XmppStanzaNode* _tmp19_;
	XmppXepOmemoParsedData* _tmp20_;
	XmppXepOmemoParsedData* _tmp21_;
	gboolean _tmp88_ = FALSE;
	gboolean _tmp89_ = FALSE;
	XmppXepOmemoParsedData* _tmp90_;
	guint8* _tmp91_;
	gint _tmp91__length1;
	GError* _inner_error0_ = NULL;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (message != NULL, FALSE);
	g_return_val_if_fail (stanza != NULL, FALSE);
	g_return_val_if_fail (conversation != NULL, FALSE);
	_tmp0_ = ((XmppStanza*) stanza)->stanza;
	_tmp1_ = xmpp_stanza_node_get_subnode (_tmp0_, "encrypted", DINO_PLUGINS_OMEMO_NS_URI, FALSE);
	encrypted_node = _tmp1_;
	_tmp4_ = encrypted_node;
	if (_tmp4_ == NULL) {
		_tmp3_ = TRUE;
	} else {
		DinoPluginsOmemoMessageFlag* _tmp5_;
		DinoPluginsOmemoMessageFlag* _tmp6_;
		_tmp5_ = dino_plugins_omemo_message_flag_get_flag (stanza);
		_tmp6_ = _tmp5_;
		_tmp3_ = _tmp6_ != NULL;
		_g_object_unref0 (_tmp6_);
	}
	if (_tmp3_) {
		_tmp2_ = TRUE;
	} else {
		XmppJid* _tmp7_;
		XmppJid* _tmp8_;
		XmppJid* _tmp9_;
		_tmp7_ = xmpp_stanza_get_from ((XmppStanza*) stanza);
		_tmp8_ = _tmp7_;
		_tmp9_ = _tmp8_;
		_tmp2_ = _tmp9_ == NULL;
		_xmpp_jid_unref0 (_tmp9_);
	}
	if (_tmp2_) {
		result = FALSE;
		_xmpp_stanza_entry_unref0 (encrypted_node);
		return result;
	}
	if (!dino_plugins_omemo_plugin_ensure_context ()) {
		result = FALSE;
		_xmpp_stanza_entry_unref0 (encrypted_node);
		return result;
	}
	_tmp10_ = self->priv->db;
	_tmp11_ = dino_plugins_omemo_database_get_identity (_tmp10_);
	_tmp12_ = _tmp11_;
	_tmp13_ = dino_entities_conversation_get_account (conversation);
	_tmp14_ = _tmp13_;
	_tmp15_ = dino_entities_account_get_id (_tmp14_);
	_tmp16_ = _tmp15_;
	identity_id = dino_plugins_omemo_database_identity_table_get_id (_tmp12_, _tmp16_);
	_tmp17_ = dino_plugins_omemo_message_flag_new ();
	flag = _tmp17_;
	_tmp18_ = flag;
	xmpp_message_stanza_add_flag (stanza, (XmppMessageFlag*) _tmp18_);
	_tmp19_ = encrypted_node;
	_tmp20_ = xmpp_xep_omemo_omemo_decryptor_parse_node ((XmppXepOmemoOmemoDecryptor*) self, _tmp19_);
	data = _tmp20_;
	_tmp21_ = data;
	if (_tmp21_ == NULL) {
		result = FALSE;
		_xmpp_xep_omemo_parsed_data_unref0 (data);
		_g_object_unref0 (flag);
		_xmpp_stanza_entry_unref0 (encrypted_node);
		return result;
	}
	{
		GeeIterator* _encr_key_it = NULL;
		XmppXepOmemoParsedData* _tmp22_;
		GeeHashMap* _tmp23_;
		GeeSet* _tmp24_;
		GeeSet* _tmp25_;
		GeeSet* _tmp26_;
		GeeIterator* _tmp27_;
		GeeIterator* _tmp28_;
		_tmp22_ = data;
		_tmp23_ = _tmp22_->our_potential_encrypted_keys;
		_tmp24_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp23_);
		_tmp25_ = _tmp24_;
		_tmp26_ = _tmp25_;
		_tmp27_ = gee_iterable_iterator ((GeeIterable*) _tmp26_);
		_tmp28_ = _tmp27_;
		_g_object_unref0 (_tmp26_);
		_encr_key_it = _tmp28_;
		while (TRUE) {
			GeeIterator* _tmp29_;
			GBytes* encr_key = NULL;
			GeeIterator* _tmp30_;
			gpointer _tmp31_;
			XmppXepOmemoParsedData* _tmp32_;
			XmppXepOmemoParsedData* _tmp33_;
			GeeHashMap* _tmp34_;
			GBytes* _tmp35_;
			gpointer _tmp36_;
			XmppXepOmemoParsedData* _tmp37_;
			GBytes* _tmp38_;
			gsize _tmp39_ = 0;
			guint8* _tmp40_;
			guchar* _tmp41_;
			gint _tmp41__length1;
			GeeList* possible_jids = NULL;
			XmppXepOmemoParsedData* _tmp42_;
			GeeList* _tmp43_;
			GeeList* _tmp44_;
			gint _tmp45_;
			gint _tmp46_;
			_tmp29_ = _encr_key_it;
			if (!gee_iterator_next (_tmp29_)) {
				break;
			}
			_tmp30_ = _encr_key_it;
			_tmp31_ = gee_iterator_get (_tmp30_);
			encr_key = (GBytes*) _tmp31_;
			_tmp32_ = data;
			_tmp33_ = data;
			_tmp34_ = _tmp33_->our_potential_encrypted_keys;
			_tmp35_ = encr_key;
			_tmp36_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp34_, _tmp35_);
			_tmp32_->is_prekey = (gboolean) ((gintptr) _tmp36_);
			_tmp37_ = data;
			_tmp38_ = encr_key;
			_tmp40_ = g_bytes_get_data (_tmp38_, &_tmp39_);
			_tmp41_ = (_tmp40_ != NULL) ? _vala_array_dup10 (_tmp40_, _tmp39_) : _tmp40_;
			_tmp41__length1 = _tmp39_;
			_tmp37_->encrypted_key = (g_free (_tmp37_->encrypted_key), NULL);
			_tmp37_->encrypted_key = _tmp41_;
			_tmp37_->encrypted_key_length1 = _tmp41__length1;
			_tmp42_ = data;
			_tmp43_ = dino_plugins_omemo_omemo_decryptor_get_potential_message_jids (self, message, _tmp42_, identity_id);
			possible_jids = _tmp43_;
			_tmp44_ = possible_jids;
			_tmp45_ = gee_collection_get_size ((GeeCollection*) _tmp44_);
			_tmp46_ = _tmp45_;
			if (_tmp46_ == 0) {
				XmppXepOmemoParsedData* _tmp47_;
				_tmp47_ = data;
				g_debug ("decrypt.vala:46: Received message from unknown entity with device id %" \
"d", _tmp47_->sid);
			}
			{
				GeeList* _possible_jid_list = NULL;
				GeeList* _tmp48_;
				gint _possible_jid_size = 0;
				GeeList* _tmp49_;
				gint _tmp50_;
				gint _tmp51_;
				gint _possible_jid_index = 0;
				_tmp48_ = possible_jids;
				_possible_jid_list = _tmp48_;
				_tmp49_ = _possible_jid_list;
				_tmp50_ = gee_collection_get_size ((GeeCollection*) _tmp49_);
				_tmp51_ = _tmp50_;
				_possible_jid_size = _tmp51_;
				_possible_jid_index = -1;
				while (TRUE) {
					gint _tmp52_;
					gint _tmp53_;
					XmppJid* possible_jid = NULL;
					GeeList* _tmp54_;
					gpointer _tmp55_;
					_possible_jid_index = _possible_jid_index + 1;
					_tmp52_ = _possible_jid_index;
					_tmp53_ = _possible_jid_size;
					if (!(_tmp52_ < _tmp53_)) {
						break;
					}
					_tmp54_ = _possible_jid_list;
					_tmp55_ = gee_list_get (_tmp54_, _possible_jid_index);
					possible_jid = (XmppJid*) _tmp55_;
					{
						guint8* key = NULL;
						XmppXepOmemoParsedData* _tmp56_;
						XmppJid* _tmp57_;
						gint _tmp58_ = 0;
						guint8* _tmp59_;
						gint key_length1;
						gint _key_size_;
						XmppXepOmemoParsedData* _tmp60_;
						guint8* _tmp61_;
						gint _tmp61__length1;
						gboolean _tmp72_ = FALSE;
						DinoEntitiesConversationType _tmp73_;
						DinoEntitiesConversationType _tmp74_;
						DinoPluginsOmemoTrustManager* _tmp78_;
						GeeHashMap* _tmp79_;
						XmppXepOmemoParsedData* _tmp80_;
						_tmp56_ = data;
						_tmp57_ = possible_jid;
						_tmp59_ = xmpp_xep_omemo_omemo_decryptor_decrypt_key ((XmppXepOmemoOmemoDecryptor*) self, _tmp56_, _tmp57_, &_tmp58_, &_inner_error0_);
						key = _tmp59_;
						key_length1 = _tmp58_;
						_key_size_ = key_length1;
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							goto __catch0_g_error;
						}
						_tmp60_ = data;
						_tmp61_ = _tmp60_->ciphertext;
						_tmp61__length1 = _tmp60_->ciphertext_length1;
						if (_tmp61_ != NULL) {
							guint8* _tmp62_ = NULL;
							guint8* _tmp63_;
							gint _tmp63__length1;
							XmppXepOmemoParsedData* _tmp64_;
							guint8* _tmp65_;
							gint _tmp65__length1;
							XmppXepOmemoParsedData* _tmp66_;
							guint8* _tmp67_;
							gint _tmp67__length1;
							gint _tmp68_ = 0;
							guint8* _tmp69_;
							gint _tmp62__length1;
							gint __tmp62__size_;
							gchar* cleartext = NULL;
							gchar* _tmp70_;
							const gchar* _tmp71_;
							_tmp63_ = key;
							_tmp63__length1 = key_length1;
							_tmp64_ = data;
							_tmp65_ = _tmp64_->iv;
							_tmp65__length1 = _tmp64_->iv_length1;
							_tmp66_ = data;
							_tmp67_ = _tmp66_->ciphertext;
							_tmp67__length1 = _tmp66_->ciphertext_length1;
							_tmp69_ = signal_vala_decrypt_ ((gint) SG_CIPHER_AES_GCM_NOPADDING, _tmp63_, (gint) _tmp63__length1, _tmp65_, (gint) _tmp65__length1, _tmp67_, (gint) _tmp67__length1, &_tmp68_, &_inner_error0_);
							_tmp62_ = _tmp69_;
							_tmp62__length1 = _tmp68_;
							__tmp62__size_ = _tmp62__length1;
							if (G_UNLIKELY (_inner_error0_ != NULL)) {
								key = (g_free (key), NULL);
								goto __catch0_g_error;
							}
							_tmp70_ = dino_plugins_omemo_omemo_decryptor_arr_to_str (self, _tmp62_, (gint) _tmp62__length1);
							cleartext = _tmp70_;
							_tmp71_ = cleartext;
							dino_entities_message_set_body (message, _tmp71_);
							_g_free0 (cleartext);
							_tmp62_ = (g_free (_tmp62_), NULL);
						}
						_tmp73_ = dino_entities_conversation_get_type_ (conversation);
						_tmp74_ = _tmp73_;
						if (_tmp74_ == DINO_ENTITIES_CONVERSATION_TYPE_GROUPCHAT) {
							XmppJid* _tmp75_;
							XmppJid* _tmp76_;
							_tmp75_ = dino_entities_message_get_real_jid (message);
							_tmp76_ = _tmp75_;
							_tmp72_ = _tmp76_ == NULL;
						} else {
							_tmp72_ = FALSE;
						}
						if (_tmp72_) {
							XmppJid* _tmp77_;
							_tmp77_ = possible_jid;
							dino_entities_message_set_real_jid (message, _tmp77_);
						}
						dino_entities_message_set_encryption (message, DINO_ENTITIES_ENCRYPTION_OMEMO);
						_tmp78_ = self->priv->trust_manager;
						_tmp79_ = _tmp78_->message_device_id_map;
						_tmp80_ = data;
						gee_abstract_map_set ((GeeAbstractMap*) _tmp79_, message, (gpointer) ((gintptr) _tmp80_->sid));
						result = TRUE;
						key = (g_free (key), NULL);
						_xmpp_jid_unref0 (possible_jid);
						_g_object_unref0 (possible_jids);
						_g_bytes_unref0 (encr_key);
						_g_object_unref0 (_encr_key_it);
						_xmpp_xep_omemo_parsed_data_unref0 (data);
						_g_object_unref0 (flag);
						_xmpp_stanza_entry_unref0 (encrypted_node);
						return result;
					}
					goto __finally0;
					__catch0_g_error:
					{
						GError* e = NULL;
						XmppJid* _tmp81_;
						gchar* _tmp82_;
						gchar* _tmp83_;
						XmppXepOmemoParsedData* _tmp84_;
						GError* _tmp85_;
						const gchar* _tmp86_;
						e = _inner_error0_;
						_inner_error0_ = NULL;
						_tmp81_ = possible_jid;
						_tmp82_ = xmpp_jid_to_string (_tmp81_);
						_tmp83_ = _tmp82_;
						_tmp84_ = data;
						_tmp85_ = e;
						_tmp86_ = _tmp85_->message;
						g_debug ("decrypt.vala:67: Decrypting message from %s/%d failed: %s", _tmp83_, _tmp84_->sid, _tmp86_);
						_g_free0 (_tmp83_);
						_g_error_free0 (e);
					}
					__finally0:
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						gboolean _tmp87_ = FALSE;
						_xmpp_jid_unref0 (possible_jid);
						_g_object_unref0 (possible_jids);
						_g_bytes_unref0 (encr_key);
						_g_object_unref0 (_encr_key_it);
						_xmpp_xep_omemo_parsed_data_unref0 (data);
						_g_object_unref0 (flag);
						_xmpp_stanza_entry_unref0 (encrypted_node);
						g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
						g_clear_error (&_inner_error0_);
						return _tmp87_;
					}
					_xmpp_jid_unref0 (possible_jid);
				}
			}
			_g_object_unref0 (possible_jids);
			_g_bytes_unref0 (encr_key);
		}
		_g_object_unref0 (_encr_key_it);
	}
	_tmp90_ = data;
	_tmp91_ = _tmp90_->ciphertext;
	_tmp91__length1 = _tmp90_->ciphertext_length1;
	if (_tmp91_ != NULL) {
		XmppXepOmemoParsedData* _tmp92_;
		GeeHashMap* _tmp93_;
		gint _tmp94_;
		gint _tmp95_;
		_tmp92_ = data;
		_tmp93_ = _tmp92_->our_potential_encrypted_keys;
		_tmp94_ = gee_abstract_map_get_size ((GeeAbstractMap*) _tmp93_);
		_tmp95_ = _tmp94_;
		_tmp89_ = _tmp95_ == 0;
	} else {
		_tmp89_ = FALSE;
	}
	if (_tmp89_) {
		DinoStreamInteractor* _tmp96_;
		DinoModuleManager* _tmp97_;
		DinoEntitiesAccount* _tmp98_;
		DinoEntitiesAccount* _tmp99_;
		XmppModuleIdentity* _tmp100_;
		gpointer _tmp101_;
		DinoPluginsOmemoStreamModule* _tmp102_;
		OmemoStore* _tmp103_;
		OmemoStore* _tmp104_;
		guint32 _tmp105_;
		guint32 _tmp106_;
		XmppXepOmemoParsedData* _tmp107_;
		_tmp96_ = self->priv->stream_interactor;
		_tmp97_ = _tmp96_->module_manager;
		_tmp98_ = dino_entities_message_get_account (message);
		_tmp99_ = _tmp98_;
		_tmp100_ = dino_plugins_omemo_stream_module_IDENTITY;
		_tmp101_ = dino_module_manager_get_module (_tmp97_, DINO_PLUGINS_OMEMO_TYPE_STREAM_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp99_, _tmp100_);
		_tmp102_ = (DinoPluginsOmemoStreamModule*) _tmp101_;
		_tmp103_ = dino_plugins_omemo_stream_module_get_store (_tmp102_);
		_tmp104_ = _tmp103_;
		_tmp105_ = omemo_store_get_local_registration_id (_tmp104_);
		_tmp106_ = _tmp105_;
		_tmp107_ = data;
		_tmp88_ = _tmp106_ != ((guint32) _tmp107_->sid);
		_g_object_unref0 (_tmp102_);
	} else {
		_tmp88_ = FALSE;
	}
	if (_tmp88_) {
		DinoPluginsOmemoDatabase* _tmp108_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp109_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp110_;
		XmppXepOmemoParsedData* _tmp111_;
		GDateTime* _tmp112_;
		GDateTime* _tmp113_;
		DinoPluginsOmemoTrustManager* _tmp114_;
		DinoEntitiesAccount* _tmp115_;
		DinoEntitiesAccount* _tmp116_;
		XmppJid* _tmp117_;
		XmppJid* _tmp118_;
		XmppXepOmemoParsedData* _tmp119_;
		_tmp108_ = self->priv->db;
		_tmp109_ = dino_plugins_omemo_database_get_identity_meta (_tmp108_);
		_tmp110_ = _tmp109_;
		_tmp111_ = data;
		_tmp112_ = dino_entities_message_get_time (message);
		_tmp113_ = _tmp112_;
		dino_plugins_omemo_database_identity_meta_table_update_last_message_undecryptable (_tmp110_, identity_id, _tmp111_->sid, _tmp113_);
		_tmp114_ = self->priv->trust_manager;
		_tmp115_ = dino_entities_conversation_get_account (conversation);
		_tmp116_ = _tmp115_;
		_tmp117_ = dino_entities_message_get_from (message);
		_tmp118_ = _tmp117_;
		_tmp119_ = data;
		g_signal_emit_by_name (_tmp114_, "bad-message-state-updated", _tmp116_, _tmp118_, _tmp119_->sid);
	}
	g_debug ("decrypt.vala:81: Received OMEMO encryped message that could not be dec" \
"rypted.");
	result = FALSE;
	_xmpp_xep_omemo_parsed_data_unref0 (data);
	_g_object_unref0 (flag);
	_xmpp_stanza_entry_unref0 (encrypted_node);
	return result;
}

static guint8*
_vala_array_dup12 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
ec_public_key_serialize_ (ec_public_key* self,
                          gint* result_length1)
{
	signal_buffer* buffer = NULL;
	gint code = 0;
	signal_buffer* _tmp0_ = NULL;
	gint _tmp1_;
	gboolean _tmp2_ = FALSE;
	signal_buffer* _tmp3_;
	guint8* _tmp4_;
	gint _tmp4__length1;
	gint _tmp5_ = 0;
	guint8* _tmp6_;
	gint _tmp6__length1;
	guint8* _tmp7_;
	gint _tmp7__length1;
	guint8* _tmp8_;
	gint _tmp8__length1;
	guint8* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp1_ = ec_public_key_serialize (&_tmp0_, self);
	_signal_buffer_free0 (buffer);
	buffer = _tmp0_;
	code = _tmp1_;
	if (code < 0) {
		_tmp2_ = code > SG_ERR_MINIMUM;
	} else {
		_tmp2_ = FALSE;
	}
	if (_tmp2_) {
		g_assert_not_reached ();
	}
	_tmp3_ = buffer;
	_tmp4_ = signal_buffer_get_data (_tmp3_, &_tmp5_);
	_tmp4__length1 = _tmp5_;
	_tmp6_ = _tmp4_;
	_tmp6__length1 = _tmp4__length1;
	_tmp7_ = (_tmp6_ != NULL) ? _vala_array_dup12 (_tmp6_, _tmp6__length1) : _tmp6_;
	_tmp7__length1 = _tmp6__length1;
	_tmp8_ = _tmp7_;
	_tmp8__length1 = _tmp7__length1;
	if (result_length1) {
		*result_length1 = _tmp8__length1;
	}
	result = _tmp8_;
	_signal_buffer_free0 (buffer);
	return result;
}

GeeList*
dino_plugins_omemo_omemo_decryptor_get_potential_message_jids (DinoPluginsOmemoOmemoDecryptor* self,
                                                               DinoEntitiesMessage* message,
                                                               XmppXepOmemoParsedData* data,
                                                               gint identity_id)
{
	GeeList* possible_jids = NULL;
	GeeArrayList* _tmp0_;
	DinoEntitiesMessageType _tmp1_;
	DinoEntitiesMessageType _tmp2_;
	GError* _inner_error0_ = NULL;
	GeeList* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (message != NULL, NULL);
	g_return_val_if_fail (data != NULL, NULL);
	_tmp0_ = gee_array_list_new (XMPP_TYPE_JID, (GBoxedCopyFunc) xmpp_jid_ref, (GDestroyNotify) xmpp_jid_unref, NULL, NULL, NULL);
	possible_jids = (GeeList*) _tmp0_;
	_tmp1_ = dino_entities_message_get_type_ (message);
	_tmp2_ = _tmp1_;
	if (_tmp2_ == DINO_ENTITIES_MESSAGE_TYPE_CHAT) {
		GeeList* _tmp3_;
		XmppJid* _tmp4_;
		XmppJid* _tmp5_;
		XmppJid* _tmp6_;
		XmppJid* _tmp7_;
		XmppJid* _tmp8_;
		_tmp3_ = possible_jids;
		_tmp4_ = dino_entities_message_get_from (message);
		_tmp5_ = _tmp4_;
		_tmp6_ = xmpp_jid_get_bare_jid (_tmp5_);
		_tmp7_ = _tmp6_;
		_tmp8_ = _tmp7_;
		gee_collection_add ((GeeCollection*) _tmp3_, _tmp8_);
		_xmpp_jid_unref0 (_tmp8_);
	} else {
		XmppJid* _tmp9_;
		XmppJid* _tmp10_;
		_tmp9_ = dino_entities_message_get_real_jid (message);
		_tmp10_ = _tmp9_;
		if (_tmp10_ != NULL) {
			GeeList* _tmp11_;
			XmppJid* _tmp12_;
			XmppJid* _tmp13_;
			XmppJid* _tmp14_;
			XmppJid* _tmp15_;
			XmppJid* _tmp16_;
			_tmp11_ = possible_jids;
			_tmp12_ = dino_entities_message_get_real_jid (message);
			_tmp13_ = _tmp12_;
			_tmp14_ = xmpp_jid_get_bare_jid (_tmp13_);
			_tmp15_ = _tmp14_;
			_tmp16_ = _tmp15_;
			gee_collection_add ((GeeCollection*) _tmp11_, _tmp16_);
			_xmpp_jid_unref0 (_tmp16_);
		} else {
			if (data->is_prekey) {
				pre_key_signal_message* msg = NULL;
				OmemoContext* _tmp17_;
				OmemoContext* _tmp18_;
				guchar* _tmp19_;
				gint _tmp19__length1;
				pre_key_signal_message* _tmp20_;
				pre_key_signal_message* _tmp21_;
				gchar* identity_key = NULL;
				pre_key_signal_message* _tmp22_;
				ec_public_key* _tmp23_;
				ec_public_key* _tmp24_;
				gint _tmp25_ = 0;
				guint8* _tmp26_;
				guint8* _tmp27_;
				gint _tmp27__length1;
				gchar* _tmp28_;
				gchar* _tmp29_;
				_tmp17_ = dino_plugins_omemo_plugin_get_context ();
				_tmp18_ = _tmp17_;
				_tmp19_ = data->encrypted_key;
				_tmp19__length1 = data->encrypted_key_length1;
				_tmp20_ = omemo_context_deserialize_signal_pre_key_message (_tmp18_, _tmp19_, (gint) _tmp19__length1, &_inner_error0_);
				_tmp21_ = _tmp20_;
				_omemo_context_unref0 (_tmp18_);
				msg = _tmp21_;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					_g_object_unref0 (possible_jids);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return NULL;
				}
				_tmp22_ = msg;
				_tmp23_ = pre_key_signal_message_get_identity_key (_tmp22_);
				_tmp24_ = _tmp23_;
				_tmp26_ = ec_public_key_serialize_ (_tmp24_, &_tmp25_);
				_tmp27_ = _tmp26_;
				_tmp27__length1 = _tmp25_;
				_tmp28_ = g_base64_encode (_tmp27_, (gint) _tmp25_);
				_tmp29_ = _tmp28_;
				_tmp27_ = (g_free (_tmp27_), NULL);
				identity_key = _tmp29_;
				{
					QliteRowIterator* _row_it = NULL;
					DinoPluginsOmemoDatabase* _tmp30_;
					DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp31_;
					DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp32_;
					QliteQueryBuilder* _tmp33_;
					QliteQueryBuilder* _tmp34_;
					DinoPluginsOmemoDatabase* _tmp35_;
					DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp36_;
					DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp37_;
					QliteColumn* _tmp38_;
					const gchar* _tmp39_;
					QliteQueryBuilder* _tmp40_;
					QliteQueryBuilder* _tmp41_;
					QliteRowIterator* _tmp42_;
					QliteRowIterator* _tmp43_;
					_tmp30_ = self->priv->db;
					_tmp31_ = dino_plugins_omemo_database_get_identity_meta (_tmp30_);
					_tmp32_ = _tmp31_;
					_tmp33_ = dino_plugins_omemo_database_identity_meta_table_get_with_device_id (_tmp32_, identity_id, data->sid);
					_tmp34_ = _tmp33_;
					_tmp35_ = self->priv->db;
					_tmp36_ = dino_plugins_omemo_database_get_identity_meta (_tmp35_);
					_tmp37_ = _tmp36_;
					_tmp38_ = _tmp37_->identity_key_public_base64;
					_tmp39_ = identity_key;
					_tmp40_ = qlite_query_builder_with (_tmp34_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp38_, "=", _tmp39_);
					_tmp41_ = _tmp40_;
					_tmp42_ = qlite_query_builder_iterator (_tmp41_);
					_tmp43_ = _tmp42_;
					_qlite_statement_builder_unref0 (_tmp41_);
					_qlite_statement_builder_unref0 (_tmp34_);
					_row_it = _tmp43_;
					while (TRUE) {
						QliteRowIterator* _tmp44_;
						QliteRow* row = NULL;
						QliteRowIterator* _tmp45_;
						QliteRow* _tmp46_;
						_tmp44_ = _row_it;
						if (!qlite_row_iterator_next (_tmp44_)) {
							break;
						}
						_tmp45_ = _row_it;
						_tmp46_ = qlite_row_iterator_get (_tmp45_);
						row = _tmp46_;
						{
							XmppJid* _tmp47_ = NULL;
							QliteRow* _tmp48_;
							DinoPluginsOmemoDatabase* _tmp49_;
							DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp50_;
							DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp51_;
							QliteColumn* _tmp52_;
							gpointer _tmp53_;
							gchar* _tmp54_;
							XmppJid* _tmp55_;
							XmppJid* _tmp56_;
							GeeList* _tmp57_;
							_tmp48_ = row;
							_tmp49_ = self->priv->db;
							_tmp50_ = dino_plugins_omemo_database_get_identity_meta (_tmp49_);
							_tmp51_ = _tmp50_;
							_tmp52_ = _tmp51_->address_name;
							_tmp53_ = qlite_row_get (_tmp48_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp52_);
							_tmp54_ = (gchar*) _tmp53_;
							_tmp55_ = xmpp_jid_new (_tmp54_, &_inner_error0_);
							_tmp56_ = _tmp55_;
							_g_free0 (_tmp54_);
							_tmp47_ = _tmp56_;
							if (G_UNLIKELY (_inner_error0_ != NULL)) {
								if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
									goto __catch0_xmpp_invalid_jid_error;
								}
								_qlite_row_unref0 (row);
								_qlite_row_iterator_unref0 (_row_it);
								_g_free0 (identity_key);
								_signal_type_unref_vapi0 (msg);
								_g_object_unref0 (possible_jids);
								g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
								g_clear_error (&_inner_error0_);
								return NULL;
							}
							_tmp57_ = possible_jids;
							gee_collection_add ((GeeCollection*) _tmp57_, _tmp47_);
							_xmpp_jid_unref0 (_tmp47_);
						}
						goto __finally0;
						__catch0_xmpp_invalid_jid_error:
						{
							GError* e = NULL;
							GError* _tmp58_;
							const gchar* _tmp59_;
							e = _inner_error0_;
							_inner_error0_ = NULL;
							_tmp58_ = e;
							_tmp59_ = _tmp58_->message;
							g_warning ("decrypt.vala:100: Ignoring invalid jid from database: %s", _tmp59_);
							_g_error_free0 (e);
						}
						__finally0:
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_qlite_row_unref0 (row);
							_qlite_row_iterator_unref0 (_row_it);
							_g_free0 (identity_key);
							_signal_type_unref_vapi0 (msg);
							_g_object_unref0 (possible_jids);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return NULL;
						}
						_qlite_row_unref0 (row);
					}
					_qlite_row_iterator_unref0 (_row_it);
				}
				_g_free0 (identity_key);
				_signal_type_unref_vapi0 (msg);
			} else {
				{
					QliteRowIterator* _row_it = NULL;
					DinoPluginsOmemoDatabase* _tmp60_;
					DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp61_;
					DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp62_;
					QliteQueryBuilder* _tmp63_;
					QliteQueryBuilder* _tmp64_;
					QliteRowIterator* _tmp65_;
					QliteRowIterator* _tmp66_;
					_tmp60_ = self->priv->db;
					_tmp61_ = dino_plugins_omemo_database_get_identity_meta (_tmp60_);
					_tmp62_ = _tmp61_;
					_tmp63_ = dino_plugins_omemo_database_identity_meta_table_get_with_device_id (_tmp62_, identity_id, data->sid);
					_tmp64_ = _tmp63_;
					_tmp65_ = qlite_query_builder_iterator (_tmp64_);
					_tmp66_ = _tmp65_;
					_qlite_statement_builder_unref0 (_tmp64_);
					_row_it = _tmp66_;
					while (TRUE) {
						QliteRowIterator* _tmp67_;
						QliteRow* row = NULL;
						QliteRowIterator* _tmp68_;
						QliteRow* _tmp69_;
						_tmp67_ = _row_it;
						if (!qlite_row_iterator_next (_tmp67_)) {
							break;
						}
						_tmp68_ = _row_it;
						_tmp69_ = qlite_row_iterator_get (_tmp68_);
						row = _tmp69_;
						{
							XmppJid* _tmp70_ = NULL;
							QliteRow* _tmp71_;
							DinoPluginsOmemoDatabase* _tmp72_;
							DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp73_;
							DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp74_;
							QliteColumn* _tmp75_;
							gpointer _tmp76_;
							gchar* _tmp77_;
							XmppJid* _tmp78_;
							XmppJid* _tmp79_;
							GeeList* _tmp80_;
							_tmp71_ = row;
							_tmp72_ = self->priv->db;
							_tmp73_ = dino_plugins_omemo_database_get_identity_meta (_tmp72_);
							_tmp74_ = _tmp73_;
							_tmp75_ = _tmp74_->address_name;
							_tmp76_ = qlite_row_get (_tmp71_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp75_);
							_tmp77_ = (gchar*) _tmp76_;
							_tmp78_ = xmpp_jid_new (_tmp77_, &_inner_error0_);
							_tmp79_ = _tmp78_;
							_g_free0 (_tmp77_);
							_tmp70_ = _tmp79_;
							if (G_UNLIKELY (_inner_error0_ != NULL)) {
								if (_inner_error0_->domain == XMPP_INVALID_JID_ERROR) {
									goto __catch1_xmpp_invalid_jid_error;
								}
								_qlite_row_unref0 (row);
								_qlite_row_iterator_unref0 (_row_it);
								_g_object_unref0 (possible_jids);
								g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
								g_clear_error (&_inner_error0_);
								return NULL;
							}
							_tmp80_ = possible_jids;
							gee_collection_add ((GeeCollection*) _tmp80_, _tmp70_);
							_xmpp_jid_unref0 (_tmp70_);
						}
						goto __finally1;
						__catch1_xmpp_invalid_jid_error:
						{
							GError* e = NULL;
							GError* _tmp81_;
							const gchar* _tmp82_;
							e = _inner_error0_;
							_inner_error0_ = NULL;
							_tmp81_ = e;
							_tmp82_ = _tmp81_->message;
							g_warning ("decrypt.vala:109: Ignoring invalid jid from database: %s", _tmp82_);
							_g_error_free0 (e);
						}
						__finally1:
						if (G_UNLIKELY (_inner_error0_ != NULL)) {
							_qlite_row_unref0 (row);
							_qlite_row_iterator_unref0 (_row_it);
							_g_object_unref0 (possible_jids);
							g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
							g_clear_error (&_inner_error0_);
							return NULL;
						}
						_qlite_row_unref0 (row);
					}
					_qlite_row_iterator_unref0 (_row_it);
				}
			}
		}
	}
	result = possible_jids;
	return result;
}

static guint8*
_vala_array_dup13 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
_vala_array_dup14 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
_vala_array_dup15 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
session_cipher_decrypt_pre_key_signal_message_ (session_cipher* self,
                                                pre_key_signal_message* ciphertext,
                                                void* decrypt_context,
                                                gint* result_length1,
                                                GError** error)
{
	signal_buffer* res = NULL;
	signal_buffer* _tmp0_ = NULL;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	gint _tmp3_ = 0;
	guint8* _tmp4_;
	gint _tmp4__length1;
	guint8* _tmp5_;
	gint _tmp5__length1;
	guint8* _tmp6_;
	gint _tmp6__length1;
	GError* _inner_error0_ = NULL;
	guint8* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (ciphertext != NULL, NULL);
	_tmp1_ = session_cipher_decrypt_pre_key_signal_message (self, ciphertext, decrypt_context, &_tmp0_);
	_signal_buffer_free0 (res);
	res = _tmp0_;
	signal_throw_gerror_by_code_ (_tmp1_, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_signal_buffer_free0 (res);
		return NULL;
	}
	_tmp2_ = signal_buffer_get_data (res, &_tmp3_);
	_tmp2__length1 = _tmp3_;
	_tmp4_ = _tmp2_;
	_tmp4__length1 = _tmp2__length1;
	_tmp5_ = (_tmp4_ != NULL) ? _vala_array_dup15 (_tmp4_, _tmp4__length1) : _tmp4_;
	_tmp5__length1 = _tmp4__length1;
	_tmp6_ = _tmp5_;
	_tmp6__length1 = _tmp5__length1;
	if (result_length1) {
		*result_length1 = _tmp6__length1;
	}
	result = _tmp6_;
	_signal_buffer_free0 (res);
	return result;
}

static guint8*
_vala_array_dup16 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
session_cipher_decrypt_signal_message_ (session_cipher* self,
                                        signal_message* ciphertext,
                                        void* decrypt_context,
                                        gint* result_length1,
                                        GError** error)
{
	signal_buffer* res = NULL;
	signal_buffer* _tmp0_ = NULL;
	gint _tmp1_;
	guint8* _tmp2_;
	gint _tmp2__length1;
	gint _tmp3_ = 0;
	guint8* _tmp4_;
	gint _tmp4__length1;
	guint8* _tmp5_;
	gint _tmp5__length1;
	guint8* _tmp6_;
	gint _tmp6__length1;
	GError* _inner_error0_ = NULL;
	guint8* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (ciphertext != NULL, NULL);
	_tmp1_ = session_cipher_decrypt_signal_message (self, ciphertext, decrypt_context, &_tmp0_);
	_signal_buffer_free0 (res);
	res = _tmp0_;
	signal_throw_gerror_by_code_ (_tmp1_, NULL, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		_signal_buffer_free0 (res);
		return NULL;
	}
	_tmp2_ = signal_buffer_get_data (res, &_tmp3_);
	_tmp2__length1 = _tmp3_;
	_tmp4_ = _tmp2_;
	_tmp4__length1 = _tmp2__length1;
	_tmp5_ = (_tmp4_ != NULL) ? _vala_array_dup16 (_tmp4_, _tmp4__length1) : _tmp4_;
	_tmp5__length1 = _tmp4__length1;
	_tmp6_ = _tmp5_;
	_tmp6__length1 = _tmp5__length1;
	if (result_length1) {
		*result_length1 = _tmp6__length1;
	}
	result = _tmp6_;
	_signal_buffer_free0 (res);
	return result;
}

static guint8*
_vala_array_dup17 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
_vala_array_dup18 (guint8* self,
                   gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
dino_plugins_omemo_omemo_decryptor_real_decrypt_key (XmppXepOmemoOmemoDecryptor* base,
                                                     XmppXepOmemoParsedData* data,
                                                     XmppJid* from_jid,
                                                     gint* result_length1,
                                                     GError** error)
{
	DinoPluginsOmemoOmemoDecryptor * self;
	gint sid = 0;
	guint8* ciphertext = NULL;
	guint8* _tmp0_;
	gint _tmp0__length1;
	guint8* _tmp1_;
	gint _tmp1__length1;
	gint ciphertext_length1;
	gint _ciphertext_size_;
	guint8* encrypted_key = NULL;
	guchar* _tmp2_;
	gint _tmp2__length1;
	guint8* _tmp3_;
	gint _tmp3__length1;
	gint encrypted_key_length1;
	gint _encrypted_key_size_;
	signal_protocol_address* address = NULL;
	gchar* _tmp4_;
	gchar* _tmp5_;
	signal_protocol_address* _tmp6_;
	signal_protocol_address* _tmp7_;
	guint8* key = NULL;
	gint key_length1 = 0;
	gint _key_size_ = 0;
	guint8* _tmp56_;
	gint _tmp56__length1;
	guint8* _tmp73_;
	gint _tmp73__length1;
	GError* _inner_error0_ = NULL;
	guint8* result;
	self = (DinoPluginsOmemoOmemoDecryptor*) base;
	g_return_val_if_fail (data != NULL, NULL);
	g_return_val_if_fail (from_jid != NULL, NULL);
	sid = data->sid;
	_tmp0_ = data->ciphertext;
	_tmp0__length1 = data->ciphertext_length1;
	_tmp1_ = (_tmp0_ != NULL) ? _vala_array_dup13 (_tmp0_, _tmp0__length1) : _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	ciphertext = _tmp1_;
	ciphertext_length1 = _tmp1__length1;
	_ciphertext_size_ = ciphertext_length1;
	_tmp2_ = data->encrypted_key;
	_tmp2__length1 = data->encrypted_key_length1;
	_tmp3_ = (_tmp2_ != NULL) ? _vala_array_dup14 (_tmp2_, _tmp2__length1) : _tmp2_;
	_tmp3__length1 = _tmp2__length1;
	encrypted_key = _tmp3_;
	encrypted_key_length1 = _tmp3__length1;
	_encrypted_key_size_ = encrypted_key_length1;
	_tmp4_ = xmpp_jid_to_string (from_jid);
	_tmp5_ = _tmp4_;
	_tmp6_ = signal_protocol_address_new (_tmp5_, (gint32) sid);
	_tmp7_ = _tmp6_;
	_g_free0 (_tmp5_);
	address = _tmp7_;
	if (data->is_prekey) {
		gint identity_id = 0;
		DinoPluginsOmemoDatabase* _tmp8_;
		DinoPluginsOmemoDatabaseIdentityTable* _tmp9_;
		DinoPluginsOmemoDatabaseIdentityTable* _tmp10_;
		DinoEntitiesAccount* _tmp11_;
		gint _tmp12_;
		gint _tmp13_;
		pre_key_signal_message* msg = NULL;
		OmemoContext* _tmp14_;
		OmemoContext* _tmp15_;
		guint8* _tmp16_;
		gint _tmp16__length1;
		pre_key_signal_message* _tmp17_;
		pre_key_signal_message* _tmp18_;
		gchar* identity_key = NULL;
		pre_key_signal_message* _tmp19_;
		ec_public_key* _tmp20_;
		ec_public_key* _tmp21_;
		gint _tmp22_ = 0;
		guint8* _tmp23_;
		guint8* _tmp24_;
		gint _tmp24__length1;
		gchar* _tmp25_;
		gchar* _tmp26_;
		gboolean ok = FALSE;
		const gchar* _tmp27_;
		gchar* _tmp29_;
		gchar* _tmp30_;
		session_cipher* cipher = NULL;
		OmemoStore* _tmp31_;
		signal_protocol_address* _tmp32_;
		session_cipher* _tmp33_;
		guint8* _tmp34_ = NULL;
		session_cipher* _tmp35_;
		pre_key_signal_message* _tmp36_;
		gint _tmp37_ = 0;
		guint8* _tmp38_;
		gint _tmp34__length1;
		gint __tmp34__size_;
		guint8* _tmp39_;
		gint _tmp39__length1;
		_tmp8_ = self->priv->db;
		_tmp9_ = dino_plugins_omemo_database_get_identity (_tmp8_);
		_tmp10_ = _tmp9_;
		_tmp11_ = self->priv->account;
		_tmp12_ = dino_entities_account_get_id (_tmp11_);
		_tmp13_ = _tmp12_;
		identity_id = dino_plugins_omemo_database_identity_table_get_id (_tmp10_, _tmp13_);
		_tmp14_ = dino_plugins_omemo_plugin_get_context ();
		_tmp15_ = _tmp14_;
		_tmp16_ = encrypted_key;
		_tmp16__length1 = encrypted_key_length1;
		_tmp17_ = omemo_context_deserialize_signal_pre_key_message (_tmp15_, _tmp16_, (gint) _tmp16__length1, &_inner_error0_);
		_tmp18_ = _tmp17_;
		_omemo_context_unref0 (_tmp15_);
		msg = _tmp18_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			key = (g_free (key), NULL);
			_signal_protocol_address_free0 (address);
			encrypted_key = (g_free (encrypted_key), NULL);
			ciphertext = (g_free (ciphertext), NULL);
			return NULL;
		}
		_tmp19_ = msg;
		_tmp20_ = pre_key_signal_message_get_identity_key (_tmp19_);
		_tmp21_ = _tmp20_;
		_tmp23_ = ec_public_key_serialize_ (_tmp21_, &_tmp22_);
		_tmp24_ = _tmp23_;
		_tmp24__length1 = _tmp22_;
		_tmp25_ = g_base64_encode (_tmp24_, (gint) _tmp22_);
		_tmp26_ = _tmp25_;
		_tmp24_ = (g_free (_tmp24_), NULL);
		identity_key = _tmp26_;
		_tmp27_ = identity_key;
		ok = dino_plugins_omemo_omemo_decryptor_update_db_for_prekey (self, identity_id, _tmp27_, from_jid, sid);
		if (!ok) {
			GError* _tmp28_;
			_tmp28_ = g_error_new ((GQuark) -1, 0, "Failed updating db for prekey");
			_inner_error0_ = _tmp28_;
			g_propagate_error (error, _inner_error0_);
			_g_free0 (identity_key);
			_signal_type_unref_vapi0 (msg);
			key = (g_free (key), NULL);
			_signal_protocol_address_free0 (address);
			encrypted_key = (g_free (encrypted_key), NULL);
			ciphertext = (g_free (ciphertext), NULL);
			return NULL;
		}
		_tmp29_ = xmpp_jid_to_string (from_jid);
		_tmp30_ = _tmp29_;
		g_debug ("decrypt.vala:133: Starting new session for decryption with device from" \
" %s/%d", _tmp30_, sid);
		_g_free0 (_tmp30_);
		_tmp31_ = self->priv->store;
		_tmp32_ = address;
		_tmp33_ = omemo_store_create_session_cipher (_tmp31_, _tmp32_, &_inner_error0_);
		cipher = _tmp33_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_g_free0 (identity_key);
			_signal_type_unref_vapi0 (msg);
			key = (g_free (key), NULL);
			_signal_protocol_address_free0 (address);
			encrypted_key = (g_free (encrypted_key), NULL);
			ciphertext = (g_free (ciphertext), NULL);
			return NULL;
		}
		_tmp35_ = cipher;
		_tmp36_ = msg;
		_tmp38_ = session_cipher_decrypt_pre_key_signal_message_ (_tmp35_, _tmp36_, NULL, &_tmp37_, &_inner_error0_);
		_tmp34_ = _tmp38_;
		_tmp34__length1 = _tmp37_;
		__tmp34__size_ = _tmp34__length1;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_session_cipher_free0 (cipher);
			_g_free0 (identity_key);
			_signal_type_unref_vapi0 (msg);
			key = (g_free (key), NULL);
			_signal_protocol_address_free0 (address);
			encrypted_key = (g_free (encrypted_key), NULL);
			ciphertext = (g_free (ciphertext), NULL);
			return NULL;
		}
		_tmp39_ = _tmp34_;
		_tmp39__length1 = _tmp34__length1;
		_tmp34_ = NULL;
		_tmp34__length1 = 0;
		key = (g_free (key), NULL);
		key = _tmp39_;
		key_length1 = _tmp39__length1;
		_key_size_ = key_length1;
		_tmp34_ = (g_free (_tmp34_), NULL);
		_session_cipher_free0 (cipher);
		_g_free0 (identity_key);
		_signal_type_unref_vapi0 (msg);
	} else {
		gchar* _tmp40_;
		gchar* _tmp41_;
		signal_message* msg = NULL;
		OmemoContext* _tmp42_;
		OmemoContext* _tmp43_;
		guint8* _tmp44_;
		gint _tmp44__length1;
		signal_message* _tmp45_;
		signal_message* _tmp46_;
		session_cipher* cipher = NULL;
		OmemoStore* _tmp47_;
		signal_protocol_address* _tmp48_;
		session_cipher* _tmp49_;
		guint8* _tmp50_ = NULL;
		session_cipher* _tmp51_;
		signal_message* _tmp52_;
		gint _tmp53_ = 0;
		guint8* _tmp54_;
		gint _tmp50__length1;
		gint __tmp50__size_;
		guint8* _tmp55_;
		gint _tmp55__length1;
		_tmp40_ = xmpp_jid_to_string (from_jid);
		_tmp41_ = _tmp40_;
		g_debug ("decrypt.vala:138: Continuing session for decryption with device from %" \
"s/%d", _tmp41_, sid);
		_g_free0 (_tmp41_);
		_tmp42_ = dino_plugins_omemo_plugin_get_context ();
		_tmp43_ = _tmp42_;
		_tmp44_ = encrypted_key;
		_tmp44__length1 = encrypted_key_length1;
		_tmp45_ = omemo_context_deserialize_signal_message (_tmp43_, _tmp44_, (gint) _tmp44__length1, &_inner_error0_);
		_tmp46_ = _tmp45_;
		_omemo_context_unref0 (_tmp43_);
		msg = _tmp46_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			key = (g_free (key), NULL);
			_signal_protocol_address_free0 (address);
			encrypted_key = (g_free (encrypted_key), NULL);
			ciphertext = (g_free (ciphertext), NULL);
			return NULL;
		}
		_tmp47_ = self->priv->store;
		_tmp48_ = address;
		_tmp49_ = omemo_store_create_session_cipher (_tmp47_, _tmp48_, &_inner_error0_);
		cipher = _tmp49_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_signal_type_unref_vapi0 (msg);
			key = (g_free (key), NULL);
			_signal_protocol_address_free0 (address);
			encrypted_key = (g_free (encrypted_key), NULL);
			ciphertext = (g_free (ciphertext), NULL);
			return NULL;
		}
		_tmp51_ = cipher;
		_tmp52_ = msg;
		_tmp54_ = session_cipher_decrypt_signal_message_ (_tmp51_, _tmp52_, NULL, &_tmp53_, &_inner_error0_);
		_tmp50_ = _tmp54_;
		_tmp50__length1 = _tmp53_;
		__tmp50__size_ = _tmp50__length1;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			g_propagate_error (error, _inner_error0_);
			_session_cipher_free0 (cipher);
			_signal_type_unref_vapi0 (msg);
			key = (g_free (key), NULL);
			_signal_protocol_address_free0 (address);
			encrypted_key = (g_free (encrypted_key), NULL);
			ciphertext = (g_free (ciphertext), NULL);
			return NULL;
		}
		_tmp55_ = _tmp50_;
		_tmp55__length1 = _tmp50__length1;
		_tmp50_ = NULL;
		_tmp50__length1 = 0;
		key = (g_free (key), NULL);
		key = _tmp55_;
		key_length1 = _tmp55__length1;
		_key_size_ = key_length1;
		_tmp50_ = (g_free (_tmp50_), NULL);
		_session_cipher_free0 (cipher);
		_signal_type_unref_vapi0 (msg);
	}
	_tmp56_ = key;
	_tmp56__length1 = key_length1;
	if (_tmp56__length1 >= 32) {
		gint authtaglength = 0;
		guint8* _tmp57_;
		gint _tmp57__length1;
		guint8* new_ciphertext = NULL;
		guint8* _tmp58_;
		gint _tmp58__length1;
		guint8* _tmp59_;
		gint new_ciphertext_length1;
		gint _new_ciphertext_size_;
		guint8* new_key = NULL;
		guint8* _tmp60_;
		gint new_key_length1;
		gint _new_key_size_;
		guint8* _tmp61_;
		gint _tmp61__length1;
		guint8* _tmp62_;
		gint _tmp62__length1;
		guint8* _tmp63_;
		gint _tmp63__length1;
		guint8* _tmp64_;
		gint _tmp64__length1;
		guint8* _tmp65_;
		gint _tmp65__length1;
		guint8* _tmp66_;
		gint _tmp66__length1;
		guint8* _tmp67_;
		gint _tmp67__length1;
		guint8* _tmp68_;
		gint _tmp68__length1;
		guint8* _tmp69_;
		gint _tmp69__length1;
		guint8* _tmp70_;
		gint _tmp70__length1;
		guint8* _tmp71_;
		gint _tmp71__length1;
		guint8* _tmp72_;
		gint _tmp72__length1;
		_tmp57_ = key;
		_tmp57__length1 = key_length1;
		authtaglength = _tmp57__length1 - 16;
		_tmp58_ = ciphertext;
		_tmp58__length1 = ciphertext_length1;
		_tmp59_ = g_new0 (guint8, _tmp58__length1 + authtaglength);
		new_ciphertext = _tmp59_;
		new_ciphertext_length1 = _tmp58__length1 + authtaglength;
		_new_ciphertext_size_ = new_ciphertext_length1;
		_tmp60_ = g_new0 (guint8, 16);
		new_key = _tmp60_;
		new_key_length1 = 16;
		_new_key_size_ = new_key_length1;
		_tmp61_ = new_ciphertext;
		_tmp61__length1 = new_ciphertext_length1;
		_tmp62_ = ciphertext;
		_tmp62__length1 = ciphertext_length1;
		_tmp63_ = ciphertext;
		_tmp63__length1 = ciphertext_length1;
		memcpy (_tmp61_, _tmp62_, (gsize) _tmp63__length1);
		_tmp64_ = new_ciphertext;
		_tmp64__length1 = new_ciphertext_length1;
		_tmp65_ = ciphertext;
		_tmp65__length1 = ciphertext_length1;
		_tmp66_ = key;
		_tmp66__length1 = key_length1;
		memcpy (((guint8*) _tmp64_) + _tmp65__length1, ((guint8*) _tmp66_) + 16, (gsize) authtaglength);
		_tmp67_ = new_key;
		_tmp67__length1 = new_key_length1;
		_tmp68_ = key;
		_tmp68__length1 = key_length1;
		memcpy (_tmp67_, _tmp68_, (gsize) 16);
		_tmp69_ = new_ciphertext;
		_tmp69__length1 = new_ciphertext_length1;
		_tmp70_ = (_tmp69_ != NULL) ? _vala_array_dup17 (_tmp69_, _tmp69__length1) : _tmp69_;
		_tmp70__length1 = _tmp69__length1;
		data->ciphertext = (g_free (data->ciphertext), NULL);
		data->ciphertext = _tmp70_;
		data->ciphertext_length1 = _tmp70__length1;
		_tmp71_ = new_key;
		_tmp71__length1 = new_key_length1;
		_tmp72_ = (_tmp71_ != NULL) ? _vala_array_dup18 (_tmp71_, _tmp71__length1) : _tmp71_;
		_tmp72__length1 = _tmp71__length1;
		key = (g_free (key), NULL);
		key = _tmp72_;
		key_length1 = _tmp72__length1;
		_key_size_ = key_length1;
		new_key = (g_free (new_key), NULL);
		new_ciphertext = (g_free (new_ciphertext), NULL);
	}
	_tmp73_ = key;
	_tmp73__length1 = key_length1;
	if (result_length1) {
		*result_length1 = _tmp73__length1;
	}
	result = _tmp73_;
	_signal_protocol_address_free0 (address);
	encrypted_key = (g_free (encrypted_key), NULL);
	ciphertext = (g_free (ciphertext), NULL);
	return result;
}

static gchar*
dino_plugins_omemo_omemo_decryptor_real_decrypt (XmppXepOmemoOmemoDecryptor* base,
                                                 guint8* ciphertext,
                                                 gint ciphertext_length1,
                                                 guint8* key,
                                                 gint key_length1,
                                                 guint8* iv,
                                                 gint iv_length1,
                                                 GError** error)
{
	DinoPluginsOmemoOmemoDecryptor * self;
	guint8* _tmp0_ = NULL;
	gint _tmp1_ = 0;
	guint8* _tmp2_;
	gint _tmp0__length1;
	gint __tmp0__size_;
	gchar* _tmp3_;
	GError* _inner_error0_ = NULL;
	gchar* result;
	self = (DinoPluginsOmemoOmemoDecryptor*) base;
	_tmp2_ = signal_vala_decrypt_ ((gint) SG_CIPHER_AES_GCM_NOPADDING, key, (gint) key_length1, iv, (gint) iv_length1, ciphertext, (gint) ciphertext_length1, &_tmp1_, &_inner_error0_);
	_tmp0_ = _tmp2_;
	_tmp0__length1 = _tmp1_;
	__tmp0__size_ = _tmp0__length1;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		g_propagate_error (error, _inner_error0_);
		return NULL;
	}
	_tmp3_ = dino_plugins_omemo_omemo_decryptor_arr_to_str (self, _tmp0_, (gint) _tmp0__length1);
	result = _tmp3_;
	_tmp0_ = (g_free (_tmp0_), NULL);
	return result;
}

static gboolean
dino_plugins_omemo_omemo_decryptor_update_db_for_prekey (DinoPluginsOmemoOmemoDecryptor* self,
                                                         gint identity_id,
                                                         const gchar* identity_key,
                                                         XmppJid* from_jid,
                                                         gint sid)
{
	QliteRow* device = NULL;
	DinoPluginsOmemoDatabase* _tmp0_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp1_;
	DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	QliteRow* _tmp5_;
	QliteRow* _tmp6_;
	gboolean _tmp7_ = FALSE;
	QliteRow* _tmp8_;
	gboolean result;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (identity_key != NULL, FALSE);
	g_return_val_if_fail (from_jid != NULL, FALSE);
	_tmp0_ = self->priv->db;
	_tmp1_ = dino_plugins_omemo_database_get_identity_meta (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = xmpp_jid_to_string (from_jid);
	_tmp4_ = _tmp3_;
	_tmp5_ = dino_plugins_omemo_database_identity_meta_table_get_device (_tmp2_, identity_id, _tmp4_, sid);
	_tmp6_ = _tmp5_;
	_g_free0 (_tmp4_);
	device = _tmp6_;
	_tmp8_ = device;
	if (_tmp8_ != NULL) {
		QliteRow* _tmp9_;
		DinoPluginsOmemoDatabase* _tmp10_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp11_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp12_;
		QliteColumn* _tmp13_;
		gpointer _tmp14_;
		gchar* _tmp15_;
		_tmp9_ = device;
		_tmp10_ = self->priv->db;
		_tmp11_ = dino_plugins_omemo_database_get_identity_meta (_tmp10_);
		_tmp12_ = _tmp11_;
		_tmp13_ = _tmp12_->identity_key_public_base64;
		_tmp14_ = qlite_row_get (_tmp9_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp13_);
		_tmp15_ = (gchar*) _tmp14_;
		_tmp7_ = _tmp15_ != NULL;
		_g_free0 (_tmp15_);
	} else {
		_tmp7_ = FALSE;
	}
	if (_tmp7_) {
		QliteRow* _tmp16_;
		DinoPluginsOmemoDatabase* _tmp17_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp18_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp19_;
		QliteColumn* _tmp20_;
		gpointer _tmp21_;
		gchar* _tmp22_;
		gboolean _tmp23_;
		_tmp16_ = device;
		_tmp17_ = self->priv->db;
		_tmp18_ = dino_plugins_omemo_database_get_identity_meta (_tmp17_);
		_tmp19_ = _tmp18_;
		_tmp20_ = _tmp19_->identity_key_public_base64;
		_tmp21_ = qlite_row_get (_tmp16_, G_TYPE_STRING, (GBoxedCopyFunc) g_strdup, (GDestroyNotify) g_free, _tmp20_);
		_tmp22_ = (gchar*) _tmp21_;
		_tmp23_ = g_strcmp0 (_tmp22_, identity_key) != 0;
		_g_free0 (_tmp22_);
		if (_tmp23_) {
			g_critical ("decrypt.vala:166: Tried to use a different identity key for a known de" \
"vice id.");
			result = FALSE;
			_qlite_row_unref0 (device);
			return result;
		}
	} else {
		gchar* _tmp24_;
		gchar* _tmp25_;
		gboolean blind_trust = FALSE;
		DinoPluginsOmemoDatabase* _tmp26_;
		DinoPluginsOmemoDatabaseTrustTable* _tmp27_;
		DinoPluginsOmemoDatabaseTrustTable* _tmp28_;
		gchar* _tmp29_;
		gchar* _tmp30_;
		gboolean _tmp31_;
		DinoPluginsOmemoTrustLevel _tmp32_ = 0;
		DinoPluginsOmemoDatabase* _tmp33_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp34_;
		DinoPluginsOmemoDatabaseIdentityMetaTable* _tmp35_;
		gchar* _tmp36_;
		gchar* _tmp37_;
		gboolean _tmp38_;
		XmppXmppStream* stream = NULL;
		DinoStreamInteractor* _tmp39_;
		DinoEntitiesAccount* _tmp40_;
		XmppXmppStream* _tmp41_;
		gboolean _tmp42_ = FALSE;
		QliteRow* _tmp43_;
		_tmp24_ = xmpp_jid_to_string (from_jid);
		_tmp25_ = _tmp24_;
		g_debug ("decrypt.vala:170: Learn new device from incoming message from %s/%d", _tmp25_, sid);
		_g_free0 (_tmp25_);
		_tmp26_ = self->priv->db;
		_tmp27_ = dino_plugins_omemo_database_get_trust (_tmp26_);
		_tmp28_ = _tmp27_;
		_tmp29_ = xmpp_jid_to_string (from_jid);
		_tmp30_ = _tmp29_;
		_tmp31_ = dino_plugins_omemo_database_trust_table_get_blind_trust (_tmp28_, (gint32) identity_id, _tmp30_, TRUE);
		_g_free0 (_tmp30_);
		blind_trust = _tmp31_;
		if (blind_trust) {
			_tmp32_ = DINO_PLUGINS_OMEMO_TRUST_LEVEL_TRUSTED;
		} else {
			_tmp32_ = DINO_PLUGINS_OMEMO_TRUST_LEVEL_UNKNOWN;
		}
		_tmp33_ = self->priv->db;
		_tmp34_ = dino_plugins_omemo_database_get_identity_meta (_tmp33_);
		_tmp35_ = _tmp34_;
		_tmp36_ = xmpp_jid_to_string (from_jid);
		_tmp37_ = _tmp36_;
		_tmp38_ = dino_plugins_omemo_database_identity_meta_table_insert_device_session (_tmp35_, (gint32) identity_id, _tmp37_, sid, identity_key, _tmp32_) < ((gint64) 0);
		_g_free0 (_tmp37_);
		if (_tmp38_) {
			g_critical ("decrypt.vala:173: Failed learning a device.");
			result = FALSE;
			_qlite_row_unref0 (device);
			return result;
		}
		_tmp39_ = self->priv->stream_interactor;
		_tmp40_ = self->priv->account;
		_tmp41_ = dino_stream_interactor_get_stream (_tmp39_, _tmp40_);
		stream = _tmp41_;
		_tmp43_ = device;
		if (_tmp43_ == NULL) {
			XmppXmppStream* _tmp44_;
			_tmp44_ = stream;
			_tmp42_ = _tmp44_ != NULL;
		} else {
			_tmp42_ = FALSE;
		}
		if (_tmp42_) {
			XmppXmppStream* _tmp45_;
			XmppModuleIdentity* _tmp46_;
			gpointer _tmp47_;
			DinoPluginsOmemoStreamModule* _tmp48_;
			XmppXmppStream* _tmp49_;
			_tmp45_ = stream;
			_tmp46_ = dino_plugins_omemo_stream_module_IDENTITY;
			_tmp47_ = xmpp_xmpp_stream_get_module (_tmp45_, DINO_PLUGINS_OMEMO_TYPE_STREAM_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp46_);
			_tmp48_ = (DinoPluginsOmemoStreamModule*) _tmp47_;
			_tmp49_ = stream;
			dino_plugins_omemo_stream_module_request_user_devicelist (_tmp48_, _tmp49_, from_jid, NULL, NULL);
			_g_object_unref0 (_tmp48_);
		}
		_g_object_unref0 (stream);
	}
	result = TRUE;
	_qlite_row_unref0 (device);
	return result;
}

static gchar*
dino_plugins_omemo_omemo_decryptor_arr_to_str (DinoPluginsOmemoOmemoDecryptor* self,
                                               guint8* arr,
                                               gint arr_length1)
{
	guint8* rarr = NULL;
	guint8* _tmp0_;
	gint rarr_length1;
	gint _rarr_size_;
	gchar* _tmp1_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = g_new0 (guint8, arr_length1 + 1);
	rarr = _tmp0_;
	rarr_length1 = arr_length1 + 1;
	_rarr_size_ = rarr_length1;
	memcpy (rarr, arr, (gsize) arr_length1);
	_tmp1_ = g_strdup ((const gchar*) rarr);
	result = _tmp1_;
	rarr = (g_free (rarr), NULL);
	return result;
}

static guint32
dino_plugins_omemo_omemo_decryptor_real_get_own_device_id (XmppXepOmemoOmemoDecryptor* base)
{
	guint32 result;
	DinoPluginsOmemoOmemoDecryptor* self;
	OmemoStore* _tmp0_;
	guint32 _tmp1_;
	guint32 _tmp2_;
	self = (DinoPluginsOmemoOmemoDecryptor*) base;
	_tmp0_ = self->priv->store;
	_tmp1_ = omemo_store_get_local_registration_id (_tmp0_);
	_tmp2_ = _tmp1_;
	result = _tmp2_;
	return result;
}

static void
dino_plugins_omemo_omemo_decryptor_class_init (DinoPluginsOmemoOmemoDecryptorClass * klass,
                                               gpointer klass_data)
{
	dino_plugins_omemo_omemo_decryptor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoOmemoDecryptor_private_offset);
	((XmppXepOmemoOmemoDecryptorClass *) klass)->decrypt_key = (guint8* (*) (XmppXepOmemoOmemoDecryptor*, XmppXepOmemoParsedData*, XmppJid*, gint*, GError**)) dino_plugins_omemo_omemo_decryptor_real_decrypt_key;
	((XmppXepOmemoOmemoDecryptorClass *) klass)->decrypt = (gchar* (*) (XmppXepOmemoOmemoDecryptor*, guint8*, gint, guint8*, gint, guint8*, gint, GError**)) dino_plugins_omemo_omemo_decryptor_real_decrypt;
	XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_CLASS (klass)->get_own_device_id = (guint32 (*) (XmppXepOmemoOmemoDecryptor*)) dino_plugins_omemo_omemo_decryptor_real_get_own_device_id;
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_plugins_omemo_omemo_decryptor_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_omemo_omemo_decryptor_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OMEMO_OMEMO_DECRYPTOR_OWN_DEVICE_ID_PROPERTY, dino_plugins_omemo_omemo_decryptor_properties[DINO_PLUGINS_OMEMO_OMEMO_DECRYPTOR_OWN_DEVICE_ID_PROPERTY] = g_param_spec_uint ("own-device-id", "own-device-id", "own-device-id", 0, G_MAXUINT, 0U, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
dino_plugins_omemo_omemo_decryptor_instance_init (DinoPluginsOmemoOmemoDecryptor * self,
                                                  gpointer klass)
{
	self->priv = dino_plugins_omemo_omemo_decryptor_get_instance_private (self);
}

static void
dino_plugins_omemo_omemo_decryptor_finalize (GObject * obj)
{
	DinoPluginsOmemoOmemoDecryptor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_OMEMO_DECRYPTOR, DinoPluginsOmemoOmemoDecryptor);
	_g_object_unref0 (self->priv->account);
	_g_object_unref0 (self->priv->store);
	_qlite_database_unref0 (self->priv->db);
	_g_object_unref0 (self->priv->stream_interactor);
	_dino_plugins_omemo_trust_manager_unref0 (self->priv->trust_manager);
	G_OBJECT_CLASS (dino_plugins_omemo_omemo_decryptor_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_omemo_decryptor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoOmemoDecryptorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_omemo_decryptor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoOmemoDecryptor), 0, (GInstanceInitFunc) dino_plugins_omemo_omemo_decryptor_instance_init, NULL };
	GType dino_plugins_omemo_omemo_decryptor_type_id;
	dino_plugins_omemo_omemo_decryptor_type_id = g_type_register_static (XMPP_XEP_OMEMO_TYPE_OMEMO_DECRYPTOR, "DinoPluginsOmemoOmemoDecryptor", &g_define_type_info, 0);
	DinoPluginsOmemoOmemoDecryptor_private_offset = g_type_add_instance_private (dino_plugins_omemo_omemo_decryptor_type_id, sizeof (DinoPluginsOmemoOmemoDecryptorPrivate));
	return dino_plugins_omemo_omemo_decryptor_type_id;
}

GType
dino_plugins_omemo_omemo_decryptor_get_type (void)
{
	static volatile gsize dino_plugins_omemo_omemo_decryptor_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_omemo_decryptor_type_id__once)) {
		GType dino_plugins_omemo_omemo_decryptor_type_id;
		dino_plugins_omemo_omemo_decryptor_type_id = dino_plugins_omemo_omemo_decryptor_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_omemo_decryptor_type_id__once, dino_plugins_omemo_omemo_decryptor_type_id);
	}
	return dino_plugins_omemo_omemo_decryptor_type_id__once;
}

static void
_vala_dino_plugins_omemo_omemo_decryptor_get_property (GObject * object,
                                                       guint property_id,
                                                       GValue * value,
                                                       GParamSpec * pspec)
{
	DinoPluginsOmemoOmemoDecryptor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_PLUGINS_OMEMO_TYPE_OMEMO_DECRYPTOR, DinoPluginsOmemoOmemoDecryptor);
	switch (property_id) {
		case DINO_PLUGINS_OMEMO_OMEMO_DECRYPTOR_OWN_DEVICE_ID_PROPERTY:
		g_value_set_uint (value, xmpp_xep_omemo_omemo_decryptor_get_own_device_id ((XmppXepOmemoOmemoDecryptor*) self));
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static inline gpointer
dino_plugins_omemo_decrypt_message_listener_get_instance_private (DinoPluginsOmemoDecryptMessageListener* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoDecryptMessageListener_private_offset);
}

DinoPluginsOmemoDecryptMessageListener*
dino_plugins_omemo_decrypt_message_listener_construct (GType object_type,
                                                       GeeHashMap* decryptors)
{
	DinoPluginsOmemoDecryptMessageListener * self = NULL;
	GeeHashMap* _tmp0_;
	g_return_val_if_fail (decryptors != NULL, NULL);
	self = (DinoPluginsOmemoDecryptMessageListener*) dino_message_listener_construct (object_type);
	_tmp0_ = _g_object_ref0 (decryptors);
	_g_object_unref0 (self->priv->decryptors);
	self->priv->decryptors = _tmp0_;
	return self;
}

DinoPluginsOmemoDecryptMessageListener*
dino_plugins_omemo_decrypt_message_listener_new (GeeHashMap* decryptors)
{
	return dino_plugins_omemo_decrypt_message_listener_construct (DINO_PLUGINS_OMEMO_TYPE_DECRYPT_MESSAGE_LISTENER, decryptors);
}

static void
dino_plugins_omemo_decrypt_message_listener_real_run_data_free (gpointer _data)
{
	DinoPluginsOmemoDecryptMessageListenerRunData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->message);
	_g_object_unref0 (_data_->stanza);
	_g_object_unref0 (_data_->conversation);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoPluginsOmemoDecryptMessageListenerRunData, _data_);
}

static void
dino_plugins_omemo_decrypt_message_listener_real_run (DinoMessageListener* base,
                                                      DinoEntitiesMessage* message,
                                                      XmppMessageStanza* stanza,
                                                      DinoEntitiesConversation* conversation,
                                                      GAsyncReadyCallback _callback_,
                                                      gpointer _user_data_)
{
	DinoPluginsOmemoDecryptMessageListener * self;
	DinoPluginsOmemoDecryptMessageListenerRunData* _data_;
	DinoPluginsOmemoDecryptMessageListener* _tmp0_;
	DinoEntitiesMessage* _tmp1_;
	XmppMessageStanza* _tmp2_;
	DinoEntitiesConversation* _tmp3_;
	g_return_if_fail (message != NULL);
	g_return_if_fail (stanza != NULL);
	g_return_if_fail (conversation != NULL);
	self = (DinoPluginsOmemoDecryptMessageListener*) base;
	_data_ = g_slice_new0 (DinoPluginsOmemoDecryptMessageListenerRunData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_plugins_omemo_decrypt_message_listener_real_run_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (message);
	_g_object_unref0 (_data_->message);
	_data_->message = _tmp1_;
	_tmp2_ = _g_object_ref0 (stanza);
	_g_object_unref0 (_data_->stanza);
	_data_->stanza = _tmp2_;
	_tmp3_ = _g_object_ref0 (conversation);
	_g_object_unref0 (_data_->conversation);
	_data_->conversation = _tmp3_;
	dino_plugins_omemo_decrypt_message_listener_real_run_co (_data_);
}

static gboolean
dino_plugins_omemo_decrypt_message_listener_run_finish (DinoMessageListener* base,
                                                        GAsyncResult* _res_)
{
	gboolean result;
	DinoPluginsOmemoDecryptMessageListenerRunData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static gboolean
dino_plugins_omemo_decrypt_message_listener_real_run_co (DinoPluginsOmemoDecryptMessageListenerRunData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = _data_->self->priv->decryptors;
	_data_->_tmp1_ = dino_entities_message_get_account (_data_->message);
	_data_->_tmp2_ = _data_->_tmp1_;
	_data_->_tmp3_ = gee_abstract_map_get ((GeeAbstractMap*) _data_->_tmp0_, _data_->_tmp2_);
	_data_->_tmp4_ = (DinoPluginsOmemoOmemoDecryptor*) _data_->_tmp3_;
	dino_plugins_omemo_omemo_decryptor_decrypt_message (_data_->_tmp4_, _data_->message, _data_->stanza, _data_->conversation);
	_g_object_unref0 (_data_->_tmp4_);
	_data_->result = FALSE;
	g_task_return_pointer (_data_->_async_result, _data_, NULL);
	if (_data_->_state_ != 0) {
		while (!g_task_get_completed (_data_->_async_result)) {
			g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
		}
	}
	g_object_unref (_data_->_async_result);
	return FALSE;
}

static const gchar*
dino_plugins_omemo_decrypt_message_listener_real_get_action_group (XmppOrderedListener* base)
{
	const gchar* result;
	DinoPluginsOmemoDecryptMessageListener* self;
	self = (DinoPluginsOmemoDecryptMessageListener*) base;
	result = "DECRYPT";
	return result;
}

static gchar**
dino_plugins_omemo_decrypt_message_listener_real_get_after_actions (XmppOrderedListener* base,
                                                                    gint* result_length1)
{
	gchar** result;
	DinoPluginsOmemoDecryptMessageListener* self;
	gchar** _tmp0_;
	gint _tmp0__length1;
	gchar** _tmp1_;
	gint _tmp1__length1;
	self = (DinoPluginsOmemoDecryptMessageListener*) base;
	_tmp0_ = self->after_actions_const;
	_tmp0__length1 = self->after_actions_const_length1;
	_tmp1_ = _tmp0_;
	_tmp1__length1 = _tmp0__length1;
	if (result_length1) {
		*result_length1 = _tmp1__length1;
	}
	result = _tmp1_;
	return result;
}

static void
dino_plugins_omemo_decrypt_message_listener_class_init (DinoPluginsOmemoDecryptMessageListenerClass * klass,
                                                        gpointer klass_data)
{
	dino_plugins_omemo_decrypt_message_listener_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoDecryptMessageListener_private_offset);
	((DinoMessageListenerClass *) klass)->run = (void (*) (DinoMessageListener*, DinoEntitiesMessage*, XmppMessageStanza*, DinoEntitiesConversation*, GAsyncReadyCallback, gpointer)) dino_plugins_omemo_decrypt_message_listener_real_run;
	((DinoMessageListenerClass *) klass)->run_finish = (gboolean (*) (DinoMessageListener*, GAsyncResult*)) dino_plugins_omemo_decrypt_message_listener_run_finish;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_action_group = (const gchar* (*) (XmppOrderedListener*)) dino_plugins_omemo_decrypt_message_listener_real_get_action_group;
	XMPP_ORDERED_LISTENER_CLASS (klass)->get_after_actions = (gchar** (*) (XmppOrderedListener*, gint*)) dino_plugins_omemo_decrypt_message_listener_real_get_after_actions;
	G_OBJECT_CLASS (klass)->get_property = _vala_dino_plugins_omemo_decrypt_message_listener_get_property;
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_omemo_decrypt_message_listener_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY, dino_plugins_omemo_decrypt_message_listener_properties[DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY] = g_param_spec_string ("action-group", "action-group", "action-group", NULL, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
	g_object_class_install_property (G_OBJECT_CLASS (klass), DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY, dino_plugins_omemo_decrypt_message_listener_properties[DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY] = g_param_spec_boxed ("after-actions", "after-actions", "after-actions", G_TYPE_STRV, G_PARAM_STATIC_STRINGS | G_PARAM_READABLE));
}

static void
dino_plugins_omemo_decrypt_message_listener_instance_init (DinoPluginsOmemoDecryptMessageListener * self,
                                                           gpointer klass)
{
	gchar** _tmp0_;
	self->priv = dino_plugins_omemo_decrypt_message_listener_get_instance_private (self);
	_tmp0_ = g_new0 (gchar*, 0 + 1);
	self->after_actions_const = _tmp0_;
	self->after_actions_const_length1 = 0;
}

static void
dino_plugins_omemo_decrypt_message_listener_finalize (GObject * obj)
{
	DinoPluginsOmemoDecryptMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_DECRYPT_MESSAGE_LISTENER, DinoPluginsOmemoDecryptMessageListener);
	self->after_actions_const = (_vala_array_free (self->after_actions_const, self->after_actions_const_length1, (GDestroyNotify) g_free), NULL);
	_g_object_unref0 (self->priv->decryptors);
	G_OBJECT_CLASS (dino_plugins_omemo_decrypt_message_listener_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_decrypt_message_listener_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoDecryptMessageListenerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_decrypt_message_listener_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoDecryptMessageListener), 0, (GInstanceInitFunc) dino_plugins_omemo_decrypt_message_listener_instance_init, NULL };
	GType dino_plugins_omemo_decrypt_message_listener_type_id;
	dino_plugins_omemo_decrypt_message_listener_type_id = g_type_register_static (DINO_TYPE_MESSAGE_LISTENER, "DinoPluginsOmemoDecryptMessageListener", &g_define_type_info, 0);
	DinoPluginsOmemoDecryptMessageListener_private_offset = g_type_add_instance_private (dino_plugins_omemo_decrypt_message_listener_type_id, sizeof (DinoPluginsOmemoDecryptMessageListenerPrivate));
	return dino_plugins_omemo_decrypt_message_listener_type_id;
}

GType
dino_plugins_omemo_decrypt_message_listener_get_type (void)
{
	static volatile gsize dino_plugins_omemo_decrypt_message_listener_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_decrypt_message_listener_type_id__once)) {
		GType dino_plugins_omemo_decrypt_message_listener_type_id;
		dino_plugins_omemo_decrypt_message_listener_type_id = dino_plugins_omemo_decrypt_message_listener_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_decrypt_message_listener_type_id__once, dino_plugins_omemo_decrypt_message_listener_type_id);
	}
	return dino_plugins_omemo_decrypt_message_listener_type_id__once;
}

static void
_vala_dino_plugins_omemo_decrypt_message_listener_get_property (GObject * object,
                                                                guint property_id,
                                                                GValue * value,
                                                                GParamSpec * pspec)
{
	DinoPluginsOmemoDecryptMessageListener * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, DINO_PLUGINS_OMEMO_TYPE_DECRYPT_MESSAGE_LISTENER, DinoPluginsOmemoDecryptMessageListener);
	switch (property_id) {
		case DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_ACTION_GROUP_PROPERTY:
		g_value_set_string (value, xmpp_ordered_listener_get_action_group ((XmppOrderedListener*) self));
		break;
		case DINO_PLUGINS_OMEMO_DECRYPT_MESSAGE_LISTENER_AFTER_ACTIONS_PROPERTY:
		{
			int length;
			g_value_set_boxed (value, xmpp_ordered_listener_get_after_actions ((XmppOrderedListener*) self, &length));
		}
		break;
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

