Browse Source

mconn-crypt: attempt to make the code more g-o-i friendly

bboozzoo/device-cache
Maciek Borzecki 10 years ago
parent
commit
4da7c06c99
2 changed files with 61 additions and 13 deletions
  1. +20
    -0
      src/mconn-crypt.c
  2. +41
    -13
      src/mconn-crypt.h

+ 20
- 0
src/mconn-crypt.c View File

@ -22,6 +22,20 @@
#include <openssl/pem.h> #include <openssl/pem.h>
#include "mconn-crypt.h" #include "mconn-crypt.h"
typedef struct _MConnCryptPrivate MConnCryptPrivate;
/**
* MConnCrypt:
*
* A simple wrapper for cypto operations.
**/
struct _MConnCrypt
{
GObject parent;
MConnCryptPrivate *priv;
};
struct _MConnCryptPrivate struct _MConnCryptPrivate
{ {
RSA *key; /* RSA key wrapper */ RSA *key; /* RSA key wrapper */
@ -87,6 +101,12 @@ MConnCrypt *mconn_crypt_new_for_key_path(const char *path)
return self; 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) void mconn_crypt_unref(MConnCrypt *self)
{ {
if (self != NULL) if (self != NULL)


+ 41
- 13
src/mconn-crypt.h View File

@ -1,6 +1,6 @@
/* ex:ts=4:sw=4:sts=4:et */ /* ex:ts=4:sw=4:sts=4:et */
/* -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
/**
/*
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
@ -14,14 +14,13 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
* *
* AUTHORS
* Maciek Borzecki <maciek.borzecki (at] gmail.com>
* Author: Maciek Borzecki <maciek.borzecki (at] gmail.com>
*/ */
#ifndef __MCONN_CRYPT_H__ #ifndef __MCONN_CRYPT_H__
#define __MCONN_CRYPT_H__ #define __MCONN_CRYPT_H__
#include <glib-object.h> #include <glib-object.h>
#include <glib.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -48,25 +47,54 @@ G_BEGIN_DECLS
typedef struct _MConnCrypt MConnCrypt; typedef struct _MConnCrypt MConnCrypt;
typedef struct _MConnCryptClass MConnCryptClass; typedef struct _MConnCryptClass MConnCryptClass;
typedef struct _MConnCryptPrivate MConnCryptPrivate;
struct _MConnCryptClass struct _MConnCryptClass
{ {
GObjectClass parent_class; GObjectClass parent_class;
}; };
struct _MConnCrypt
{
GObject parent;
MConnCryptPrivate *priv;
};
GType mconn_crypt_get_type (void) G_GNUC_CONST; 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); 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); 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); gchar * mconn_crypt_get_public_key_pem(MConnCrypt *crypt);
G_END_DECLS G_END_DECLS
#endif /* __MCONN_CRYPT_H__ */ #endif /* __MCONN_CRYPT_H__ */

Loading…
Cancel
Save