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

#include "omemo.h"
#include <glib.h>
#include <glib-object.h>
#include "libdino.h"
#include "crypto-vala.h"
#include <stdlib.h>
#include <string.h>
#include <gio/gio.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  {
	DINO_PLUGINS_OMEMO_OMEMO_FILE_ENCRYPTOR_0_PROPERTY,
	DINO_PLUGINS_OMEMO_OMEMO_FILE_ENCRYPTOR_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_omemo_file_encryptor_properties[DINO_PLUGINS_OMEMO_OMEMO_FILE_ENCRYPTOR_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 _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _dino_file_meta_unref0(var) ((var == NULL) ? NULL : (var = (dino_file_meta_unref (var), NULL)))
#define _dino_file_send_data_unref0(var) ((var == NULL) ? NULL : (var = (dino_file_send_data_unref (var), NULL)))

static gpointer dino_plugins_omemo_omemo_http_file_meta_parent_class = NULL;
static gpointer dino_plugins_omemo_omemo_file_encryptor_parent_class = NULL;
static DinoFileEncryptorIface * dino_plugins_omemo_omemo_file_encryptor_dino_file_encryptor_parent_iface = NULL;

static void dino_plugins_omemo_omemo_http_file_meta_finalize (DinoFileMeta * obj);
static GType dino_plugins_omemo_omemo_http_file_meta_get_type_once (void);
static gboolean dino_plugins_omemo_omemo_file_encryptor_real_can_encrypt_file (DinoFileEncryptor* base,
                                                                        DinoEntitiesConversation* conversation,
                                                                        DinoEntitiesFileTransfer* file_transfer);
static DinoFileMeta* dino_plugins_omemo_omemo_file_encryptor_real_encrypt_file (DinoFileEncryptor* base,
                                                                         DinoEntitiesConversation* conversation,
                                                                         DinoEntitiesFileTransfer* file_transfer,
                                                                         GError** error);
static guint8* _vala_array_dup4 (guint8* self,
                          gssize length);
static guint8* _vala_array_dup5 (guint8* self,
                          gssize length);
static DinoFileSendData* dino_plugins_omemo_omemo_file_encryptor_real_preprocess_send_file (DinoFileEncryptor* base,
                                                                                     DinoEntitiesConversation* conversation,
                                                                                     DinoEntitiesFileTransfer* file_transfer,
                                                                                     DinoFileSendData* file_send_data,
                                                                                     DinoFileMeta* file_meta,
                                                                                     GError** error);
static GType dino_plugins_omemo_omemo_file_encryptor_get_type_once (void);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

DinoPluginsOmemoOmemoHttpFileMeta*
dino_plugins_omemo_omemo_http_file_meta_construct (GType object_type)
{
	DinoPluginsOmemoOmemoHttpFileMeta* self = NULL;
	self = (DinoPluginsOmemoOmemoHttpFileMeta*) dino_http_file_meta_construct (object_type);
	return self;
}

DinoPluginsOmemoOmemoHttpFileMeta*
dino_plugins_omemo_omemo_http_file_meta_new (void)
{
	return dino_plugins_omemo_omemo_http_file_meta_construct (DINO_PLUGINS_OMEMO_TYPE_OMEMO_HTTP_FILE_META);
}

static void
dino_plugins_omemo_omemo_http_file_meta_class_init (DinoPluginsOmemoOmemoHttpFileMetaClass * klass,
                                                    gpointer klass_data)
{
	dino_plugins_omemo_omemo_http_file_meta_parent_class = g_type_class_peek_parent (klass);
	((DinoFileMetaClass *) klass)->finalize = dino_plugins_omemo_omemo_http_file_meta_finalize;
}

static void
dino_plugins_omemo_omemo_http_file_meta_instance_init (DinoPluginsOmemoOmemoHttpFileMeta * self,
                                                       gpointer klass)
{
}

static void
dino_plugins_omemo_omemo_http_file_meta_finalize (DinoFileMeta * obj)
{
	DinoPluginsOmemoOmemoHttpFileMeta * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_OMEMO_HTTP_FILE_META, DinoPluginsOmemoOmemoHttpFileMeta);
	self->iv = (g_free (self->iv), NULL);
	self->key = (g_free (self->key), NULL);
	DINO_FILE_META_CLASS (dino_plugins_omemo_omemo_http_file_meta_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_omemo_http_file_meta_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoOmemoHttpFileMetaClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_omemo_http_file_meta_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoOmemoHttpFileMeta), 0, (GInstanceInitFunc) dino_plugins_omemo_omemo_http_file_meta_instance_init, NULL };
	GType dino_plugins_omemo_omemo_http_file_meta_type_id;
	dino_plugins_omemo_omemo_http_file_meta_type_id = g_type_register_static (DINO_TYPE_HTTP_FILE_META, "DinoPluginsOmemoOmemoHttpFileMeta", &g_define_type_info, 0);
	return dino_plugins_omemo_omemo_http_file_meta_type_id;
}

GType
dino_plugins_omemo_omemo_http_file_meta_get_type (void)
{
	static volatile gsize dino_plugins_omemo_omemo_http_file_meta_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_omemo_http_file_meta_type_id__once)) {
		GType dino_plugins_omemo_omemo_http_file_meta_type_id;
		dino_plugins_omemo_omemo_http_file_meta_type_id = dino_plugins_omemo_omemo_http_file_meta_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_omemo_http_file_meta_type_id__once, dino_plugins_omemo_omemo_http_file_meta_type_id);
	}
	return dino_plugins_omemo_omemo_http_file_meta_type_id__once;
}

static gboolean
dino_plugins_omemo_omemo_file_encryptor_real_can_encrypt_file (DinoFileEncryptor* base,
                                                               DinoEntitiesConversation* conversation,
                                                               DinoEntitiesFileTransfer* file_transfer)
{
	DinoPluginsOmemoOmemoFileEncryptor * self;
	DinoEntitiesEncryption _tmp0_;
	DinoEntitiesEncryption _tmp1_;
	gboolean result;
	self = (DinoPluginsOmemoOmemoFileEncryptor*) base;
	g_return_val_if_fail (conversation != NULL, FALSE);
	g_return_val_if_fail (file_transfer != NULL, FALSE);
	_tmp0_ = dino_entities_file_transfer_get_encryption (file_transfer);
	_tmp1_ = _tmp0_;
	result = _tmp1_ == DINO_ENTITIES_ENCRYPTION_OMEMO;
	return result;
}

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

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

static DinoFileMeta*
dino_plugins_omemo_omemo_file_encryptor_real_encrypt_file (DinoFileEncryptor* base,
                                                           DinoEntitiesConversation* conversation,
                                                           DinoEntitiesFileTransfer* file_transfer,
                                                           GError** error)
{
	DinoPluginsOmemoOmemoFileEncryptor * self;
	static const guint KEY_SIZE = (guint) 32;
	static const guint IV_SIZE = (guint) 12;
	DinoPluginsOmemoOmemoHttpFileMeta* omemo_http_file_meta = NULL;
	DinoPluginsOmemoOmemoHttpFileMeta* _tmp0_;
	const gchar* _tmp44_;
	const gchar* _tmp45_;
	const gchar* _tmp46_;
	const gchar* _tmp47_;
	GError* _inner_error0_ = NULL;
	DinoFileMeta* result;
	self = (DinoPluginsOmemoOmemoFileEncryptor*) base;
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (file_transfer != NULL, NULL);
	_tmp0_ = dino_plugins_omemo_omemo_http_file_meta_new ();
	omemo_http_file_meta = _tmp0_;
	{
		guint8* iv = NULL;
		guint8* _tmp1_;
		gint iv_length1;
		gint _iv_size_;
		OmemoContext* _tmp2_;
		OmemoContext* _tmp3_;
		guint8* _tmp4_;
		gint _tmp4__length1;
		guint8* key = NULL;
		guint8* _tmp5_;
		gint key_length1;
		gint _key_size_;
		OmemoContext* _tmp6_;
		OmemoContext* _tmp7_;
		guint8* _tmp8_;
		gint _tmp8__length1;
		CryptoSymmetricCipher* cipher = NULL;
		CryptoSymmetricCipher* _tmp9_;
		CryptoSymmetricCipher* _tmp10_;
		guint8* _tmp11_;
		gint _tmp11__length1;
		CryptoSymmetricCipher* _tmp12_;
		guint8* _tmp13_;
		gint _tmp13__length1;
		DinoPluginsOmemoOmemoHttpFileMeta* _tmp14_;
		guint8* _tmp15_;
		gint _tmp15__length1;
		guint8* _tmp16_;
		gint _tmp16__length1;
		DinoPluginsOmemoOmemoHttpFileMeta* _tmp17_;
		guint8* _tmp18_;
		gint _tmp18__length1;
		guint8* _tmp19_;
		gint _tmp19__length1;
		DinoPluginsOmemoOmemoHttpFileMeta* _tmp20_;
		gint64 _tmp21_;
		gint64 _tmp22_;
		DinoPluginsOmemoOmemoHttpFileMeta* _tmp23_;
		gchar* _tmp24_;
		GInputStream* _tmp25_;
		GInputStream* _tmp26_;
		CryptoSymmetricCipher* _tmp27_;
		CryptoSymmetricCipherEncrypter* _tmp28_;
		CryptoSymmetricCipherEncrypter* _tmp29_;
		GConverterInputStream* _tmp30_;
		GConverterInputStream* _tmp31_;
		_tmp1_ = g_new0 (guint8, IV_SIZE);
		iv = _tmp1_;
		iv_length1 = IV_SIZE;
		_iv_size_ = iv_length1;
		_tmp2_ = dino_plugins_omemo_plugin_get_context ();
		_tmp3_ = _tmp2_;
		_tmp4_ = iv;
		_tmp4__length1 = iv_length1;
		omemo_context_randomize (_tmp3_, _tmp4_, (gint) _tmp4__length1, &_inner_error0_);
		_omemo_context_unref0 (_tmp3_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			iv = (g_free (iv), NULL);
			if (_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_tmp5_ = g_new0 (guint8, KEY_SIZE);
		key = _tmp5_;
		key_length1 = KEY_SIZE;
		_key_size_ = key_length1;
		_tmp6_ = dino_plugins_omemo_plugin_get_context ();
		_tmp7_ = _tmp6_;
		_tmp8_ = key;
		_tmp8__length1 = key_length1;
		omemo_context_randomize (_tmp7_, _tmp8_, (gint) _tmp8__length1, &_inner_error0_);
		_omemo_context_unref0 (_tmp7_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			key = (g_free (key), NULL);
			iv = (g_free (iv), NULL);
			if (_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_tmp9_ = crypto_symmetric_cipher_new ("AES-GCM", &_inner_error0_);
		cipher = _tmp9_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			key = (g_free (key), NULL);
			iv = (g_free (iv), NULL);
			if (_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_tmp10_ = cipher;
		_tmp11_ = key;
		_tmp11__length1 = key_length1;
		crypto_symmetric_cipher_set_key (_tmp10_, _tmp11_, (gint) _tmp11__length1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_crypto_symmetric_cipher_unref0 (cipher);
			key = (g_free (key), NULL);
			iv = (g_free (iv), NULL);
			if (_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_tmp12_ = cipher;
		_tmp13_ = iv;
		_tmp13__length1 = iv_length1;
		crypto_symmetric_cipher_set_iv (_tmp12_, _tmp13_, (gint) _tmp13__length1, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			_crypto_symmetric_cipher_unref0 (cipher);
			key = (g_free (key), NULL);
			iv = (g_free (iv), NULL);
			if (_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_tmp14_ = omemo_http_file_meta;
		_tmp15_ = iv;
		_tmp15__length1 = iv_length1;
		_tmp16_ = (_tmp15_ != NULL) ? _vala_array_dup4 (_tmp15_, _tmp15__length1) : _tmp15_;
		_tmp16__length1 = _tmp15__length1;
		_tmp14_->iv = (g_free (_tmp14_->iv), NULL);
		_tmp14_->iv = _tmp16_;
		_tmp14_->iv_length1 = _tmp16__length1;
		_tmp17_ = omemo_http_file_meta;
		_tmp18_ = key;
		_tmp18__length1 = key_length1;
		_tmp19_ = (_tmp18_ != NULL) ? _vala_array_dup5 (_tmp18_, _tmp18__length1) : _tmp18_;
		_tmp19__length1 = _tmp18__length1;
		_tmp17_->key = (g_free (_tmp17_->key), NULL);
		_tmp17_->key = _tmp19_;
		_tmp17_->key_length1 = _tmp19__length1;
		_tmp20_ = omemo_http_file_meta;
		_tmp21_ = dino_entities_file_transfer_get_size (file_transfer);
		_tmp22_ = _tmp21_;
		((DinoFileMeta*) _tmp20_)->size = _tmp22_ + 16;
		_tmp23_ = omemo_http_file_meta;
		_tmp24_ = g_strdup ("application/octet-stream");
		_g_free0 (((DinoFileMeta*) _tmp23_)->mime_type);
		((DinoFileMeta*) _tmp23_)->mime_type = _tmp24_;
		_tmp25_ = dino_entities_file_transfer_get_input_stream (file_transfer);
		_tmp26_ = _tmp25_;
		_tmp27_ = cipher;
		cipher = NULL;
		_tmp28_ = crypto_symmetric_cipher_encrypter_new (_tmp27_, (gsize) 16);
		_tmp29_ = _tmp28_;
		_tmp30_ = (GConverterInputStream*) g_converter_input_stream_new (_tmp26_, (GConverter*) _tmp29_);
		_tmp31_ = _tmp30_;
		dino_entities_file_transfer_set_input_stream (file_transfer, (GInputStream*) _tmp31_);
		_g_object_unref0 (_tmp31_);
		_g_object_unref0 (_tmp29_);
		_crypto_symmetric_cipher_unref0 (cipher);
		key = (g_free (key), NULL);
		iv = (g_free (iv), NULL);
	}
	goto __finally0;
	__catch0_crypto_error:
	{
		GError* _error_ = NULL;
		GError* _tmp32_;
		const gchar* _tmp33_;
		gchar* _tmp34_;
		gchar* _tmp35_;
		GError* _tmp36_;
		GError* _tmp37_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp32_ = _error_;
		_tmp33_ = _tmp32_->message;
		_tmp34_ = g_strdup_printf ("OMEMO file encryption error: %s", _tmp33_);
		_tmp35_ = _tmp34_;
		_tmp36_ = g_error_new_literal (DINO_FILE_SEND_ERROR, DINO_FILE_SEND_ERROR_ENCRYPTION_FAILED, _tmp35_);
		_tmp37_ = _tmp36_;
		_g_free0 (_tmp35_);
		_inner_error0_ = _tmp37_;
		_g_error_free0 (_error_);
		goto __finally0;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* _error_ = NULL;
		GError* _tmp38_;
		const gchar* _tmp39_;
		gchar* _tmp40_;
		gchar* _tmp41_;
		GError* _tmp42_;
		GError* _tmp43_;
		_error_ = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp38_ = _error_;
		_tmp39_ = _tmp38_->message;
		_tmp40_ = g_strdup_printf ("OMEMO file encryption error: %s", _tmp39_);
		_tmp41_ = _tmp40_;
		_tmp42_ = g_error_new_literal (DINO_FILE_SEND_ERROR, DINO_FILE_SEND_ERROR_ENCRYPTION_FAILED, _tmp41_);
		_tmp43_ = _tmp42_;
		_g_free0 (_tmp41_);
		_inner_error0_ = _tmp43_;
		_g_error_free0 (_error_);
		goto __finally0;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		if (_inner_error0_->domain == DINO_FILE_SEND_ERROR) {
			g_propagate_error (error, _inner_error0_);
			_dino_file_meta_unref0 (omemo_http_file_meta);
			return NULL;
		} else {
			_dino_file_meta_unref0 (omemo_http_file_meta);
			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;
		}
	}
	_tmp44_ = dino_entities_file_transfer_get_file_name (file_transfer);
	_tmp45_ = _tmp44_;
	_tmp46_ = dino_entities_file_transfer_get_server_file_name (file_transfer);
	_tmp47_ = _tmp46_;
	g_debug ("file_encryptor.vala:49: Encrypting file %s as %s", _tmp45_, _tmp47_);
	result = (DinoFileMeta*) omemo_http_file_meta;
	return result;
}

static gpointer
_dino_file_send_data_ref0 (gpointer self)
{
	return self ? dino_file_send_data_ref (self) : NULL;
}

static gpointer
_dino_file_meta_ref0 (gpointer self)
{
	return self ? dino_file_meta_ref (self) : NULL;
}

static glong
string_strnlen (gchar* str,
                glong maxlen)
{
	gchar* end = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	glong result;
	_tmp0_ = memchr (str, 0, (gsize) maxlen);
	end = _tmp0_;
	_tmp1_ = end;
	if (_tmp1_ == NULL) {
		result = maxlen;
		return result;
	} else {
		gchar* _tmp2_;
		_tmp2_ = end;
		result = (glong) (_tmp2_ - str);
		return result;
	}
}

static gchar*
string_substring (const gchar* self,
                  glong offset,
                  glong len)
{
	glong string_length = 0L;
	gboolean _tmp0_ = FALSE;
	gchar* _tmp3_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	if (offset >= ((glong) 0)) {
		_tmp0_ = len >= ((glong) 0);
	} else {
		_tmp0_ = FALSE;
	}
	if (_tmp0_) {
		string_length = string_strnlen ((gchar*) self, offset + len);
	} else {
		gint _tmp1_;
		gint _tmp2_;
		_tmp1_ = strlen (self);
		_tmp2_ = _tmp1_;
		string_length = (glong) _tmp2_;
	}
	if (offset < ((glong) 0)) {
		offset = string_length + offset;
		g_return_val_if_fail (offset >= ((glong) 0), NULL);
	} else {
		g_return_val_if_fail (offset <= string_length, NULL);
	}
	if (len < ((glong) 0)) {
		len = string_length - offset;
	}
	g_return_val_if_fail ((offset + len) <= string_length, NULL);
	_tmp3_ = g_strndup (((gchar*) self) + offset, (gsize) len);
	result = _tmp3_;
	return result;
}

static DinoFileSendData*
dino_plugins_omemo_omemo_file_encryptor_real_preprocess_send_file (DinoFileEncryptor* base,
                                                                   DinoEntitiesConversation* conversation,
                                                                   DinoEntitiesFileTransfer* file_transfer,
                                                                   DinoFileSendData* file_send_data,
                                                                   DinoFileMeta* file_meta,
                                                                   GError** error)
{
	DinoPluginsOmemoOmemoFileEncryptor * self;
	DinoHttpFileSendData* send_data = NULL;
	DinoHttpFileSendData* _tmp0_;
	DinoHttpFileSendData* _tmp1_;
	DinoPluginsOmemoOmemoHttpFileMeta* omemo_http_file_meta = NULL;
	DinoPluginsOmemoOmemoHttpFileMeta* _tmp2_;
	DinoPluginsOmemoOmemoHttpFileMeta* _tmp3_;
	gchar* iv_and_key = NULL;
	gchar* _tmp4_;
	DinoPluginsOmemoOmemoHttpFileMeta* _tmp5_;
	guint8* _tmp6_;
	gint _tmp6__length1;
	DinoPluginsOmemoOmemoHttpFileMeta* _tmp11_;
	guint8* _tmp12_;
	gint _tmp12__length1;
	gchar* aesgcm_link = NULL;
	DinoHttpFileSendData* _tmp17_;
	const gchar* _tmp18_;
	const gchar* _tmp19_;
	gchar* _tmp20_;
	gchar* _tmp21_;
	const gchar* _tmp22_;
	gchar* _tmp23_;
	gchar* _tmp24_;
	const gchar* _tmp25_;
	gchar* _tmp26_;
	gchar* _tmp27_;
	gchar* _tmp28_;
	DinoHttpFileSendData* _tmp29_;
	const gchar* _tmp30_;
	DinoHttpFileSendData* _tmp31_;
	DinoFileSendData* _tmp32_;
	DinoFileSendData* result;
	self = (DinoPluginsOmemoOmemoFileEncryptor*) base;
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (file_transfer != NULL, NULL);
	g_return_val_if_fail (file_send_data != NULL, NULL);
	g_return_val_if_fail (file_meta != NULL, NULL);
	_tmp0_ = _dino_file_send_data_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (file_send_data, DINO_TYPE_HTTP_FILE_SEND_DATA) ? ((DinoHttpFileSendData*) file_send_data) : NULL);
	send_data = _tmp0_;
	_tmp1_ = send_data;
	if (_tmp1_ == NULL) {
		result = NULL;
		_dino_file_send_data_unref0 (send_data);
		return result;
	}
	_tmp2_ = _dino_file_meta_ref0 (DINO_PLUGINS_OMEMO_IS_OMEMO_HTTP_FILE_META (file_meta) ? ((DinoPluginsOmemoOmemoHttpFileMeta*) file_meta) : NULL);
	omemo_http_file_meta = _tmp2_;
	_tmp3_ = omemo_http_file_meta;
	if (_tmp3_ == NULL) {
		result = NULL;
		_dino_file_meta_unref0 (omemo_http_file_meta);
		_dino_file_send_data_unref0 (send_data);
		return result;
	}
	_tmp4_ = g_strdup ("");
	iv_and_key = _tmp4_;
	_tmp5_ = omemo_http_file_meta;
	_tmp6_ = _tmp5_->iv;
	_tmp6__length1 = _tmp5_->iv_length1;
	{
		guint8* byte_collection = NULL;
		gint byte_collection_length1 = 0;
		gint _byte_collection_size_ = 0;
		gint byte_it = 0;
		byte_collection = _tmp6_;
		byte_collection_length1 = _tmp6__length1;
		for (byte_it = 0; byte_it < byte_collection_length1; byte_it = byte_it + 1) {
			guint8 byte = 0U;
			byte = byte_collection[byte_it];
			{
				const gchar* _tmp7_;
				gchar* _tmp8_;
				gchar* _tmp9_;
				gchar* _tmp10_;
				_tmp7_ = iv_and_key;
				_tmp8_ = g_strdup_printf ("%02x", byte);
				_tmp9_ = _tmp8_;
				_tmp10_ = g_strconcat (_tmp7_, _tmp9_, NULL);
				_g_free0 (iv_and_key);
				iv_and_key = _tmp10_;
				_g_free0 (_tmp9_);
			}
		}
	}
	_tmp11_ = omemo_http_file_meta;
	_tmp12_ = _tmp11_->key;
	_tmp12__length1 = _tmp11_->key_length1;
	{
		guint8* byte_collection = NULL;
		gint byte_collection_length1 = 0;
		gint _byte_collection_size_ = 0;
		gint byte_it = 0;
		byte_collection = _tmp12_;
		byte_collection_length1 = _tmp12__length1;
		for (byte_it = 0; byte_it < byte_collection_length1; byte_it = byte_it + 1) {
			guint8 byte = 0U;
			byte = byte_collection[byte_it];
			{
				const gchar* _tmp13_;
				gchar* _tmp14_;
				gchar* _tmp15_;
				gchar* _tmp16_;
				_tmp13_ = iv_and_key;
				_tmp14_ = g_strdup_printf ("%02x", byte);
				_tmp15_ = _tmp14_;
				_tmp16_ = g_strconcat (_tmp13_, _tmp15_, NULL);
				_g_free0 (iv_and_key);
				iv_and_key = _tmp16_;
				_g_free0 (_tmp15_);
			}
		}
	}
	_tmp17_ = send_data;
	_tmp18_ = dino_http_file_send_data_get_url_down (_tmp17_);
	_tmp19_ = _tmp18_;
	_tmp20_ = g_strconcat (_tmp19_, "#", NULL);
	_tmp21_ = _tmp20_;
	_tmp22_ = iv_and_key;
	_tmp23_ = g_strconcat (_tmp21_, _tmp22_, NULL);
	_tmp24_ = _tmp23_;
	_g_free0 (_tmp21_);
	aesgcm_link = _tmp24_;
	_tmp25_ = aesgcm_link;
	_tmp26_ = string_substring (_tmp25_, (glong) 8, (glong) -1);
	_tmp27_ = _tmp26_;
	_tmp28_ = g_strconcat ("aesgcm://", _tmp27_, NULL);
	_g_free0 (aesgcm_link);
	aesgcm_link = _tmp28_;
	_g_free0 (_tmp27_);
	_tmp29_ = send_data;
	_tmp30_ = aesgcm_link;
	dino_http_file_send_data_set_url_down (_tmp29_, _tmp30_);
	_tmp31_ = send_data;
	dino_http_file_send_data_set_encrypt_message (_tmp31_, TRUE);
	_tmp32_ = _dino_file_send_data_ref0 (file_send_data);
	result = _tmp32_;
	_g_free0 (aesgcm_link);
	_g_free0 (iv_and_key);
	_dino_file_meta_unref0 (omemo_http_file_meta);
	_dino_file_send_data_unref0 (send_data);
	return result;
}

DinoPluginsOmemoOmemoFileEncryptor*
dino_plugins_omemo_omemo_file_encryptor_construct (GType object_type)
{
	DinoPluginsOmemoOmemoFileEncryptor * self = NULL;
	self = (DinoPluginsOmemoOmemoFileEncryptor*) g_object_new (object_type, NULL);
	return self;
}

DinoPluginsOmemoOmemoFileEncryptor*
dino_plugins_omemo_omemo_file_encryptor_new (void)
{
	return dino_plugins_omemo_omemo_file_encryptor_construct (DINO_PLUGINS_OMEMO_TYPE_OMEMO_FILE_ENCRYPTOR);
}

static void
dino_plugins_omemo_omemo_file_encryptor_class_init (DinoPluginsOmemoOmemoFileEncryptorClass * klass,
                                                    gpointer klass_data)
{
	dino_plugins_omemo_omemo_file_encryptor_parent_class = g_type_class_peek_parent (klass);
}

static void
dino_plugins_omemo_omemo_file_encryptor_dino_file_encryptor_interface_init (DinoFileEncryptorIface * iface,
                                                                            gpointer iface_data)
{
	dino_plugins_omemo_omemo_file_encryptor_dino_file_encryptor_parent_iface = g_type_interface_peek_parent (iface);
	iface->can_encrypt_file = (gboolean (*) (DinoFileEncryptor*, DinoEntitiesConversation*, DinoEntitiesFileTransfer*)) dino_plugins_omemo_omemo_file_encryptor_real_can_encrypt_file;
	iface->encrypt_file = (DinoFileMeta* (*) (DinoFileEncryptor*, DinoEntitiesConversation*, DinoEntitiesFileTransfer*, GError**)) dino_plugins_omemo_omemo_file_encryptor_real_encrypt_file;
	iface->preprocess_send_file = (DinoFileSendData* (*) (DinoFileEncryptor*, DinoEntitiesConversation*, DinoEntitiesFileTransfer*, DinoFileSendData*, DinoFileMeta*, GError**)) dino_plugins_omemo_omemo_file_encryptor_real_preprocess_send_file;
}

static void
dino_plugins_omemo_omemo_file_encryptor_instance_init (DinoPluginsOmemoOmemoFileEncryptor * self,
                                                       gpointer klass)
{
}

static GType
dino_plugins_omemo_omemo_file_encryptor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoOmemoFileEncryptorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_omemo_file_encryptor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoOmemoFileEncryptor), 0, (GInstanceInitFunc) dino_plugins_omemo_omemo_file_encryptor_instance_init, NULL };
	static const GInterfaceInfo dino_file_encryptor_info = { (GInterfaceInitFunc) dino_plugins_omemo_omemo_file_encryptor_dino_file_encryptor_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_omemo_omemo_file_encryptor_type_id;
	dino_plugins_omemo_omemo_file_encryptor_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOmemoOmemoFileEncryptor", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_omemo_omemo_file_encryptor_type_id, DINO_TYPE_FILE_ENCRYPTOR, &dino_file_encryptor_info);
	return dino_plugins_omemo_omemo_file_encryptor_type_id;
}

GType
dino_plugins_omemo_omemo_file_encryptor_get_type (void)
{
	static volatile gsize dino_plugins_omemo_omemo_file_encryptor_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_omemo_file_encryptor_type_id__once)) {
		GType dino_plugins_omemo_omemo_file_encryptor_type_id;
		dino_plugins_omemo_omemo_file_encryptor_type_id = dino_plugins_omemo_omemo_file_encryptor_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_omemo_file_encryptor_type_id__once, dino_plugins_omemo_omemo_file_encryptor_type_id);
	}
	return dino_plugins_omemo_omemo_file_encryptor_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;
}

