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

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "omemo.h"
#include "xmpp-vala.h"
#include <glib-object.h>
#include <gio/gio.h>
#include <gee.h>
#include "crypto-vala.h"

#define DINO_PLUGINS_JET_OMEMO_NS_URI "urn:xmpp:jingle:jet-omemo:0"
#define DINO_PLUGINS_JET_OMEMO_AES_128_GCM_URI "urn:xmpp:ciphers:aes-128-gcm-nopadding"
#define DINO_PLUGINS_JET_OMEMO_MODULE_KEY_SIZE ((guint) 16)
#define DINO_PLUGINS_JET_OMEMO_MODULE_IV_SIZE ((guint) 12)
#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_JET_OMEMO_MODULE_0_PROPERTY,
	DINO_PLUGINS_JET_OMEMO_MODULE_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_jet_omemo_module_properties[DINO_PLUGINS_JET_OMEMO_MODULE_NUM_PROPERTIES];
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_jid_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_jid_unref (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
typedef struct _DinoPluginsJetOmemoModuleIsAvailableData DinoPluginsJetOmemoModuleIsAvailableData;
#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 _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 _xmpp_xep_omemo_encryption_result_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_omemo_encryption_result_unref (var), NULL)))
#define _xmpp_xep_omemo_encryption_data_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_xep_omemo_encryption_data_unref (var), NULL)))
enum  {
	DINO_PLUGINS_JET_OMEMO_AES_GCM_CIPHER_0_PROPERTY,
	DINO_PLUGINS_JET_OMEMO_AES_GCM_CIPHER_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_jet_omemo_aes_gcm_cipher_properties[DINO_PLUGINS_JET_OMEMO_AES_GCM_CIPHER_NUM_PROPERTIES];
#define _omemo_context_unref0(var) ((var == NULL) ? NULL : (var = (omemo_context_unref (var), NULL)))
#define _crypto_symmetric_cipher_unref0(var) ((var == NULL) ? NULL : (var = (crypto_symmetric_cipher_unref (var), NULL)))
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _DinoPluginsJetOmemoModuleIsAvailableData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoPluginsJetOmemoModule* self;
	XmppXmppStream* stream;
	XmppJid* full_jid;
	gboolean result;
	gboolean* has_feature;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepServiceDiscoveryModule* _tmp2_;
	gboolean _tmp3_;
	gboolean* _tmp4_;
	gboolean* _tmp5_;
	gboolean _tmp6_;
	gboolean* _tmp7_;
	gboolean* _tmp8_;
	XmppModuleIdentity* _tmp9_;
	gpointer _tmp10_;
	XmppXepJetModule* _tmp11_;
	gboolean _tmp12_;
};

struct _DinoPluginsJetOmemoAesGcmCipherPrivate {
	guint key_size;
	guint default_iv_size;
	gchar* uri;
};

static gpointer dino_plugins_jet_omemo_module_parent_class = NULL;
XmppModuleIdentity* dino_plugins_jet_omemo_module_IDENTITY = NULL;
static XmppXepJetEnvelopEncodingIface * dino_plugins_jet_omemo_module_xmpp_xep_jet_envelop_encoding_parent_iface = NULL;
static gint DinoPluginsJetOmemoAesGcmCipher_private_offset;
static gpointer dino_plugins_jet_omemo_aes_gcm_cipher_parent_class = NULL;
static XmppXepJetCipherIface * dino_plugins_jet_omemo_aes_gcm_cipher_xmpp_xep_jet_cipher_parent_iface = NULL;

static void dino_plugins_jet_omemo_module_real_attach (XmppXmppStreamModule* base,
                                                XmppXmppStream* stream);
static void dino_plugins_jet_omemo_module_real_detach (XmppXmppStreamModule* base,
                                                XmppXmppStream* stream);
static void dino_plugins_jet_omemo_module_is_available_data_free (gpointer _data);
static gboolean dino_plugins_jet_omemo_module_is_available_co (DinoPluginsJetOmemoModuleIsAvailableData* _data_);
static void dino_plugins_jet_omemo_module_is_available_ready (GObject* source_object,
                                                       GAsyncResult* _res_,
                                                       gpointer _user_data_);
static gboolean* _bool_dup (gboolean* self);
static gchar* dino_plugins_jet_omemo_module_real_get_type_uri (XmppXepJetEnvelopEncoding* base);
static XmppXepJetTransportSecret* dino_plugins_jet_omemo_module_real_decode_envolop (XmppXepJetEnvelopEncoding* base,
                                                                              XmppXmppStream* stream,
                                                                              XmppJid* local_full_jid,
                                                                              XmppJid* peer_full_jid,
                                                                              XmppStanzaNode* security,
                                                                              GError** error);
static guchar* _vala_array_dup6 (guchar* self,
                          gssize length);
static void dino_plugins_jet_omemo_module_real_encode_envelop (XmppXepJetEnvelopEncoding* base,
                                                        XmppXmppStream* stream,
                                                        XmppJid* local_full_jid,
                                                        XmppJid* peer_full_jid,
                                                        XmppXepJetSecurityParameters* security_params,
                                                        XmppStanzaNode* security);
static guint8* _vala_array_dup7 (guint8* self,
                          gssize length);
static guint8* _vala_array_dup8 (guint8* self,
                          gssize length);
static gchar* dino_plugins_jet_omemo_module_real_get_ns (XmppXmppStreamModule* base);
static gchar* dino_plugins_jet_omemo_module_real_get_id (XmppXmppStreamModule* base);
static void dino_plugins_jet_omemo_module_finalize (GObject * obj);
static GType dino_plugins_jet_omemo_module_get_type_once (void);
static gchar* dino_plugins_jet_omemo_aes_gcm_cipher_real_get_cipher_uri (XmppXepJetCipher* base);
static XmppXepJetTransportSecret* dino_plugins_jet_omemo_aes_gcm_cipher_real_generate_random_secret (XmppXepJetCipher* base);
static GInputStream* dino_plugins_jet_omemo_aes_gcm_cipher_real_wrap_input_stream (XmppXepJetCipher* base,
                                                                            GInputStream* input,
                                                                            XmppXepJetTransportSecret* secret);
static GOutputStream* dino_plugins_jet_omemo_aes_gcm_cipher_real_wrap_output_stream (XmppXepJetCipher* base,
                                                                              GOutputStream* output,
                                                                              XmppXepJetTransportSecret* secret);
static void dino_plugins_jet_omemo_aes_gcm_cipher_finalize (GObject * obj);
static GType dino_plugins_jet_omemo_aes_gcm_cipher_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static void
dino_plugins_jet_omemo_module_real_attach (XmppXmppStreamModule* base,
                                           XmppXmppStream* stream)
{
	DinoPluginsJetOmemoModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepJetModule* _tmp2_;
	gboolean _tmp3_;
	self = (DinoPluginsJetOmemoModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_xep_jet_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_JET_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppXepJetModule*) _tmp1_;
	_tmp3_ = _tmp2_ != NULL;
	_g_object_unref0 (_tmp2_);
	if (_tmp3_) {
		XmppModuleIdentity* _tmp4_;
		gpointer _tmp5_;
		XmppXepServiceDiscoveryModule* _tmp6_;
		XmppModuleIdentity* _tmp7_;
		gpointer _tmp8_;
		XmppXepJetModule* _tmp9_;
		XmppModuleIdentity* _tmp10_;
		gpointer _tmp11_;
		XmppXepJetModule* _tmp12_;
		DinoPluginsJetOmemoAesGcmCipher* _tmp13_;
		DinoPluginsJetOmemoAesGcmCipher* _tmp14_;
		_tmp4_ = xmpp_xep_service_discovery_module_IDENTITY;
		_tmp5_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_SERVICE_DISCOVERY_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp4_);
		_tmp6_ = (XmppXepServiceDiscoveryModule*) _tmp5_;
		xmpp_xep_service_discovery_module_add_feature (_tmp6_, stream, DINO_PLUGINS_JET_OMEMO_NS_URI);
		_g_object_unref0 (_tmp6_);
		_tmp7_ = xmpp_xep_jet_module_IDENTITY;
		_tmp8_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_JET_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp7_);
		_tmp9_ = (XmppXepJetModule*) _tmp8_;
		xmpp_xep_jet_module_register_envelop_encoding (_tmp9_, (XmppXepJetEnvelopEncoding*) self);
		_g_object_unref0 (_tmp9_);
		_tmp10_ = xmpp_xep_jet_module_IDENTITY;
		_tmp11_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_JET_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp10_);
		_tmp12_ = (XmppXepJetModule*) _tmp11_;
		_tmp13_ = dino_plugins_jet_omemo_aes_gcm_cipher_new (DINO_PLUGINS_JET_OMEMO_MODULE_KEY_SIZE, DINO_PLUGINS_JET_OMEMO_MODULE_IV_SIZE, DINO_PLUGINS_JET_OMEMO_AES_128_GCM_URI);
		_tmp14_ = _tmp13_;
		xmpp_xep_jet_module_register_cipher (_tmp12_, (XmppXepJetCipher*) _tmp14_);
		_g_object_unref0 (_tmp14_);
		_g_object_unref0 (_tmp12_);
	}
}

static void
dino_plugins_jet_omemo_module_real_detach (XmppXmppStreamModule* base,
                                           XmppXmppStream* stream)
{
	DinoPluginsJetOmemoModule * self;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	XmppXepServiceDiscoveryModule* _tmp2_;
	self = (DinoPluginsJetOmemoModule*) base;
	g_return_if_fail (stream != NULL);
	_tmp0_ = xmpp_xep_service_discovery_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_SERVICE_DISCOVERY_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (XmppXepServiceDiscoveryModule*) _tmp1_;
	xmpp_xep_service_discovery_module_remove_feature (_tmp2_, stream, DINO_PLUGINS_JET_OMEMO_NS_URI);
	_g_object_unref0 (_tmp2_);
}

static void
dino_plugins_jet_omemo_module_is_available_data_free (gpointer _data)
{
	DinoPluginsJetOmemoModuleIsAvailableData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->stream);
	_xmpp_jid_unref0 (_data_->full_jid);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoPluginsJetOmemoModuleIsAvailableData, _data_);
}

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

static gpointer
_xmpp_jid_ref0 (gpointer self)
{
	return self ? xmpp_jid_ref (self) : NULL;
}

void
dino_plugins_jet_omemo_module_is_available (DinoPluginsJetOmemoModule* self,
                                            XmppXmppStream* stream,
                                            XmppJid* full_jid,
                                            GAsyncReadyCallback _callback_,
                                            gpointer _user_data_)
{
	DinoPluginsJetOmemoModuleIsAvailableData* _data_;
	DinoPluginsJetOmemoModule* _tmp0_;
	XmppXmppStream* _tmp1_;
	XmppJid* _tmp2_;
	g_return_if_fail (self != NULL);
	g_return_if_fail (stream != NULL);
	g_return_if_fail (full_jid != NULL);
	_data_ = g_slice_new0 (DinoPluginsJetOmemoModuleIsAvailableData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_plugins_jet_omemo_module_is_available_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (stream);
	_g_object_unref0 (_data_->stream);
	_data_->stream = _tmp1_;
	_tmp2_ = _xmpp_jid_ref0 (full_jid);
	_xmpp_jid_unref0 (_data_->full_jid);
	_data_->full_jid = _tmp2_;
	dino_plugins_jet_omemo_module_is_available_co (_data_);
}

gboolean
dino_plugins_jet_omemo_module_is_available_finish (DinoPluginsJetOmemoModule* self,
                                                   GAsyncResult* _res_)
{
	gboolean result;
	DinoPluginsJetOmemoModuleIsAvailableData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), NULL);
	result = _data_->result;
	return result;
}

static void
dino_plugins_jet_omemo_module_is_available_ready (GObject* source_object,
                                                  GAsyncResult* _res_,
                                                  gpointer _user_data_)
{
	DinoPluginsJetOmemoModuleIsAvailableData* _data_;
	_data_ = _user_data_;
	_data_->_source_object_ = source_object;
	_data_->_res_ = _res_;
	dino_plugins_jet_omemo_module_is_available_co (_data_);
}

static gboolean*
_bool_dup (gboolean* self)
{
	gboolean* dup;
	dup = g_new0 (gboolean, 1);
	memcpy (dup, self, sizeof (gboolean));
	return dup;
}

static gpointer
__bool_dup0 (gpointer self)
{
	return self ? _bool_dup (self) : NULL;
}

static gboolean
dino_plugins_jet_omemo_module_is_available_co (DinoPluginsJetOmemoModuleIsAvailableData* _data_)
{
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		case 1:
		goto _state_1;
		case 2:
		goto _state_2;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	_data_->_tmp0_ = xmpp_xep_service_discovery_module_IDENTITY;
	_data_->_tmp1_ = xmpp_xmpp_stream_get_module (_data_->stream, XMPP_XEP_SERVICE_DISCOVERY_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp0_);
	_data_->_tmp2_ = (XmppXepServiceDiscoveryModule*) _data_->_tmp1_;
	_data_->_state_ = 1;
	xmpp_xep_service_discovery_module_has_entity_feature (_data_->_tmp2_, _data_->stream, _data_->full_jid, DINO_PLUGINS_JET_OMEMO_NS_URI, dino_plugins_jet_omemo_module_is_available_ready, _data_);
	return FALSE;
	_state_1:
	_data_->_tmp3_ = xmpp_xep_service_discovery_module_has_entity_feature_finish (_data_->_tmp2_, _data_->_res_);
	_data_->_tmp4_ = __bool_dup0 (&_data_->_tmp3_);
	_data_->_tmp5_ = _data_->_tmp4_;
	_g_object_unref0 (_data_->_tmp2_);
	_data_->has_feature = _data_->_tmp5_;
	_data_->_tmp7_ = _data_->has_feature;
	if (_data_->_tmp7_ == NULL) {
		_data_->_tmp6_ = TRUE;
	} else {
		_data_->_tmp8_ = _data_->has_feature;
		_data_->_tmp6_ = !((gboolean) (*_data_->_tmp8_));
	}
	if (_data_->_tmp6_) {
		_data_->result = FALSE;
		_g_free0 (_data_->has_feature);
		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;
	}
	_data_->_tmp9_ = xmpp_xep_jet_module_IDENTITY;
	_data_->_tmp10_ = xmpp_xmpp_stream_get_module (_data_->stream, XMPP_XEP_JET_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _data_->_tmp9_);
	_data_->_tmp11_ = (XmppXepJetModule*) _data_->_tmp10_;
	_data_->_state_ = 2;
	xmpp_xep_jet_module_is_available (_data_->_tmp11_, _data_->stream, _data_->full_jid, dino_plugins_jet_omemo_module_is_available_ready, _data_);
	return FALSE;
	_state_2:
	_data_->_tmp12_ = xmpp_xep_jet_module_is_available_finish (_data_->_tmp11_, _data_->_res_);
	_g_object_unref0 (_data_->_tmp11_);
	_data_->result = _data_->_tmp12_;
	_g_free0 (_data_->has_feature);
	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 gchar*
dino_plugins_jet_omemo_module_real_get_type_uri (XmppXepJetEnvelopEncoding* base)
{
	DinoPluginsJetOmemoModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (DinoPluginsJetOmemoModule*) base;
	_tmp0_ = g_strdup (DINO_PLUGINS_OMEMO_NS_URI);
	result = _tmp0_;
	return result;
}

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

static XmppXepJetTransportSecret*
dino_plugins_jet_omemo_module_real_decode_envolop (XmppXepJetEnvelopEncoding* base,
                                                   XmppXmppStream* stream,
                                                   XmppJid* local_full_jid,
                                                   XmppJid* peer_full_jid,
                                                   XmppStanzaNode* security,
                                                   GError** error)
{
	DinoPluginsJetOmemoModule * self;
	XmppStanzaNode* encrypted = NULL;
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppXepOmemoOmemoDecryptor* decryptor = NULL;
	XmppModuleIdentity* _tmp3_;
	gpointer _tmp4_;
	XmppXepOmemoParsedData* data = NULL;
	XmppXepOmemoOmemoDecryptor* _tmp5_;
	XmppStanzaNode* _tmp6_;
	XmppXepOmemoParsedData* _tmp7_;
	XmppXepOmemoParsedData* _tmp8_;
	GError* _tmp50_;
	GError* _inner_error0_ = NULL;
	XmppXepJetTransportSecret* result;
	self = (DinoPluginsJetOmemoModule*) base;
	g_return_val_if_fail (stream != NULL, NULL);
	g_return_val_if_fail (local_full_jid != NULL, NULL);
	g_return_val_if_fail (peer_full_jid != NULL, NULL);
	g_return_val_if_fail (security != NULL, NULL);
	_tmp0_ = xmpp_stanza_node_get_subnode (security, "encrypted", DINO_PLUGINS_OMEMO_NS_URI, FALSE);
	encrypted = _tmp0_;
	_tmp1_ = encrypted;
	if (_tmp1_ == NULL) {
		GError* _tmp2_;
		_tmp2_ = g_error_new_literal (XMPP_XEP_JINGLE_IQ_ERROR, XMPP_XEP_JINGLE_IQ_ERROR_BAD_REQUEST, "Invalid JET-OMEMO envelop: missing encrypted element");
		_inner_error0_ = _tmp2_;
		if (_inner_error0_->domain == XMPP_XEP_JINGLE_IQ_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_xmpp_stanza_entry_unref0 (encrypted);
			return NULL;
		} else {
			_xmpp_stanza_entry_unref0 (encrypted);
			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;
		}
	}
	_tmp3_ = xmpp_xep_omemo_omemo_decryptor_IDENTITY;
	_tmp4_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_OMEMO_TYPE_OMEMO_DECRYPTOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp3_);
	decryptor = (XmppXepOmemoOmemoDecryptor*) _tmp4_;
	_tmp5_ = decryptor;
	_tmp6_ = encrypted;
	_tmp7_ = xmpp_xep_omemo_omemo_decryptor_parse_node (_tmp5_, _tmp6_);
	data = _tmp7_;
	_tmp8_ = data;
	if (_tmp8_ == NULL) {
		GError* _tmp9_;
		_tmp9_ = g_error_new_literal (XMPP_XEP_JINGLE_IQ_ERROR, XMPP_XEP_JINGLE_IQ_ERROR_BAD_REQUEST, "Invalid JET-OMEMO envelop: bad encrypted element");
		_inner_error0_ = _tmp9_;
		if (_inner_error0_->domain == XMPP_XEP_JINGLE_IQ_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_xmpp_xep_omemo_parsed_data_unref0 (data);
			_g_object_unref0 (decryptor);
			_xmpp_stanza_entry_unref0 (encrypted);
			return NULL;
		} else {
			_xmpp_xep_omemo_parsed_data_unref0 (data);
			_g_object_unref0 (decryptor);
			_xmpp_stanza_entry_unref0 (encrypted);
			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;
		}
	}
	{
		GeeIterator* _encr_key_it = NULL;
		XmppXepOmemoParsedData* _tmp10_;
		GeeHashMap* _tmp11_;
		GeeSet* _tmp12_;
		GeeSet* _tmp13_;
		GeeSet* _tmp14_;
		GeeIterator* _tmp15_;
		GeeIterator* _tmp16_;
		_tmp10_ = data;
		_tmp11_ = _tmp10_->our_potential_encrypted_keys;
		_tmp12_ = gee_abstract_map_get_keys ((GeeAbstractMap*) _tmp11_);
		_tmp13_ = _tmp12_;
		_tmp14_ = _tmp13_;
		_tmp15_ = gee_iterable_iterator ((GeeIterable*) _tmp14_);
		_tmp16_ = _tmp15_;
		_g_object_unref0 (_tmp14_);
		_encr_key_it = _tmp16_;
		while (TRUE) {
			GeeIterator* _tmp17_;
			GBytes* encr_key = NULL;
			GeeIterator* _tmp18_;
			gpointer _tmp19_;
			XmppXepOmemoParsedData* _tmp20_;
			XmppXepOmemoParsedData* _tmp21_;
			GeeHashMap* _tmp22_;
			GBytes* _tmp23_;
			gpointer _tmp24_;
			XmppXepOmemoParsedData* _tmp25_;
			GBytes* _tmp26_;
			gsize _tmp27_ = 0;
			guint8* _tmp28_;
			guchar* _tmp29_;
			gint _tmp29__length1;
			_tmp17_ = _encr_key_it;
			if (!gee_iterator_next (_tmp17_)) {
				break;
			}
			_tmp18_ = _encr_key_it;
			_tmp19_ = gee_iterator_get (_tmp18_);
			encr_key = (GBytes*) _tmp19_;
			_tmp20_ = data;
			_tmp21_ = data;
			_tmp22_ = _tmp21_->our_potential_encrypted_keys;
			_tmp23_ = encr_key;
			_tmp24_ = gee_abstract_map_get ((GeeAbstractMap*) _tmp22_, _tmp23_);
			_tmp20_->is_prekey = (gboolean) ((gintptr) _tmp24_);
			_tmp25_ = data;
			_tmp26_ = encr_key;
			_tmp28_ = g_bytes_get_data (_tmp26_, &_tmp27_);
			_tmp29_ = (_tmp28_ != NULL) ? _vala_array_dup6 (_tmp28_, _tmp27_) : _tmp28_;
			_tmp29__length1 = _tmp27_;
			_tmp25_->encrypted_key = (g_free (_tmp25_->encrypted_key), NULL);
			_tmp25_->encrypted_key = _tmp29_;
			_tmp25_->encrypted_key_length1 = _tmp29__length1;
			{
				guint8* key = NULL;
				XmppXepOmemoOmemoDecryptor* _tmp30_;
				XmppXepOmemoParsedData* _tmp31_;
				XmppJid* _tmp32_;
				XmppJid* _tmp33_;
				XmppJid* _tmp34_;
				gint _tmp35_ = 0;
				guint8* _tmp36_;
				guint8* _tmp37_;
				gint _tmp37__length1;
				gint key_length1;
				gint _key_size_;
				guint8* _tmp38_;
				gint _tmp38__length1;
				XmppXepOmemoParsedData* _tmp39_;
				guint8* _tmp40_;
				gint _tmp40__length1;
				XmppXepJetTransportSecret* _tmp41_;
				_tmp30_ = decryptor;
				_tmp31_ = data;
				_tmp32_ = xmpp_jid_get_bare_jid (peer_full_jid);
				_tmp33_ = _tmp32_;
				_tmp34_ = _tmp33_;
				_tmp36_ = xmpp_xep_omemo_omemo_decryptor_decrypt_key (_tmp30_, _tmp31_, _tmp34_, &_tmp35_, &_inner_error0_);
				_tmp37_ = _tmp36_;
				_tmp37__length1 = _tmp35_;
				_xmpp_jid_unref0 (_tmp34_);
				key = _tmp37_;
				key_length1 = _tmp37__length1;
				_key_size_ = key_length1;
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					goto __catch0_g_error;
				}
				_tmp38_ = key;
				_tmp38__length1 = key_length1;
				_tmp39_ = data;
				_tmp40_ = _tmp39_->iv;
				_tmp40__length1 = _tmp39_->iv_length1;
				_tmp41_ = xmpp_xep_jet_transport_secret_new (_tmp38_, _tmp38__length1, _tmp40_, _tmp40__length1);
				result = _tmp41_;
				key = (g_free (key), NULL);
				_g_bytes_unref0 (encr_key);
				_g_object_unref0 (_encr_key_it);
				_xmpp_xep_omemo_parsed_data_unref0 (data);
				_g_object_unref0 (decryptor);
				_xmpp_stanza_entry_unref0 (encrypted);
				return result;
			}
			goto __finally0;
			__catch0_g_error:
			{
				GError* e = NULL;
				XmppJid* _tmp42_;
				XmppJid* _tmp43_;
				XmppJid* _tmp44_;
				gchar* _tmp45_;
				gchar* _tmp46_;
				XmppXepOmemoParsedData* _tmp47_;
				GError* _tmp48_;
				const gchar* _tmp49_;
				e = _inner_error0_;
				_inner_error0_ = NULL;
				_tmp42_ = xmpp_jid_get_bare_jid (peer_full_jid);
				_tmp43_ = _tmp42_;
				_tmp44_ = _tmp43_;
				_tmp45_ = xmpp_jid_to_string (_tmp44_);
				_tmp46_ = _tmp45_;
				_tmp47_ = data;
				_tmp48_ = e;
				_tmp49_ = _tmp48_->message;
				g_debug ("jet_omemo.vala:60: Decrypting JET key from %s/%d failed: %s", _tmp46_, _tmp47_->sid, _tmp49_);
				_g_free0 (_tmp46_);
				_xmpp_jid_unref0 (_tmp44_);
				_g_error_free0 (e);
			}
			__finally0:
			if (G_UNLIKELY (_inner_error0_ != NULL)) {
				if (_inner_error0_->domain == XMPP_XEP_JINGLE_IQ_ERROR) {
					g_propagate_error (error, _inner_error0_);
					_g_bytes_unref0 (encr_key);
					_g_object_unref0 (_encr_key_it);
					_xmpp_xep_omemo_parsed_data_unref0 (data);
					_g_object_unref0 (decryptor);
					_xmpp_stanza_entry_unref0 (encrypted);
					return NULL;
				} else {
					_g_bytes_unref0 (encr_key);
					_g_object_unref0 (_encr_key_it);
					_xmpp_xep_omemo_parsed_data_unref0 (data);
					_g_object_unref0 (decryptor);
					_xmpp_stanza_entry_unref0 (encrypted);
					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;
				}
			}
			_g_bytes_unref0 (encr_key);
		}
		_g_object_unref0 (_encr_key_it);
	}
	_tmp50_ = g_error_new_literal (XMPP_XEP_JINGLE_IQ_ERROR, XMPP_XEP_JINGLE_IQ_ERROR_NOT_ACCEPTABLE, "Not encrypted for targeted device");
	_inner_error0_ = _tmp50_;
	if (_inner_error0_->domain == XMPP_XEP_JINGLE_IQ_ERROR) {
		g_propagate_error (error, _inner_error0_);
		_xmpp_xep_omemo_parsed_data_unref0 (data);
		_g_object_unref0 (decryptor);
		_xmpp_stanza_entry_unref0 (encrypted);
		return NULL;
	} else {
		_xmpp_xep_omemo_parsed_data_unref0 (data);
		_g_object_unref0 (decryptor);
		_xmpp_stanza_entry_unref0 (encrypted);
		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;
	}
}

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

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

static void
dino_plugins_jet_omemo_module_real_encode_envelop (XmppXepJetEnvelopEncoding* base,
                                                   XmppXmppStream* stream,
                                                   XmppJid* local_full_jid,
                                                   XmppJid* peer_full_jid,
                                                   XmppXepJetSecurityParameters* security_params,
                                                   XmppStanzaNode* security)
{
	DinoPluginsJetOmemoModule * self;
	OmemoStore* store = NULL;
	XmppModuleIdentity* _tmp0_;
	gpointer _tmp1_;
	DinoPluginsOmemoStreamModule* _tmp2_;
	OmemoStore* _tmp3_;
	OmemoStore* _tmp4_;
	OmemoStore* _tmp5_;
	OmemoStore* _tmp6_;
	XmppXepOmemoEncryptionData* encryption_data = NULL;
	guint32 _tmp7_;
	guint32 _tmp8_;
	XmppXepOmemoEncryptionData* _tmp9_;
	XmppXepJetTransportSecret* _tmp10_;
	XmppXepJetTransportSecret* _tmp11_;
	guint8* _tmp12_;
	gint _tmp12__length1;
	gint _tmp13_ = 0;
	guint8* _tmp14_;
	gint _tmp14__length1;
	guint8* _tmp15_;
	gint _tmp15__length1;
	XmppXepJetTransportSecret* _tmp16_;
	XmppXepJetTransportSecret* _tmp17_;
	guint8* _tmp18_;
	gint _tmp18__length1;
	gint _tmp19_ = 0;
	guint8* _tmp20_;
	gint _tmp20__length1;
	guint8* _tmp21_;
	gint _tmp21__length1;
	XmppXepOmemoOmemoEncryptor* encryptor = NULL;
	XmppModuleIdentity* _tmp22_;
	gpointer _tmp23_;
	XmppJid* _tmp24_;
	XmppJid* _tmp25_;
	XmppJid* _tmp26_;
	XmppXepOmemoEncryptionResult* _tmp27_;
	XmppXepOmemoEncryptionResult* _tmp28_;
	XmppStanzaNode* _tmp29_;
	XmppStanzaNode* _tmp30_;
	XmppStanzaNode* _tmp31_;
	XmppStanzaNode* _tmp32_;
	GError* _inner_error0_ = NULL;
	self = (DinoPluginsJetOmemoModule*) base;
	g_return_if_fail (stream != NULL);
	g_return_if_fail (local_full_jid != NULL);
	g_return_if_fail (peer_full_jid != NULL);
	g_return_if_fail (security_params != NULL);
	g_return_if_fail (security != NULL);
	_tmp0_ = dino_plugins_omemo_stream_module_IDENTITY;
	_tmp1_ = xmpp_xmpp_stream_get_module (stream, DINO_PLUGINS_OMEMO_TYPE_STREAM_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp0_);
	_tmp2_ = (DinoPluginsOmemoStreamModule*) _tmp1_;
	_tmp3_ = dino_plugins_omemo_stream_module_get_store (_tmp2_);
	_tmp4_ = _tmp3_;
	_tmp5_ = _g_object_ref0 (_tmp4_);
	_tmp6_ = _tmp5_;
	_g_object_unref0 (_tmp2_);
	store = _tmp6_;
	_tmp7_ = omemo_store_get_local_registration_id (store);
	_tmp8_ = _tmp7_;
	_tmp9_ = xmpp_xep_omemo_encryption_data_new (_tmp8_);
	encryption_data = _tmp9_;
	_tmp10_ = xmpp_xep_jet_security_parameters_get_secret (security_params);
	_tmp11_ = _tmp10_;
	_tmp12_ = xmpp_xep_jet_transport_secret_get_initialization_vector (_tmp11_, &_tmp13_);
	_tmp12__length1 = _tmp13_;
	_tmp14_ = _tmp12_;
	_tmp14__length1 = _tmp12__length1;
	_tmp15_ = (_tmp14_ != NULL) ? _vala_array_dup7 (_tmp14_, _tmp14__length1) : _tmp14_;
	_tmp15__length1 = _tmp14__length1;
	encryption_data->iv = (g_free (encryption_data->iv), NULL);
	encryption_data->iv = _tmp15_;
	encryption_data->iv_length1 = _tmp15__length1;
	_tmp16_ = xmpp_xep_jet_security_parameters_get_secret (security_params);
	_tmp17_ = _tmp16_;
	_tmp18_ = xmpp_xep_jet_transport_secret_get_transport_key (_tmp17_, &_tmp19_);
	_tmp18__length1 = _tmp19_;
	_tmp20_ = _tmp18_;
	_tmp20__length1 = _tmp18__length1;
	_tmp21_ = (_tmp20_ != NULL) ? _vala_array_dup8 (_tmp20_, _tmp20__length1) : _tmp20_;
	_tmp21__length1 = _tmp20__length1;
	encryption_data->keytag = (g_free (encryption_data->keytag), NULL);
	encryption_data->keytag = _tmp21_;
	encryption_data->keytag_length1 = _tmp21__length1;
	_tmp22_ = xmpp_xep_omemo_omemo_encryptor_IDENTITY;
	_tmp23_ = xmpp_xmpp_stream_get_module (stream, XMPP_XEP_OMEMO_TYPE_OMEMO_ENCRYPTOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, _tmp22_);
	encryptor = (XmppXepOmemoOmemoEncryptor*) _tmp23_;
	_tmp24_ = xmpp_jid_get_bare_jid (peer_full_jid);
	_tmp25_ = _tmp24_;
	_tmp26_ = _tmp25_;
	_tmp27_ = xmpp_xep_omemo_omemo_encryptor_encrypt_key_to_recipient (encryptor, stream, encryption_data, _tmp26_, &_inner_error0_);
	_tmp28_ = _tmp27_;
	_xmpp_xep_omemo_encryption_result_unref0 (_tmp28_);
	_xmpp_jid_unref0 (_tmp26_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_g_object_unref0 (encryptor);
		_xmpp_xep_omemo_encryption_data_unref0 (encryption_data);
		_g_object_unref0 (store);
		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;
	}
	_tmp29_ = xmpp_xep_omemo_encryption_data_get_encrypted_node (encryption_data);
	_tmp30_ = _tmp29_;
	_tmp31_ = xmpp_stanza_node_put_node (security, _tmp30_);
	_tmp32_ = _tmp31_;
	_xmpp_stanza_entry_unref0 (_tmp32_);
	_xmpp_stanza_entry_unref0 (_tmp30_);
	_g_object_unref0 (encryptor);
	_xmpp_xep_omemo_encryption_data_unref0 (encryption_data);
	_g_object_unref0 (store);
}

static gchar*
dino_plugins_jet_omemo_module_real_get_ns (XmppXmppStreamModule* base)
{
	DinoPluginsJetOmemoModule * self;
	gchar* _tmp0_;
	gchar* result;
	self = (DinoPluginsJetOmemoModule*) base;
	_tmp0_ = g_strdup (DINO_PLUGINS_JET_OMEMO_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
dino_plugins_jet_omemo_module_real_get_id (XmppXmppStreamModule* base)
{
	DinoPluginsJetOmemoModule * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (DinoPluginsJetOmemoModule*) base;
	_tmp0_ = dino_plugins_jet_omemo_module_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

DinoPluginsJetOmemoModule*
dino_plugins_jet_omemo_module_construct (GType object_type)
{
	DinoPluginsJetOmemoModule * self = NULL;
	self = (DinoPluginsJetOmemoModule*) xmpp_xmpp_stream_module_construct (object_type);
	return self;
}

DinoPluginsJetOmemoModule*
dino_plugins_jet_omemo_module_new (void)
{
	return dino_plugins_jet_omemo_module_construct (DINO_PLUGINS_JET_OMEMO_TYPE_MODULE);
}

static void
dino_plugins_jet_omemo_module_class_init (DinoPluginsJetOmemoModuleClass * klass,
                                          gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	dino_plugins_jet_omemo_module_parent_class = g_type_class_peek_parent (klass);
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) dino_plugins_jet_omemo_module_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) dino_plugins_jet_omemo_module_real_detach;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) dino_plugins_jet_omemo_module_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) dino_plugins_jet_omemo_module_real_get_id;
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_jet_omemo_module_finalize;
	_tmp0_ = xmpp_module_identity_new (DINO_PLUGINS_JET_OMEMO_TYPE_MODULE, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, DINO_PLUGINS_JET_OMEMO_NS_URI, "0396_jet_omemo");
	dino_plugins_jet_omemo_module_IDENTITY = _tmp0_;
}

static void
dino_plugins_jet_omemo_module_xmpp_xep_jet_envelop_encoding_interface_init (XmppXepJetEnvelopEncodingIface * iface,
                                                                            gpointer iface_data)
{
	dino_plugins_jet_omemo_module_xmpp_xep_jet_envelop_encoding_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_type_uri = (gchar* (*) (XmppXepJetEnvelopEncoding*)) dino_plugins_jet_omemo_module_real_get_type_uri;
	iface->decode_envolop = (XmppXepJetTransportSecret* (*) (XmppXepJetEnvelopEncoding*, XmppXmppStream*, XmppJid*, XmppJid*, XmppStanzaNode*, GError**)) dino_plugins_jet_omemo_module_real_decode_envolop;
	iface->encode_envelop = (void (*) (XmppXepJetEnvelopEncoding*, XmppXmppStream*, XmppJid*, XmppJid*, XmppXepJetSecurityParameters*, XmppStanzaNode*)) dino_plugins_jet_omemo_module_real_encode_envelop;
}

static void
dino_plugins_jet_omemo_module_instance_init (DinoPluginsJetOmemoModule * self,
                                             gpointer klass)
{
}

static void
dino_plugins_jet_omemo_module_finalize (GObject * obj)
{
	DinoPluginsJetOmemoModule * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_JET_OMEMO_TYPE_MODULE, DinoPluginsJetOmemoModule);
	G_OBJECT_CLASS (dino_plugins_jet_omemo_module_parent_class)->finalize (obj);
}

static GType
dino_plugins_jet_omemo_module_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsJetOmemoModuleClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_jet_omemo_module_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsJetOmemoModule), 0, (GInstanceInitFunc) dino_plugins_jet_omemo_module_instance_init, NULL };
	static const GInterfaceInfo xmpp_xep_jet_envelop_encoding_info = { (GInterfaceInitFunc) dino_plugins_jet_omemo_module_xmpp_xep_jet_envelop_encoding_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_jet_omemo_module_type_id;
	dino_plugins_jet_omemo_module_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_MODULE, "DinoPluginsJetOmemoModule", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_jet_omemo_module_type_id, XMPP_XEP_JET_TYPE_ENVELOP_ENCODING, &xmpp_xep_jet_envelop_encoding_info);
	return dino_plugins_jet_omemo_module_type_id;
}

GType
dino_plugins_jet_omemo_module_get_type (void)
{
	static volatile gsize dino_plugins_jet_omemo_module_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_jet_omemo_module_type_id__once)) {
		GType dino_plugins_jet_omemo_module_type_id;
		dino_plugins_jet_omemo_module_type_id = dino_plugins_jet_omemo_module_get_type_once ();
		g_once_init_leave (&dino_plugins_jet_omemo_module_type_id__once, dino_plugins_jet_omemo_module_type_id);
	}
	return dino_plugins_jet_omemo_module_type_id__once;
}

static inline gpointer
dino_plugins_jet_omemo_aes_gcm_cipher_get_instance_private (DinoPluginsJetOmemoAesGcmCipher* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsJetOmemoAesGcmCipher_private_offset);
}

DinoPluginsJetOmemoAesGcmCipher*
dino_plugins_jet_omemo_aes_gcm_cipher_construct (GType object_type,
                                                 guint key_size,
                                                 guint default_iv_size,
                                                 const gchar* uri)
{
	DinoPluginsJetOmemoAesGcmCipher * self = NULL;
	gchar* _tmp0_;
	g_return_val_if_fail (uri != NULL, NULL);
	self = (DinoPluginsJetOmemoAesGcmCipher*) g_object_new (object_type, NULL);
	self->priv->key_size = key_size;
	self->priv->default_iv_size = default_iv_size;
	_tmp0_ = g_strdup (uri);
	_g_free0 (self->priv->uri);
	self->priv->uri = _tmp0_;
	return self;
}

DinoPluginsJetOmemoAesGcmCipher*
dino_plugins_jet_omemo_aes_gcm_cipher_new (guint key_size,
                                           guint default_iv_size,
                                           const gchar* uri)
{
	return dino_plugins_jet_omemo_aes_gcm_cipher_construct (DINO_PLUGINS_JET_OMEMO_TYPE_AES_GCM_CIPHER, key_size, default_iv_size, uri);
}

static gchar*
dino_plugins_jet_omemo_aes_gcm_cipher_real_get_cipher_uri (XmppXepJetCipher* base)
{
	DinoPluginsJetOmemoAesGcmCipher * self;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	gchar* result;
	self = (DinoPluginsJetOmemoAesGcmCipher*) base;
	_tmp0_ = self->priv->uri;
	_tmp1_ = g_strdup (_tmp0_);
	result = _tmp1_;
	return result;
}

static XmppXepJetTransportSecret*
dino_plugins_jet_omemo_aes_gcm_cipher_real_generate_random_secret (XmppXepJetCipher* base)
{
	DinoPluginsJetOmemoAesGcmCipher * self;
	guint8* iv = NULL;
	guint8* _tmp0_;
	gint iv_length1;
	gint _iv_size_;
	OmemoContext* _tmp1_;
	OmemoContext* _tmp2_;
	guint8* _tmp3_;
	gint _tmp3__length1;
	guint8* key = NULL;
	guint8* _tmp4_;
	gint key_length1;
	gint _key_size_;
	OmemoContext* _tmp5_;
	OmemoContext* _tmp6_;
	guint8* _tmp7_;
	gint _tmp7__length1;
	guint8* _tmp8_;
	gint _tmp8__length1;
	guint8* _tmp9_;
	gint _tmp9__length1;
	XmppXepJetTransportSecret* _tmp10_;
	GError* _inner_error0_ = NULL;
	XmppXepJetTransportSecret* result;
	self = (DinoPluginsJetOmemoAesGcmCipher*) base;
	_tmp0_ = g_new0 (guint8, self->priv->default_iv_size);
	iv = _tmp0_;
	iv_length1 = self->priv->default_iv_size;
	_iv_size_ = iv_length1;
	_tmp1_ = dino_plugins_omemo_plugin_get_context ();
	_tmp2_ = _tmp1_;
	_tmp3_ = iv;
	_tmp3__length1 = iv_length1;
	omemo_context_randomize (_tmp2_, _tmp3_, (gint) _tmp3__length1, &_inner_error0_);
	_omemo_context_unref0 (_tmp2_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		iv = (g_free (iv), NULL);
		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;
	}
	_tmp4_ = g_new0 (guint8, self->priv->key_size);
	key = _tmp4_;
	key_length1 = self->priv->key_size;
	_key_size_ = key_length1;
	_tmp5_ = dino_plugins_omemo_plugin_get_context ();
	_tmp6_ = _tmp5_;
	_tmp7_ = key;
	_tmp7__length1 = key_length1;
	omemo_context_randomize (_tmp6_, _tmp7_, (gint) _tmp7__length1, &_inner_error0_);
	_omemo_context_unref0 (_tmp6_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		key = (g_free (key), NULL);
		iv = (g_free (iv), NULL);
		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;
	}
	_tmp8_ = key;
	_tmp8__length1 = key_length1;
	_tmp9_ = iv;
	_tmp9__length1 = iv_length1;
	_tmp10_ = xmpp_xep_jet_transport_secret_new (_tmp8_, _tmp8__length1, _tmp9_, _tmp9__length1);
	result = _tmp10_;
	key = (g_free (key), NULL);
	iv = (g_free (iv), NULL);
	return result;
}

static GInputStream*
dino_plugins_jet_omemo_aes_gcm_cipher_real_wrap_input_stream (XmppXepJetCipher* base,
                                                              GInputStream* input,
                                                              XmppXepJetTransportSecret* secret)
{
	DinoPluginsJetOmemoAesGcmCipher * self;
	guint8* _tmp0_;
	gint _tmp0__length1;
	gint _tmp1_ = 0;
	guint8* _tmp2_;
	gint _tmp2__length1;
	CryptoSymmetricCipher* cipher = NULL;
	CryptoSymmetricCipher* _tmp3_;
	CryptoSymmetricCipher* _tmp4_;
	guint8* _tmp5_;
	gint _tmp5__length1;
	gint _tmp6_ = 0;
	guint8* _tmp7_;
	gint _tmp7__length1;
	CryptoSymmetricCipher* _tmp8_;
	guint8* _tmp9_;
	gint _tmp9__length1;
	gint _tmp10_ = 0;
	guint8* _tmp11_;
	gint _tmp11__length1;
	CryptoSymmetricCipher* _tmp12_;
	CryptoSymmetricCipherDecrypter* _tmp13_;
	CryptoSymmetricCipherDecrypter* _tmp14_;
	GConverterInputStream* _tmp15_;
	GInputStream* _tmp16_;
	GError* _inner_error0_ = NULL;
	GInputStream* result;
	self = (DinoPluginsJetOmemoAesGcmCipher*) base;
	g_return_val_if_fail (input != NULL, NULL);
	g_return_val_if_fail (secret != NULL, NULL);
	_tmp0_ = xmpp_xep_jet_transport_secret_get_transport_key (secret, &_tmp1_);
	_tmp0__length1 = _tmp1_;
	_tmp2_ = _tmp0_;
	_tmp2__length1 = _tmp0__length1;
	_vala_return_val_if_fail (((guint) _tmp2__length1) == self->priv->key_size, "secret.transport_key.length == key_size", NULL);
	_tmp3_ = crypto_symmetric_cipher_new ("AES-GCM", &_inner_error0_);
	cipher = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
	_tmp4_ = cipher;
	_tmp5_ = xmpp_xep_jet_transport_secret_get_transport_key (secret, &_tmp6_);
	_tmp5__length1 = _tmp6_;
	_tmp7_ = _tmp5_;
	_tmp7__length1 = _tmp5__length1;
	crypto_symmetric_cipher_set_key (_tmp4_, _tmp7_, (gint) _tmp7__length1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_crypto_symmetric_cipher_unref0 (cipher);
		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;
	}
	_tmp8_ = cipher;
	_tmp9_ = xmpp_xep_jet_transport_secret_get_initialization_vector (secret, &_tmp10_);
	_tmp9__length1 = _tmp10_;
	_tmp11_ = _tmp9_;
	_tmp11__length1 = _tmp9__length1;
	crypto_symmetric_cipher_set_iv (_tmp8_, _tmp11_, (gint) _tmp11__length1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_crypto_symmetric_cipher_unref0 (cipher);
		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;
	}
	_tmp12_ = cipher;
	cipher = NULL;
	_tmp13_ = crypto_symmetric_cipher_decrypter_new (_tmp12_, (gsize) 16);
	_tmp14_ = _tmp13_;
	_tmp15_ = (GConverterInputStream*) g_converter_input_stream_new (input, (GConverter*) _tmp14_);
	_tmp16_ = (GInputStream*) _tmp15_;
	_g_object_unref0 (_tmp14_);
	result = _tmp16_;
	_crypto_symmetric_cipher_unref0 (cipher);
	return result;
}

static GOutputStream*
dino_plugins_jet_omemo_aes_gcm_cipher_real_wrap_output_stream (XmppXepJetCipher* base,
                                                               GOutputStream* output,
                                                               XmppXepJetTransportSecret* secret)
{
	DinoPluginsJetOmemoAesGcmCipher * self;
	guint8* _tmp0_;
	gint _tmp0__length1;
	gint _tmp1_ = 0;
	guint8* _tmp2_;
	gint _tmp2__length1;
	CryptoSymmetricCipher* cipher = NULL;
	CryptoSymmetricCipher* _tmp3_;
	CryptoSymmetricCipher* _tmp4_;
	guint8* _tmp5_;
	gint _tmp5__length1;
	gint _tmp6_ = 0;
	guint8* _tmp7_;
	gint _tmp7__length1;
	CryptoSymmetricCipher* _tmp8_;
	guint8* _tmp9_;
	gint _tmp9__length1;
	gint _tmp10_ = 0;
	guint8* _tmp11_;
	gint _tmp11__length1;
	CryptoSymmetricCipher* _tmp12_;
	CryptoSymmetricCipherEncrypter* _tmp13_;
	CryptoSymmetricCipherEncrypter* _tmp14_;
	GConverterOutputStream* _tmp15_;
	GOutputStream* _tmp16_;
	GError* _inner_error0_ = NULL;
	GOutputStream* result;
	self = (DinoPluginsJetOmemoAesGcmCipher*) base;
	g_return_val_if_fail (output != NULL, NULL);
	g_return_val_if_fail (secret != NULL, NULL);
	_tmp0_ = xmpp_xep_jet_transport_secret_get_transport_key (secret, &_tmp1_);
	_tmp0__length1 = _tmp1_;
	_tmp2_ = _tmp0_;
	_tmp2__length1 = _tmp0__length1;
	_vala_return_val_if_fail (((guint) _tmp2__length1) == self->priv->key_size, "secret.transport_key.length == key_size", NULL);
	_tmp3_ = crypto_symmetric_cipher_new ("AES-GCM", &_inner_error0_);
	cipher = _tmp3_;
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		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;
	}
	_tmp4_ = cipher;
	_tmp5_ = xmpp_xep_jet_transport_secret_get_transport_key (secret, &_tmp6_);
	_tmp5__length1 = _tmp6_;
	_tmp7_ = _tmp5_;
	_tmp7__length1 = _tmp5__length1;
	crypto_symmetric_cipher_set_key (_tmp4_, _tmp7_, (gint) _tmp7__length1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_crypto_symmetric_cipher_unref0 (cipher);
		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;
	}
	_tmp8_ = cipher;
	_tmp9_ = xmpp_xep_jet_transport_secret_get_initialization_vector (secret, &_tmp10_);
	_tmp9__length1 = _tmp10_;
	_tmp11_ = _tmp9_;
	_tmp11__length1 = _tmp9__length1;
	crypto_symmetric_cipher_set_iv (_tmp8_, _tmp11_, (gint) _tmp11__length1, &_inner_error0_);
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		_crypto_symmetric_cipher_unref0 (cipher);
		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;
	}
	_tmp12_ = cipher;
	cipher = NULL;
	_tmp13_ = crypto_symmetric_cipher_encrypter_new (_tmp12_, (gsize) 16);
	_tmp14_ = _tmp13_;
	_tmp15_ = (GConverterOutputStream*) g_converter_output_stream_new (output, (GConverter*) _tmp14_);
	_tmp16_ = (GOutputStream*) _tmp15_;
	_g_object_unref0 (_tmp14_);
	result = _tmp16_;
	_crypto_symmetric_cipher_unref0 (cipher);
	return result;
}

static void
dino_plugins_jet_omemo_aes_gcm_cipher_class_init (DinoPluginsJetOmemoAesGcmCipherClass * klass,
                                                  gpointer klass_data)
{
	dino_plugins_jet_omemo_aes_gcm_cipher_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsJetOmemoAesGcmCipher_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_jet_omemo_aes_gcm_cipher_finalize;
}

static void
dino_plugins_jet_omemo_aes_gcm_cipher_xmpp_xep_jet_cipher_interface_init (XmppXepJetCipherIface * iface,
                                                                          gpointer iface_data)
{
	dino_plugins_jet_omemo_aes_gcm_cipher_xmpp_xep_jet_cipher_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_cipher_uri = (gchar* (*) (XmppXepJetCipher*)) dino_plugins_jet_omemo_aes_gcm_cipher_real_get_cipher_uri;
	iface->generate_random_secret = (XmppXepJetTransportSecret* (*) (XmppXepJetCipher*)) dino_plugins_jet_omemo_aes_gcm_cipher_real_generate_random_secret;
	iface->wrap_input_stream = (GInputStream* (*) (XmppXepJetCipher*, GInputStream*, XmppXepJetTransportSecret*)) dino_plugins_jet_omemo_aes_gcm_cipher_real_wrap_input_stream;
	iface->wrap_output_stream = (GOutputStream* (*) (XmppXepJetCipher*, GOutputStream*, XmppXepJetTransportSecret*)) dino_plugins_jet_omemo_aes_gcm_cipher_real_wrap_output_stream;
}

static void
dino_plugins_jet_omemo_aes_gcm_cipher_instance_init (DinoPluginsJetOmemoAesGcmCipher * self,
                                                     gpointer klass)
{
	self->priv = dino_plugins_jet_omemo_aes_gcm_cipher_get_instance_private (self);
}

static void
dino_plugins_jet_omemo_aes_gcm_cipher_finalize (GObject * obj)
{
	DinoPluginsJetOmemoAesGcmCipher * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_JET_OMEMO_TYPE_AES_GCM_CIPHER, DinoPluginsJetOmemoAesGcmCipher);
	_g_free0 (self->priv->uri);
	G_OBJECT_CLASS (dino_plugins_jet_omemo_aes_gcm_cipher_parent_class)->finalize (obj);
}

static GType
dino_plugins_jet_omemo_aes_gcm_cipher_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsJetOmemoAesGcmCipherClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_jet_omemo_aes_gcm_cipher_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsJetOmemoAesGcmCipher), 0, (GInstanceInitFunc) dino_plugins_jet_omemo_aes_gcm_cipher_instance_init, NULL };
	static const GInterfaceInfo xmpp_xep_jet_cipher_info = { (GInterfaceInitFunc) dino_plugins_jet_omemo_aes_gcm_cipher_xmpp_xep_jet_cipher_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_jet_omemo_aes_gcm_cipher_type_id;
	dino_plugins_jet_omemo_aes_gcm_cipher_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsJetOmemoAesGcmCipher", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_jet_omemo_aes_gcm_cipher_type_id, XMPP_XEP_JET_TYPE_CIPHER, &xmpp_xep_jet_cipher_info);
	DinoPluginsJetOmemoAesGcmCipher_private_offset = g_type_add_instance_private (dino_plugins_jet_omemo_aes_gcm_cipher_type_id, sizeof (DinoPluginsJetOmemoAesGcmCipherPrivate));
	return dino_plugins_jet_omemo_aes_gcm_cipher_type_id;
}

GType
dino_plugins_jet_omemo_aes_gcm_cipher_get_type (void)
{
	static volatile gsize dino_plugins_jet_omemo_aes_gcm_cipher_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_jet_omemo_aes_gcm_cipher_type_id__once)) {
		GType dino_plugins_jet_omemo_aes_gcm_cipher_type_id;
		dino_plugins_jet_omemo_aes_gcm_cipher_type_id = dino_plugins_jet_omemo_aes_gcm_cipher_get_type_once ();
		g_once_init_leave (&dino_plugins_jet_omemo_aes_gcm_cipher_type_id__once, dino_plugins_jet_omemo_aes_gcm_cipher_type_id);
	}
	return dino_plugins_jet_omemo_aes_gcm_cipher_type_id__once;
}

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;
}

