# GLib and GTK+ stuff
PKG_CHECK_MODULES(GLIB,
- glib-2.0 >= 2.30.0
+ glib-2.0 >= 2.32.0
gmodule-no-export-2.0
gthread-2.0
gobject-2.0
egg-asn1x.c egg-asn1x.h \
egg-asn1-defs.c egg-asn1-defs.h \
egg-buffer.c egg-buffer.h \
- egg-bytes.c egg-bytes.h \
egg-dh.c egg-dh.h \
egg-dn.c egg-dn.h \
egg-error.h \
}
guint
-egg_armor_parse (EggBytes *data,
+egg_armor_parse (GBytes *data,
EggArmorCallback callback,
gpointer user_data)
{
guchar *decoded = NULL;
gsize n_decoded = 0;
GHashTable *headers = NULL;
- EggBytes *dec;
- EggBytes *outer;
+ GBytes *dec;
+ GBytes *outer;
GQuark type;
gsize n_at;
g_return_val_if_fail (data != NULL, 0);
- at = egg_bytes_get_data (data);
- n_at = egg_bytes_get_size (data);
+ at = g_bytes_get_data (data, &n_at);
while (n_at > 0) {
if (beg != end) {
if (armor_parse_block (beg, end - beg, &decoded, &n_decoded, &headers)) {
g_assert (outer_end > outer_beg);
- dec = egg_bytes_new_with_free_func (decoded, n_decoded,
- egg_secure_free, decoded);
+ dec = g_bytes_new_with_free_func (decoded, n_decoded,
+ egg_secure_free, decoded);
if (callback != NULL) {
- outer = egg_bytes_new_with_free_func (outer_beg, outer_end - outer_beg,
- egg_bytes_unref, egg_bytes_ref (data));
+ outer = g_bytes_new_with_free_func (outer_beg, outer_end - outer_beg,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (data));
(callback) (type, dec, outer, headers, user_data);
- egg_bytes_unref (outer);
+ g_bytes_unref (outer);
}
- egg_bytes_unref (dec);
+ g_bytes_unref (dec);
++nfound;
if (headers)
g_hash_table_remove_all (headers);
#include <glib.h>
-#include <egg/egg-bytes.h>
-
typedef void (*EggArmorCallback) (GQuark type,
- EggBytes *data,
- EggBytes *outer,
+ GBytes *data,
+ GBytes *outer,
GHashTable *headers,
gpointer user_data);
GHashTable* egg_armor_headers_new (void);
-guint egg_armor_parse (EggBytes *data,
+guint egg_armor_parse (GBytes *data,
EggArmorCallback callback,
gpointer user_data);
Atlv *tlv;
Aenc *enc;
- EggBytes *backing;
+ GBytes *backing;
gchar* failure;
gint chosen : 1;
struct _Abits {
guint n_bits;
- EggBytes *bits;
+ GBytes *bits;
};
/* Forward Declarations */
-static gboolean anode_decode_anything (GNode*, EggBytes*, Atlv*);
-static gboolean anode_decode_anything_for_flags (GNode *, EggBytes*, Atlv*, gint);
+static gboolean anode_decode_anything (GNode*, GBytes*, Atlv*);
+static gboolean anode_decode_anything_for_flags (GNode *, GBytes*, Atlv*, gint);
static gboolean anode_validate_anything (GNode*, gboolean);
static gboolean anode_encode_prepare (GNode*, gboolean want);
return la < lb ? -1 : 1;
}
-static inline EggBytes *
+static inline GBytes *
anode_get_backing (GNode *node)
{
Anode *an = node->data;
{
Anode *an = node->data;
if (an->backing)
- egg_bytes_unref (an->backing);
+ g_bytes_unref (an->backing);
an->backing = NULL;
}
static inline void
anode_set_backing (GNode *node,
- EggBytes *backing)
+ GBytes *backing)
{
Anode *an = node->data;
if (backing)
- egg_bytes_ref (backing);
+ g_bytes_ref (backing);
if (an->backing)
- egg_bytes_unref (an->backing);
+ g_bytes_unref (an->backing);
an->backing = backing;
}
static void
anode_set_tlv_data (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *tlv)
{
Anode *an = node->data;
Abits *ab = data;
g_assert (ab != NULL);
if (ab->bits)
- egg_bytes_unref (ab->bits);
+ g_bytes_unref (ab->bits);
g_slice_free (Abits, ab);
}
static gboolean
anode_decode_choice (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *tlv)
{
gboolean have = FALSE;
static gboolean
anode_decode_sequence_or_set (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *outer)
{
GNode *child;
static gboolean
anode_decode_sequence_or_set_of (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *outer)
{
GNode *child, *other;
static gboolean
anode_decode_primitive (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *tlv,
gint flags)
{
static gboolean
anode_decode_structured (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *tlv,
gint flags)
{
static gboolean
anode_decode_anything_for_flags (GNode *node,
- EggBytes *bytes,
+ GBytes *bytes,
Atlv *tlv,
gint flags)
{
static gboolean
anode_decode_anything (GNode *node,
- EggBytes *bytes,
+ GBytes *bytes,
Atlv *tlv)
{
gint flags = anode_def_flags (node);
gboolean
egg_asn1x_decode_no_validate (GNode *asn,
- EggBytes *data)
+ GBytes *data)
{
const guchar *dat;
gsize size;
egg_asn1x_clear (asn);
- dat = egg_bytes_get_data (data);
+ dat = g_bytes_get_data (data, &size);
g_return_val_if_fail (dat != NULL, FALSE);
- size = egg_bytes_get_size (data);
if (!anode_decode_tlv_for_data (dat, dat + size, &tlv))
return anode_failure (asn, "content is not encoded properly");
gboolean
egg_asn1x_decode (GNode *asn,
- EggBytes *data)
+ GBytes *data)
{
gboolean ret;
static gboolean
anode_encode_build (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
guchar *data,
gsize n_data)
{
guchar *data,
gsize n_data)
{
- EggBytes *bytes = user_data;
- g_assert (egg_bytes_get_size (bytes) >= n_data);
- memcpy (data, egg_bytes_get_data (bytes), n_data);
+ GBytes *bytes = user_data;
+ g_assert (g_bytes_get_size (bytes) >= n_data);
+ memcpy (data, g_bytes_get_data (bytes, NULL), n_data);
return TRUE;
}
guchar *data,
gsize n_data)
{
- EggBytes *value = user_data;
+ GBytes *value = user_data;
gboolean sign;
const gchar *p;
* byte is already calculated into n_data, see egg_asn1x_set_integer_as_usg
*/
- p = egg_bytes_get_data (value);
+ p = g_bytes_get_data (value, NULL);
g_return_val_if_fail (p != NULL, FALSE);
sign = !!(p[0] & 0x80);
data += 1;
/* Fill in the actual data */
- memcpy (data, egg_bytes_get_data (ab->bits), len);
+ memcpy (data, g_bytes_get_data (ab->bits, NULL), len);
/* Set the extra bits to zero */
if (len && empty) {
static gboolean
anode_encode_prepare_simple (GNode *node, gboolean want)
{
- EggBytes *backing;
- EggBytes *bytes;
+ GBytes *backing;
+ GBytes *bytes;
Aenc *enc;
Atlv *tlv;
if (backing == NULL)
return FALSE;
- bytes = egg_bytes_new_with_free_func ((guchar *)tlv->buf + tlv->off, tlv->len,
- egg_bytes_unref, egg_bytes_ref (backing));
- anode_set_enc_data (node, anode_encoder_bytes, bytes, egg_bytes_unref);
+ bytes = g_bytes_new_with_free_func ((guchar *)tlv->buf + tlv->off, tlv->len,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
+ anode_set_enc_data (node, anode_encoder_bytes, bytes,
+ (GDestroyNotify)g_bytes_unref);
}
tlv->buf = tlv->end = NULL;
g_slice_free (AllocatorClosure, closure);
}
-static EggBytes *
+static GBytes *
new_bytes_with_allocator (EggAllocator allocator,
guchar **data,
gsize length)
closure = g_slice_new (AllocatorClosure);
closure->allocated = *data;
closure->allocator = allocator;
- return egg_bytes_new_with_free_func (*data, length,
+ return g_bytes_new_with_free_func (*data, length,
destroy_with_allocator,
closure);
} else {
*data = g_malloc (length);
- return egg_bytes_new_take (*data, length);
+ return g_bytes_new_take (*data, length);
}
}
-EggBytes *
+GBytes *
egg_asn1x_encode (GNode *asn,
EggAllocator allocator)
{
- EggBytes *bytes;
+ GBytes *bytes;
guchar *data;
gsize length;
Atlv *tlv;
return bytes;
}
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
anode_encode_rollback (asn);
return NULL;
}
return TRUE;
}
-EggBytes *
+GBytes *
egg_asn1x_get_integer_as_raw (GNode *node)
{
- EggBytes *backing;
+ GBytes *backing;
Atlv *tlv;
g_return_val_if_fail (node, FALSE);
if (backing == NULL)
return NULL;
- return egg_bytes_new_with_free_func (tlv->buf + tlv->off, tlv->len,
- egg_bytes_unref, egg_bytes_ref (backing));
+ return g_bytes_new_with_free_func (tlv->buf + tlv->off, tlv->len,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
}
-EggBytes *
+GBytes *
egg_asn1x_get_integer_as_usg (GNode *node)
{
- EggBytes *backing;
+ GBytes *backing;
const guchar *p;
gboolean sign;
Atlv *tlv;
}
}
- return egg_bytes_new_with_free_func (p, n_data,
- egg_bytes_unref,
- egg_bytes_ref (backing));
+ return g_bytes_new_with_free_func (p, n_data,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
}
void
egg_asn1x_set_integer_as_raw (GNode *node,
- EggBytes *value)
+ GBytes *value)
{
g_return_if_fail (value != NULL);
- egg_asn1x_take_integer_as_raw (node, egg_bytes_ref (value));
+ egg_asn1x_take_integer_as_raw (node, g_bytes_ref (value));
}
void
egg_asn1x_take_integer_as_raw (GNode *node,
- EggBytes *value)
+ GBytes *value)
{
gboolean sign;
const guchar *p;
g_return_if_fail (anode_def_type (node) == EGG_ASN1X_INTEGER);
/* Make sure the integer is properly encoded in twos complement*/
- p = egg_bytes_get_data (value);
+ p = g_bytes_get_data (value, NULL);
g_return_if_fail (p != NULL);
sign = !!(p[0] & 0x80);
return;
}
- anode_encode_tlv_and_enc (node, egg_bytes_get_size (value), anode_encoder_bytes,
- value, egg_bytes_unref);
+ anode_encode_tlv_and_enc (node, g_bytes_get_size (value), anode_encoder_bytes,
+ value, (GDestroyNotify)g_bytes_unref);
}
void
egg_asn1x_set_integer_as_usg (GNode *node,
- EggBytes *value)
+ GBytes *value)
{
g_return_if_fail (value != NULL);
- egg_asn1x_take_integer_as_usg (node, egg_bytes_ref (value));
+ egg_asn1x_take_integer_as_usg (node, g_bytes_ref (value));
}
void
egg_asn1x_take_integer_as_usg (GNode *node,
- EggBytes *value)
+ GBytes *value)
{
gboolean sign;
const guchar *p;
g_return_if_fail (anode_def_type (node) == EGG_ASN1X_INTEGER);
/* Make sure the integer is properly encoded in twos complement*/
- p = egg_bytes_get_data (value);
+ p = g_bytes_get_data (value, &len);
g_return_if_fail (p != NULL);
sign = !!(p[0] & 0x80);
- len = egg_bytes_get_size (value);
/*
* If in two's complement this would be negative, add a zero byte so
len += 1;
anode_encode_tlv_and_enc (node, len, anode_encoder_unsigned,
- value, egg_bytes_unref);
+ value, (GDestroyNotify)g_bytes_unref);
}
-EggBytes *
+GBytes *
egg_asn1x_get_element_raw (GNode *node)
{
- EggBytes *backing;
+ GBytes *backing;
const guchar *p;
gsize len;
Atlv *tlv;
p = tlv->buf;
}
- return egg_bytes_new_with_free_func (p, len, egg_bytes_unref,
- egg_bytes_ref (backing));
+ return g_bytes_new_with_free_func (p, len, (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
}
gboolean
egg_asn1x_set_element_raw (GNode *node,
- EggBytes *element)
+ GBytes *element)
{
Atlv dtlv, *tlv;
gint oft, flags;
const guchar *data;
guchar cls_type;
- EggBytes *sub;
+ GBytes *sub;
gsize size;
g_return_val_if_fail (node != NULL, FALSE);
anode_clear (node);
memset (&dtlv, 0, sizeof (dtlv));
- data = egg_bytes_get_data (element);
+ data = g_bytes_get_data (element, &size);
g_return_val_if_fail (data != NULL, FALSE);
- size = egg_bytes_get_size (element);
-
/* Decode the beginning TLV */
if (!anode_decode_tlv_for_data (data, data + size, &dtlv))
return FALSE;
tlv->oft = oft;
}
- sub = egg_bytes_new_with_free_func (dtlv.buf + dtlv.off, dtlv.len,
- egg_bytes_unref, egg_bytes_ref (element));
+ sub = g_bytes_new_with_free_func (dtlv.buf + dtlv.off, dtlv.len,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (element));
/* Setup encoding of the contents */
- anode_set_enc_data (node, anode_encoder_bytes, sub, egg_bytes_unref);
+ anode_set_enc_data (node, anode_encoder_bytes, sub, (GDestroyNotify)g_bytes_unref);
return TRUE;
}
-EggBytes *
+GBytes *
egg_asn1x_get_raw_value (GNode *node)
{
- EggBytes *backing;
+ GBytes *backing;
Atlv *tlv;
g_return_val_if_fail (node, NULL);
if (backing == NULL)
return NULL;
- return egg_bytes_new_with_free_func (tlv->buf + tlv->off, tlv->len,
- egg_bytes_unref, egg_bytes_ref (backing));
+ return g_bytes_new_with_free_func (tlv->buf + tlv->off, tlv->len,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
}
guchar*
return TRUE;
}
-EggBytes *
+GBytes *
egg_asn1x_get_string_as_bytes (GNode *node)
{
gpointer raw;
if (raw == NULL)
return NULL;
- return egg_bytes_new_take (raw, length);
+ return g_bytes_new_take (raw, length);
}
gchar *
return egg_asn1x_set_string_as_raw (node, (guchar*)data, n_data, destroy);
}
-EggBytes *
+GBytes *
egg_asn1x_get_bits_as_raw (GNode *node, guint *n_bits)
{
- EggBytes *backing;
+ GBytes *backing;
guchar padded;
Atlv *tlv;
g_return_val_if_fail (tlv->len > 1, NULL);
*n_bits = ((tlv->len - 1) * 8) - padded;
- return egg_bytes_new_with_free_func (tlv->buf + tlv->off + 1, tlv->len - 1,
- egg_bytes_unref, egg_bytes_ref (backing));
+ return g_bytes_new_with_free_func (tlv->buf + tlv->off + 1, tlv->len - 1,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
}
void
egg_asn1x_set_bits_as_raw (GNode *node,
- EggBytes *value,
+ GBytes *value,
guint n_bits)
{
g_return_if_fail (value != NULL);
- egg_asn1x_take_bits_as_raw (node, egg_bytes_ref (value), n_bits);
+ egg_asn1x_take_bits_as_raw (node, g_bytes_ref (value), n_bits);
}
void
egg_asn1x_take_bits_as_raw (GNode *node,
- EggBytes *value,
+ GBytes *value,
guint n_bits)
{
gint type;
data[(length - i) - 1] = (value >> i * 8) & 0xFF;
ab = g_slice_new0 (Abits);
- ab->bits = egg_bytes_new_take (data, sizeof (gulong));
+ ab->bits = g_bytes_new_take (data, sizeof (gulong));
ab->n_bits = n_bits;
anode_encode_tlv_and_enc (node, length + 1, anode_encoder_bit_string, ab, abits_destroy);
GNode*
egg_asn1x_create_and_decode (const EggAsn1xDef *defs,
const gchar *identifier,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn;
#include <glib.h>
-#include "egg-bytes.h"
-
#ifndef HAVE_EGG_ALLOCATOR
typedef void* (*EggAllocator) (void* p, gsize);
#define HAVE_EGG_ALLOCATOR
GNode* egg_asn1x_create_and_decode (const EggAsn1xDef *defs,
const gchar *type,
- EggBytes *data);
+ GBytes *data);
void egg_asn1x_dump (GNode *asn);
void egg_asn1x_clear (GNode *asn);
gboolean egg_asn1x_decode (GNode *asn,
- EggBytes *data);
+ GBytes *data);
gboolean egg_asn1x_decode_no_validate (GNode *asn,
- EggBytes *data);
+ GBytes *data);
gboolean egg_asn1x_validate (GNode *asn,
gboolean strict);
-EggBytes * egg_asn1x_encode (GNode *asn,
+GBytes * egg_asn1x_encode (GNode *asn,
EggAllocator allocator);
const gchar* egg_asn1x_message (GNode *asn);
gboolean egg_asn1x_set_integer_as_ulong (GNode *node,
gulong value);
-EggBytes * egg_asn1x_get_integer_as_raw (GNode *node);
+GBytes * egg_asn1x_get_integer_as_raw (GNode *node);
void egg_asn1x_set_integer_as_raw (GNode *node,
- EggBytes *value);
+ GBytes *value);
void egg_asn1x_take_integer_as_raw (GNode *node,
- EggBytes *value);
+ GBytes *value);
-EggBytes * egg_asn1x_get_integer_as_usg (GNode *node);
+GBytes * egg_asn1x_get_integer_as_usg (GNode *node);
void egg_asn1x_set_integer_as_usg (GNode *node,
- EggBytes *value);
+ GBytes *value);
void egg_asn1x_take_integer_as_usg (GNode *node,
- EggBytes *value);
+ GBytes *value);
-EggBytes * egg_asn1x_get_raw_value (GNode *node);
+GBytes * egg_asn1x_get_raw_value (GNode *node);
-EggBytes * egg_asn1x_get_element_raw (GNode *node);
+GBytes * egg_asn1x_get_element_raw (GNode *node);
gboolean egg_asn1x_set_element_raw (GNode *node,
- EggBytes *value);
+ GBytes *value);
guchar* egg_asn1x_get_string_as_raw (GNode *node,
EggAllocator allocator,
gsize n_data,
GDestroyNotify destroy);
-EggBytes * egg_asn1x_get_string_as_bytes (GNode *node);
+GBytes * egg_asn1x_get_string_as_bytes (GNode *node);
-EggBytes * egg_asn1x_get_bits_as_raw (GNode *node,
+GBytes * egg_asn1x_get_bits_as_raw (GNode *node,
guint *n_bits);
void egg_asn1x_set_bits_as_raw (GNode *node,
- EggBytes *value,
+ GBytes *value,
guint n_bits);
void egg_asn1x_take_bits_as_raw (GNode *node,
- EggBytes *value,
+ GBytes *value,
guint n_bits);
gboolean egg_asn1x_get_bits_as_ulong (GNode *node,
+++ /dev/null
-/*
- * Copyright © 2009, 2010 Codethink Limited
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the licence, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Author: Ryan Lortie <desrt@desrt.ca>
- */
-
-#include "config.h"
-
-#include "egg-bytes.h"
-
-#include <glib.h>
-
-#include <string.h>
-
-struct _EggBytes
-{
- gconstpointer data;
- gsize size;
- gint ref_count;
- GDestroyNotify free_func;
- gpointer user_data;
-};
-
-/**
- * egg_bytes_new:
- * @data: (array length=size): the data to be used for the bytes
- * @size: the size of @data
- *
- * Creates a new #EggBytes from @data.
- *
- * @data is copied.
- *
- * Returns: (transfer full): a new #EggBytes
- *
- * Since: 2.32
- */
-EggBytes *
-egg_bytes_new (gconstpointer data,
- gsize size)
-{
- return egg_bytes_new_take (g_memdup (data, size), size);
-}
-
-/**
- * egg_bytes_new_take:
- * @data: (transfer full) (array length=size): the data to be used for the bytes
- * @size: the size of @data
- *
- * Creates a new #EggBytes from @data.
- *
- * After this call, @data belongs to the bytes and may no longer be
- * modified by the caller. g_free() will be called on @data when the
- * bytes is no longer in use. Because of this @data must have been created by
- * a call to g_malloc(), g_malloc0() or g_realloc() or by one of the many
- * functions that wrap these calls (such as g_new(), g_strdup(), etc).
- *
- * Returns: (transfer full): a new #EggBytes
- *
- * Since: 2.32
- */
-EggBytes *
-egg_bytes_new_take (gpointer data,
- gsize size)
-{
- return egg_bytes_new_with_free_func (data, size, g_free, data);
-}
-
-
-/**
- * egg_bytes_new_static:
- * @data: (array length=size): the data to be used for the bytes
- * @size: the size of @data
- *
- * Creates a new #EggBytes from static data.
- *
- * @data must be static (ie: never modified or freed).
- *
- * Returns: (transfer full): a new #EggBytes
- *
- * Since: 2.32
- */
-EggBytes *
-egg_bytes_new_static (gconstpointer data,
- gsize size)
-{
- return egg_bytes_new_with_free_func (data, size, NULL, NULL);
-}
-
-/**
- * egg_bytes_new_with_free_func:
- * @data: (array length=size): the data to be used for the bytes
- * @size: the size of @data
- * @free_func: the function to call to release the data
- * @user_data: data to pass to @free_func
- *
- * Creates a #EggBytes from @data.
- *
- * When the last reference is dropped, @free_func will be called with the
- * @user_data argument.
- *
- * @data must not be modified after this call is made until @free_func has
- * been called to indicate that the bytes is no longer in use.
- *
- * Returns: (transfer full): a new #EggBytes
- *
- * Since: 2.32
- */
-EggBytes *
-egg_bytes_new_with_free_func (gconstpointer data,
- gsize size,
- GDestroyNotify free_func,
- gpointer user_data)
-{
- EggBytes *bytes;
-
- bytes = g_slice_new (EggBytes);
- bytes->data = data;
- bytes->size = size;
- bytes->free_func = free_func;
- bytes->user_data = user_data;
- bytes->ref_count = 1;
-
- return (EggBytes *)bytes;
-}
-
-/**
- * egg_bytes_new_from_bytes:
- * @bytes: a #EggBytes
- * @offset: offset which subsection starts at
- * @length: length of subsucsection
- *
- * Creates a #EggBytes which is a subsection of another #EggBytes.
- *
- * A reference to @bytes will be held by the newly created #EggBytes until
- * the byte data is no longer needed.
- *
- * Returns: (transfer full): a new #EggBytes
- *
- * Since: 2.32
- */
-EggBytes *
-egg_bytes_new_from_bytes (EggBytes *bytes,
- goffset offset,
- gsize length)
-{
- g_return_val_if_fail (bytes != NULL, NULL);
- g_return_val_if_fail (offset <= bytes->size, NULL);
- g_return_val_if_fail (offset + length <= bytes->size, NULL);
-
- return egg_bytes_new_with_free_func ((gchar *)bytes->data + offset, length,
- egg_bytes_unref, egg_bytes_ref (bytes));
-}
-
-/**
- * egg_bytes_get_data:
- * @bytes: a #EggBytes
- *
- * Get the byte data in the #EggBytes. This data should not be modified.
- *
- * This function will always return the same pointer for a given #EggBytes.
- *
- * Returns: a pointer to the byte data
- *
- * Since: 2.32
- */
-gconstpointer
-egg_bytes_get_data (EggBytes *bytes)
-{
- g_return_val_if_fail (bytes != NULL, NULL);
- return bytes->data;
-}
-
-/**
- * egg_bytes_get_size:
- * @bytes: a #EggBytes
- *
- * Get the size of the byte data in the #EggBytes.
- *
- * This function will always return the same value for a given #EggBytes.
- *
- * Returns: the size
- *
- * Since: 2.32
- */
-gsize
-egg_bytes_get_size (EggBytes *bytes)
-{
- g_return_val_if_fail (bytes != NULL, 0);
- return bytes->size;
-}
-
-
-/**
- * egg_bytes_ref:
- * @bytes: a #EggBytes
- *
- * Increase the reference count on @bytes.
- *
- * Returns: (transfer full): the #EggBytes
- *
- * Since: 2.32
- */
-EggBytes *
-egg_bytes_ref (EggBytes *bytes)
-{
- g_return_val_if_fail (bytes != NULL, NULL);
-
- g_atomic_int_inc (&bytes->ref_count);
-
- return bytes;
-}
-
-/**
- * egg_bytes_unref:
- * @bytes: (transfer full) (type GLib.Bytes): a #EggBytes
- *
- * Releases a reference on @bytes. This may result in the bytes being
- * freed.
- *
- * Since: 2.32
- */
-void
-egg_bytes_unref (gpointer bytes)
-{
- EggBytes *bytes_ = bytes;
-
- g_return_if_fail (bytes_ != NULL);
-
- if (g_atomic_int_dec_and_test (&bytes_->ref_count))
- {
- if (bytes_->free_func != NULL)
- bytes_->free_func (bytes_->user_data);
- g_slice_free (EggBytes, bytes);
- }
-}
-
-/**
- * egg_bytes_equal:
- * @bytes1: (type GLib.Bytes): a pointer to a #EggBytes
- * @bytes2: (type GLib.Bytes): a pointer to a #EggBytes to compare with @bytes1
- *
- * Compares the two #EggBytes values being pointed to and returns
- * %TRUE if they are equal.
- *
- * This function can be passed to g_hash_table_new() as the @key_equal_func
- * parameter, when using non-%NULL #EggBytes pointers as keys in a #GHashTable.
- *
- * Returns: %TRUE if the two keys match.
- *
- * Since: 2.32
- */
-gboolean
-egg_bytes_equal (gconstpointer bytes1,
- gconstpointer bytes2)
-{
- const EggBytes *b1 = bytes1;
- const EggBytes *b2 = bytes2;
-
- g_return_val_if_fail (bytes1 != NULL, FALSE);
- g_return_val_if_fail (bytes2 != NULL, FALSE);
-
- return b1->size == b2->size &&
- memcmp (b1->data, b2->data, b1->size) == 0;
-}
-
-/**
- * egg_bytes_hash:
- * @bytes: (type GLib.Bytes): a pointer to a #EggBytes key
- *
- * Creates an integer hash code for the byte data in the #EggBytes.
- *
- * This function can be passed to g_hash_table_new() as the @key_equal_func
- * parameter, when using non-%NULL #EggBytes pointers as keys in a #GHashTable.
- *
- * Returns: a hash value corresponding to the key.
- *
- * Since: 2.32
- */
-guint
-egg_bytes_hash (gconstpointer bytes)
-{
- const EggBytes *a = bytes;
- const signed char *p, *e;
- guint32 h = 5381;
-
- g_return_val_if_fail (bytes != NULL, 0);
-
- for (p = (signed char *)a->data, e = (signed char *)a->data + a->size; p != e; p++)
- h = (h << 5) + h + *p;
-
- return h;
-}
-
-/**
- * egg_bytes_compare:
- * @bytes1: (type GLib.Bytes): a pointer to a #EggBytes
- * @bytes2: (type GLib.Bytes): a pointer to a #EggBytes to compare with @bytes1
- *
- * Compares the two #EggBytes values.
- *
- * This function can be passed to g_tree_new() when using non-%NULL #EggBytes
- * pointers as keys in a #GTree.
- *
- * Returns: a negative value if bytes2 is lesser, a positive value if bytes2 is
- * greater, and zero if bytes2 is equal to bytes1
- *
- * Since: 2.32
- */
-gint
-egg_bytes_compare (gconstpointer bytes1,
- gconstpointer bytes2)
-{
- const EggBytes *b1 = bytes1;
- const EggBytes *b2 = bytes2;
- gint ret;
-
- g_return_val_if_fail (bytes1 != NULL, 0);
- g_return_val_if_fail (bytes2 != NULL, 0);
-
- ret = memcmp (b1->data, b2->data, MIN (b1->size, b2->size));
- if (ret == 0 && b1->size != b2->size)
- ret = b1->size < b2->size ? -1 : 1;
- return ret;
-}
-
-/**
- * egg_bytes_unref_to_array:
- * @bytes: (transfer full): a #EggBytes
- *
- * Unreferences the bytes, and returns a new mutable #GByteArray containing
- * the same byte data.
- *
- * As an optimization, the byte data is transferred to the array without copying
- * if: this was the last reference to bytes and bytes was created with
- * egg_bytes_new(), egg_bytes_new_take() or g_byte_array_free_to_bytes(). In all
- * other cases the data is copied.
- *
- * Returns: (transfer full): a new mutable #GByteArray containing the same byte data
- *
- * Since: 2.32
- */
-GByteArray *
-egg_bytes_unref_to_array (EggBytes *bytes)
-{
- GByteArray *result = NULL;
-#if 0
- gpointer data;
- gsize size;
-#endif
-
- g_return_val_if_fail (bytes != NULL, NULL);
-
-#if 0
- data = egg_bytes_try_steal_and_unref (bytes, NULL, &size);
- if (data != NULL)
- {
- /*
- * Optimal path: if this is was the last reference, then we can have
- * the GByteArray assume the data from this EggBytes without copying.
- */
- result = g_byte_array_new_take (data, size);
- }
- else
-#endif
- {
- /*
- * Copy: Non g_malloc (or compatible) allocator, or static memory,
- * so we have to copy, and then unref.
- */
- result = g_byte_array_append (g_byte_array_new (), bytes->data, bytes->size);
- egg_bytes_unref (bytes);
- }
-
- return result;
-}
-
-/*
- * The behavior of this function with regards to references cannot be easily
- * modeled by most gobject-introspection consumers, so we use (skip).
- */
-
-/**
- * egg_bytes_try_steal_and_unref: (skip)
- * @bytes: a #EggBytes
- * @free_func: the function data is freed with, or %NULL for default
- * @size: location to return the length of the data
- *
- * This is an advanced function, and seldom used.
- *
- * Try to take ownership of the data in the byte array. This is only successful
- * if this is the last reference and @free_func matches the function that would
- * have been used to free the data. This is to demonstrate that the caller
- * is aware of the how the data in the #EggBytes was allocated. If %NULL is passed
- * for @free_func this represents the standard Glib allocation routines.
- *
- * You should use %NULL instead of passing g_free() for @free_func. This is
- * because the actual address of g_free() varies depending on how the calling
- * application and library was linked.
- *
- * If the attempt to take ownership of the byte data is successful according to
- * the above criteria, then the data is returned and @size is set to the length
- * of the data. The #EggBytes is unreferenced and is no longer valid.
- *
- * If the attempt to take ownership of the byte data is unsuccessful, %NULL is
- * returned. The #EggBytes is not unreferenced, and the caller must unreference
- * the #EggBytes elsewhere.
- *
- * It is always incorrect to ignore the return value from this function.
- *
- * Returns: the stolen data, or %NULL if attempt failed
- *
- * Since: 2.32
- */
-gpointer
-egg_bytes_try_steal_and_unref (EggBytes *bytes,
- GDestroyNotify free_func,
- gsize *size)
-{
- gpointer result;
-
- g_return_val_if_fail (bytes != NULL, NULL);
- g_return_val_if_fail (size != NULL, NULL);
-
- if (free_func == NULL)
- free_func = g_free;
- if (bytes->free_func != free_func)
- return NULL;
-
- /* Are we the only reference? */
- if (g_atomic_int_get (&bytes->ref_count) == 1)
- {
- *size = bytes->size;
- result = (gpointer)bytes->data;
- g_slice_free (EggBytes, bytes);
- return result;
- }
-
- return NULL;
-}
+++ /dev/null
-/*
- * Copyright © 2009, 2010 Codethink Limited
- * Copyright © 2011 Collabora Ltd.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the licence, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Author: Ryan Lortie <desrt@desrt.ca>
- * Stef Walter <stefw@collabora.co.uk>
- */
-
-#ifndef __EGG_BYTES_H__
-#define __EGG_BYTES_H__
-
-#include <glib.h>
-
-/**
- * EggBytes:
- *
- * A simple refcounted data type representing an immutable byte sequence
- * from an unspecified origin.
- *
- * The purpose of a #EggBytes is to keep the memory region that it holds
- * alive for as long as anyone holds a reference to the bytes. When
- * the last reference count is dropped, the memory is released. Multiple
- * unrelated callers can use byte data in the #EggBytes without coordinating
- * their activities, resting assured that the byte data will not change or
- * move while they hold a reference.
- *
- * A #EggBytes can come from many different origins that may have
- * different procedures for freeing the memory region. Examples are
- * memory from g_malloc(), from memory slices, from a #GMappedFile or
- * memory from other allocators.
- *
- * #EggBytes work well as keys in #GHashTable. Use egg_bytes_equal() and
- * egg_bytes_hash() as parameters to g_hash_table_new() or g_hash_table_new_full().
- * #EggBytes can also be used as keys in a #GTree by passing the egg_bytes_compare()
- * function to g_tree_new().
- *
- * The data pointed to by this bytes must not be modified. For a mutable
- * array of bytes see #GByteArray. Use egg_bytes_unref_to_array() to create a
- * mutable array for a #EggBytes sequence. To create an immutable #EggBytes from
- * a mutable #GByteArray, use the g_byte_array_free_to_bytes() function.
- *
- * Since: 2.32
- **/
-
-typedef struct _EggBytes EggBytes;
-
-EggBytes * egg_bytes_new (gconstpointer data,
- gsize size);
-
-EggBytes * egg_bytes_new_take (gpointer data,
- gsize size);
-
-EggBytes * egg_bytes_new_static (gconstpointer data,
- gsize size);
-
-EggBytes * egg_bytes_new_with_free_func (gconstpointer data,
- gsize size,
- GDestroyNotify free_func,
- gpointer user_data);
-
-EggBytes * egg_bytes_new_from_bytes (EggBytes *bytes,
- goffset offset,
- gsize length);
-
-gconstpointer egg_bytes_get_data (EggBytes *bytes);
-
-gsize egg_bytes_get_size (EggBytes *bytes);
-
-EggBytes * egg_bytes_ref (EggBytes *bytes);
-
-void egg_bytes_unref (gpointer bytes);
-
-GByteArray * egg_bytes_unref_to_array (EggBytes *bytes);
-
-gpointer egg_bytes_try_steal_and_unref (EggBytes *bytes,
- GDestroyNotify free_func,
- gsize *size);
-
-guint egg_bytes_hash (gconstpointer bytes);
-
-gboolean egg_bytes_equal (gconstpointer bytes1,
- gconstpointer bytes2);
-
-gint egg_bytes_compare (gconstpointer bytes1,
- gconstpointer bytes2);
-
-#endif /* __EGG_BYTES_H__ */
static const char HEXC[] = "0123456789ABCDEF";
static gchar*
-dn_print_hex_value (EggBytes *val)
+dn_print_hex_value (GBytes *val)
{
- const gchar *data = egg_bytes_get_data (val);
- gsize size = egg_bytes_get_size (val);
+ const gchar *data = g_bytes_get_data (val, NULL);
+ gsize size = g_bytes_get_size (val);
GString *result = g_string_sized_new (size * 2 + 1);
gsize i;
static gchar*
dn_print_oid_value_parsed (GQuark oid,
guint flags,
- EggBytes *val)
+ GBytes *val)
{
GNode *asn1, *node;
- EggBytes *value;
+ GBytes *value;
const gchar *data;
gsize size;
gchar *result;
node = asn1;
value = egg_asn1x_get_raw_value (node);
- data = egg_bytes_get_data (value);
- size = egg_bytes_get_size (value);
+ data = g_bytes_get_data (value, &size);
/*
* Now we make sure it's UTF-8.
result = g_strndup (data, size);
}
- egg_bytes_unref (value);
+ g_bytes_unref (value);
egg_asn1x_destroy (asn1);
return result;
static gchar*
dn_print_oid_value (GQuark oid,
guint flags,
- EggBytes *val)
+ GBytes *val)
{
gchar *value;
const gchar *name;
guint flags;
GQuark oid;
- EggBytes *value;
+ GBytes *value;
gchar *display;
gchar *result;
"=", display, NULL);
g_free (display);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
return result;
}
{
gboolean done = FALSE;
const gchar *name;
- EggBytes *value;
+ GBytes *value;
GNode *node;
GQuark oid;
gint i, j;
g_return_val_if_fail (value, NULL);
result = dn_print_oid_value (oid, egg_oid_get_flags (oid), value);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
return result;
}
}
{
gboolean done = FALSE;
GNode *node;
- EggBytes *value;
+ GBytes *value;
GQuark oid;
guint i, j;
if (callback)
(callback) (i, oid, value, user_data);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
}
}
gchar *
egg_dn_print_value (GQuark oid,
- EggBytes *value)
+ GBytes *value)
{
g_return_val_if_fail (oid != 0, NULL);
g_return_val_if_fail (value != NULL, NULL);
GQuark oid,
const gchar *string)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *node;
GNode *value;
GNode *val;
g_return_if_reached ();
egg_asn1x_destroy (value);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
#include <glib.h>
-#include "egg/egg-bytes.h"
-
gchar* egg_dn_read (GNode *node);
gchar* egg_dn_read_part (GNode *node,
typedef void (*EggDnCallback) (guint index,
GQuark oid,
- EggBytes *value,
+ GBytes *value,
gpointer user_data);
gboolean egg_dn_parse (GNode *node,
gpointer user_data);
gchar* egg_dn_print_value (GQuark oid,
- EggBytes *value);
+ GBytes *value);
void egg_dn_add_string_part (GNode *node,
GQuark oid,
egg_openssl_decrypt_block (const gchar *dekinfo,
const gchar *password,
gssize n_password,
- EggBytes *data,
+ GBytes *data,
gsize *n_decrypted)
{
gcry_cipher_hd_t ch;
g_free (iv);
/* Allocate output area */
- *n_decrypted = egg_bytes_get_size (data);
+ *n_decrypted = g_bytes_get_size (data);
decrypted = egg_secure_alloc (*n_decrypted);
gcry = gcry_cipher_decrypt (ch, decrypted, *n_decrypted,
- egg_bytes_get_data (data),
- egg_bytes_get_size (data));
+ g_bytes_get_data (data, NULL),
+ g_bytes_get_size (data));
if (gcry) {
egg_secure_free (decrypted);
g_return_val_if_reached (NULL);
egg_openssl_encrypt_block (const gchar *dekinfo,
const gchar *password,
gssize n_password,
- EggBytes *data,
+ GBytes *data,
gsize *n_encrypted)
{
gsize n_overflow, n_batch, n_padding;
g_return_val_if_fail (!gcry, NULL);
g_free (iv);
- dat = egg_bytes_get_data (data);
- n_data = egg_bytes_get_size (data);
+ dat = g_bytes_get_data (data, &n_data);
/* Allocate output area */
n_overflow = (n_data % ivlen);
#include <glib.h>
-#include <egg/egg-bytes.h>
-
int egg_openssl_parse_algo (const gchar *name, int *mode);
guchar * egg_openssl_encrypt_block (const gchar *dekinfo,
const gchar *password,
gssize n_password,
- EggBytes *data,
+ GBytes *data,
gsize *n_encrypted);
guchar * egg_openssl_decrypt_block (const gchar *dekinfo,
const gchar *password,
gssize n_password,
- EggBytes *data,
+ GBytes *data,
gsize *n_decrypted);
const gchar* egg_openssl_get_dekinfo (GHashTable *headers);
int hash_algo,
const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_cipher_hd_t *cih)
{
GNode *asn = NULL;
gcry_error_t gcry;
- EggBytes *salt = NULL;
+ GBytes *salt = NULL;
gsize n_block, n_key;
gulong iterations;
guchar *key = NULL;
n_block = gcry_cipher_get_algo_blklen (cipher_algo);
if (!egg_symkey_generate_pbe (cipher_algo, hash_algo, password, n_password,
- egg_bytes_get_data (salt), egg_bytes_get_size (salt),
+ g_bytes_get_data (salt, NULL), g_bytes_get_size (salt),
iterations, &key, n_block > 1 ? &iv : NULL))
goto done;
done:
g_free (iv);
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
egg_secure_free (key);
egg_asn1x_destroy (asn);
}
static gboolean
-setup_pkcs5_rc2_params (EggBytes *data,
+setup_pkcs5_rc2_params (GBytes *data,
gcry_cipher_hd_t cih)
{
GNode *asn = NULL;
gcry_error_t gcry;
- EggBytes *iv = NULL;
+ GBytes *iv = NULL;
gulong version;
gboolean ret = FALSE;
if (!iv)
goto done;
- gcry = gcry_cipher_setiv (cih, egg_bytes_get_data (iv), egg_bytes_get_size (iv));
+ gcry = gcry_cipher_setiv (cih, g_bytes_get_data (iv, NULL), g_bytes_get_size (iv));
if (gcry != 0) {
- g_message ("couldn't set %lu byte iv on cipher", (gulong)egg_bytes_get_size (iv));
+ g_message ("couldn't set %lu byte iv on cipher", (gulong)g_bytes_get_size (iv));
goto done;
}
done:
if (iv != NULL)
- egg_bytes_unref (iv);
+ g_bytes_unref (iv);
egg_asn1x_destroy (asn);
return ret;
}
static gboolean
-setup_pkcs5_des_params (EggBytes *data,
+setup_pkcs5_des_params (GBytes *data,
gcry_cipher_hd_t cih)
{
GNode *asn = NULL;
gcry_error_t gcry;
- EggBytes *iv;
+ GBytes *iv;
gboolean ret;
g_assert (data);
if (!iv)
return FALSE;
- gcry = gcry_cipher_setiv (cih, egg_bytes_get_data (iv), egg_bytes_get_size (iv));
+ gcry = gcry_cipher_setiv (cih, g_bytes_get_data (iv, NULL), g_bytes_get_size (iv));
if (gcry != 0) {
- g_message ("couldn't set %lu byte iv on cipher", (gulong)egg_bytes_get_size (iv));
+ g_message ("couldn't set %lu byte iv on cipher", (gulong)g_bytes_get_size (iv));
ret = FALSE;
} else {
ret = TRUE;
}
- egg_bytes_unref (iv);
+ g_bytes_unref (iv);
return ret;
}
static gboolean
setup_pkcs5_pbkdf2_params (const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
int cipher_algo,
gcry_cipher_hd_t cih)
{
gboolean ret;
gcry_error_t gcry;
guchar *key = NULL;
- EggBytes *salt = NULL;
+ GBytes *salt = NULL;
gsize n_key;
gulong iterations;
goto done;
if (!egg_symkey_generate_pbkdf2 (cipher_algo, GCRY_MD_SHA1, password, n_password,
- egg_bytes_get_data (salt), egg_bytes_get_size (salt),
+ g_bytes_get_data (salt, NULL), g_bytes_get_size (salt),
iterations, &key, NULL))
goto done;
done:
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
egg_secure_free (key);
egg_asn1x_destroy (asn);
return ret;
static gboolean
read_cipher_pkcs5_pbes2 (const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_cipher_hd_t *cih)
{
GNode *asn = NULL;
gboolean r, ret;
GQuark key_deriv_algo, enc_oid;
- EggBytes *params = NULL;
+ GBytes *params = NULL;
gcry_error_t gcry;
int algo, mode;
goto done;
}
- egg_bytes_unref (params);
+ g_bytes_unref (params);
params = egg_asn1x_get_element_raw (egg_asn1x_node (asn, "keyDerivationFunc", "parameters", NULL));
if (!params)
goto done;
}
if (params != NULL)
- egg_bytes_unref (params);
+ g_bytes_unref (params);
egg_asn1x_destroy (asn);
return ret;
}
int cipher_mode,
const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_cipher_hd_t *cih)
{
GNode *asn = NULL;
gcry_error_t gcry;
gboolean ret;
- EggBytes *salt = NULL;
+ GBytes *salt = NULL;
gsize n_block, n_key;
gulong iterations;
guchar *key = NULL;
/* Generate IV and key using salt read above */
if (!egg_symkey_generate_pkcs12 (cipher_algo, GCRY_MD_SHA1, password, n_password,
- egg_bytes_get_data (salt), egg_bytes_get_size (salt),
+ g_bytes_get_data (salt, NULL), g_bytes_get_size (salt),
iterations, &key, n_block > 1 ? &iv : NULL))
goto done;
}
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
g_free (iv);
egg_secure_free (key);
egg_asn1x_destroy (asn);
read_mac_pkcs12_pbe (int hash_algo,
const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_md_hd_t *mdh,
gsize *digest_len)
{
gcry_error_t gcry;
gboolean ret;
gsize n_key;
- EggBytes *salt = NULL;
+ GBytes *salt = NULL;
gulong iterations;
guchar *key = NULL;
/* Generate IV and key using salt read above */
if (!egg_symkey_generate_pkcs12_mac (hash_algo, password, n_password,
- egg_bytes_get_data (salt), egg_bytes_get_size (salt),
+ g_bytes_get_data (salt, NULL), g_bytes_get_size (salt),
iterations, &key))
goto done;
}
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
egg_secure_free (key);
egg_asn1x_destroy (asn);
return ret;
egg_symkey_read_cipher (GQuark oid_scheme,
const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_cipher_hd_t *cih)
{
gboolean ret = FALSE;
egg_symkey_read_mac (GQuark oid_scheme,
const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_md_hd_t *mdh,
gsize *digest_len)
{
#include <gcrypt.h>
-#include <egg/egg-bytes.h>
-
gboolean egg_symkey_generate_simple (int cipher_algo,
int hash_algo,
const gchar *password,
gboolean egg_symkey_read_cipher (GQuark oid_scheme,
const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_cipher_hd_t *cih);
gboolean egg_symkey_read_mac (GQuark oid_scheme,
const gchar *password,
gsize n_password,
- EggBytes *data,
+ GBytes *data,
gcry_md_hd_t *mdh,
gsize *digest_len);
#define egg_assert_cmpbytes(a, cmp, b, nb) \
do { gpointer __p1 = (gpointer)(a); gconstpointer __p2 = (b); gsize __n2 = (nb); \
- if (egg_bytes_get_size (__p1) cmp __n2 && memcmp (egg_bytes_get_data (__p1), __p2, __n2) cmp 0) ; else \
+ if (g_bytes_get_size (__p1) cmp __n2 && memcmp (g_bytes_get_data (__p1, NULL), __p2, __n2) cmp 0) ; else \
egg_assertion_message_cmpmem (G_LOG_DOMAIN, __FILE__, __LINE__, \
G_STRFUNC, #a " " #cmp " " #b, \
- egg_bytes_get_data (__p1), egg_bytes_get_size(__p1), #cmp, __p2, __n2); } while (0)
+ g_bytes_get_data (__p1, NULL), g_bytes_get_size(__p1), #cmp, __p2, __n2); } while (0)
void egg_assertion_message_cmpmem (const char *domain, const char *file,
int line, const char *func,
static void
test_boolean (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gboolean value;
g_assert_not_reached ();
/* Decode a false */
- bytes = egg_bytes_new_static (BFALSE, XL (BFALSE));
+ bytes = g_bytes_new_static (BFALSE, XL (BFALSE));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
value = TRUE;
if (!egg_asn1x_get_boolean (asn, &value))
g_assert_not_reached ();
g_assert (value == FALSE);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
/* Decode a true */
- bytes = egg_bytes_new_static (BTRUE, XL (BTRUE));
+ bytes = g_bytes_new_static (BTRUE, XL (BTRUE));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
value = FALSE;
if (!egg_asn1x_get_boolean (asn, &value))
g_assert_not_reached ();
g_assert (value == TRUE);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
egg_asn1x_clear (asn);
test_null (void)
{
GNode *asn;
- EggBytes *data;
+ GBytes *data;
asn = egg_asn1x_create (test_asn1_tab, "TestNull");
g_assert (asn);
g_assert_not_reached ();
data = egg_asn1x_encode (asn, g_realloc);
- egg_assert_cmpmem (NULL_TEST, XL (NULL_TEST), ==, egg_bytes_get_data (data), egg_bytes_get_size (data));
+ egg_assert_cmpmem (NULL_TEST, XL (NULL_TEST), ==, g_bytes_get_data (data, NULL), g_bytes_get_size (data));
if (!egg_asn1x_decode (asn, data))
g_assert_not_reached ();
egg_asn1x_destroy (asn);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
}
static void
{
GNode *asn;
gulong value;
- EggBytes *bytes;
+ GBytes *bytes;
asn = egg_asn1x_create (test_asn1_tab, "TestInteger");
g_assert (asn);
g_assert_not_reached ();
/* Should suceed now */
- bytes = egg_bytes_new_static (I33, XL (I33));
+ bytes = g_bytes_new_static (I33, XL (I33));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
if (!egg_asn1x_get_integer_as_ulong (asn, &value))
g_assert_not_reached ();
g_assert (value == 42);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
egg_asn1x_clear (asn);
{
GNode *asn;
gulong value;
- EggBytes *check;
+ GBytes *check;
guchar val;
- EggBytes *bytes;
- EggBytes *usg;
+ GBytes *bytes;
+ GBytes *usg;
asn = egg_asn1x_create (test_asn1_tab, "TestInteger");
g_assert (asn);
g_assert_cmpint (EGG_ASN1X_INTEGER, ==, egg_asn1x_type (asn));
/* Check with ulong */
- bytes = egg_bytes_new_static (I253, XL (I253));
+ bytes = g_bytes_new_static (I253, XL (I253));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
if (!egg_asn1x_get_integer_as_ulong (asn, &value))
g_assert_not_reached ();
g_assert (value == 253);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
egg_asn1x_clear (asn);
g_assert_not_reached ();
check = egg_asn1x_encode (asn, NULL);
- egg_assert_cmpmem (I253, XL (I253), ==, egg_bytes_get_data (check), egg_bytes_get_size (check));
- egg_bytes_unref (check);
+ egg_assert_cmpmem (I253, XL (I253), ==, g_bytes_get_data (check, NULL), g_bytes_get_size (check));
+ g_bytes_unref (check);
/* Now check with usg */
- bytes = egg_bytes_new_static (I253, XL (I253));
+ bytes = g_bytes_new_static (I253, XL (I253));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
val = 0xFD; /* == 253 */
usg = egg_asn1x_get_integer_as_usg (asn);
- egg_assert_cmpmem (&val, 1, ==, egg_bytes_get_data (usg), egg_bytes_get_size (usg));
- egg_bytes_unref (usg);
+ egg_assert_cmpmem (&val, 1, ==, g_bytes_get_data (usg, NULL), g_bytes_get_size (usg));
+ g_bytes_unref (usg);
egg_asn1x_clear (asn);
- egg_asn1x_take_integer_as_usg (asn, egg_bytes_new_static (&val, 1));
+ egg_asn1x_take_integer_as_usg (asn, g_bytes_new_static (&val, 1));
check = egg_asn1x_encode (asn, NULL);
- egg_assert_cmpsize (egg_bytes_get_size (check), ==, XL (I253));
- egg_assert_cmpmem (I253, XL (I253), ==, egg_bytes_get_data (check), egg_bytes_get_size (check));
- egg_bytes_unref (check);
+ egg_assert_cmpsize (g_bytes_get_size (check), ==, XL (I253));
+ egg_assert_cmpmem (I253, XL (I253), ==, g_bytes_get_data (check, NULL), g_bytes_get_size (check));
+ g_bytes_unref (check);
egg_asn1x_destroy (asn);
}
{
GNode *asn;
gchar *value;
- EggBytes *bytes;
+ GBytes *bytes;
asn = egg_asn1x_create (test_asn1_tab, "TestOctetString");
g_assert (asn);
g_assert_not_reached ();
/* Should work */
- bytes = egg_bytes_new_static (SFARNSWORTH, XL (SFARNSWORTH));
+ bytes = g_bytes_new_static (SFARNSWORTH, XL (SFARNSWORTH));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
value = egg_asn1x_get_string_as_utf8 (asn, NULL);
g_assert_cmpstr (value, ==, "farnsworth");
static void
test_generalized_time (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
glong value;
g_assert (value == -1);
/* Should work */
- bytes = egg_bytes_new_static (TGENERALIZED, XL (TGENERALIZED));
+ bytes = g_bytes_new_static (TGENERALIZED, XL (TGENERALIZED));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
value = egg_asn1x_get_time_as_long (asn);
g_assert (value == 1185368728);
static void
test_implicit_encode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gchar *value;
g_assert (asn);
/* Should work */
- bytes = egg_bytes_new_static (SIMPLICIT, XL (SIMPLICIT));
+ bytes = g_bytes_new_static (SIMPLICIT, XL (SIMPLICIT));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
value = egg_asn1x_get_string_as_utf8 (asn, NULL);
g_assert_cmpstr (value, ==, "implicit");
g_free (value);
static void
test_implicit_decode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestImplicit");
egg_assert_cmpbytes (bytes, ==, SIMPLICIT, XL (SIMPLICIT));
egg_asn1x_destroy (asn);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
test_explicit_decode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gchar *value;
g_assert (asn);
/* Should work */
- bytes = egg_bytes_new_static (SEXPLICIT, XL (SEXPLICIT));
+ bytes = g_bytes_new_static (SEXPLICIT, XL (SEXPLICIT));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
value = egg_asn1x_get_string_as_utf8 (asn, NULL);
g_assert_cmpstr (value, ==, "explicit");
static void
test_explicit_encode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestExplicit");
egg_assert_cmpbytes (bytes, ==, SEXPLICIT, XL (SEXPLICIT));
egg_asn1x_destroy (asn);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
test_universal_decode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gchar *value;
g_assert (asn);
/* Should work */
- bytes = egg_bytes_new_static (SUNIVERSAL, XL (SUNIVERSAL));
+ bytes = g_bytes_new_static (SUNIVERSAL, XL (SUNIVERSAL));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
value = egg_asn1x_get_string_as_utf8 (asn, NULL);
g_assert_cmpstr (value, ==, "universal");
static void
test_universal_encode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestUniversal");
egg_assert_cmpbytes (bytes, ==, SUNIVERSAL, XL (SUNIVERSAL));
egg_asn1x_destroy (asn);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
test_bit_string_decode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
- EggBytes *bits;
+ GBytes *bits;
guint n_bits;
const guchar *data;
g_assert_cmpint (EGG_ASN1X_BIT_STRING, ==, egg_asn1x_type (asn));
/* Should work */
- bytes = egg_bytes_new_static (BITS_TEST, XL (BITS_TEST));
+ bytes = g_bytes_new_static (BITS_TEST, XL (BITS_TEST));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
bits = egg_asn1x_get_bits_as_raw (asn, &n_bits);
g_assert (bits != NULL);
g_assert_cmpuint (n_bits, ==, 18);
- data = egg_bytes_get_data (bits);
+ data = g_bytes_get_data (bits, NULL);
g_assert_cmpint (data[0], ==, 0x6e);
g_assert_cmpint (data[1], ==, 0x5d);
g_assert_cmpint (data[2], ==, 0xc0);
- egg_bytes_unref (bits);
+ g_bytes_unref (bits);
egg_asn1x_destroy (asn);
}
static void
test_bit_string_decode_bad (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestBitString");
g_assert (asn);
/* Should not work */
- bytes = egg_bytes_new_static (BITS_BAD, XL (BITS_BAD));
+ bytes = g_bytes_new_static (BITS_BAD, XL (BITS_BAD));
if (egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
egg_asn1x_destroy (asn);
}
static void
test_bit_string_decode_ulong (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gulong bits;
guint n_bits;
g_assert (asn);
/* Should work */
- bytes = egg_bytes_new_static (BITS_TEST, XL (BITS_TEST));
+ bytes = g_bytes_new_static (BITS_TEST, XL (BITS_TEST));
if (!egg_asn1x_decode (asn, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
if (!egg_asn1x_get_bits_as_ulong (asn, &bits, &n_bits))
g_assert_not_reached ();
static void
test_bit_string_encode_decode (void)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
guchar bits[] = { 0x5d, 0x6e, 0x83 };
- EggBytes *check;
+ GBytes *check;
const guchar *ch;
guint n_bits = 17;
guint n_check;
asn = egg_asn1x_create (test_asn1_tab, "TestBitString");
g_assert (asn);
- egg_asn1x_take_bits_as_raw (asn, egg_bytes_new (bits, 3), n_bits);
+ egg_asn1x_take_bits_as_raw (asn, g_bytes_new (bits, 3), n_bits);
data = egg_asn1x_encode (asn, NULL);
g_assert (data);
if (!egg_asn1x_decode (asn, data))
g_assert_not_reached ();
- egg_bytes_unref (data);
+ g_bytes_unref (data);
check = egg_asn1x_get_bits_as_raw (asn, &n_check);
g_assert (check != NULL);
g_assert_cmpuint (n_check, ==, 17);
- ch = egg_bytes_get_data (check);
+ ch = g_bytes_get_data (check, NULL);
g_assert_cmpint (ch[0], ==, 0x5d);
g_assert_cmpint (ch[1], ==, 0x6e);
g_assert_cmpint (ch[2], ==, 0x80);
- egg_bytes_unref (check);
+ g_bytes_unref (check);
egg_asn1x_destroy (asn);
}
static void
test_bit_string_encode_decode_ulong (void)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
gulong check, bits = 0x0101b977;
guint n_check, n_bits = 18;
if (!egg_asn1x_decode (asn, data))
g_assert_not_reached ();
- egg_bytes_unref (data);
+ g_bytes_unref (data);
if (!egg_asn1x_get_bits_as_ulong (asn, &check, &n_check))
g_assert_not_reached ();
static void
test_bit_string_encode_decode_zero (void)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestBitString");
g_assert (asn);
- egg_asn1x_take_bits_as_raw (asn, egg_bytes_new_static ("", 0), 0);
+ egg_asn1x_take_bits_as_raw (asn, g_bytes_new_static ("", 0), 0);
data = egg_asn1x_encode (asn, NULL);
g_assert (data);
- egg_assert_cmpmem (egg_bytes_get_data (data), egg_bytes_get_size (data), ==, BITS_ZERO, XL (BITS_ZERO));
+ egg_assert_cmpmem (g_bytes_get_data (data, NULL), g_bytes_get_size (data), ==, BITS_ZERO, XL (BITS_ZERO));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
static void
test_have (void)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestBoolean");
g_assert (egg_asn1x_have (asn));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
static void
test_any_set_raw (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn, *node;
- EggBytes *data;
- EggBytes *check;
+ GBytes *data;
+ GBytes *check;
/* ENCODED SEQUENCE ANY with OCTET STRING */
const gchar SEQ_ENCODING[] = "\x30\x0C\x04\x0A""farnsworth";
node = egg_asn1x_node (asn, "contents", NULL);
g_assert (node);
- bytes = egg_bytes_new_with_free_func (SFARNSWORTH, XL (SFARNSWORTH),
+ bytes = g_bytes_new_with_free_func (SFARNSWORTH, XL (SFARNSWORTH),
test_is_freed, NULL);
if (!egg_asn1x_set_element_raw (node, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
data = egg_asn1x_encode (asn, NULL);
g_assert (data != NULL);
egg_assert_cmpbytes (check, ==, SFARNSWORTH, XL (SFARNSWORTH));
- egg_bytes_unref (data);
- egg_bytes_unref (check);
+ g_bytes_unref (data);
+ g_bytes_unref (check);
egg_asn1x_destroy (asn);
g_assert (is_freed);
}
static void
test_any_set_raw_explicit (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn, *node;
- EggBytes *data;
- EggBytes *check;
+ GBytes *data;
+ GBytes *check;
/* ENCODED SEQUENCE [89] ANY with OCTET STRING */
const gchar SEQ_ENCODING[] = "\x30\x0F\xBF\x59\x0C\x04\x0A""farnsworth";
node = egg_asn1x_node (asn, "contents", NULL);
g_assert (node);
- bytes = egg_bytes_new_with_free_func (SFARNSWORTH, XL (SFARNSWORTH), test_is_freed, NULL);
+ bytes = g_bytes_new_with_free_func (SFARNSWORTH, XL (SFARNSWORTH), test_is_freed, NULL);
if (!egg_asn1x_set_element_raw (node, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
data = egg_asn1x_encode (asn, NULL);
g_assert (data != NULL);
egg_assert_cmpbytes (check, ==, SFARNSWORTH, XL (SFARNSWORTH));
- egg_bytes_unref (data);
- egg_bytes_unref (check);
+ g_bytes_unref (data);
+ g_bytes_unref (check);
egg_asn1x_destroy (asn);
g_assert (is_freed);
}
static void
test_choice_not_chosen (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn, *node;
- EggBytes *data;
+ GBytes *data;
asn = egg_asn1x_create (test_asn1_tab, "TestAnyChoice");
g_assert (asn);
node = egg_asn1x_node (asn, "choiceShortTag", NULL);
g_assert (node);
- bytes = egg_bytes_new_static (SFARNSWORTH, XL (SFARNSWORTH));
+ bytes = g_bytes_new_static (SFARNSWORTH, XL (SFARNSWORTH));
if (!egg_asn1x_set_element_raw (node, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
/* egg_asn1x_set_choice() was not called */
data = egg_asn1x_encode (asn, NULL);
static void
perform_asn1_any_choice_set_raw (const gchar *choice, const gchar *encoding, gsize n_encoding)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn, *node;
- EggBytes *data;
- EggBytes *check;
+ GBytes *data;
+ GBytes *check;
asn = egg_asn1x_create (test_asn1_tab, "TestAnyChoice");
g_assert (asn);
if (!egg_asn1x_set_choice (asn, node))
g_assert_not_reached ();
- bytes = egg_bytes_new_with_free_func (SFARNSWORTH, XL (SFARNSWORTH), test_is_freed, NULL);
+ bytes = g_bytes_new_with_free_func (SFARNSWORTH, XL (SFARNSWORTH), test_is_freed, NULL);
if (!egg_asn1x_set_element_raw (node, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
data = egg_asn1x_encode (asn, NULL);
if (data == NULL) {
egg_assert_cmpbytes (check, ==, SFARNSWORTH, XL (SFARNSWORTH));
- egg_bytes_unref (data);
- egg_bytes_unref (check);
+ g_bytes_unref (data);
+ g_bytes_unref (check);
egg_asn1x_destroy (asn);
g_assert (is_freed);
}
static void
test_append (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
GNode *child;
- EggBytes *data;
+ GBytes *data;
/* SEQUENCE OF with one INTEGER = 1 */
const gchar SEQOF_ONE[] = "\x30\x03\x02\x01\x01";
/* SEQUENCE OF with two INTEGER = 1, 2 */
const gchar SEQOF_TWO[] = "\x30\x06\x02\x01\x01\x02\x01\x02";
- bytes = egg_bytes_new_static (SEQOF_ONE, XL (SEQOF_ONE));
+ bytes = g_bytes_new_static (SEQOF_ONE, XL (SEQOF_ONE));
asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestSeqOf", bytes);
g_assert (asn);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
g_assert_cmpint (EGG_ASN1X_SEQUENCE_OF, ==, egg_asn1x_type (asn));
egg_assert_cmpbytes (data, ==, SEQOF_TWO, XL (SEQOF_TWO));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
static void
test_append_and_clear (void)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestSeqOf");
g_assert_cmpuint (egg_asn1x_count (asn), ==, 0);
egg_asn1x_destroy (asn);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
}
static void
test_setof (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
- EggBytes *data;
+ GBytes *data;
/* SEQUENCE OF with one INTEGER = 3 */
const gchar SETOF_ONE[] = "\x31\x03\x02\x01\x03";
/* SET OF with two INTEGER = 1, 3, 8 */
const gchar SETOF_THREE[] = "\x31\x09\x02\x01\x01\x02\x01\x03\x02\x01\x08";
- bytes = egg_bytes_new_static (SETOF_ONE, XL (SETOF_ONE));
+ bytes = g_bytes_new_static (SETOF_ONE, XL (SETOF_ONE));
asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestSetOf", bytes);
g_assert (asn != NULL);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
g_assert_cmpint (EGG_ASN1X_SET_OF, ==, egg_asn1x_type (asn));
egg_assert_cmpbytes (data, ==, SETOF_THREE, XL (SETOF_THREE));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
static void
test_setof_empty (void)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
/* SEQUENCE OF with nothing */
egg_assert_cmpbytes (data, ==, SETOF_NONE, XL (SETOF_NONE));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
static void
test_enumerated (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
- EggBytes *data;
+ GBytes *data;
GQuark value;
- bytes = egg_bytes_new_static (ENUM_TWO, XL (ENUM_TWO));
+ bytes = g_bytes_new_static (ENUM_TWO, XL (ENUM_TWO));
asn = egg_asn1x_create_and_decode (test_asn1_tab, "TestEnumerated", bytes);
g_assert (asn != NULL);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
g_assert_cmpint (EGG_ASN1X_ENUMERATED, ==, egg_asn1x_type (asn));
egg_assert_cmpbytes (data, ==, ENUM_THREE, XL (ENUM_THREE));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
static void
setup (Test *test, gconstpointer unused)
{
- EggBytes *bytes;
+ GBytes *bytes;
if (!g_file_get_contents (SRCDIR "/files/test-certificate-1.der",
(gchar**)&test->data, &test->n_data, NULL))
test->asn1 = egg_asn1x_create (pkix_asn1_tab, "Certificate");
g_assert (test->asn1 != NULL);
- bytes = egg_bytes_new_static (test->data, test->n_data);
+ bytes = g_bytes_new_static (test->data, test->n_data);
if (!egg_asn1x_decode (test->asn1, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
static void
test_asn1_integers (Test* test, gconstpointer unused)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
gboolean ret;
gulong val;
g_assert_cmpuint (val, ==, 209384022);
egg_asn1x_destroy (asn);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
}
static void
test_boolean_seq (Test* test, gconstpointer unused)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn = NULL;
gboolean value, ret;
ret = egg_asn1x_set_boolean (egg_asn1x_node (asn, "boolean", NULL), FALSE);
g_assert (ret == TRUE);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
data = egg_asn1x_encode (asn, NULL);
g_assert (data != NULL);
g_assert (ret);
g_assert (value == FALSE);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
static void
test_write_value (Test* test, gconstpointer unused)
{
- EggBytes *encoded;
+ GBytes *encoded;
GNode *asn = NULL;
guchar *data;
gsize n_data;
g_assert (memcmp (data, "SOME DATA", 9) == 0);
g_free (data);
- egg_bytes_unref (encoded);
+ g_bytes_unref (encoded);
egg_asn1x_destroy (asn);
}
static void
test_element_length_content (Test* test, gconstpointer unused)
{
- EggBytes *buffer;
+ GBytes *buffer;
GNode *asn = NULL;
const guchar *content;
gsize n_content;
g_assert (buffer != NULL);
/* Now the real test */
- length = egg_asn1x_element_length (egg_bytes_get_data (buffer),
- egg_bytes_get_size (buffer) + 1024);
+ length = egg_asn1x_element_length (g_bytes_get_data (buffer, NULL),
+ g_bytes_get_size (buffer) + 1024);
g_assert_cmpint (length, ==, 13);
- content = egg_asn1x_element_content (egg_bytes_get_data (buffer),
+ content = egg_asn1x_element_content (g_bytes_get_data (buffer, NULL),
length, &n_content);
g_assert (content != NULL);
g_assert_cmpuint (n_content, ==, 11);
g_assert (content == NULL);
egg_asn1x_destroy (asn);
- egg_bytes_unref (buffer);
+ g_bytes_unref (buffer);
}
static void
test_read_element (Test* test, gconstpointer unused)
{
- EggBytes *buffer;
+ GBytes *buffer;
GNode *asn = NULL;
- EggBytes *data;
+ GBytes *data;
asn = egg_asn1x_create (test_asn1_tab, "TestData");
g_assert ("asn test structure is null" && asn != NULL);
/* Now the real test */
data = egg_asn1x_get_element_raw (egg_asn1x_node (asn, "data", NULL));
g_assert (data != NULL);
- g_assert_cmpint (egg_bytes_get_size (data), ==, 11);
- egg_bytes_unref (data);
+ g_assert_cmpint (g_bytes_get_size (data), ==, 11);
+ g_bytes_unref (data);
data = egg_asn1x_get_raw_value (egg_asn1x_node (asn, "data", NULL));
g_assert (data != NULL);
egg_assert_cmpbytes (data, ==, "SOME DATA", 9);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
- egg_bytes_unref (buffer);
+ g_bytes_unref (buffer);
}
static void
test_oid (Test* test, gconstpointer unused)
{
- EggBytes *buffer;
+ GBytes *buffer;
GNode *asn = NULL;
GNode *node;
GQuark oid, check;
if (!egg_asn1x_set_oid_as_quark (egg_asn1x_node (asn, "oid", NULL), g_quark_from_static_string ("5.4.3.2.1678")))
g_assert_not_reached ();
- egg_bytes_unref (buffer);
+ g_bytes_unref (buffer);
buffer = egg_asn1x_encode (asn, NULL);
g_assert (buffer != NULL);
g_assert (oid);
g_assert_cmpstr (g_quark_to_string (oid), ==, "5.4.3.2.1678");
- egg_bytes_unref (buffer);
+ g_bytes_unref (buffer);
egg_asn1x_destroy (asn);
}
const gchar *identifier)
{
GNode *asn;
- EggBytes *encoded;
+ GBytes *encoded;
gpointer data;
gsize n_data;
- EggBytes *bytes;
+ GBytes *bytes;
if (!g_file_get_contents (file, (gchar**)&data, &n_data, NULL))
g_assert_not_reached ();
- bytes = egg_bytes_new_take (data, n_data);
+ bytes = g_bytes_new_take (data, n_data);
asn = egg_asn1x_create (defs, identifier);
egg_asn1x_dump (asn);
egg_asn1x_clear (asn);
egg_asn1x_destroy (asn);
- egg_bytes_unref (bytes);
- egg_bytes_unref (encoded);
+ g_bytes_unref (bytes);
+ g_bytes_unref (encoded);
}
int
static void
setup (Test *test, gconstpointer unused)
{
- EggBytes *bytes;
+ GBytes *bytes;
if (!g_file_get_contents (SRCDIR "/files/test-certificate-1.der",
(gchar**)&test->data, &test->n_data, NULL))
test->asn1 = egg_asn1x_create (pkix_asn1_tab, "Certificate");
g_assert (test->asn1 != NULL);
- bytes = egg_bytes_new_static (test->data, test->n_data);
+ bytes = g_bytes_new_static (test->data, test->n_data);
if (!egg_asn1x_decode (test->asn1, bytes))
g_assert_not_reached ();
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
{
const guchar value[] = { 0x13, 0x1a, 0x54, 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x61, 0x6c, 0x20, 0x50, 0x72, 0x65, 0x6d, 0x69, 0x75, 0x6d, 0x20, 0x43, 0x41 };
gsize n_value = 28;
- EggBytes *bytes;
+ GBytes *bytes;
GQuark oid;
gchar *text;
/* Some printable strings */
oid = g_quark_from_static_string ("2.5.4.3");
- bytes = egg_bytes_new_static (value, n_value);
+ bytes = g_bytes_new_static (value, n_value);
text = egg_dn_print_value (oid, bytes);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
g_assert_cmpstr (text, ==, "Thawte Personal Premium CA");
g_free (text);
/* Unknown oid */
oid = g_quark_from_static_string ("1.1.1.1.1.1");
- bytes = egg_bytes_new_static (value, n_value);
+ bytes = g_bytes_new_static (value, n_value);
text = egg_dn_print_value (oid, bytes);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
g_assert_cmpstr (text, ==, "#131A54686177746520506572736F6E616C205072656D69756D204341");
g_free (text);
}
static void
concatenate_dn (guint index,
GQuark oid,
- EggBytes *value,
+ GBytes *value,
gpointer user_data)
{
GString *dn = user_data;
g_assert (oid);
g_assert (value != NULL);
- g_assert (egg_bytes_get_size (value) != 0);
+ g_assert (g_bytes_get_size (value) != 0);
g_assert (index == last_index);
++last_index;
test_add_dn_part (Test *test,
gconstpointer unused)
{
- EggBytes *check;
- EggBytes *dn;
+ GBytes *check;
+ GBytes *dn;
GNode *check_dn;
GNode *asn;
GNode *node;
check = egg_asn1x_encode (check_dn, NULL);
egg_asn1x_destroy (asn);
- egg_assert_cmpbytes (dn, ==, egg_bytes_get_data (check), egg_bytes_get_size (check));
+ egg_assert_cmpbytes (dn, ==, g_bytes_get_data (check, NULL), g_bytes_get_size (check));
- egg_bytes_unref (dn);
- egg_bytes_unref (check);
+ g_bytes_unref (dn);
+ g_bytes_unref (check);
}
int
#include <string.h>
#include <unistd.h>
-#include <egg/egg-bytes.h>
-
EGG_SECURE_DEFINE_GLIB_GLOBALS ();
typedef struct {
- EggBytes *input;
+ GBytes *input;
GQuark reftype;
guchar *refenc;
guchar *refdata;
if (!g_file_get_contents (SRCDIR "/files/pem-rsa-enc.key", &contents, &length, NULL))
g_assert_not_reached ();
- test->input = egg_bytes_new_take (contents, length);
+ test->input = g_bytes_new_take (contents, length);
}
static void
teardown (Test *test, gconstpointer unused)
{
- egg_bytes_unref (test->input);
+ g_bytes_unref (test->input);
g_free (test->refenc);
egg_secure_free (test->refdata);
g_hash_table_destroy (test->refheaders);
static void
parse_reference (GQuark type,
- EggBytes *data,
- EggBytes *outer,
+ GBytes *data,
+ GBytes *outer,
GHashTable *headers,
gpointer user_data)
{
test->reftype = type;
g_assert ("no data in PEM callback" && data != NULL);
- g_assert ("no data in PEM callback" && egg_bytes_get_size (data) > 0);
- test->refenc = g_memdup (egg_bytes_get_data (data), egg_bytes_get_size (data));
- test->n_refenc = egg_bytes_get_size (data);
+ g_assert ("no data in PEM callback" && g_bytes_get_size (data) > 0);
+ test->refenc = g_memdup (g_bytes_get_data (data, NULL), g_bytes_get_size (data));
+ test->n_refenc = g_bytes_get_size (data);
g_assert ("no headers present in file" && headers != NULL);
g_assert (!test->refheaders);
test->refdata = egg_openssl_decrypt_block (dekinfo, "booo", 4, data, &test->n_refdata);
g_assert ("no data returned from openssl decrypt" && test->refdata != NULL);
- g_assert ("invalid amount of data returned from openssl decrypt" && test->n_refdata == egg_bytes_get_size (data));
+ g_assert ("invalid amount of data returned from openssl decrypt" && test->n_refdata == g_bytes_get_size (data));
}
static void
const gchar *dekinfo;
guchar *encrypted;
gsize n_encrypted;
- EggBytes *data;
+ GBytes *data;
guint num;
num = egg_armor_parse (test->input, parse_reference, test);
dekinfo = egg_openssl_get_dekinfo (test->refheaders);
g_assert ("no dekinfo in headers" && dekinfo != NULL);
- data = egg_bytes_new_static (test->refdata, test->n_refdata);
+ data = g_bytes_new_static (test->refdata, test->n_refdata);
encrypted = egg_openssl_encrypt_block (dekinfo, "booo", 4, data, &n_encrypted);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
g_assert ("no data returned from openssl encrypt" && encrypted != NULL);
g_assert ("invalid amount of data returned from openssl encrypt" && test->n_refdata <= n_encrypted);
const gchar *dekinfo;
guchar *encrypted, *decrypted;
gsize n_encrypted, n_decrypted;
- EggBytes *data;
+ GBytes *data;
int i;
guint num;
dekinfo = egg_openssl_prep_dekinfo (test->refheaders);
- data = egg_bytes_new_static (TEST_DATA, TEST_DATA_L);
+ data = g_bytes_new_static (TEST_DATA, TEST_DATA_L);
encrypted = egg_openssl_encrypt_block (dekinfo, "password", -1, data, &n_encrypted);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
g_assert ("no data returned from openssl encrypt" && encrypted != NULL);
g_assert ("invalid amount of data returned from openssl encrypt" && TEST_DATA_L <= n_encrypted);
- data = egg_bytes_new_with_free_func (encrypted, n_encrypted, egg_secure_free, encrypted);
+ data = g_bytes_new_with_free_func (encrypted, n_encrypted, egg_secure_free, encrypted);
decrypted = egg_openssl_decrypt_block (dekinfo, "password", 8, data, &n_decrypted);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
g_assert ("no data returned from openssl decrypt" && decrypted != NULL);
#include <glib/gi18n-lib.h>
-EggBytes *
+GBytes *
_gcr_certificate_extension_find (GNode *cert,
GQuark oid,
gboolean *critical)
}
gboolean
-_gcr_certificate_extension_basic_constraints (EggBytes *data,
+_gcr_certificate_extension_basic_constraints (GBytes *data,
gboolean *is_ca,
gint *path_len)
{
}
GQuark *
-_gcr_certificate_extension_extended_key_usage (EggBytes *data)
+_gcr_certificate_extension_extended_key_usage (GBytes *data)
{
GNode *asn = NULL;
GNode *node;
}
gpointer
-_gcr_certificate_extension_subject_key_identifier (EggBytes *data,
+_gcr_certificate_extension_subject_key_identifier (GBytes *data,
gsize *n_keyid)
{
GNode *asn = NULL;
}
gboolean
-_gcr_certificate_extension_key_usage (EggBytes *data,
+_gcr_certificate_extension_key_usage (GBytes *data,
gulong *key_usage)
{
GNode *asn = NULL;
{
GNode *decode = NULL;
GQuark oid;
- EggBytes *value;
+ GBytes *value;
general->type = GCR_GENERAL_NAME_OTHER;
general->description = _("Other Name");
general->display = egg_asn1x_get_string_as_utf8 (decode, g_realloc);
}
- egg_bytes_unref (value);
+ g_bytes_unref (value);
egg_asn1x_destroy (decode);
}
}
GArray*
-_gcr_certificate_extension_subject_alt_name (EggBytes *data)
+_gcr_certificate_extension_subject_alt_name (GBytes *data)
{
GNode *asn = NULL;
guint count, i;
for (i = 0; names && i < names->len; i++) {
name = &g_array_index (names, GcrGeneralName, i);
g_free (name->display);
- egg_bytes_unref (name->raw);
+ g_bytes_unref (name->raw);
}
g_array_free (names, TRUE);
}
#include <glib.h>
-#include <egg/egg-bytes.h>
-
G_BEGIN_DECLS
-EggBytes * _gcr_certificate_extension_find (GNode *cert,
+GBytes * _gcr_certificate_extension_find (GNode *cert,
GQuark oid,
gboolean *critical);
-gboolean _gcr_certificate_extension_basic_constraints (EggBytes *data,
+gboolean _gcr_certificate_extension_basic_constraints (GBytes *data,
gboolean *is_ca,
gint *path_len);
-GQuark * _gcr_certificate_extension_extended_key_usage (EggBytes *data);
+GQuark * _gcr_certificate_extension_extended_key_usage (GBytes *data);
-gpointer _gcr_certificate_extension_subject_key_identifier (EggBytes *data,
+gpointer _gcr_certificate_extension_subject_key_identifier (GBytes *data,
gsize *n_keyid);
typedef enum {
GCR_KEY_USAGE_CRL_SIGN = 1 << 6,
} GcrCertificateExtensionKeyUsage;
-gboolean _gcr_certificate_extension_key_usage (EggBytes *data,
+gboolean _gcr_certificate_extension_key_usage (GBytes *data,
gulong *key_usage);
typedef enum {
GcrGeneralNameType type;
const gchar *description;
gchar *display;
- EggBytes *raw;
+ GBytes *raw;
} GcrGeneralName;
-GArray * _gcr_certificate_extension_subject_alt_name (EggBytes *data);
+GArray * _gcr_certificate_extension_subject_alt_name (GBytes *data);
void _gcr_general_names_free (GArray *names);
static gboolean
append_extension_basic_constraints (GcrRenderer *renderer,
GcrDisplayView *view,
- EggBytes *data)
+ GBytes *data)
{
gboolean is_ca = FALSE;
gint path_len = -1;
static gboolean
append_extension_extended_key_usage (GcrRenderer *renderer,
GcrDisplayView *view,
- EggBytes *data)
+ GBytes *data)
{
GQuark *oids;
GString *text;
static gboolean
append_extension_subject_key_identifier (GcrRenderer *renderer,
GcrDisplayView *view,
- EggBytes *data)
+ GBytes *data)
{
gpointer keyid;
gsize n_keyid;
static gboolean
append_extension_key_usage (GcrRenderer *renderer,
GcrDisplayView *view,
- EggBytes *data)
+ GBytes *data)
{
gulong key_usage;
GString *text;
static gboolean
append_extension_subject_alt_name (GcrRenderer *renderer,
GcrDisplayView *view,
- EggBytes *data)
+ GBytes *data)
{
GArray *general_names;
GcrGeneralName *general;
general = &g_array_index (general_names, GcrGeneralName, i);
if (general->display == NULL)
_gcr_display_view_append_hex (view, renderer, general->description,
- egg_bytes_get_data (general->raw),
- egg_bytes_get_size (general->raw));
+ g_bytes_get_data (general->raw, NULL),
+ g_bytes_get_size (general->raw));
else
_gcr_display_view_append_value (view, renderer, general->description,
general->display, FALSE);
gsize n_data;
GcrDisplayView *view;
GcrCertificate *cert;
- EggBytes *number;
+ GBytes *number;
gulong version;
guint bits, index;
gchar *display;
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
GDate date;
GIcon *icon;
_gcr_display_view_set_icon (view, GCR_RENDERER (self), icon);
g_object_unref (icon);
- bytes = egg_bytes_new_static (data, n_data);
+ bytes = g_bytes_new_static (data, n_data);
asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", bytes);
g_return_if_fail (asn != NULL);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
display = calculate_label (self);
_gcr_display_view_append_title (view, renderer, display);
number = egg_asn1x_get_integer_as_raw (egg_asn1x_node (asn, "tbsCertificate", "serialNumber", NULL));
g_return_if_fail (number != NULL);
_gcr_display_view_append_hex (view, renderer, _("Serial Number"),
- egg_bytes_get_data (number),
- egg_bytes_get_size (number));
- egg_bytes_unref (number);
+ g_bytes_get_data (number, NULL),
+ g_bytes_get_size (number));
+ g_bytes_unref (number);
display = g_malloc0 (128);
if (egg_asn1x_get_time_as_date (egg_asn1x_node (asn, "tbsCertificate", "validity", "notBefore", NULL), &date)) {
static void
on_parsed_dn_part (guint index,
GQuark oid,
- EggBytes *value,
+ GBytes *value,
gpointer user_data)
{
GcrRenderer *renderer = ((AppendDnClosure *)user_data)->renderer;
{
const gchar *text;
gchar *display;
- EggBytes *value;
+ GBytes *value;
guchar *raw;
gsize n_raw;
GQuark oid;
"algorithm", "parameters", NULL));
if (value) {
_gcr_display_view_append_hex (view, renderer, _("Key Parameters"),
- egg_bytes_get_data (value),
- egg_bytes_get_size (value));
- egg_bytes_unref (value);
+ g_bytes_get_data (value, NULL),
+ g_bytes_get_size (value));
+ g_bytes_unref (value);
}
if (key_nbits > 0) {
}
value = egg_asn1x_get_element_raw (subject_public_key);
- raw = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (value),
- egg_bytes_get_size (value),
+ raw = gcr_fingerprint_from_subject_public_key_info (g_bytes_get_data (value, NULL),
+ g_bytes_get_size (value),
G_CHECKSUM_SHA1, &n_raw);
_gcr_display_view_append_hex (view, renderer, _("Key SHA1 Fingerprint"), raw, n_raw);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
g_free (raw);
value = egg_asn1x_get_bits_as_raw (egg_asn1x_node (subject_public_key, "subjectPublicKey", NULL), &bits);
_gcr_display_view_append_hex (view, renderer, _("Public Key"),
- egg_bytes_get_data (value), bits / 8);
- egg_bytes_unref (value);
+ g_bytes_get_data (value, NULL), bits / 8);
+ g_bytes_unref (value);
}
void
GNode *asn)
{
const gchar *text;
- EggBytes *value;
+ GBytes *value;
GQuark oid;
guint bits;
value = egg_asn1x_get_element_raw (egg_asn1x_node (asn, "signatureAlgorithm", "parameters", NULL));
if (value) {
_gcr_display_view_append_hex (view, renderer, _("Signature Parameters"),
- egg_bytes_get_data (value),
- egg_bytes_get_size (value));
- egg_bytes_unref (value);
+ g_bytes_get_data (value, NULL),
+ g_bytes_get_size (value));
+ g_bytes_unref (value);
}
value = egg_asn1x_get_bits_as_raw (egg_asn1x_node (asn, "signature", NULL), &bits);
_gcr_display_view_append_hex (view, renderer, _("Signature"),
- egg_bytes_get_data (value), bits / 8);
- egg_bytes_unref (value);
+ g_bytes_get_data (value, NULL), bits / 8);
+ g_bytes_unref (value);
}
void
GNode *node)
{
GQuark oid;
- EggBytes *value;
+ GBytes *value;
gboolean critical;
gboolean ret = FALSE;
/* Otherwise the default raw display */
if (ret == FALSE)
ret = append_extension_hex (renderer, view, oid,
- egg_bytes_get_data (value),
- egg_bytes_get_size (value));
+ g_bytes_get_data (value, NULL),
+ g_bytes_get_size (value));
/* Critical */
if (ret == TRUE && egg_asn1x_get_boolean (egg_asn1x_node (node, "critical", NULL), &critical)) {
GcrDisplayView *view,
GNode *attribute)
{
- EggBytes *value;
+ GBytes *value;
GNode *node;
GNode *asn;
guint i;
GNode *attribute)
{
GQuark oid;
- EggBytes *value;
+ GBytes *value;
const gchar *text;
GNode *node;
gboolean ret = FALSE;
break;
value = egg_asn1x_get_element_raw (node);
_gcr_display_view_append_hex (view, renderer, _("Value"),
- egg_bytes_get_data (value),
- egg_bytes_get_size (value));
- egg_bytes_unref (value);
+ g_bytes_get_data (value, NULL),
+ g_bytes_get_size (value));
+ g_bytes_unref (value);
}
}
}
const GckAttribute *value;
GNode *asn = NULL;
gulong type = 0;
- EggBytes *bytes;
+ GBytes *bytes;
g_return_if_fail (GCR_IS_CERTIFICATE_REQUEST_RENDERER (self));
return;
}
- bytes = egg_bytes_new_with_free_func (value->value, value->length,
+ bytes = g_bytes_new_with_free_func (value->value, value->length,
gck_attributes_unref, gck_attributes_ref (attrs));
asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "pkcs-10-CertificationRequest", bytes);
}
}
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
if (type == 0)
return;
egg_dn_add_string_part (dn, GCR_OID_NAME_CN, cn);
}
-static EggBytes *
-hash_sha1_pkcs1 (EggBytes *data)
+static GBytes *
+hash_sha1_pkcs1 (GBytes *data)
{
const guchar SHA1_ASN[15] = /* Object ID is 1.3.14.3.2.26 */
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
memcpy (hash, SHA1_ASN, sizeof (SHA1_ASN));
checksum = g_checksum_new (G_CHECKSUM_SHA1);
- g_checksum_update (checksum, egg_bytes_get_data (data), egg_bytes_get_size (data));
+ g_checksum_update (checksum, g_bytes_get_data (data, NULL), g_bytes_get_size (data));
g_checksum_get_digest (checksum, hash + sizeof (SHA1_ASN), &n_digest);
g_checksum_free (checksum);
- return egg_bytes_new_take (hash, n_hash);
+ return g_bytes_new_take (hash, n_hash);
}
-static EggBytes *
-hash_sha1 (EggBytes *data)
+static GBytes *
+hash_sha1 (GBytes *data)
{
GChecksum *checksum;
guchar *hash;
hash = g_malloc (n_hash);
checksum = g_checksum_new (G_CHECKSUM_SHA1);
- g_checksum_update (checksum, egg_bytes_get_data (data), egg_bytes_get_size (data));
+ g_checksum_update (checksum, g_bytes_get_data (data, NULL), g_bytes_get_size (data));
g_checksum_get_digest (checksum, hash, &n_hash);
g_checksum_free (checksum);
- return egg_bytes_new_take (hash, n_hash);
+ return g_bytes_new_take (hash, n_hash);
}
-static EggBytes *
+static GBytes *
prepare_to_be_signed (GcrCertificateRequest *self,
GckMechanism *mechanism)
{
GNode *node;
- EggBytes *data;
- EggBytes *hash;
+ GBytes *data;
+ GBytes *hash;
g_assert (mechanism != NULL);
case CKM_RSA_PKCS:
hash = hash_sha1_pkcs1 (data);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
return hash;
case CKM_DSA:
hash = hash_sha1 (data);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
return hash;
default:
gsize *n_mechanisms,
GError **error)
{
- EggBytes *encoded;
+ GBytes *encoded;
GNode *node;
GQuark oid;
*algorithm = GCR_OID_PKIX1_SHA1_WITH_DSA;
} else {
- egg_bytes_unref (encoded);
+ g_bytes_unref (encoded);
g_set_error (error, GCR_DATA_ERROR, GCR_ERROR_UNRECOGNIZED,
_("Unsupported key type for certificate request"));
return FALSE;
if (!egg_asn1x_set_element_raw (node, encoded))
g_return_val_if_reached (FALSE);
- egg_bytes_unref (encoded);
+ g_bytes_unref (encoded);
return TRUE;
}
guchar *result,
gsize n_result)
{
- EggBytes *data;
+ GBytes *data;
GNode *params;
GNode *node;
node = egg_asn1x_node (self->asn, "signature", NULL);
- egg_asn1x_take_bits_as_raw (node, egg_bytes_new_take (result, n_result), n_result * 8);
+ egg_asn1x_take_bits_as_raw (node, g_bytes_new_take (result, n_result), n_result * 8);
node = egg_asn1x_node (self->asn, "signatureAlgorithm", "algorithm", NULL);
egg_asn1x_set_oid_as_quark (node, algorithm);
params = egg_asn1x_node (subject_public_key, "algorithm", "parameters", NULL);
data = egg_asn1x_encode (params, NULL);
egg_asn1x_set_element_raw (node, data);
- egg_bytes_unref (data);
+ g_bytes_unref (data);
}
/**
gsize n_mechanisms;
GckMechanism mechanism = { 0, };
GQuark algorithm = 0;
- EggBytes *tbs;
+ GBytes *tbs;
GckSession *session;
guchar *signature;
gsize n_signature;
tbs = prepare_to_be_signed (self, &mechanism);
session = gck_object_get_session (self->private_key);
signature = gck_session_sign_full (session, self->private_key, &mechanism,
- egg_bytes_get_data (tbs),
- egg_bytes_get_size (tbs),
+ g_bytes_get_data (tbs, NULL),
+ g_bytes_get_size (tbs),
&n_signature, cancellable, error);
g_object_unref (session);
- egg_bytes_unref (tbs);
+ g_bytes_unref (tbs);
if (!signature) {
egg_asn1x_destroy (subject_public_key);
GNode *subject_public_key;
GckMechanism mechanism;
GckSession *session;
- EggBytes *tbs;
+ GBytes *tbs;
} CompleteClosure;
static void
g_clear_object (&closure->cancellable);
g_clear_object (&closure->session);
if (closure->tbs)
- egg_bytes_unref (closure->tbs);
+ g_bytes_unref (closure->tbs);
g_free (closure);
}
gck_session_sign_async (closure->session,
closure->request->private_key,
&closure->mechanism,
- egg_bytes_get_data (closure->tbs),
- egg_bytes_get_size (closure->tbs),
+ g_bytes_get_data (closure->tbs, NULL),
+ g_bytes_get_size (closure->tbs),
closure->cancellable,
on_certificate_request_signed,
g_object_ref (res));
gboolean textual,
gsize *length)
{
- EggBytes *bytes;
+ GBytes *bytes;
gpointer encoded;
gpointer data;
gsize size;
return NULL;
}
- size = egg_bytes_get_size (bytes);
- encoded = g_byte_array_free (egg_bytes_unref_to_array (bytes), FALSE);
+ size = g_bytes_get_size (bytes);
+ encoded = g_byte_array_free (g_bytes_unref_to_array (bytes), FALSE);
if (textual) {
data = egg_armor_write (encoded, size,
/* Forward declarations */
-static EggBytes * _gcr_certificate_get_subject_const (GcrCertificate *self);
-static EggBytes * _gcr_certificate_get_issuer_const (GcrCertificate *self);
+static GBytes * _gcr_certificate_get_subject_const (GcrCertificate *self);
+static GBytes * _gcr_certificate_get_issuer_const (GcrCertificate *self);
enum {
PROP_FIRST = 0x0007000,
certificate_info_load (GcrCertificate *cert)
{
GcrCertificateInfo *info;
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn1;
gconstpointer der;
gsize n_der;
}
/* TODO: Once GBytes is public, add to GcrCertificate interface */
- bytes = egg_bytes_new_static (der, n_der);
+ bytes = g_bytes_new_static (der, n_der);
/* Cache is invalid or non existent */
asn1 = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", bytes);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
if (asn1 == NULL) {
g_warning ("a derived class provided an invalid or unparseable X.509 DER certificate data.");
return egg_dn_read_part (egg_asn1x_node (info->asn1, "tbsCertificate", "issuer", "rdnSequence", NULL), part);
}
-static EggBytes *
+static GBytes *
_gcr_certificate_get_issuer_const (GcrCertificate *self)
{
GcrCertificateInfo *info;
gcr_certificate_get_issuer_raw (GcrCertificate *self,
gsize *n_data)
{
- EggBytes *bytes;
+ GBytes *bytes;
guchar *result;
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
if (bytes == NULL)
return NULL;
- *n_data = egg_bytes_get_size (bytes);
- result = g_memdup (egg_bytes_get_data (bytes), *n_data);
- egg_bytes_unref (bytes);
+ *n_data = g_bytes_get_size (bytes);
+ result = g_memdup (g_bytes_get_data (bytes, NULL), *n_data);
+ g_bytes_unref (bytes);
return result;
}
gboolean
gcr_certificate_is_issuer (GcrCertificate *self, GcrCertificate *issuer)
{
- EggBytes *subject_dn;
- EggBytes *issuer_dn;
+ GBytes *subject_dn;
+ GBytes *issuer_dn;
gboolean ret;
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), FALSE);
issuer_dn = _gcr_certificate_get_issuer_const (self);
g_return_val_if_fail (issuer_dn, FALSE);
- ret = egg_bytes_equal (subject_dn, issuer_dn);
+ ret = g_bytes_equal (subject_dn, issuer_dn);
- egg_bytes_unref (subject_dn);
- egg_bytes_unref (issuer_dn);
+ g_bytes_unref (subject_dn);
+ g_bytes_unref (issuer_dn);
return ret;
}
return egg_dn_read (egg_asn1x_node (info->asn1, "tbsCertificate", "subject", "rdnSequence", NULL));
}
-static EggBytes *
+static GBytes *
_gcr_certificate_get_subject_const (GcrCertificate *self)
{
GcrCertificateInfo *info;
guchar *
gcr_certificate_get_subject_raw (GcrCertificate *self, gsize *n_data)
{
- EggBytes *bytes;
+ GBytes *bytes;
guchar *result;
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
if (bytes == NULL)
return NULL;
- *n_data = egg_bytes_get_size (bytes);
- result = g_memdup (egg_bytes_get_data (bytes), *n_data);
+ *n_data = g_bytes_get_size (bytes);
+ result = g_memdup (g_bytes_get_data (bytes, NULL), *n_data);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
return result;
}
gcr_certificate_get_serial_number (GcrCertificate *self, gsize *n_length)
{
GcrCertificateInfo *info;
- EggBytes *bytes;
+ GBytes *bytes;
guchar *result;
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), NULL);
bytes = egg_asn1x_get_integer_as_raw (egg_asn1x_node (info->asn1, "tbsCertificate", "serialNumber", NULL));
g_return_val_if_fail (bytes != NULL, NULL);
- *n_length = egg_bytes_get_size (bytes);
- result = g_memdup (egg_bytes_get_data (bytes), *n_length);
+ *n_length = g_bytes_get_size (bytes);
+ result = g_memdup (g_bytes_get_data (bytes, NULL), *n_length);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
return result;
}
gint *path_len)
{
GcrCertificateInfo *info;
- EggBytes *value;
+ GBytes *value;
g_return_val_if_fail (GCR_IS_CERTIFICATE (self), FALSE);
if (!_gcr_certificate_extension_basic_constraints (value, is_ca, path_len))
g_return_val_if_reached (FALSE);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
return TRUE;
}
gsize *n_fingerprint)
{
gpointer fingerprint = NULL;
- EggBytes *info;
+ GBytes *info;
GNode *asn;
g_return_val_if_fail (attrs != NULL, NULL);
if (asn != NULL) {
info = egg_asn1x_encode (asn, NULL);
- fingerprint = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (info),
- egg_bytes_get_size (info),
+ fingerprint = gcr_fingerprint_from_subject_public_key_info (g_bytes_get_data (info, NULL),
+ g_bytes_get_size (info),
checksum_type,
n_fingerprint);
- egg_bytes_unref (info);
+ g_bytes_unref (info);
}
egg_asn1x_destroy (asn);
#include "gck/gck.h"
#include "egg/egg-asn1x.h"
-#include "egg/egg-bytes.h"
#include <gdk/gdk.h>
#include <glib/gi18n-lib.h>
GckObject *object;
GIcon *icon;
gulong notify_sig;
- EggBytes *spk;
+ GBytes *spk;
};
static void gcr_key_renderer_renderer_iface (GcrRendererIface *iface);
gsize *n_fingerprint)
{
if (self->pv->spk)
- return gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (self->pv->spk),
- egg_bytes_get_size (self->pv->spk),
+ return gcr_fingerprint_from_subject_public_key_info (g_bytes_get_data (self->pv->spk, NULL),
+ g_bytes_get_size (self->pv->spk),
algorithm, n_fingerprint);
return gcr_fingerprint_from_attributes (attrs, algorithm, n_fingerprint);
} else {
if (self->pv->spk)
- egg_bytes_unref (self->pv->spk);
+ g_bytes_unref (self->pv->spk);
self->pv->spk = NULL;
self->pv->spk = egg_asn1x_encode (node, NULL);
update_subject_public_key (GcrKeyRenderer *self)
{
if (self->pv->spk)
- egg_bytes_unref (self->pv->spk);
+ g_bytes_unref (self->pv->spk);
self->pv->spk = NULL;
if (!self->pv->object)
GcrKeyRenderer *self = GCR_KEY_RENDERER (obj);
if (self->pv->spk)
- egg_bytes_unref (self->pv->spk);
+ g_bytes_unref (self->pv->spk);
self->pv->spk = NULL;
if (self->pv->object && self->pv->notify_sig) {
GcrOpenpgpCallback callback;
gpointer user_data;
guint count;
- EggBytes *backing;
+ GBytes *backing;
GPtrArray *records;
} openpgp_parse_closure;
{
openpgp_parse_closure *closure = data;
g_ptr_array_unref (closure->records);
- egg_bytes_unref (closure->backing);
+ g_bytes_unref (closure->backing);
g_free (closure);
}
const guchar *block,
const guchar *end)
{
- EggBytes *outer;
+ GBytes *outer;
gsize length;
GPtrArray *records;
records = closure->records;
closure->records = g_ptr_array_new_with_free_func (_gcr_record_free);
- outer = egg_bytes_new_with_free_func (block, length, egg_bytes_unref,
- egg_bytes_ref (closure->backing));
+ outer = g_bytes_new_with_free_func (block, length, (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (closure->backing));
if (closure->callback)
(closure->callback) (records, outer, closure->user_data);
- egg_bytes_unref (outer);
+ g_bytes_unref (outer);
g_ptr_array_unref (records);
}
guint
-_gcr_openpgp_parse (EggBytes *data,
+_gcr_openpgp_parse (GBytes *data,
GcrOpenpgpParseFlags flags,
GcrOpenpgpCallback callback,
gpointer user_data)
/* For libgcrypt */
_gcr_initialize_library ();
- at = egg_bytes_get_data (data);
- end = at + egg_bytes_get_size (data);
+ at = g_bytes_get_data (data, NULL);
+ end = at + g_bytes_get_size (data);
block = NULL;
closure = g_new0 (openpgp_parse_closure, 1);
closure->callback = callback;
closure->user_data = user_data;
- closure->backing = egg_bytes_ref (data);
+ closure->backing = g_bytes_ref (data);
closure->records = g_ptr_array_new_with_free_func (_gcr_record_free);
while (at != NULL && at != end) {
#include <glib.h>
-#include <egg/egg-bytes.h>
-
#include <gck/gck.h>
typedef enum {
G_BEGIN_DECLS
typedef void (*GcrOpenpgpCallback) (GPtrArray *records,
- EggBytes *outer,
+ GBytes *outer,
gpointer user_data);
-guint _gcr_openpgp_parse (EggBytes *data,
+guint _gcr_openpgp_parse (GBytes *data,
GcrOpenpgpParseFlags flags,
GcrOpenpgpCallback callback,
gpointer user_data);
static GcrDataError
parse_v1_public_line (const gchar *line,
gsize length,
- EggBytes *backing,
+ GBytes *backing,
GcrOpensshPubCallback callback,
gpointer user_data)
{
GckBuilder builder = GCK_BUILDER_INIT;
GckAttributes *attrs;
gchar *label, *options;
- EggBytes *bytes;
+ GBytes *bytes;
gint bits;
g_assert (line);
attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
if (callback != NULL) {
- bytes = egg_bytes_new_with_free_func (outer, n_outer,
- egg_bytes_unref,
- egg_bytes_ref (backing));
+ bytes = g_bytes_new_with_free_func (outer, n_outer,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
(callback) (attrs, label, options, bytes, user_data);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
gck_attributes_unref (attrs);
static GcrDataError
parse_v2_public_line (const gchar *line,
gsize length,
- EggBytes *backing,
+ GBytes *backing,
GcrOpensshPubCallback callback,
gpointer user_data)
{
gchar *label = NULL;
const gchar *outer = line;
gsize n_outer = length;
- EggBytes *bytes;
+ GBytes *bytes;
gulong algo;
g_assert (line);
attrs = gck_attributes_ref_sink (gck_builder_end (&builder));
if (callback != NULL) {
- bytes = egg_bytes_new_with_free_func (outer, n_outer,
- egg_bytes_unref,
- egg_bytes_ref (backing));
+ bytes = g_bytes_new_with_free_func (outer, n_outer,
+ (GDestroyNotify)g_bytes_unref,
+ g_bytes_ref (backing));
(callback) (attrs, label, options, bytes, user_data);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
gck_attributes_unref (attrs);
}
guint
-_gcr_openssh_pub_parse (EggBytes *data,
+_gcr_openssh_pub_parse (GBytes *data,
GcrOpensshPubCallback callback,
gpointer user_data)
{
g_return_val_if_fail (data != NULL, FALSE);
- line = egg_bytes_get_data (data);
- length = egg_bytes_get_size (data);
+ line = g_bytes_get_data (data, NULL);
+ length = g_bytes_get_size (data);
last = FALSE;
num_parsed = 0;
#include <gck/gck.h>
-#include <egg/egg-bytes.h>
-
G_BEGIN_DECLS
typedef void (*GcrOpensshPubCallback) (GckAttributes *attrs,
const gchar *label,
const gchar *options,
- EggBytes *outer,
+ GBytes *outer,
gpointer user_data);
-guint _gcr_openssh_pub_parse (EggBytes *data,
+guint _gcr_openssh_pub_parse (GBytes *data,
GcrOpensshPubCallback callback,
gpointer user_data);
GckAttributes *attrs;
const gchar *description;
gchar *label;
- EggBytes *data;
+ GBytes *data;
gboolean sensitive;
GcrDataFormat format;
struct _GcrParsed *next;
typedef struct _ParserFormat {
gint format_id;
- gint (*function) (GcrParser *self, EggBytes *data);
+ gint (*function) (GcrParser *self, GBytes *data);
} ParserFormat;
/* Forward declarations */
static void
parsed_attribute_bytes (GcrParsed *parsed,
CK_ATTRIBUTE_TYPE type,
- EggBytes *data)
+ GBytes *data)
{
g_assert (parsed != NULL);
gck_builder_add_data (&parsed->builder, type,
- egg_bytes_get_data (data),
- egg_bytes_get_size (data));
+ g_bytes_get_data (data, NULL),
+ g_bytes_get_size (data));
}
static gboolean
const gchar *part,
CK_ATTRIBUTE_TYPE type)
{
- EggBytes *value;
+ GBytes *value;
g_assert (asn);
g_assert (parsed);
return FALSE;
parsed_attribute_bytes (parsed, type, value);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
return TRUE;
}
const gchar *part,
CK_ATTRIBUTE_TYPE type)
{
- EggBytes *value;
+ GBytes *value;
g_assert (asn);
g_assert (parsed);
return FALSE;
parsed_attribute_bytes (parsed, type, value);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
return TRUE;
}
static void
parsing_block (GcrParsed *parsed,
gint format,
- EggBytes *data)
+ GBytes *data)
{
g_assert (parsed != NULL);
g_assert (data != NULL);
g_assert (parsed->data == NULL);
parsed->format = format;
- parsed->data = egg_bytes_ref (data);
+ parsed->data = g_bytes_ref (data);
}
static void
gck_builder_clear (&parsed->builder);
gck_attributes_unref (parsed->attrs);
if (parsed->data)
- egg_bytes_unref (parsed->data);
+ g_bytes_unref (parsed->data);
g_free (parsed->label);
g_free (parsed);
}
static gint
parse_der_private_key_rsa (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
gint res = GCR_ERROR_UNRECOGNIZED;
GNode *asn = NULL;
static gint
parse_der_private_key_dsa (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
gint ret = GCR_ERROR_UNRECOGNIZED;
GNode *asn = NULL;
static gint
parse_der_private_key_dsa_parts (GcrParser *self,
- EggBytes *keydata,
- EggBytes *params)
+ GBytes *keydata,
+ GBytes *params)
{
gint ret = GCR_ERROR_UNRECOGNIZED;
GNode *asn_params = NULL;
static gint
parse_der_private_key (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
gint res;
static gint
handle_subject_public_key_rsa (GcrParser *self,
GcrParsed *parsed,
- EggBytes *key,
- EggBytes *params)
+ GBytes *key,
+ GBytes *params)
{
gint res = GCR_ERROR_FAILURE;
GNode *asn = NULL;
static gint
handle_subject_public_key_dsa (GcrParser *self,
GcrParsed *parsed,
- EggBytes *key,
- EggBytes *params)
+ GBytes *key,
+ GBytes *params)
{
gint res = GCR_ERROR_FAILURE;
GNode *key_asn = NULL;
static gint
parse_der_subject_public_key (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GcrParsed *parsed;
- EggBytes *params;
- EggBytes *key;
+ GBytes *params;
+ GBytes *key;
GNode *asn = NULL;
GNode *node;
GQuark oid;
else
ret = GCR_ERROR_UNRECOGNIZED;
- egg_bytes_unref (key);
- egg_bytes_unref (params);
+ g_bytes_unref (key);
+ g_bytes_unref (params);
if (ret == SUCCESS)
parsed_fire (self, parsed);
static gint
parse_der_pkcs8_plain (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
gint ret;
CK_KEY_TYPE key_type;
GQuark key_algo;
- EggBytes *keydata = NULL;
- EggBytes *params = NULL;
+ GBytes *keydata = NULL;
+ GBytes *params = NULL;
GNode *asn = NULL;
GcrParsed *parsed;
}
if (keydata)
- egg_bytes_unref (keydata);
+ g_bytes_unref (keydata);
if (params)
- egg_bytes_unref (params);
+ g_bytes_unref (params);
egg_asn1x_destroy (asn);
pop_parsed (self, parsed);
return ret;
static gint
parse_der_pkcs8_encrypted (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
PasswordState pstate = PASSWORD_STATE_INIT;
GNode *asn = NULL;
gint ret, r;
GQuark scheme;
guchar *crypted = NULL;
- EggBytes *params = NULL;
- EggBytes *cbytes;
+ GBytes *params = NULL;
+ GBytes *cbytes;
gsize n_crypted;
const gchar *password;
GcrParsed *parsed;
if (l > 0)
n_crypted = l;
- cbytes = egg_bytes_new_with_free_func (crypted, n_crypted,
+ cbytes = g_bytes_new_with_free_func (crypted, n_crypted,
egg_secure_free, crypted);
crypted = NULL;
/* Try to parse the resulting key */
r = parse_der_pkcs8_plain (self, cbytes);
- egg_bytes_unref (cbytes);
+ g_bytes_unref (cbytes);
if (r != GCR_ERROR_UNRECOGNIZED) {
ret = r;
done:
if (params)
- egg_bytes_unref (params);
+ g_bytes_unref (params);
if (cih)
gcry_cipher_close (cih);
egg_asn1x_destroy (asn);
static gint
parse_der_pkcs8 (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
gint ret;
static gint
parse_der_certificate (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
gchar *name = NULL;
GcrParsed *parsed;
static gint
handle_pkcs7_signed_data (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
GNode *node;
gint ret;
- EggBytes *certificate;
+ GBytes *certificate;
int i;
ret = GCR_ERROR_UNRECOGNIZED;
certificate = egg_asn1x_get_element_raw (node);
ret = parse_der_certificate (self, certificate);
- egg_bytes_unref (certificate);
+ g_bytes_unref (certificate);
if (ret != SUCCESS)
goto done;
static gint
parse_der_pkcs7 (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
GNode *node;
gint ret;
- EggBytes *content = NULL;
+ GBytes *content = NULL;
GQuark oid;
GcrParsed *parsed;
done:
if (content)
- egg_bytes_unref (content);
+ g_bytes_unref (content);
egg_asn1x_destroy (asn);
pop_parsed (self, parsed);
return ret;
static GNode *
decode_pkcs12_asn1_accepting_invalid_crap (const EggAsn1xDef *defs,
const gchar *identifier,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn;
static gint
handle_pkcs12_cert_bag (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
GNode *asn_content = NULL;
guchar *certificate = NULL;
- EggBytes *element = NULL;
+ GBytes *element = NULL;
gsize n_certificate;
- EggBytes *bytes;
+ GBytes *bytes;
gint ret;
ret = GCR_ERROR_UNRECOGNIZED;
if (!certificate)
goto done;
- bytes = egg_bytes_new_take (certificate, n_certificate);
+ bytes = g_bytes_new_take (certificate, n_certificate);
ret = parse_der_certificate (self, bytes);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
done:
if (element)
- egg_bytes_unref (element);
+ g_bytes_unref (element);
egg_asn1x_destroy (asn_content);
egg_asn1x_destroy (asn);
return ret;
guint count, i;
GQuark oid;
GNode *node;
- EggBytes *element;
+ GBytes *element;
GNode *asn_str;
gchar *result;
element = egg_asn1x_get_element_raw (node);
asn_str = egg_asn1x_create_and_decode (pkix_asn1_tab, "BMPString",
element);
- egg_bytes_unref (element);
+ g_bytes_unref (element);
if (asn_str) {
result = egg_asn1x_get_bmpstring_as_utf8 (asn_str);
egg_asn1x_destroy (asn_str);
static gint
handle_pkcs12_bag (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
gint ret, r;
guint count = 0;
GQuark oid;
- EggBytes *element = NULL;
+ GBytes *element = NULL;
gchar *friendly;
guint i;
GcrParsed *parsed;
}
if (element != NULL)
- egg_bytes_unref (element);
+ g_bytes_unref (element);
pop_parsed (self, parsed);
static gint
handle_pkcs12_encrypted_bag (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
PasswordState pstate = PASSWORD_STATE_INIT;
GNode *asn = NULL;
gcry_cipher_hd_t cih = NULL;
gcry_error_t gcry;
guchar *crypted = NULL;
- EggBytes *params = NULL;
+ GBytes *params = NULL;
gsize n_crypted;
const gchar *password;
- EggBytes *cbytes;
+ GBytes *cbytes;
GQuark scheme;
gint ret, r;
gint l;
if (l > 0)
n_crypted = l;
- cbytes = egg_bytes_new_with_free_func (crypted, n_crypted, egg_secure_free, crypted);
+ cbytes = g_bytes_new_with_free_func (crypted, n_crypted, egg_secure_free, crypted);
crypted = NULL;
/* Try to parse the resulting key */
r = handle_pkcs12_bag (self, cbytes);
- egg_bytes_unref (cbytes);
+ g_bytes_unref (cbytes);
if (r != GCR_ERROR_UNRECOGNIZED) {
ret = r;
done:
if (params)
- egg_bytes_unref (params);
+ g_bytes_unref (params);
if (cih)
gcry_cipher_close (cih);
egg_asn1x_destroy (asn);
static gint
handle_pkcs12_safe (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
GNode *asn_content = NULL;
gint ret, r;
- EggBytes *bag = NULL;
- EggBytes *content;
+ GBytes *bag = NULL;
+ GBytes *content;
GQuark oid;
guint i;
GNode *node;
goto done;
r = handle_pkcs12_bag (self, content);
- egg_bytes_unref (content);
+ g_bytes_unref (content);
/* Encrypted data first needs decryption */
} else if (oid == GCR_OID_PKCS7_ENCRYPTED_DATA) {
r = GCR_ERROR_UNRECOGNIZED;
}
- egg_bytes_unref (bag);
+ g_bytes_unref (bag);
bag = NULL;
if (r == GCR_ERROR_FAILURE ||
done:
if (bag != NULL)
- egg_bytes_unref (bag);
+ g_bytes_unref (bag);
egg_asn1x_destroy (asn);
egg_asn1x_destroy (asn_content);
return ret;
static gint
verify_pkcs12_safe (GcrParser *self,
GNode *asn,
- EggBytes *content)
+ GBytes *content)
{
PasswordState pstate = PASSWORD_STATE_INIT;
const gchar *password;
gsize n_digest;
GQuark algorithm;
GNode *mac_data;
- EggBytes *params = NULL;
+ GBytes *params = NULL;
int ret, r;
ret = GCR_ERROR_FAILURE;
r = GCR_ERROR_FAILURE;
} else {
- gcry_md_write (mdh, egg_bytes_get_data (content), egg_bytes_get_size (content));
+ gcry_md_write (mdh, g_bytes_get_data (content, NULL), g_bytes_get_size (content));
mac_digest = gcry_md_read (mdh, 0);
g_return_val_if_fail (mac_digest, GCR_ERROR_FAILURE);
r = memcmp (mac_digest, digest, n_digest) == 0 ? SUCCESS : GCR_ERROR_LOCKED;
done:
if (params)
- egg_bytes_unref (params);
+ g_bytes_unref (params);
if (mdh)
gcry_md_close (mdh);
g_free (digest);
static gint
parse_der_pkcs12 (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
GNode *asn_content = NULL;
gint ret;
- EggBytes *element = NULL;
- EggBytes *content = NULL;
+ GBytes *element = NULL;
+ GBytes *content = NULL;
GQuark oid;
GcrParsed *parsed;
done:
if (element)
- egg_bytes_unref (element);
+ g_bytes_unref (element);
if (content)
- egg_bytes_unref (content);
+ g_bytes_unref (content);
egg_asn1x_destroy (asn_content);
egg_asn1x_destroy (asn);
pop_parsed (self, parsed);
static gint
parse_der_pkcs10 (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
GNode *node;
static gint
parse_der_spkac (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn = NULL;
GcrParsed *parsed;
static gint
parse_base64_spkac (GcrParser *self,
- EggBytes *dat)
+ GBytes *dat)
{
const gchar *PREFIX = "SPKAC=";
const gsize PREFIX_LEN = 6;
guchar *spkac;
gsize n_spkac;
const guchar *data;
- EggBytes *bytes;
+ GBytes *bytes;
gsize n_data;
gint ret;
- data = egg_bytes_get_data (dat);
- n_data = egg_bytes_get_size (dat);
+ data = g_bytes_get_data (dat, &n_data);
if (n_data > PREFIX_LEN && memcmp (PREFIX, data, PREFIX_LEN))
return GCR_ERROR_UNRECOGNIZED;
spkac = g_base64_decode ((const gchar *)data, &n_spkac);
if (spkac != NULL) {
- bytes = egg_bytes_new_take (spkac, n_spkac);
+ bytes = g_bytes_new_take (spkac, n_spkac);
ret = parse_der_spkac (self, bytes);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
} else {
ret = GCR_ERROR_FAILURE;
}
static void
on_openpgp_packet (GPtrArray *records,
- EggBytes *outer,
+ GBytes *outer,
gpointer user_data)
{
GcrParser *self = GCR_PARSER (user_data);
static gint
parse_openpgp_packets (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
gint num_parsed;
handle_plain_pem (GcrParser *self,
gint format_id,
gint want_format,
- EggBytes *data)
+ GBytes *data)
{
ParserFormat *format;
gint format_id,
gint want_format,
GHashTable *headers,
- EggBytes *data)
+ GBytes *data)
{
PasswordState pstate = PASSWORD_STATE_INIT;
const gchar *password;
guchar *decrypted;
gsize n_decrypted;
const gchar *val;
- EggBytes *dbytes;
+ GBytes *dbytes;
gint res;
gint l;
if (l > 0)
n_decrypted = l;
- dbytes = egg_bytes_new_with_free_func (decrypted, n_decrypted,
+ dbytes = g_bytes_new_with_free_func (decrypted, n_decrypted,
egg_secure_free, decrypted);
decrypted = NULL;
/* Try to parse */
res = handle_plain_pem (self, format_id, want_format, dbytes);
- egg_bytes_unref (dbytes);
+ g_bytes_unref (dbytes);
/* Unrecognized is a bad password */
if (res != GCR_ERROR_UNRECOGNIZED)
static void
handle_pem_data (GQuark type,
- EggBytes *data,
- EggBytes *outer,
+ GBytes *data,
+ GBytes *outer,
GHashTable *headers,
gpointer user_data)
{
static gint
handle_pem_format (GcrParser *self,
gint subformat,
- EggBytes *data)
+ GBytes *data)
{
HandlePemArgs ctx = { self, GCR_ERROR_UNRECOGNIZED, subformat };
guint found;
- if (egg_bytes_get_size (data) == 0)
+ if (g_bytes_get_size (data) == 0)
return GCR_ERROR_UNRECOGNIZED;
found = egg_armor_parse (data, handle_pem_data, &ctx);
static gint
parse_pem (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, 0, data);
}
static gint
parse_pem_private_key_rsa (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_PRIVATE_KEY_RSA, data);
}
static gint
parse_pem_private_key_dsa (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_PRIVATE_KEY_DSA, data);
}
static gint
parse_pem_certificate (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_CERTIFICATE_X509, data);
}
static gint
parse_pem_pkcs8_plain (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_PKCS8_PLAIN, data);
}
static gint
parse_pem_pkcs8_encrypted (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_PKCS8_ENCRYPTED, data);
}
static gint
parse_pem_pkcs7 (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_PKCS7, data);
}
static gint
parse_pem_pkcs10 (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_PKCS10, data);
}
static gint
parse_pem_pkcs12 (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_DER_PKCS12, data);
}
static gint
parse_openpgp_armor (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
return handle_pem_format (self, GCR_FORMAT_OPENPGP_PACKET, data);
}
on_openssh_public_key_parsed (GckAttributes *attrs,
const gchar *label,
const gchar *options,
- EggBytes *outer,
+ GBytes *outer,
gpointer user_data)
{
GcrParser *self = GCR_PARSER (user_data);
static gint
parse_openssh_public (GcrParser *self,
- EggBytes *data)
+ GBytes *data)
{
guint num_parsed;
typedef struct _ForeachArgs {
GcrParser *parser;
- EggBytes *data;
+ GBytes *data;
gint result;
} ForeachArgs;
if (data && n_data) {
/* TODO: Once GBytes is in the API, copy here */
- args.data = egg_bytes_new_static (data, n_data);
+ args.data = g_bytes_new_static (data, n_data);
/* Just the specific formats requested */
if (self->pv->specific_formats) {
}
}
- egg_bytes_unref (args.data);
+ g_bytes_unref (args.data);
}
switch (args.result) {
/* Find the block of data to copy */
while (parsed != NULL) {
if (parsed->data != NULL) {
- copy->data = egg_bytes_ref (parsed->data);
+ copy->data = g_bytes_ref (parsed->data);
copy->sensitive = parsed->sensitive;
break;
}
gck_attributes_unref (par->attrs);
g_free (par->label);
if (par->data)
- egg_bytes_unref (par->data);
+ g_bytes_unref (par->data);
g_free (par);
}
}
g_return_val_if_fail (n_data != NULL, NULL);
while (parsed != NULL) {
- if (parsed->data != NULL) {
- *n_data = egg_bytes_get_size (parsed->data);
- return egg_bytes_get_data (parsed->data);
- }
+ if (parsed->data != NULL)
+ return g_bytes_get_data (parsed->data, n_data);
parsed = parsed->next;
}
const GckAttribute *exponent;
GNode *key_asn;
GNode *params_asn;
- EggBytes *key;
- EggBytes *params;
- EggBytes *usg;
+ GBytes *key;
+ GBytes *params;
+ GBytes *usg;
_gcr_oids_init ();
params_asn = egg_asn1x_create (pk_asn1_tab, "RSAParameters");
g_return_val_if_fail (params_asn, FALSE);
- usg = egg_bytes_new_with_free_func (modulus->value, modulus->length,
+ usg = g_bytes_new_with_free_func (modulus->value, modulus->length,
gck_attributes_unref,
gck_attributes_ref (attrs));
egg_asn1x_set_integer_as_usg (egg_asn1x_node (key_asn, "modulus", NULL), usg);
- egg_bytes_unref (usg);
+ g_bytes_unref (usg);
- usg = egg_bytes_new_with_free_func (exponent->value, exponent->length,
+ usg = g_bytes_new_with_free_func (exponent->value, exponent->length,
gck_attributes_unref,
gck_attributes_ref (attrs));
egg_asn1x_set_integer_as_usg (egg_asn1x_node (key_asn, "publicExponent", NULL), usg);
- egg_bytes_unref (usg);
+ g_bytes_unref (usg);
key = egg_asn1x_encode (key_asn, NULL);
egg_asn1x_destroy (key_asn);
egg_asn1x_destroy (params_asn);
egg_asn1x_set_bits_as_raw (egg_asn1x_node (info_asn, "subjectPublicKey", NULL),
- key, egg_bytes_get_size (key) * 8);
+ key, g_bytes_get_size (key) * 8);
egg_asn1x_set_oid_as_quark (egg_asn1x_node (info_asn, "algorithm", "algorithm", NULL), GCR_OID_PKIX1_RSA);
egg_asn1x_set_element_raw (egg_asn1x_node (info_asn, "algorithm", "parameters", NULL), params);
- egg_bytes_unref (key);
- egg_bytes_unref (params);
+ g_bytes_unref (key);
+ g_bytes_unref (params);
return TRUE;
}
gcry = gcry_mpi_aprint (GCRYMPI_FMT_STD, &buffer, &n_buffer, my);
g_return_val_if_fail (gcry == 0, FALSE);
- egg_asn1x_take_integer_as_raw (key_asn, egg_bytes_new_with_free_func (buffer, n_buffer,
+ egg_asn1x_take_integer_as_raw (key_asn, g_bytes_new_with_free_func (buffer, n_buffer,
gcry_free, buffer));
gcry_mpi_release (mp);
{
const GckAttribute *value, *g, *q, *p;
GNode *key_asn, *params_asn;
- EggBytes *key;
- EggBytes *params;
+ GBytes *key;
+ GBytes *params;
_gcr_oids_init ();
g_return_val_if_fail (params_asn, FALSE);
egg_asn1x_take_integer_as_usg (egg_asn1x_node (params_asn, "p", NULL),
- egg_bytes_new_with_free_func (p->value, p->length,
+ g_bytes_new_with_free_func (p->value, p->length,
gck_attributes_unref,
gck_attributes_ref (attrs)));
egg_asn1x_take_integer_as_usg (egg_asn1x_node (params_asn, "q", NULL),
- egg_bytes_new_with_free_func (q->value, q->length,
+ g_bytes_new_with_free_func (q->value, q->length,
gck_attributes_unref,
gck_attributes_ref (attrs)));
egg_asn1x_take_integer_as_usg (egg_asn1x_node (params_asn, "g", NULL),
- egg_bytes_new_with_free_func (g->value, g->length,
+ g_bytes_new_with_free_func (g->value, g->length,
gck_attributes_unref,
gck_attributes_ref (attrs)));
} else if (klass == CKO_PUBLIC_KEY) {
egg_asn1x_take_integer_as_usg (key_asn,
- egg_bytes_new_with_free_func (value->value, value->length,
+ g_bytes_new_with_free_func (value->value, value->length,
gck_attributes_unref,
gck_attributes_ref (attrs)));
} else {
egg_asn1x_destroy (params_asn);
egg_asn1x_set_bits_as_raw (egg_asn1x_node (info_asn, "subjectPublicKey", NULL),
- key, egg_bytes_get_size (key) * 8);
+ key, g_bytes_get_size (key) * 8);
egg_asn1x_set_element_raw (egg_asn1x_node (info_asn, "algorithm", "parameters", NULL), params);
egg_asn1x_set_oid_as_quark (egg_asn1x_node (info_asn, "algorithm", "algorithm", NULL), GCR_OID_PKIX1_DSA);
- egg_bytes_unref (key);
- egg_bytes_unref (params);
+ g_bytes_unref (key);
+ g_bytes_unref (params);
return TRUE;
}
cert_subject_public_key_from_attributes (GckAttributes *attributes)
{
const GckAttribute *attr;
- EggBytes *bytes;
+ GBytes *bytes;
GNode *cert;
GNode *asn;
return NULL;
}
- bytes = egg_bytes_new_with_free_func (attr->value, attr->length,
+ bytes = g_bytes_new_with_free_func (attr->value, attr->length,
gck_attributes_unref,
gck_attributes_ref (attributes));
cert = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", bytes);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
if (cert == NULL) {
_gcr_debug ("couldn't parse certificate value");
}
static guint
-calculate_rsa_key_size (EggBytes *data)
+calculate_rsa_key_size (GBytes *data)
{
GNode *asn;
- EggBytes *content;
+ GBytes *content;
guint key_size;
asn = egg_asn1x_create_and_decode (pk_asn1_tab, "RSAPublicKey", data);
egg_asn1x_destroy (asn);
/* Removes the complement */
- key_size = (egg_bytes_get_size (content) / 2) * 2 * 8;
+ key_size = (g_bytes_get_size (content) / 2) * 2 * 8;
- egg_bytes_unref (content);
+ g_bytes_unref (content);
return key_size;
}
static guint
-calculate_dsa_params_size (EggBytes *data)
+calculate_dsa_params_size (GBytes *data)
{
GNode *asn;
- EggBytes *content;
+ GBytes *content;
guint key_size;
asn = egg_asn1x_create_and_decode (pk_asn1_tab, "DSAParameters", data);
egg_asn1x_destroy (asn);
/* Removes the complement */
- key_size = (egg_bytes_get_size (content) / 2) * 2 * 8;
+ key_size = (g_bytes_get_size (content) / 2) * 2 * 8;
- egg_bytes_unref (content);
+ g_bytes_unref (content);
return key_size;
}
guint
_gcr_subject_public_key_calculate_size (GNode *subject_public_key)
{
- EggBytes *key;
+ GBytes *key;
guint key_size = 0;
guint n_bits;
GQuark oid;
key = egg_asn1x_get_bits_as_raw (egg_asn1x_node (subject_public_key, "subjectPublicKey", NULL), &n_bits);
g_return_val_if_fail (key != NULL, 0);
key_size = calculate_rsa_key_size (key);
- egg_bytes_unref (key);
+ g_bytes_unref (key);
/* The DSA key size is discovered by the prime in params */
} else if (oid == GCR_OID_PKIX1_DSA) {
key = egg_asn1x_get_element_raw (egg_asn1x_node (subject_public_key, "algorithm", "parameters", NULL));
key_size = calculate_dsa_params_size (key);
- egg_bytes_unref (key);
+ g_bytes_unref (key);
} else {
g_message ("unsupported key algorithm: %s", g_quark_to_string (oid));
static void
on_packet_print_records (GPtrArray *records,
- EggBytes *packet,
+ GBytes *packet,
gpointer user_data)
{
gchar *string;
}
static gboolean
-parse_binary (EggBytes *contents)
+parse_binary (GBytes *contents)
{
guint packets;
static void
on_armor_parsed (GQuark type,
- EggBytes *data,
- EggBytes *outer,
+ GBytes *data,
+ GBytes *outer,
GHashTable *headers,
gpointer user_data)
{
}
static gboolean
-parse_armor_or_binary (EggBytes *contents)
+parse_armor_or_binary (GBytes *contents)
{
gboolean result;
guint parts;
GError *error = NULL;
gchar *contents;
gsize length;
- EggBytes *bytes;
+ GBytes *bytes;
int ret;
g_set_prgname ("frob-openpgp");
return 1;
}
- bytes = egg_bytes_new_take (contents, length);
+ bytes = g_bytes_new_take (contents, length);
ret = 0;
if (!parse_armor_or_binary (bytes)) {
g_printerr ("frob-openpgp: no openpgp data found in data");
ret = 1;
}
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
return ret;
}
#include <errno.h>
typedef struct {
- EggBytes *cert_rsa;
- EggBytes *key_rsa;
- EggBytes *cert_dsa;
- EggBytes *key_dsa;
+ GBytes *cert_rsa;
+ GBytes *key_rsa;
+ GBytes *cert_dsa;
+ GBytes *key_dsa;
} Test;
static void
g_file_get_contents (SRCDIR "/files/client.crt", &contents, &length, &error);
g_assert_no_error (error);
- test->cert_rsa = egg_bytes_new_take (contents, length);
+ test->cert_rsa = g_bytes_new_take (contents, length);
g_file_get_contents (SRCDIR "/files/client.key", &contents, &length, &error);
g_assert_no_error (error);
- test->key_rsa = egg_bytes_new_take (contents, length);
+ test->key_rsa = g_bytes_new_take (contents, length);
g_file_get_contents (SRCDIR "/files/generic-dsa.crt", &contents, &length, &error);
g_assert_no_error (error);
- test->cert_dsa = egg_bytes_new_take (contents, length);
+ test->cert_dsa = g_bytes_new_take (contents, length);
g_file_get_contents (SRCDIR "/files/generic-dsa.key", &contents, &length, &error);
g_assert_no_error (error);
- test->key_dsa = egg_bytes_new_take (contents, length);
+ test->key_dsa = g_bytes_new_take (contents, length);
}
static void
teardown (Test *test, gconstpointer unused)
{
- egg_bytes_unref (test->cert_rsa);
- egg_bytes_unref (test->key_rsa);
- egg_bytes_unref (test->cert_dsa);
- egg_bytes_unref (test->key_dsa);
+ g_bytes_unref (test->cert_rsa);
+ g_bytes_unref (test->key_rsa);
+ g_bytes_unref (test->cert_dsa);
+ g_bytes_unref (test->key_dsa);
}
static void
}
static GckAttributes*
-parse_attributes_for_key (EggBytes *data)
+parse_attributes_for_key (GBytes *data)
{
GcrParser *parser;
GckAttributes *attrs = NULL;
parser = gcr_parser_new ();
g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), &attrs);
- gcr_parser_parse_data (parser, egg_bytes_get_data (data),
- egg_bytes_get_size (data), &error);
+ gcr_parser_parse_data (parser, g_bytes_get_data (data, NULL),
+ g_bytes_get_size (data), &error);
g_assert_no_error (error);
g_object_unref (parser);
}
static GckAttributes *
-build_attributes_for_cert (EggBytes *data)
+build_attributes_for_cert (GBytes *data)
{
GckBuilder builder = GCK_BUILDER_INIT;
- gck_builder_add_data (&builder, CKA_VALUE, egg_bytes_get_data (data),
- egg_bytes_get_size (data));
+ gck_builder_add_data (&builder, CKA_VALUE, g_bytes_get_data (data, NULL),
+ g_bytes_get_size (data));
gck_builder_add_ulong (&builder, CKA_CLASS, CKO_CERTIFICATE);
gck_builder_add_ulong (&builder, CKA_CERTIFICATE_TYPE, CKC_X_509);
return gck_attributes_ref_sink (gck_builder_end (&builder));
}
-static EggBytes *
-parse_subject_public_key_info_for_cert (EggBytes *data)
+static GBytes *
+parse_subject_public_key_info_for_cert (GBytes *data)
{
- EggBytes *info;
+ GBytes *info;
GNode *asn;
asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", data);
test_rsa (Test *test, gconstpointer unused)
{
GckAttributes *key, *cert;
- EggBytes *info;
+ GBytes *info;
guchar *fingerprint1, *fingerprint2, *fingerprint3;
gsize n_fingerprint1, n_fingerprint2, n_fingerprint3;
info = parse_subject_public_key_info_for_cert (test->cert_rsa);
cert = build_attributes_for_cert (test->cert_rsa);
- fingerprint1 = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (info),
- egg_bytes_get_size (info),
+ fingerprint1 = gcr_fingerprint_from_subject_public_key_info (g_bytes_get_data (info, NULL),
+ g_bytes_get_size (info),
G_CHECKSUM_SHA1, &n_fingerprint1);
fingerprint2 = gcr_fingerprint_from_attributes (key, G_CHECKSUM_SHA1, &n_fingerprint2);
fingerprint3 = gcr_fingerprint_from_attributes (cert, G_CHECKSUM_SHA1, &n_fingerprint3);
g_free (fingerprint2);
g_free (fingerprint3);
- egg_bytes_unref (info);
+ g_bytes_unref (info);
gck_attributes_unref (key);
gck_attributes_unref (cert);
}
test_dsa (Test *test, gconstpointer unused)
{
GckAttributes *key, *cert;
- EggBytes *info;
+ GBytes *info;
guchar *fingerprint1, *fingerprint2, *fingerprint3;
gsize n_fingerprint1, n_fingerprint2, n_fingerprint3;
info = parse_subject_public_key_info_for_cert (test->cert_dsa);
cert = build_attributes_for_cert (test->cert_dsa);
- fingerprint1 = gcr_fingerprint_from_subject_public_key_info (egg_bytes_get_data (info),
- egg_bytes_get_size (info),
+ fingerprint1 = gcr_fingerprint_from_subject_public_key_info (g_bytes_get_data (info, NULL),
+ g_bytes_get_size (info),
G_CHECKSUM_SHA1, &n_fingerprint1);
fingerprint2 = gcr_fingerprint_from_attributes (key, G_CHECKSUM_SHA1, &n_fingerprint2);
fingerprint3 = gcr_fingerprint_from_attributes (cert, G_CHECKSUM_SHA1, &n_fingerprint3);
g_free (fingerprint2);
g_free (fingerprint3);
- egg_bytes_unref (info);
+ g_bytes_unref (info);
gck_attributes_unref (key);
gck_attributes_unref (cert);
}
static void
on_openpgp_packet (GPtrArray *records,
- EggBytes *outer,
+ GBytes *outer,
gpointer user_data)
{
Test *test = user_data;
static void
on_armor_parsed (GQuark type,
- EggBytes *data,
- EggBytes *outer,
+ GBytes *data,
+ GBytes *outer,
GHashTable *headers,
gpointer user_data)
{
gconstpointer data)
{
GError *error = NULL;
- EggBytes *bytes;
+ GBytes *bytes;
gchar *armor;
gsize length;
guint parts;
g_file_get_contents (test->fixture->filename, &armor, &length, &error);
g_assert_no_error (error);
- bytes = egg_bytes_new_take (armor, length);
+ bytes = g_bytes_new_take (armor, length);
parts = egg_armor_parse (bytes, on_armor_parsed, test);
g_assert_cmpuint (parts, ==, 1);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
gconstpointer data)
{
GError *error = NULL;
- EggBytes *bytes;
+ GBytes *bytes;
gchar *binary;
gsize length;
guint seen;
g_file_get_contents (test->fixture->filename, &binary, &length, &error);
g_assert_no_error (error);
- bytes = egg_bytes_new_take (binary, length);
+ bytes = g_bytes_new_take (binary, length);
seen = _gcr_openpgp_parse (bytes, test->fixture->flags, on_openpgp_packet, test);
g_assert_cmpuint (seen, >, 0);
g_assert_not_reached ();
}
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
int
on_openssh_pub_parse (GckAttributes *attrs,
const gchar *label,
const gchar *options,
- EggBytes *outer,
+ GBytes *outer,
gpointer user_data)
{
Test *test = user_data;
gconstpointer unused)
{
const gchar *data = OPENSSH_PUBLIC_RSA1 EXTRA_LINES_WITHOUT_KEY;
- EggBytes *bytes;
+ GBytes *bytes;
gint keys;
test->expected_label = "rsa-key@example.com";
- bytes = egg_bytes_new_static (data, strlen (data));
+ bytes = g_bytes_new_static (data, strlen (data));
keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
gconstpointer unused)
{
const gchar *data = OPENSSH_PUBLIC_RSA2 EXTRA_LINES_WITHOUT_KEY;
- EggBytes *bytes;
+ GBytes *bytes;
gint keys;
test->expected_label = "rsa-key@example.com";
- bytes = egg_bytes_new_static (data, strlen (data));
+ bytes = g_bytes_new_static (data, strlen (data));
keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
gconstpointer unused)
{
const gchar *data = OPENSSH_PUBLIC_DSA2 EXTRA_LINES_WITHOUT_KEY;
- EggBytes *bytes;
+ GBytes *bytes;
gint keys;
test->expected_label = "dsa-key@example.com";
- bytes = egg_bytes_new_static (data, strlen (data));
+ bytes = g_bytes_new_static (data, strlen (data));
keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
gconstpointer unused)
{
const gchar *data = "option1,option2=\"value 2\",option3 " OPENSSH_PUBLIC_RSA1;
- EggBytes *bytes;
+ GBytes *bytes;
gint keys;
test->expected_options = "option1,option2=\"value 2\",option3";
- bytes = egg_bytes_new_static (data, strlen (data));
+ bytes = g_bytes_new_static (data, strlen (data));
keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
static void
gconstpointer unused)
{
const gchar *data = "option1,option2=\"value 2\",option3 " OPENSSH_PUBLIC_RSA2;
- EggBytes *bytes;
+ GBytes *bytes;
gint keys;
test->expected_options = "option1,option2=\"value 2\",option3";
- bytes = egg_bytes_new_static (data, strlen (data));
+ bytes = g_bytes_new_static (data, strlen (data));
keys = _gcr_openssh_pub_parse (bytes, on_openssh_pub_parse, test);
g_assert_cmpint (keys, ==, 1);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
int
GList *modules = NULL;
CK_FUNCTION_LIST_PTR f;
GckModule *module;
- EggBytes *subject;
- EggBytes *bytes;
+ GBytes *subject;
+ GBytes *bytes;
GNode *asn, *node;
CK_RV rv;
gcr_pkcs11_set_modules (modules);
gck_list_unref_free (modules);
- bytes = egg_bytes_new_static (test->cert_data, test->n_cert_data);
+ bytes = g_bytes_new_static (test->cert_data, test->n_cert_data);
asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", bytes);
g_assert (asn);
node = egg_asn1x_node (asn, "tbsCertificate", "subject", NULL);
gck_builder_add_ulong (&builder, CKA_CLASS, CKO_CERTIFICATE);
gck_builder_add_ulong (&builder, CKA_CERTIFICATE_TYPE, CKC_X_509);
gck_builder_add_data (&builder, CKA_SUBJECT,
- egg_bytes_get_data (subject),
- egg_bytes_get_size (subject));
+ g_bytes_get_data (subject, NULL),
+ g_bytes_get_size (subject));
gck_mock_module_add_object (gck_builder_end (&builder));
- egg_bytes_unref (bytes);
- egg_bytes_unref (subject);
+ g_bytes_unref (bytes);
+ g_bytes_unref (subject);
egg_asn1x_destroy (asn);
}
} TestFixture;
typedef struct {
- EggBytes *crt_data;
+ GBytes *crt_data;
GckAttributes *crt_attrs;
- EggBytes *key_data;
+ GBytes *key_data;
GckAttributes *prv_attrs;
- EggBytes *spk_data;
+ GBytes *spk_data;
GckAttributes *pub_attrs;
} TestAttributes;
}
static GckAttributes *
-parse_attributes (EggBytes *data)
+parse_attributes (GBytes *data)
{
GcrParser *parser;
GckAttributes *attrs = NULL;
parser = gcr_parser_new ();
g_signal_connect (parser, "parsed", G_CALLBACK (on_parser_parsed), &attrs);
- gcr_parser_parse_data (parser, egg_bytes_get_data (data),
- egg_bytes_get_size (data), &error);
+ gcr_parser_parse_data (parser, g_bytes_get_data (data, NULL),
+ g_bytes_get_size (data), &error);
g_assert_no_error (error);
g_object_unref (parser);
filename = g_strdup_printf (SRCDIR "/files/%s.crt", fixture->basename);
g_file_get_contents (filename, &contents, &length, &error);
g_assert_no_error (error);
- test->crt_data = egg_bytes_new_take (contents, length);
+ test->crt_data = g_bytes_new_take (contents, length);
test->crt_attrs = parse_attributes (test->crt_data);
g_assert (gck_attributes_find_ulong (test->crt_attrs, CKA_CLASS, &klass));
gck_assert_cmpulong (klass, ==, CKO_CERTIFICATE);
filename = g_strdup_printf (SRCDIR "/files/%s.key", fixture->basename);
g_file_get_contents (filename, &contents, &length, &error);
g_assert_no_error (error);
- test->key_data = egg_bytes_new_take (contents, length);
+ test->key_data = g_bytes_new_take (contents, length);
test->prv_attrs = parse_attributes (test->key_data);
g_assert (gck_attributes_find_ulong (test->prv_attrs, CKA_CLASS, &klass));
gck_assert_cmpulong (klass, ==, CKO_PRIVATE_KEY);
filename = g_strdup_printf (SRCDIR "/files/%s.spk", fixture->basename);
g_file_get_contents (filename, &contents, &length, &error);
g_assert_no_error (error);
- test->spk_data = egg_bytes_new_take (contents, length);
+ test->spk_data = g_bytes_new_take (contents, length);
test->pub_attrs = parse_attributes (test->spk_data);
g_assert (gck_attributes_find_ulong (test->pub_attrs, CKA_CLASS, &klass));
gck_assert_cmpulong (klass, ==, CKO_PUBLIC_KEY);
teardown_attributes (TestAttributes *test,
gconstpointer unused)
{
- egg_bytes_unref (test->crt_data);
- egg_bytes_unref (test->key_data);
- egg_bytes_unref (test->spk_data);
+ g_bytes_unref (test->crt_data);
+ g_bytes_unref (test->key_data);
+ g_bytes_unref (test->spk_data);
gck_attributes_unref (test->crt_attrs);
gck_attributes_unref (test->prv_attrs);
gck_attributes_unref (test->pub_attrs);
GckAttributes *attrs)
{
GNode *info;
- EggBytes *data;
+ GBytes *data;
info = _gcr_subject_public_key_for_attributes (attrs);
g_assert (info != NULL);
data = egg_asn1x_encode (info, NULL);
- egg_assert_cmpbytes (data, ==, egg_bytes_get_data (test->spk_data),
- egg_bytes_get_size (test->spk_data));
+ egg_assert_cmpbytes (data, ==, g_bytes_get_data (test->spk_data, NULL),
+ g_bytes_get_size (test->spk_data));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (info);
}
g_assert (info != NULL);
/* TODO: until encoding, we don't have readable attributes */
- egg_bytes_unref (egg_asn1x_encode (info, NULL));
+ g_bytes_unref (egg_asn1x_encode (info, NULL));
size = _gcr_subject_public_key_calculate_size (info);
g_assert_cmpuint (size, ==, fixture->key_size);
GckObject *object)
{
GError *error = NULL;
- EggBytes *data;
+ GBytes *data;
GNode *info;
info = _gcr_subject_public_key_load (object, NULL, &error);
g_assert (info != NULL);
data = egg_asn1x_encode (info, NULL);
- egg_assert_cmpbytes (data, ==, egg_bytes_get_data (test->at.spk_data),
- egg_bytes_get_size (test->at.spk_data));
+ egg_assert_cmpbytes (data, ==, g_bytes_get_data (test->at.spk_data, NULL),
+ g_bytes_get_size (test->at.spk_data));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (info);
}
{
GAsyncResult *result = NULL;
GError *error = NULL;
- EggBytes *data;
+ GBytes *data;
GNode *info;
_gcr_subject_public_key_load_async (object, NULL, on_async_result, &result);
g_object_unref (result);
data = egg_asn1x_encode (info, NULL);
- egg_assert_cmpbytes (data, ==, egg_bytes_get_data (test->at.spk_data),
- egg_bytes_get_size (test->at.spk_data));
+ egg_assert_cmpbytes (data, ==, g_bytes_get_data (test->at.spk_data, NULL),
+ g_bytes_get_size (test->at.spk_data));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (info);
}
const gulong INVALID = 0xFFF00FF; /* invalid handle, should not be used */
GckObject *object;
GError *error = NULL;
- EggBytes *data;
+ GBytes *data;
GNode *info;
object = g_object_new (mock_object_get_type (),
g_assert (info != NULL);
data = egg_asn1x_encode (info, NULL);
- egg_assert_cmpbytes (data, ==, egg_bytes_get_data (test->at.spk_data),
- egg_bytes_get_size (test->at.spk_data));
+ egg_assert_cmpbytes (data, ==, g_bytes_get_data (test->at.spk_data, NULL),
+ g_bytes_get_size (test->at.spk_data));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (info);
g_object_unref (object);
}
GckAttributes *partial;
GckObject *object;
GError *error = NULL;
- EggBytes *data;
+ GBytes *data;
GNode *info;
guint i;
g_assert (info != NULL);
data = egg_asn1x_encode (info, NULL);
- egg_assert_cmpbytes (data, ==, egg_bytes_get_data (test->at.spk_data),
- egg_bytes_get_size (test->at.spk_data));
+ egg_assert_cmpbytes (data, ==, g_bytes_get_data (test->at.spk_data, NULL),
+ g_bytes_get_size (test->at.spk_data));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (info);
g_object_unref (object);
}