From 4da7c06c991d9bc55044912f0f2a7085e10716e2 Mon Sep 17 00:00:00 2001 From: Maciek Borzecki Date: Mon, 12 Jan 2015 23:27:59 +0100 Subject: [PATCH] mconn-crypt: attempt to make the code more g-o-i friendly --- src/mconn-crypt.c | 20 ++++++++++++++++++ src/mconn-crypt.h | 54 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 61 insertions(+), 13 deletions(-) diff --git a/src/mconn-crypt.c b/src/mconn-crypt.c index 7a691c6..fdf63d5 100644 --- a/src/mconn-crypt.c +++ b/src/mconn-crypt.c @@ -22,6 +22,20 @@ #include #include "mconn-crypt.h" +typedef struct _MConnCryptPrivate MConnCryptPrivate; + +/** + * MConnCrypt: + * + * A simple wrapper for cypto operations. + **/ + +struct _MConnCrypt +{ + GObject parent; + MConnCryptPrivate *priv; +}; + struct _MConnCryptPrivate { RSA *key; /* RSA key wrapper */ @@ -87,6 +101,12 @@ MConnCrypt *mconn_crypt_new_for_key_path(const char *path) return self; } +MConnCrypt * mconn_crypt_ref(MConnCrypt *self) +{ + g_assert(IS_MCONN_CRYPT(self)); + return MCONN_CRYPT(g_object_ref(self)); +} + void mconn_crypt_unref(MConnCrypt *self) { if (self != NULL) diff --git a/src/mconn-crypt.h b/src/mconn-crypt.h index dd84f8b..a131521 100644 --- a/src/mconn-crypt.h +++ b/src/mconn-crypt.h @@ -1,6 +1,6 @@ /* ex:ts=4:sw=4:sts=4:et */ /* -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ -/** +/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. @@ -14,14 +14,13 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * - * AUTHORS - * Maciek Borzecki + * Author: Maciek Borzecki */ #ifndef __MCONN_CRYPT_H__ #define __MCONN_CRYPT_H__ #include - +#include G_BEGIN_DECLS @@ -48,25 +47,54 @@ G_BEGIN_DECLS typedef struct _MConnCrypt MConnCrypt; typedef struct _MConnCryptClass MConnCryptClass; -typedef struct _MConnCryptPrivate MConnCryptPrivate; - struct _MConnCryptClass { GObjectClass parent_class; }; -struct _MConnCrypt -{ - GObject parent; - MConnCryptPrivate *priv; -}; - GType mconn_crypt_get_type (void) G_GNUC_CONST; +/** + * mconn_crypt_new_for_key_path: + * @path: key path + * + * Returns: (transfer full) (element-type MConnCrypt): new object + */ MConnCrypt *mconn_crypt_new_for_key_path(const char *path); + +/** + * mconn_crypt_unref: + * @crypt: crypt object + */ +void mconn_crypt_unref(MConnCrypt *crypt); + +/** + * mconn_crypt_ref: + * @crypt: crypt object + * + * Take reference to crypt object + * Returns: (transfer none): reffed object + */ void mconn_crypt_unref(MConnCrypt *crypt); -GBytes * mconn_crypt_decrypt(MConnCrypt *crypt, GBytes *data, GError **err); + +/** + * mconn_crypt_decrypt: + * @crypt: crypt object + * @data: (type GBytes): data + * @error: return location for a GError or NULL + * + * Returns: (transfer full): a new #GBytes with decoded data + */ +GBytes * mconn_crypt_decrypt(MConnCrypt *crypt, GBytes *data, GError **error); + +/** + * mconn_crypt_get_public_key_pem: + * @crypt: crypt object + * + * Returns: (transfer full): allocated string with public key in PEM format + */ gchar * mconn_crypt_get_public_key_pem(MConnCrypt *crypt); + G_END_DECLS #endif /* __MCONN_CRYPT_H__ */