Browse Source

mconn-crypt: m_conn namespace changed to mconn

Part of namespac cleanup work.
bboozzoo/namespace-cleanup
Maciek Borzecki 9 years ago
parent
commit
4b11424310
2 changed files with 72 additions and 72 deletions
  1. +42
    -42
      src/mconn-crypt.c
  2. +30
    -30
      src/mconn-crypt.h

+ 42
- 42
src/mconn-crypt.c View File

@ -23,55 +23,55 @@
#include "mconn-crypt.h" #include "mconn-crypt.h"
/* encrypted data padding */ /* encrypted data padding */
#define M_CONN_CRYPT_RSA_PADDING RSA_PKCS1_PADDING
#define MCONN_CRYPT_RSA_PADDING RSA_PKCS1_PADDING
typedef struct _MConnCryptPrivate MConnCryptPrivate;
typedef struct _MconnCryptPrivate MconnCryptPrivate;
/** /**
* MConnCrypt:
* MconnCrypt:
* *
* A simple wrapper for cypto operations. * A simple wrapper for cypto operations.
**/ **/
struct _MConnCrypt
struct _MconnCrypt
{ {
GObject parent; GObject parent;
MConnCryptPrivate *priv;
MconnCryptPrivate *priv;
}; };
struct _MConnCryptPrivate
struct _MconnCryptPrivate
{ {
RSA *key; /* RSA key wrapper */ RSA *key; /* RSA key wrapper */
}; };
static void m_conn_crypt_dispose (GObject *object);
static void m_conn_crypt_finalize (GObject *object);
static gchar *__m_conn_get_public_key_as_pem(MConnCryptPrivate *priv);
static gboolean __m_conn_load_key(MConnCryptPrivate *priv, const char *path);
static gboolean __m_conn_generate_key_at_path(const char *path);
static void mconn_crypt_dispose (GObject *object);
static void mconn_crypt_finalize (GObject *object);
static gchar *__mconn_get_public_key_as_pem(MconnCryptPrivate *priv);
static gboolean __mconn_load_key(MconnCryptPrivate *priv, const char *path);
static gboolean __mconn_generate_key_at_path(const char *path);
G_DEFINE_TYPE_WITH_PRIVATE (MConnCrypt, m_conn_crypt, G_TYPE_OBJECT);
G_DEFINE_TYPE_WITH_PRIVATE (MconnCrypt, mconn_crypt, G_TYPE_OBJECT);
static void static void
m_conn_crypt_class_init (MConnCryptClass *klass)
mconn_crypt_class_init (MconnCryptClass *klass)
{ {
GObjectClass *gobject_class = (GObjectClass *)klass; GObjectClass *gobject_class = (GObjectClass *)klass;
gobject_class->dispose = m_conn_crypt_dispose;
gobject_class->finalize = m_conn_crypt_finalize;
gobject_class->dispose = mconn_crypt_dispose;
gobject_class->finalize = mconn_crypt_finalize;
} }
static void static void
m_conn_crypt_init (MConnCrypt *self)
mconn_crypt_init (MconnCrypt *self)
{ {
g_debug("mconn-crypt: new instance"); g_debug("mconn-crypt: new instance");
self->priv = m_conn_crypt_get_instance_private(self);
self->priv = mconn_crypt_get_instance_private(self);
} }
static void static void
m_conn_crypt_dispose (GObject *object)
mconn_crypt_dispose (GObject *object)
{ {
MConnCrypt *self = (MConnCrypt *)object;
MconnCrypt *self = (MconnCrypt *)object;
if (self->priv->key != NULL) if (self->priv->key != NULL)
{ {
@ -79,54 +79,54 @@ m_conn_crypt_dispose (GObject *object)
self->priv->key = NULL; self->priv->key = NULL;
} }
G_OBJECT_CLASS (m_conn_crypt_parent_class)->dispose (object);
G_OBJECT_CLASS (mconn_crypt_parent_class)->dispose (object);
} }
static void static void
m_conn_crypt_finalize (GObject *object)
mconn_crypt_finalize (GObject *object)
{ {
MConnCrypt *self = (MConnCrypt *)object;
MconnCrypt *self = (MconnCrypt *)object;
g_signal_handlers_destroy (object); g_signal_handlers_destroy (object);
G_OBJECT_CLASS (m_conn_crypt_parent_class)->finalize (object);
G_OBJECT_CLASS (mconn_crypt_parent_class)->finalize (object);
} }
MConnCrypt *m_conn_crypt_new_for_key_path(const char *path)
MconnCrypt *mconn_crypt_new_for_key_path(const char *path)
{ {
g_debug("mconn-crypt: new crypt for key %s", path); g_debug("mconn-crypt: new crypt for key %s", path);
MConnCrypt *self = g_object_new(M_CONN_TYPE_CRYPT, NULL);
MconnCrypt *self = g_object_new(MCONN_TYPE_CRYPT, NULL);
if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE)
__m_conn_generate_key_at_path(path);
__mconn_generate_key_at_path(path);
if (__m_conn_load_key(self->priv, path) == FALSE)
if (__mconn_load_key(self->priv, path) == FALSE)
{ {
m_conn_crypt_unref(self);
mconn_crypt_unref(self);
return NULL; return NULL;
} }
return self; return self;
} }
MConnCrypt * m_conn_crypt_ref(MConnCrypt *self)
MconnCrypt * mconn_crypt_ref(MconnCrypt *self)
{ {
g_assert(IS_M_CONN_CRYPT(self));
return M_CONN_CRYPT(g_object_ref(self));
g_assert(IS_MCONN_CRYPT(self));
return MCONN_CRYPT(g_object_ref(self));
} }
void m_conn_crypt_unref(MConnCrypt *self)
void mconn_crypt_unref(MconnCrypt *self)
{ {
if (self != NULL) if (self != NULL)
{ {
g_assert(IS_M_CONN_CRYPT(self));
g_assert(IS_MCONN_CRYPT(self));
g_object_unref(self); g_object_unref(self);
} }
} }
GByteArray * m_conn_crypt_decrypt(MConnCrypt *self, GBytes *data, GError **err)
GByteArray * mconn_crypt_decrypt(MconnCrypt *self, GBytes *data, GError **err)
{ {
g_assert(IS_M_CONN_CRYPT(self));
g_assert(IS_MCONN_CRYPT(self));
g_assert(self->priv->key); g_assert(self->priv->key);
g_debug("decrypt: %zu bytes of data", g_bytes_get_size(data)); g_debug("decrypt: %zu bytes of data", g_bytes_get_size(data));
@ -142,7 +142,7 @@ GByteArray * m_conn_crypt_decrypt(MConnCrypt *self, GBytes *data, GError **err)
g_bytes_get_data(data, NULL), g_bytes_get_data(data, NULL),
(unsigned char *)out_data->data, (unsigned char *)out_data->data,
self->priv->key, self->priv->key,
M_CONN_CRYPT_RSA_PADDING);
MCONN_CRYPT_RSA_PADDING);
g_debug("decrypted size: %d", dec_size); g_debug("decrypted size: %d", dec_size);
g_assert(dec_size != -1); g_assert(dec_size != -1);
@ -151,18 +151,18 @@ GByteArray * m_conn_crypt_decrypt(MConnCrypt *self, GBytes *data, GError **err)
return out_data; return out_data;
} }
gchar *m_conn_crypt_get_public_key_pem(MConnCrypt *self)
gchar *mconn_crypt_get_public_key_pem(MconnCrypt *self)
{ {
g_assert(IS_M_CONN_CRYPT(self));
g_assert(IS_MCONN_CRYPT(self));
g_assert(self->priv); g_assert(self->priv);
g_assert(self->priv->key); g_assert(self->priv->key);
return __m_conn_get_public_key_as_pem(self->priv);
return __mconn_get_public_key_as_pem(self->priv);
} }
/** /**
* *
*/ */
static gchar *__m_conn_get_public_key_as_pem(MConnCryptPrivate *priv)
static gchar *__mconn_get_public_key_as_pem(MconnCryptPrivate *priv)
{ {
gchar *pubkey = NULL; gchar *pubkey = NULL;
@ -189,7 +189,7 @@ static gchar *__m_conn_get_public_key_as_pem(MConnCryptPrivate *priv)
return pubkey; return pubkey;
} }
static gboolean __m_conn_load_key(MConnCryptPrivate *priv, const char *path)
static gboolean __mconn_load_key(MconnCryptPrivate *priv, const char *path)
{ {
if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE) if (g_file_test(path, G_FILE_TEST_EXISTS) == FALSE)
{ {
@ -224,7 +224,7 @@ static gboolean __m_conn_load_key(MConnCryptPrivate *priv, const char *path)
return TRUE; return TRUE;
} }
static gboolean __m_conn_generate_key_at_path(const char *path)
static gboolean __mconn_generate_key_at_path(const char *path)
{ {
gboolean ret = TRUE; gboolean ret = TRUE;
RSA *rsa = NULL; RSA *rsa = NULL;


+ 30
- 30
src/mconn-crypt.h View File

@ -25,77 +25,77 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define M_CONN_TYPE_CRYPT \
(m_conn_crypt_get_type())
#define M_CONN_CRYPT(obj) \
#define MCONN_TYPE_CRYPT \
(mconn_crypt_get_type())
#define MCONN_CRYPT(obj) \
(G_TYPE_CHECK_INSTANCE_CAST ((obj), \ (G_TYPE_CHECK_INSTANCE_CAST ((obj), \
M_CONN_TYPE_CRYPT, \
MConnCrypt))
#define M_CONN_CRYPT_CLASS(klass) \
MCONN_TYPE_CRYPT, \
MconnCrypt))
#define MCONN_CRYPT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST ((klass), \ (G_TYPE_CHECK_CLASS_CAST ((klass), \
M_CONN_TYPE_CRYPT, \
MConnCryptClass))
#define IS_M_CONN_CRYPT(obj) \
MCONN_TYPE_CRYPT, \
MconnCryptClass))
#define IS_MCONN_CRYPT(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \
M_CONN_TYPE_CRYPT))
#define IS_M_CONN_CRYPT_CLASS(klass) \
MCONN_TYPE_CRYPT))
#define IS_MCONN_CRYPT_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE ((klass), \ (G_TYPE_CHECK_CLASS_TYPE ((klass), \
M_CONN_TYPE_CRYPT))
#define M_CONN_CRYPT_GET_CLASS(obj) \
MCONN_TYPE_CRYPT))
#define MCONN_CRYPT_GET_CLASS(obj) \
(G_TYPE_INSTANCE_GET_CLASS ((obj), \ (G_TYPE_INSTANCE_GET_CLASS ((obj), \
M_CONN_TYPE_CRYPT, \
MConnCryptClass))
MCONN_TYPE_CRYPT, \
MconnCryptClass))
typedef struct _MConnCrypt MConnCrypt;
typedef struct _MConnCryptClass MConnCryptClass;
struct _MConnCryptClass
typedef struct _MconnCrypt MconnCrypt;
typedef struct _MconnCryptClass MconnCryptClass;
struct _MconnCryptClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
}; };
GType m_conn_crypt_get_type (void) G_GNUC_CONST;
GType mconn_crypt_get_type (void) G_GNUC_CONST;
/** /**
* m_conn_crypt_new_for_key_path: (constructor)
* mconn_crypt_new_for_key_path: (constructor)
* @path: key path * @path: key path
* *
* Returns: (transfer full): new object * Returns: (transfer full): new object
*/ */
MConnCrypt *m_conn_crypt_new_for_key_path(const char *path);
MconnCrypt *mconn_crypt_new_for_key_path(const char *path);
/** /**
* m_conn_crypt_unref:
* mconn_crypt_unref:
* @crypt: crypt object * @crypt: crypt object
*/ */
void m_conn_crypt_unref(MConnCrypt *crypt);
void mconn_crypt_unref(MconnCrypt *crypt);
/** /**
* m_conn_crypt_ref:
* mconn_crypt_ref:
* @crypt: crypt object * @crypt: crypt object
* *
* Take reference to crypt object * Take reference to crypt object
* Returns: (transfer none): reffed object * Returns: (transfer none): reffed object
*/ */
MConnCrypt *m_conn_crypt_ref(MConnCrypt *crypt);
MconnCrypt *mconn_crypt_ref(MconnCrypt *crypt);
/** /**
* m_conn_crypt_decrypt:
* mconn_crypt_decrypt:
* @crypt: crypt object * @crypt: crypt object
* @data: (type GBytes): data * @data: (type GBytes): data
* @error: return location for a GError or NULL * @error: return location for a GError or NULL
* *
* Returns: (transfer full): a new #GByteArray with decoded data * Returns: (transfer full): a new #GByteArray with decoded data
*/ */
GByteArray * m_conn_crypt_decrypt(MConnCrypt *crypt, GBytes *data, GError **error);
GByteArray * mconn_crypt_decrypt(MconnCrypt *crypt, GBytes *data, GError **error);
/** /**
* m_conn_crypt_get_public_key_pem:
* mconn_crypt_get_public_key_pem:
* @crypt: crypt object * @crypt: crypt object
* *
* Returns: (transfer full): allocated string with public key in PEM format * Returns: (transfer full): allocated string with public key in PEM format
*/ */
gchar * m_conn_crypt_get_public_key_pem(MConnCrypt *crypt);
gchar * mconn_crypt_get_public_key_pem(MconnCrypt *crypt);
G_END_DECLS G_END_DECLS
#endif /* __M_CONN_CRYPT_H__ */
#endif /* __MCONN_CRYPT_H__ */

Loading…
Cancel
Save