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

#include "xmpp-vala.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <glib-object.h>
#include <gee.h>
#include <gobject/gvaluecollector.h>

#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  {
	XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_0_PROPERTY,
	XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_OWN_DEVICE_ID_PROPERTY,
	XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_omemo_omemo_decryptor_properties[XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_NUM_PROPERTIES];
#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_free0(var) (var = (g_free (var), NULL))
#define _g_bytes_unref0(var) ((var == NULL) ? NULL : (var = (g_bytes_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
typedef struct _XmppXepOmemoParamSpecParsedData XmppXepOmemoParamSpecParsedData;

struct _XmppXepOmemoParamSpecParsedData {
	GParamSpec parent_instance;
};

static gpointer xmpp_xep_omemo_omemo_decryptor_parent_class = NULL;
XmppModuleIdentity* xmpp_xep_omemo_omemo_decryptor_IDENTITY = NULL;
static gpointer xmpp_xep_omemo_parsed_data_parent_class = NULL;

static gchar* xmpp_xep_omemo_omemo_decryptor_real_decrypt (XmppXepOmemoOmemoDecryptor* self,
                                                    guint8* ciphertext,
                                                    gint ciphertext_length1,
                                                    guint8* key,
                                                    gint key_length1,
                                                    guint8* iv,
                                                    gint iv_length1,
                                                    GError** error);
static guint8* xmpp_xep_omemo_omemo_decryptor_real_decrypt_key (XmppXepOmemoOmemoDecryptor* self,
                                                         XmppXepOmemoParsedData* data,
                                                         XmppJid* from_jid,
                                                         gint* result_length1,
                                                         GError** error);
static guint8* _vala_array_dup12 (guint8* self,
                           gssize length);
static void xmpp_xep_omemo_omemo_decryptor_real_attach (XmppXmppStreamModule* base,
                                                 XmppXmppStream* stream);
static void xmpp_xep_omemo_omemo_decryptor_real_detach (XmppXmppStreamModule* base,
                                                 XmppXmppStream* stream);
static gchar* xmpp_xep_omemo_omemo_decryptor_real_get_ns (XmppXmppStreamModule* base);
static gchar* xmpp_xep_omemo_omemo_decryptor_real_get_id (XmppXmppStreamModule* base);
static void xmpp_xep_omemo_omemo_decryptor_finalize (GObject * obj);
static GType xmpp_xep_omemo_omemo_decryptor_get_type_once (void);
static void _vala_xmpp_xep_omemo_omemo_decryptor_get_property (GObject * object,
                                                        guint property_id,
                                                        GValue * value,
                                                        GParamSpec * pspec);
static void xmpp_xep_omemo_parsed_data_finalize (XmppXepOmemoParsedData * obj);
static GType xmpp_xep_omemo_parsed_data_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static gchar*
xmpp_xep_omemo_omemo_decryptor_real_decrypt (XmppXepOmemoOmemoDecryptor* self,
                                             guint8* ciphertext,
                                             gint ciphertext_length1,
                                             guint8* key,
                                             gint key_length1,
                                             guint8* iv,
                                             gint iv_length1,
                                             GError** error)
{
	g_critical ("Type `%s' does not implement abstract method `xmpp_xep_omemo_omemo_decryptor_decrypt'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

gchar*
xmpp_xep_omemo_omemo_decryptor_decrypt (XmppXepOmemoOmemoDecryptor* self,
                                        guint8* ciphertext,
                                        gint ciphertext_length1,
                                        guint8* key,
                                        gint key_length1,
                                        guint8* iv,
                                        gint iv_length1,
                                        GError** error)
{
	XmppXepOmemoOmemoDecryptorClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_GET_CLASS (self);
	if (_klass_->decrypt) {
		return _klass_->decrypt (self, ciphertext, ciphertext_length1, key, key_length1, iv, iv_length1, error);
	}
	return NULL;
}

static guint8*
xmpp_xep_omemo_omemo_decryptor_real_decrypt_key (XmppXepOmemoOmemoDecryptor* self,
                                                 XmppXepOmemoParsedData* data,
                                                 XmppJid* from_jid,
                                                 gint* result_length1,
                                                 GError** error)
{
	g_critical ("Type `%s' does not implement abstract method `xmpp_xep_omemo_omemo_decryptor_decrypt_key'", g_type_name (G_TYPE_FROM_INSTANCE (self)));
	return NULL;
}

guint8*
xmpp_xep_omemo_omemo_decryptor_decrypt_key (XmppXepOmemoOmemoDecryptor* self,
                                            XmppXepOmemoParsedData* data,
                                            XmppJid* from_jid,
                                            gint* result_length1,
                                            GError** error)
{
	XmppXepOmemoOmemoDecryptorClass* _klass_;
	g_return_val_if_fail (self != NULL, NULL);
	_klass_ = XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_GET_CLASS (self);
	if (_klass_->decrypt_key) {
		return _klass_->decrypt_key (self, data, from_jid, result_length1, error);
	}
	return NULL;
}

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

XmppXepOmemoParsedData*
xmpp_xep_omemo_omemo_decryptor_parse_node (XmppXepOmemoOmemoDecryptor* self,
                                           XmppStanzaNode* encrypted_node)
{
	XmppXepOmemoParsedData* ret = NULL;
	XmppXepOmemoParsedData* _tmp0_;
	XmppStanzaNode* header_node = NULL;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppXepOmemoParsedData* _tmp3_;
	XmppStanzaNode* _tmp4_;
	XmppXepOmemoParsedData* _tmp5_;
	gchar* payload_str = NULL;
	const gchar* _tmp6_;
	gchar* _tmp7_;
	const gchar* _tmp8_;
	gchar* iv_str = NULL;
	XmppStanzaNode* _tmp13_;
	const gchar* _tmp14_;
	gchar* _tmp15_;
	const gchar* _tmp16_;
	XmppXepOmemoParsedData* _tmp17_;
	const gchar* _tmp18_;
	gsize _tmp19_ = 0;
	guchar* _tmp20_;
	XmppXepOmemoParsedData* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (encrypted_node != NULL, NULL);
	_tmp0_ = xmpp_xep_omemo_parsed_data_new ();
	ret = _tmp0_;
	_tmp1_ = xmpp_stanza_node_get_subnode (encrypted_node, "header", NULL, FALSE);
	header_node = _tmp1_;
	_tmp2_ = header_node;
	if (_tmp2_ == NULL) {
		g_warning ("omemo_decryptor.vala:22: Can't parse OMEMO node: No header node");
		result = NULL;
		_xmpp_stanza_entry_unref0 (header_node);
		_xmpp_xep_omemo_parsed_data_unref0 (ret);
		return result;
	}
	_tmp3_ = ret;
	_tmp4_ = header_node;
	_tmp3_->sid = xmpp_stanza_node_get_attribute_int (_tmp4_, "sid", -1, NULL);
	_tmp5_ = ret;
	if (_tmp5_->sid == -1) {
		g_warning ("omemo_decryptor.vala:28: Can't parse OMEMO node: No sid");
		result = NULL;
		_xmpp_stanza_entry_unref0 (header_node);
		_xmpp_xep_omemo_parsed_data_unref0 (ret);
		return result;
	}
	_tmp6_ = xmpp_stanza_node_get_deep_string_content (encrypted_node, "payload", NULL);
	_tmp7_ = g_strdup (_tmp6_);
	payload_str = _tmp7_;
	_tmp8_ = payload_str;
	if (_tmp8_ != NULL) {
		XmppXepOmemoParsedData* _tmp9_;
		const gchar* _tmp10_;
		gsize _tmp11_ = 0;
		guchar* _tmp12_;
		_tmp9_ = ret;
		_tmp10_ = payload_str;
		_tmp12_ = g_base64_decode (_tmp10_, &_tmp11_);
		_tmp9_->ciphertext = (g_free (_tmp9_->ciphertext), NULL);
		_tmp9_->ciphertext = _tmp12_;
		_tmp9_->ciphertext_length1 = _tmp11_;
	}
	_tmp13_ = header_node;
	_tmp14_ = xmpp_stanza_node_get_deep_string_content (_tmp13_, "iv", NULL);
	_tmp15_ = g_strdup (_tmp14_);
	iv_str = _tmp15_;
	_tmp16_ = iv_str;
	if (_tmp16_ == NULL) {
		g_warning ("omemo_decryptor.vala:37: Can't parse OMEMO node: No iv");
		result = NULL;
		_g_free0 (iv_str);
		_g_free0 (payload_str);
		_xmpp_stanza_entry_unref0 (header_node);
		_xmpp_xep_omemo_parsed_data_unref0 (ret);
		return result;
	}
	_tmp17_ = ret;
	_tmp18_ = iv_str;
	_tmp20_ = g_base64_decode (_tmp18_, &_tmp19_);
	_tmp17_->iv = (g_free (_tmp17_->iv), NULL);
	_tmp17_->iv = _tmp20_;
	_tmp17_->iv_length1 = _tmp19_;
	{
		GeeList* _key_node_list = NULL;
		XmppStanzaNode* _tmp21_;
		GeeList* _tmp22_;
		gint _key_node_size = 0;
		GeeList* _tmp23_;
		gint _tmp24_;
		gint _tmp25_;
		gint _key_node_index = 0;
		_tmp21_ = header_node;
		_tmp22_ = xmpp_stanza_node_get_subnodes (_tmp21_, "key", NULL, FALSE);
		_key_node_list = _tmp22_;
		_tmp23_ = _key_node_list;
		_tmp24_ = gee_collection_get_size ((GeeCollection*) _tmp23_);
		_tmp25_ = _tmp24_;
		_key_node_size = _tmp25_;
		_key_node_index = -1;
		while (TRUE) {
			gint _tmp26_;
			gint _tmp27_;
			XmppStanzaNode* key_node = NULL;
			GeeList* _tmp28_;
			gpointer _tmp29_;
			XmppStanzaNode* _tmp30_;
			guint32 _tmp31_;
			guint32 _tmp32_;
			XmppStanzaNode* _tmp33_;
			guint32 _tmp34_;
			guint32 _tmp35_;
			_key_node_index = _key_node_index + 1;
			_tmp26_ = _key_node_index;
			_tmp27_ = _key_node_size;
			if (!(_tmp26_ < _tmp27_)) {
				break;
			}
			_tmp28_ = _key_node_list;
			_tmp29_ = gee_list_get (_tmp28_, _key_node_index);
			key_node = (XmppStanzaNode*) _tmp29_;
			_tmp30_ = key_node;
			_tmp31_ = xmpp_xep_omemo_omemo_decryptor_get_own_device_id (self);
			_tmp32_ = _tmp31_;
			g_debug ("omemo_decryptor.vala:43: Is ours? %d =? %u", xmpp_stanza_node_get_attribute_int (_tmp30_, "rid", -1, NULL), (guint) _tmp32_);
			_tmp33_ = key_node;
			_tmp34_ = xmpp_xep_omemo_omemo_decryptor_get_own_device_id (self);
			_tmp35_ = _tmp34_;
			if (((guint32) xmpp_stanza_node_get_attribute_int (_tmp33_, "rid", -1, NULL)) == _tmp35_) {
				gchar* key_node_content = NULL;
				XmppStanzaNode* _tmp36_;
				const gchar* _tmp37_;
				gchar* _tmp38_;
				const gchar* _tmp39_;
				guchar* encrypted_key = NULL;
				const gchar* _tmp40_;
				gsize _tmp41_ = 0;
				guchar* _tmp42_;
				gint encrypted_key_length1;
				gint _encrypted_key_size_;
				XmppXepOmemoParsedData* _tmp43_;
				GeeHashMap* _tmp44_;
				guchar* _tmp45_;
				gint _tmp45__length1;
				guint8* _tmp46_;
				gint _tmp46__length1;
				GBytes* _tmp47_;
				GBytes* _tmp48_;
				XmppStanzaNode* _tmp49_;
				_tmp36_ = key_node;
				_tmp37_ = xmpp_stanza_entry_get_string_content ((XmppStanzaEntry*) _tmp36_);
				_tmp38_ = g_strdup (_tmp37_);
				key_node_content = _tmp38_;
				_tmp39_ = key_node_content;
				if (_tmp39_ == NULL) {
					_g_free0 (key_node_content);
					_xmpp_stanza_entry_unref0 (key_node);
					continue;
				}
				_tmp40_ = key_node_content;
				_tmp42_ = g_base64_decode (_tmp40_, &_tmp41_);
				encrypted_key = _tmp42_;
				encrypted_key_length1 = _tmp41_;
				_encrypted_key_size_ = encrypted_key_length1;
				_tmp43_ = ret;
				_tmp44_ = _tmp43_->our_potential_encrypted_keys;
				_tmp45_ = encrypted_key;
				_tmp45__length1 = encrypted_key_length1;
				_tmp46_ = (_tmp45_ != NULL) ? _vala_array_dup12 (_tmp45_, _tmp45__length1) : _tmp45_;
				_tmp46__length1 = _tmp45__length1;
				_tmp47_ = g_bytes_new_take (_tmp46_, _tmp46__length1);
				_tmp48_ = _tmp47_;
				_tmp49_ = key_node;
				gee_abstract_map_set ((GeeAbstractMap*) _tmp44_, _tmp48_, (gpointer) ((gintptr) xmpp_stanza_node_get_attribute_bool (_tmp49_, "prekey", FALSE, NULL)));
				_g_bytes_unref0 (_tmp48_);
				encrypted_key = (g_free (encrypted_key), NULL);
				_g_free0 (key_node_content);
			}
			_xmpp_stanza_entry_unref0 (key_node);
		}
		_g_object_unref0 (_key_node_list);
	}
	result = ret;
	_g_free0 (iv_str);
	_g_free0 (payload_str);
	_xmpp_stanza_entry_unref0 (header_node);
	return result;
}

static void
xmpp_xep_omemo_omemo_decryptor_real_attach (XmppXmppStreamModule* base,
                                            XmppXmppStream* stream)
{
	XmppXepOmemoOmemoDecryptor * self;
	self = (XmppXepOmemoOmemoDecryptor*) base;
	g_return_if_fail (stream != NULL);
}

static void
xmpp_xep_omemo_omemo_decryptor_real_detach (XmppXmppStreamModule* base,
                                            XmppXmppStream* stream)
{
	XmppXepOmemoOmemoDecryptor * self;
	self = (XmppXepOmemoOmemoDecryptor*) base;
	g_return_if_fail (stream != NULL);
}

static gchar*
xmpp_xep_omemo_omemo_decryptor_real_get_ns (XmppXmppStreamModule* base)
{
	XmppXepOmemoOmemoDecryptor * self;
	gchar* _tmp0_;
	gchar* result;
	self = (XmppXepOmemoOmemoDecryptor*) base;
	_tmp0_ = g_strdup (XMPP_XEP_OMEMO_NS_URI);
	result = _tmp0_;
	return result;
}

static gchar*
xmpp_xep_omemo_omemo_decryptor_real_get_id (XmppXmppStreamModule* base)
{
	XmppXepOmemoOmemoDecryptor * self;
	XmppModuleIdentity* _tmp0_;
	const gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* result;
	self = (XmppXepOmemoOmemoDecryptor*) base;
	_tmp0_ = xmpp_xep_omemo_omemo_decryptor_IDENTITY;
	_tmp1_ = xmpp_module_identity_get_id (_tmp0_);
	_tmp2_ = _tmp1_;
	_tmp3_ = g_strdup (_tmp2_);
	result = _tmp3_;
	return result;
}

XmppXepOmemoOmemoDecryptor*
xmpp_xep_omemo_omemo_decryptor_construct (GType object_type)
{
	XmppXepOmemoOmemoDecryptor * self = NULL;
	self = (XmppXepOmemoOmemoDecryptor*) xmpp_xmpp_stream_module_construct (object_type);
	return self;
}

guint32
xmpp_xep_omemo_omemo_decryptor_get_own_device_id (XmppXepOmemoOmemoDecryptor* self)
{
	XmppXepOmemoOmemoDecryptorClass* _klass_;
	g_return_val_if_fail (self != NULL, 0U);
	_klass_ = XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_GET_CLASS (self);
	if (_klass_->get_own_device_id) {
		return _klass_->get_own_device_id (self);
	}
	return 0U;
}

static void
xmpp_xep_omemo_omemo_decryptor_class_init (XmppXepOmemoOmemoDecryptorClass * klass,
                                           gpointer klass_data)
{
	XmppModuleIdentity* _tmp0_;
	xmpp_xep_omemo_omemo_decryptor_parent_class = g_type_class_peek_parent (klass);
	((XmppXepOmemoOmemoDecryptorClass *) klass)->decrypt = (gchar* (*) (XmppXepOmemoOmemoDecryptor*, guint8*, gint, guint8*, gint, guint8*, gint, GError**)) xmpp_xep_omemo_omemo_decryptor_real_decrypt;
	((XmppXepOmemoOmemoDecryptorClass *) klass)->decrypt_key = (guint8* (*) (XmppXepOmemoOmemoDecryptor*, XmppXepOmemoParsedData*, XmppJid*, gint*, GError**)) xmpp_xep_omemo_omemo_decryptor_real_decrypt_key;
	((XmppXmppStreamModuleClass *) klass)->attach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_omemo_omemo_decryptor_real_attach;
	((XmppXmppStreamModuleClass *) klass)->detach = (void (*) (XmppXmppStreamModule*, XmppXmppStream*)) xmpp_xep_omemo_omemo_decryptor_real_detach;
	((XmppXmppStreamModuleClass *) klass)->get_ns = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_omemo_omemo_decryptor_real_get_ns;
	((XmppXmppStreamModuleClass *) klass)->get_id = (gchar* (*) (XmppXmppStreamModule*)) xmpp_xep_omemo_omemo_decryptor_real_get_id;
	G_OBJECT_CLASS (klass)->get_property = _vala_xmpp_xep_omemo_omemo_decryptor_get_property;
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_omemo_omemo_decryptor_finalize;
	g_object_class_install_property (G_OBJECT_CLASS (klass), XMPP_XEP_OMEMO_OMEMO_DECRYPTOR_OWN_DEVICE_ID_PROPERTY, xmpp_xep_omemo_omemo_decryptor_properties[XMPP_XEP_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));
	_tmp0_ = xmpp_module_identity_new (XMPP_XEP_OMEMO_TYPE_OMEMO_DECRYPTOR, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, XMPP_XEP_OMEMO_NS_URI, "0384_omemo_decryptor");
	xmpp_xep_omemo_omemo_decryptor_IDENTITY = _tmp0_;
}

static void
xmpp_xep_omemo_omemo_decryptor_instance_init (XmppXepOmemoOmemoDecryptor * self,
                                              gpointer klass)
{
}

static void
xmpp_xep_omemo_omemo_decryptor_finalize (GObject * obj)
{
	XmppXepOmemoOmemoDecryptor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_OMEMO_TYPE_OMEMO_DECRYPTOR, XmppXepOmemoOmemoDecryptor);
	G_OBJECT_CLASS (xmpp_xep_omemo_omemo_decryptor_parent_class)->finalize (obj);
}

static GType
xmpp_xep_omemo_omemo_decryptor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepOmemoOmemoDecryptorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_omemo_omemo_decryptor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepOmemoOmemoDecryptor), 0, (GInstanceInitFunc) xmpp_xep_omemo_omemo_decryptor_instance_init, NULL };
	GType xmpp_xep_omemo_omemo_decryptor_type_id;
	xmpp_xep_omemo_omemo_decryptor_type_id = g_type_register_static (XMPP_TYPE_XMPP_STREAM_MODULE, "XmppXepOmemoOmemoDecryptor", &g_define_type_info, G_TYPE_FLAG_ABSTRACT);
	return xmpp_xep_omemo_omemo_decryptor_type_id;
}

GType
xmpp_xep_omemo_omemo_decryptor_get_type (void)
{
	static volatile gsize xmpp_xep_omemo_omemo_decryptor_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_omemo_omemo_decryptor_type_id__once)) {
		GType xmpp_xep_omemo_omemo_decryptor_type_id;
		xmpp_xep_omemo_omemo_decryptor_type_id = xmpp_xep_omemo_omemo_decryptor_get_type_once ();
		g_once_init_leave (&xmpp_xep_omemo_omemo_decryptor_type_id__once, xmpp_xep_omemo_omemo_decryptor_type_id);
	}
	return xmpp_xep_omemo_omemo_decryptor_type_id__once;
}

static void
_vala_xmpp_xep_omemo_omemo_decryptor_get_property (GObject * object,
                                                   guint property_id,
                                                   GValue * value,
                                                   GParamSpec * pspec)
{
	XmppXepOmemoOmemoDecryptor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (object, XMPP_XEP_OMEMO_TYPE_OMEMO_DECRYPTOR, XmppXepOmemoOmemoDecryptor);
	switch (property_id) {
		default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
		break;
	}
}

XmppXepOmemoParsedData*
xmpp_xep_omemo_parsed_data_construct (GType object_type)
{
	XmppXepOmemoParsedData* self = NULL;
	self = (XmppXepOmemoParsedData*) g_type_create_instance (object_type);
	return self;
}

XmppXepOmemoParsedData*
xmpp_xep_omemo_parsed_data_new (void)
{
	return xmpp_xep_omemo_parsed_data_construct (XMPP_XEP_OMEMO_TYPE_PARSED_DATA);
}

static void
xmpp_xep_omemo_value_parsed_data_init (GValue* value)
{
	value->data[0].v_pointer = NULL;
}

static void
xmpp_xep_omemo_value_parsed_data_free_value (GValue* value)
{
	if (value->data[0].v_pointer) {
		xmpp_xep_omemo_parsed_data_unref (value->data[0].v_pointer);
	}
}

static void
xmpp_xep_omemo_value_parsed_data_copy_value (const GValue* src_value,
                                             GValue* dest_value)
{
	if (src_value->data[0].v_pointer) {
		dest_value->data[0].v_pointer = xmpp_xep_omemo_parsed_data_ref (src_value->data[0].v_pointer);
	} else {
		dest_value->data[0].v_pointer = NULL;
	}
}

static gpointer
xmpp_xep_omemo_value_parsed_data_peek_pointer (const GValue* value)
{
	return value->data[0].v_pointer;
}

static gchar*
xmpp_xep_omemo_value_parsed_data_collect_value (GValue* value,
                                                guint n_collect_values,
                                                GTypeCValue* collect_values,
                                                guint collect_flags)
{
	if (collect_values[0].v_pointer) {
		XmppXepOmemoParsedData * object;
		object = collect_values[0].v_pointer;
		if (object->parent_instance.g_class == NULL) {
			return g_strconcat ("invalid unclassed object pointer for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		} else if (!g_value_type_compatible (G_TYPE_FROM_INSTANCE (object), G_VALUE_TYPE (value))) {
			return g_strconcat ("invalid object type `", g_type_name (G_TYPE_FROM_INSTANCE (object)), "' for value type `", G_VALUE_TYPE_NAME (value), "'", NULL);
		}
		value->data[0].v_pointer = xmpp_xep_omemo_parsed_data_ref (object);
	} else {
		value->data[0].v_pointer = NULL;
	}
	return NULL;
}

static gchar*
xmpp_xep_omemo_value_parsed_data_lcopy_value (const GValue* value,
                                              guint n_collect_values,
                                              GTypeCValue* collect_values,
                                              guint collect_flags)
{
	XmppXepOmemoParsedData ** object_p;
	object_p = collect_values[0].v_pointer;
	if (!object_p) {
		return g_strdup_printf ("value location for `%s' passed as NULL", G_VALUE_TYPE_NAME (value));
	}
	if (!value->data[0].v_pointer) {
		*object_p = NULL;
	} else if (collect_flags & G_VALUE_NOCOPY_CONTENTS) {
		*object_p = value->data[0].v_pointer;
	} else {
		*object_p = xmpp_xep_omemo_parsed_data_ref (value->data[0].v_pointer);
	}
	return NULL;
}

GParamSpec*
xmpp_xep_omemo_param_spec_parsed_data (const gchar* name,
                                       const gchar* nick,
                                       const gchar* blurb,
                                       GType object_type,
                                       GParamFlags flags)
{
	XmppXepOmemoParamSpecParsedData* spec;
	g_return_val_if_fail (g_type_is_a (object_type, XMPP_XEP_OMEMO_TYPE_PARSED_DATA), NULL);
	spec = g_param_spec_internal (G_TYPE_PARAM_OBJECT, name, nick, blurb, flags);
	G_PARAM_SPEC (spec)->value_type = object_type;
	return G_PARAM_SPEC (spec);
}

gpointer
xmpp_xep_omemo_value_get_parsed_data (const GValue* value)
{
	g_return_val_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_OMEMO_TYPE_PARSED_DATA), NULL);
	return value->data[0].v_pointer;
}

void
xmpp_xep_omemo_value_set_parsed_data (GValue* value,
                                      gpointer v_object)
{
	XmppXepOmemoParsedData * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_OMEMO_TYPE_PARSED_DATA));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_OMEMO_TYPE_PARSED_DATA));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
		xmpp_xep_omemo_parsed_data_ref (value->data[0].v_pointer);
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_omemo_parsed_data_unref (old);
	}
}

void
xmpp_xep_omemo_value_take_parsed_data (GValue* value,
                                       gpointer v_object)
{
	XmppXepOmemoParsedData * old;
	g_return_if_fail (G_TYPE_CHECK_VALUE_TYPE (value, XMPP_XEP_OMEMO_TYPE_PARSED_DATA));
	old = value->data[0].v_pointer;
	if (v_object) {
		g_return_if_fail (G_TYPE_CHECK_INSTANCE_TYPE (v_object, XMPP_XEP_OMEMO_TYPE_PARSED_DATA));
		g_return_if_fail (g_value_type_compatible (G_TYPE_FROM_INSTANCE (v_object), G_VALUE_TYPE (value)));
		value->data[0].v_pointer = v_object;
	} else {
		value->data[0].v_pointer = NULL;
	}
	if (old) {
		xmpp_xep_omemo_parsed_data_unref (old);
	}
}

static void
xmpp_xep_omemo_parsed_data_class_init (XmppXepOmemoParsedDataClass * klass,
                                       gpointer klass_data)
{
	xmpp_xep_omemo_parsed_data_parent_class = g_type_class_peek_parent (klass);
	((XmppXepOmemoParsedDataClass *) klass)->finalize = xmpp_xep_omemo_parsed_data_finalize;
}

static void
xmpp_xep_omemo_parsed_data_instance_init (XmppXepOmemoParsedData * self,
                                          gpointer klass)
{
	GeeHashMap* _tmp0_;
	_tmp0_ = gee_hash_map_new (G_TYPE_BYTES, (GBoxedCopyFunc) g_bytes_ref, (GDestroyNotify) g_bytes_unref, G_TYPE_BOOLEAN, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
	self->our_potential_encrypted_keys = _tmp0_;
	self->ref_count = 1;
}

static void
xmpp_xep_omemo_parsed_data_finalize (XmppXepOmemoParsedData * obj)
{
	XmppXepOmemoParsedData * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_OMEMO_TYPE_PARSED_DATA, XmppXepOmemoParsedData);
	g_signal_handlers_destroy (self);
	self->ciphertext = (g_free (self->ciphertext), NULL);
	self->iv = (g_free (self->iv), NULL);
	self->encrypted_key = (g_free (self->encrypted_key), NULL);
	_g_object_unref0 (self->our_potential_encrypted_keys);
}

static GType
xmpp_xep_omemo_parsed_data_get_type_once (void)
{
	static const GTypeValueTable g_define_type_value_table = { xmpp_xep_omemo_value_parsed_data_init, xmpp_xep_omemo_value_parsed_data_free_value, xmpp_xep_omemo_value_parsed_data_copy_value, xmpp_xep_omemo_value_parsed_data_peek_pointer, "p", xmpp_xep_omemo_value_parsed_data_collect_value, "p", xmpp_xep_omemo_value_parsed_data_lcopy_value };
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepOmemoParsedDataClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_omemo_parsed_data_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepOmemoParsedData), 0, (GInstanceInitFunc) xmpp_xep_omemo_parsed_data_instance_init, &g_define_type_value_table };
	static const GTypeFundamentalInfo g_define_type_fundamental_info = { (G_TYPE_FLAG_CLASSED | G_TYPE_FLAG_INSTANTIATABLE | G_TYPE_FLAG_DERIVABLE | G_TYPE_FLAG_DEEP_DERIVABLE) };
	GType xmpp_xep_omemo_parsed_data_type_id;
	xmpp_xep_omemo_parsed_data_type_id = g_type_register_fundamental (g_type_fundamental_next (), "XmppXepOmemoParsedData", &g_define_type_info, &g_define_type_fundamental_info, 0);
	return xmpp_xep_omemo_parsed_data_type_id;
}

GType
xmpp_xep_omemo_parsed_data_get_type (void)
{
	static volatile gsize xmpp_xep_omemo_parsed_data_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_omemo_parsed_data_type_id__once)) {
		GType xmpp_xep_omemo_parsed_data_type_id;
		xmpp_xep_omemo_parsed_data_type_id = xmpp_xep_omemo_parsed_data_get_type_once ();
		g_once_init_leave (&xmpp_xep_omemo_parsed_data_type_id__once, xmpp_xep_omemo_parsed_data_type_id);
	}
	return xmpp_xep_omemo_parsed_data_type_id__once;
}

gpointer
xmpp_xep_omemo_parsed_data_ref (gpointer instance)
{
	XmppXepOmemoParsedData * self;
	self = instance;
	g_atomic_int_inc (&self->ref_count);
	return instance;
}

void
xmpp_xep_omemo_parsed_data_unref (gpointer instance)
{
	XmppXepOmemoParsedData * self;
	self = instance;
	if (g_atomic_int_dec_and_test (&self->ref_count)) {
		XMPP_XEP_OMEMO_PARSED_DATA_GET_CLASS (self)->finalize (self);
		g_type_free_instance ((GTypeInstance *) self);
	}
}

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

