summaryrefslogtreecommitdiff
path: root/egg
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2012-06-20 08:28:55 +0200
committerStef Walter <stefw@gnome.org>2012-06-20 08:30:20 +0200
commit2fce6f29272b9e78fb047913aab8531ddec2203e (patch)
treeee38ab7952375200ff8750095db615509efd4b6a /egg
parent7201cf3f86a76fc297102386c765194e04263a11 (diff)
downloadgcr-2fce6f29272b9e78fb047913aab8531ddec2203e.tar.gz
Use GBytes instead of our own EggBytes
* Bump glib minimum version to 2.32
Diffstat (limited to 'egg')
-rw-r--r--egg/Makefile.am1
-rw-r--r--egg/egg-armor.c22
-rw-r--r--egg/egg-armor.h8
-rw-r--r--egg/egg-asn1x.c178
-rw-r--r--egg/egg-asn1x.h36
-rw-r--r--egg/egg-bytes.c454
-rw-r--r--egg/egg-bytes.h102
-rw-r--r--egg/egg-dn.c35
-rw-r--r--egg/egg-dn.h6
-rw-r--r--egg/egg-openssl.c13
-rw-r--r--egg/egg-openssl.h6
-rw-r--r--egg/egg-symkey.c64
-rw-r--r--egg/egg-symkey.h6
-rw-r--r--egg/egg-testing.h4
-rw-r--r--egg/tests/test-asn1.c282
-rw-r--r--egg/tests/test-asn1x.c10
-rw-r--r--egg/tests/test-dn.c30
-rw-r--r--egg/tests/test-openssl.c36
18 files changed, 362 insertions, 931 deletions
diff --git a/egg/Makefile.am b/egg/Makefile.am
index 045902f..bfc6c33 100644
--- a/egg/Makefile.am
+++ b/egg/Makefile.am
@@ -30,7 +30,6 @@ libegg_la_SOURCES = \
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 \
diff --git a/egg/egg-armor.c b/egg/egg-armor.c
index 473e42e..812f1aa 100644
--- a/egg/egg-armor.c
+++ b/egg/egg-armor.c
@@ -269,7 +269,7 @@ egg_armor_headers_new (void)
}
guint
-egg_armor_parse (EggBytes *data,
+egg_armor_parse (GBytes *data,
EggArmorCallback callback,
gpointer user_data)
{
@@ -279,14 +279,13 @@ egg_armor_parse (EggBytes *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) {
@@ -305,15 +304,16 @@ egg_armor_parse (EggBytes *data,
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);
diff --git a/egg/egg-armor.h b/egg/egg-armor.h
index 586a0d2..e32d44d 100644
--- a/egg/egg-armor.h
+++ b/egg/egg-armor.h
@@ -26,17 +26,15 @@
#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);
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index cea8dad..0fabb74 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -139,7 +139,7 @@ struct _Anode {
Atlv *tlv;
Aenc *enc;
- EggBytes *backing;
+ GBytes *backing;
gchar* failure;
gint chosen : 1;
@@ -153,12 +153,12 @@ struct _Abuf {
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);
@@ -372,7 +372,7 @@ compare_tlvs (Atlv *tlva, Atlv *tlvb)
return la < lb ? -1 : 1;
}
-static inline EggBytes *
+static inline GBytes *
anode_get_backing (GNode *node)
{
Anode *an = node->data;
@@ -384,25 +384,25 @@ anode_clr_backing (GNode *node)
{
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;
@@ -516,7 +516,7 @@ abits_destroy (gpointer 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);
}
@@ -871,7 +871,7 @@ anode_decode_tlv_for_contents (Atlv *outer, gboolean first, Atlv *tlv)
static gboolean
anode_decode_choice (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *tlv)
{
gboolean have = FALSE;
@@ -929,7 +929,7 @@ anode_decode_struct_any (GNode *node, Atlv *tlv)
static gboolean
anode_decode_sequence_or_set (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *outer)
{
GNode *child;
@@ -962,7 +962,7 @@ anode_decode_sequence_or_set (GNode *node,
static gboolean
anode_decode_sequence_or_set_of (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *outer)
{
GNode *child, *other;
@@ -1008,7 +1008,7 @@ anode_decode_sequence_or_set_of (GNode *node,
static gboolean
anode_decode_primitive (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *tlv,
gint flags)
{
@@ -1054,7 +1054,7 @@ anode_decode_primitive (GNode *node,
static gboolean
anode_decode_structured (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
Atlv *tlv,
gint flags)
{
@@ -1156,7 +1156,7 @@ anode_decode_option_or_default (GNode *node, Atlv *tlv, gint flags)
static gboolean
anode_decode_anything_for_flags (GNode *node,
- EggBytes *bytes,
+ GBytes *bytes,
Atlv *tlv,
gint flags)
{
@@ -1189,7 +1189,7 @@ anode_decode_anything_for_flags (GNode *node,
static gboolean
anode_decode_anything (GNode *node,
- EggBytes *bytes,
+ GBytes *bytes,
Atlv *tlv)
{
gint flags = anode_def_flags (node);
@@ -1202,7 +1202,7 @@ anode_decode_anything (GNode *node,
gboolean
egg_asn1x_decode_no_validate (GNode *asn,
- EggBytes *data)
+ GBytes *data)
{
const guchar *dat;
gsize size;
@@ -1213,10 +1213,9 @@ egg_asn1x_decode_no_validate (GNode *asn,
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");
@@ -1231,7 +1230,7 @@ egg_asn1x_decode_no_validate (GNode *asn,
gboolean
egg_asn1x_decode (GNode *asn,
- EggBytes *data)
+ GBytes *data)
{
gboolean ret;
@@ -1405,7 +1404,7 @@ anode_encode_tlv_and_enc (GNode *node,
static gboolean
anode_encode_build (GNode *node,
- EggBytes *backing,
+ GBytes *backing,
guchar *data,
gsize n_data)
{
@@ -1566,9 +1565,9 @@ anode_encoder_bytes (gpointer user_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;
}
@@ -1588,7 +1587,7 @@ anode_encoder_unsigned (gpointer user_data,
guchar *data,
gsize n_data)
{
- EggBytes *value = user_data;
+ GBytes *value = user_data;
gboolean sign;
const gchar *p;
@@ -1598,7 +1597,7 @@ anode_encoder_unsigned (gpointer user_data,
* 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);
@@ -1693,7 +1692,7 @@ anode_encoder_bit_string (gpointer user_data,
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) {
@@ -1707,8 +1706,8 @@ anode_encoder_bit_string (gpointer user_data,
static gboolean
anode_encode_prepare_simple (GNode *node, gboolean want)
{
- EggBytes *backing;
- EggBytes *bytes;
+ GBytes *backing;
+ GBytes *bytes;
Aenc *enc;
Atlv *tlv;
@@ -1723,9 +1722,11 @@ anode_encode_prepare_simple (GNode *node, gboolean want)
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;
@@ -1844,7 +1845,7 @@ destroy_with_allocator (gpointer data)
g_slice_free (AllocatorClosure, closure);
}
-static EggBytes *
+static GBytes *
new_bytes_with_allocator (EggAllocator allocator,
guchar **data,
gsize length)
@@ -1858,20 +1859,20 @@ new_bytes_with_allocator (EggAllocator allocator,
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;
@@ -1903,7 +1904,7 @@ egg_asn1x_encode (GNode *asn,
return bytes;
}
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
anode_encode_rollback (asn);
return NULL;
}
@@ -2769,10 +2770,10 @@ egg_asn1x_set_integer_as_ulong (GNode *node, gulong value)
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);
@@ -2786,14 +2787,15 @@ egg_asn1x_get_integer_as_raw (GNode *node)
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;
@@ -2831,22 +2833,22 @@ egg_asn1x_get_integer_as_usg (GNode *node)
}
}
- 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;
@@ -2856,7 +2858,7 @@ egg_asn1x_take_integer_as_raw (GNode *node,
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);
@@ -2865,21 +2867,21 @@ egg_asn1x_take_integer_as_raw (GNode *node,
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;
@@ -2890,11 +2892,10 @@ egg_asn1x_take_integer_as_usg (GNode *node,
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
@@ -2905,13 +2906,13 @@ egg_asn1x_take_integer_as_usg (GNode *node,
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;
@@ -2934,19 +2935,19 @@ egg_asn1x_get_element_raw (GNode *node)
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);
@@ -2955,11 +2956,9 @@ egg_asn1x_set_element_raw (GNode *node,
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;
@@ -2994,18 +2993,19 @@ egg_asn1x_set_element_raw (GNode *node,
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);
@@ -3019,8 +3019,9 @@ egg_asn1x_get_raw_value (GNode *node)
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*
@@ -3077,7 +3078,7 @@ egg_asn1x_set_string_as_raw (GNode *node, guchar *data, gsize n_data, GDestroyNo
return TRUE;
}
-EggBytes *
+GBytes *
egg_asn1x_get_string_as_bytes (GNode *node)
{
gpointer raw;
@@ -3089,7 +3090,7 @@ egg_asn1x_get_string_as_bytes (GNode *node)
if (raw == NULL)
return NULL;
- return egg_bytes_new_take (raw, length);
+ return g_bytes_new_take (raw, length);
}
gchar *
@@ -3149,10 +3150,10 @@ egg_asn1x_set_string_as_utf8 (GNode *node, gchar *data, GDestroyNotify destroy)
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;
@@ -3173,22 +3174,23 @@ egg_asn1x_get_bits_as_raw (GNode *node, guint *n_bits)
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;
@@ -3278,7 +3280,7 @@ egg_asn1x_set_bits_as_ulong (GNode *node, gulong bits, guint n_bits)
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);
@@ -4170,7 +4172,7 @@ egg_asn1x_create_quark (const EggAsn1xDef *defs,
GNode*
egg_asn1x_create_and_decode (const EggAsn1xDef *defs,
const gchar *identifier,
- EggBytes *data)
+ GBytes *data)
{
GNode *asn;
diff --git a/egg/egg-asn1x.h b/egg/egg-asn1x.h
index 94d60fa..036b9ce 100644
--- a/egg/egg-asn1x.h
+++ b/egg/egg-asn1x.h
@@ -26,8 +26,6 @@
#include <glib.h>
-#include "egg-bytes.h"
-
#ifndef HAVE_EGG_ALLOCATOR
typedef void* (*EggAllocator) (void* p, gsize);
#define HAVE_EGG_ALLOCATOR
@@ -68,22 +66,22 @@ GNode* egg_asn1x_create_quark (const EggAsn1xDef *defs,
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);
@@ -125,28 +123,28 @@ gboolean egg_asn1x_get_integer_as_ulong (GNode *node,
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,
@@ -157,17 +155,17 @@ gboolean egg_asn1x_set_string_as_raw (GNode *node,
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,
diff --git a/egg/egg-bytes.c b/egg/egg-bytes.c
deleted file mode 100644
index 8f58da2..0000000
--- a/egg/egg-bytes.c
+++ /dev/null
@@ -1,454 +0,0 @@
-/*
- * 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;
-}
diff --git a/egg/egg-bytes.h b/egg/egg-bytes.h
deleted file mode 100644
index d25432f..0000000
--- a/egg/egg-bytes.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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__ */
diff --git a/egg/egg-dn.c b/egg/egg-dn.c
index 2ec5751..e3b092e 100644
--- a/egg/egg-dn.c
+++ b/egg/egg-dn.c
@@ -33,10 +33,10 @@
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;
@@ -52,10 +52,10 @@ dn_print_hex_value (EggBytes *val)
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;
@@ -82,8 +82,7 @@ dn_print_oid_value_parsed (GQuark oid,
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.
@@ -100,7 +99,7 @@ dn_print_oid_value_parsed (GQuark oid,
result = g_strndup (data, size);
}
- egg_bytes_unref (value);
+ g_bytes_unref (value);
egg_asn1x_destroy (asn1);
return result;
@@ -109,7 +108,7 @@ dn_print_oid_value_parsed (GQuark oid,
static gchar*
dn_print_oid_value (GQuark oid,
guint flags,
- EggBytes *val)
+ GBytes *val)
{
gchar *value;
@@ -130,7 +129,7 @@ dn_parse_rdn (GNode *asn)
const gchar *name;
guint flags;
GQuark oid;
- EggBytes *value;
+ GBytes *value;
gchar *display;
gchar *result;
@@ -150,7 +149,7 @@ dn_parse_rdn (GNode *asn)
"=", display, NULL);
g_free (display);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
return result;
}
@@ -201,7 +200,7 @@ egg_dn_read_part (GNode *asn, const gchar *match)
{
gboolean done = FALSE;
const gchar *name;
- EggBytes *value;
+ GBytes *value;
GNode *node;
GQuark oid;
gint i, j;
@@ -238,7 +237,7 @@ egg_dn_read_part (GNode *asn, const gchar *match)
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;
}
}
@@ -251,7 +250,7 @@ egg_dn_parse (GNode *asn, EggDnCallback callback, gpointer user_data)
{
gboolean done = FALSE;
GNode *node;
- EggBytes *value;
+ GBytes *value;
GQuark oid;
guint i, j;
@@ -285,7 +284,7 @@ egg_dn_parse (GNode *asn, EggDnCallback callback, gpointer user_data)
if (callback)
(callback) (i, oid, value, user_data);
- egg_bytes_unref (value);
+ g_bytes_unref (value);
}
}
@@ -294,7 +293,7 @@ egg_dn_parse (GNode *asn, EggDnCallback callback, gpointer user_data)
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);
@@ -337,7 +336,7 @@ egg_dn_add_string_part (GNode *asn,
GQuark oid,
const gchar *string)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *node;
GNode *value;
GNode *val;
@@ -384,5 +383,5 @@ egg_dn_add_string_part (GNode *asn,
g_return_if_reached ();
egg_asn1x_destroy (value);
- egg_bytes_unref (bytes);
+ g_bytes_unref (bytes);
}
diff --git a/egg/egg-dn.h b/egg/egg-dn.h
index 08251ec..a75e73d 100644
--- a/egg/egg-dn.h
+++ b/egg/egg-dn.h
@@ -26,8 +26,6 @@
#include <glib.h>
-#include "egg/egg-bytes.h"
-
gchar* egg_dn_read (GNode *node);
gchar* egg_dn_read_part (GNode *node,
@@ -35,7 +33,7 @@ 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,
@@ -43,7 +41,7 @@ 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,
diff --git a/egg/egg-openssl.c b/egg/egg-openssl.c
index 2433f07..5515be1 100644
--- a/egg/egg-openssl.c
+++ b/egg/egg-openssl.c
@@ -206,7 +206,7 @@ guchar *
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;
@@ -245,12 +245,12 @@ egg_openssl_decrypt_block (const gchar *dekinfo,
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);
@@ -265,7 +265,7 @@ guchar *
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;
@@ -305,8 +305,7 @@ egg_openssl_encrypt_block (const gchar *dekinfo,
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);
diff --git a/egg/egg-openssl.h b/egg/egg-openssl.h
index 642d906..6c94a7b 100644
--- a/egg/egg-openssl.h
+++ b/egg/egg-openssl.h
@@ -26,20 +26,18 @@
#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);
diff --git a/egg/egg-symkey.c b/egg/egg-symkey.c
index 3d402d3..d5459a5 100644
--- a/egg/egg-symkey.c
+++ b/egg/egg-symkey.c
@@ -662,12 +662,12 @@ read_cipher_pkcs5_pbe (int cipher_algo,
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;
@@ -703,7 +703,7 @@ read_cipher_pkcs5_pbe (int cipher_algo,
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;
@@ -722,7 +722,7 @@ read_cipher_pkcs5_pbe (int cipher_algo,
done:
g_free (iv);
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
egg_secure_free (key);
egg_asn1x_destroy (asn);
@@ -730,12 +730,12 @@ done:
}
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;
@@ -754,9 +754,9 @@ setup_pkcs5_rc2_params (EggBytes *data,
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;
}
@@ -764,18 +764,18 @@ setup_pkcs5_rc2_params (EggBytes *data,
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);
@@ -792,22 +792,22 @@ setup_pkcs5_des_params (EggBytes *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)
{
@@ -815,7 +815,7 @@ setup_pkcs5_pbkdf2_params (const gchar *password,
gboolean ret;
gcry_error_t gcry;
guchar *key = NULL;
- EggBytes *salt = NULL;
+ GBytes *salt = NULL;
gsize n_key;
gulong iterations;
@@ -835,7 +835,7 @@ setup_pkcs5_pbkdf2_params (const gchar *password,
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;
@@ -852,7 +852,7 @@ setup_pkcs5_pbkdf2_params (const gchar *password,
done:
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
egg_secure_free (key);
egg_asn1x_destroy (asn);
return ret;
@@ -861,13 +861,13 @@ done:
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;
@@ -941,7 +941,7 @@ read_cipher_pkcs5_pbes2 (const gchar *password,
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;
@@ -955,7 +955,7 @@ done:
}
if (params != NULL)
- egg_bytes_unref (params);
+ g_bytes_unref (params);
egg_asn1x_destroy (asn);
return ret;
}
@@ -965,13 +965,13 @@ read_cipher_pkcs12_pbe (int cipher_algo,
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;
@@ -1003,7 +1003,7 @@ read_cipher_pkcs12_pbe (int cipher_algo,
/* 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;
@@ -1026,7 +1026,7 @@ done:
}
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
g_free (iv);
egg_secure_free (key);
egg_asn1x_destroy (asn);
@@ -1037,7 +1037,7 @@ static gboolean
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)
{
@@ -1045,7 +1045,7 @@ read_mac_pkcs12_pbe (int hash_algo,
gcry_error_t gcry;
gboolean ret;
gsize n_key;
- EggBytes *salt = NULL;
+ GBytes *salt = NULL;
gulong iterations;
guchar *key = NULL;
@@ -1074,7 +1074,7 @@ read_mac_pkcs12_pbe (int hash_algo,
/* 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;
@@ -1097,7 +1097,7 @@ done:
}
if (salt != NULL)
- egg_bytes_unref (salt);
+ g_bytes_unref (salt);
egg_secure_free (key);
egg_asn1x_destroy (asn);
return ret;
@@ -1107,7 +1107,7 @@ gboolean
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;
@@ -1175,7 +1175,7 @@ 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)
{
diff --git a/egg/egg-symkey.h b/egg/egg-symkey.h
index 92defef..8498613 100644
--- a/egg/egg-symkey.h
+++ b/egg/egg-symkey.h
@@ -26,8 +26,6 @@
#include <gcrypt.h>
-#include <egg/egg-bytes.h>
-
gboolean egg_symkey_generate_simple (int cipher_algo,
int hash_algo,
const gchar *password,
@@ -79,13 +77,13 @@ gboolean egg_symkey_generate_pbkdf2 (int cipher_algo
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);
diff --git a/egg/egg-testing.h b/egg/egg-testing.h
index d6cfbe5..a058e09 100644
--- a/egg/egg-testing.h
+++ b/egg/egg-testing.h
@@ -39,10 +39,10 @@
#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,
diff --git a/egg/tests/test-asn1.c b/egg/tests/test-asn1.c
index 7844c92..95667de 100644
--- a/egg/tests/test-asn1.c
+++ b/egg/tests/test-asn1.c
@@ -61,7 +61,7 @@ const gchar ENUM_THREE[] = "\x0A\x01\x03";
static void
test_boolean (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gboolean value;
@@ -75,24 +75,24 @@ test_boolean (void)
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);
@@ -107,7 +107,7 @@ static void
test_null (void)
{
GNode *asn;
- EggBytes *data;
+ GBytes *data;
asn = egg_asn1x_create (test_asn1_tab, "TestNull");
g_assert (asn);
@@ -118,13 +118,13 @@ test_null (void)
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
@@ -132,7 +132,7 @@ test_integer (void)
{
GNode *asn;
gulong value;
- EggBytes *bytes;
+ GBytes *bytes;
asn = egg_asn1x_create (test_asn1_tab, "TestInteger");
g_assert (asn);
@@ -144,13 +144,13 @@ test_integer (void)
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);
@@ -166,10 +166,10 @@ test_unsigned (void)
{
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);
@@ -177,13 +177,13 @@ test_unsigned (void)
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);
@@ -191,28 +191,28 @@ test_unsigned (void)
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);
}
@@ -222,7 +222,7 @@ test_octet_string (void)
{
GNode *asn;
gchar *value;
- EggBytes *bytes;
+ GBytes *bytes;
asn = egg_asn1x_create (test_asn1_tab, "TestOctetString");
g_assert (asn);
@@ -234,10 +234,10 @@ test_octet_string (void)
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");
@@ -255,7 +255,7 @@ test_octet_string (void)
static void
test_generalized_time (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
glong value;
@@ -269,10 +269,10 @@ test_generalized_time (void)
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);
@@ -288,7 +288,7 @@ test_generalized_time (void)
static void
test_implicit_encode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gchar *value;
@@ -296,10 +296,10 @@ test_implicit_encode (void)
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);
@@ -310,7 +310,7 @@ test_implicit_encode (void)
static void
test_implicit_decode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestImplicit");
@@ -323,13 +323,13 @@ test_implicit_decode (void)
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;
@@ -337,10 +337,10 @@ test_explicit_decode (void)
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");
@@ -352,7 +352,7 @@ test_explicit_decode (void)
static void
test_explicit_encode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestExplicit");
@@ -365,13 +365,13 @@ test_explicit_encode (void)
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;
@@ -379,10 +379,10 @@ test_universal_decode (void)
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");
@@ -394,7 +394,7 @@ test_universal_decode (void)
static void
test_universal_encode (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
asn = egg_asn1x_create (test_asn1_tab, "TestUniversal");
@@ -407,15 +407,15 @@ test_universal_encode (void)
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;
@@ -425,37 +425,37 @@ test_bit_string_decode (void)
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);
}
@@ -463,7 +463,7 @@ test_bit_string_decode_bad (void)
static void
test_bit_string_decode_ulong (void)
{
- EggBytes *bytes;
+ GBytes *bytes;
GNode *asn;
gulong bits;
guint n_bits;
@@ -472,10 +472,10 @@ test_bit_string_decode_ulong (void)
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 ();
@@ -489,10 +489,10 @@ test_bit_string_decode_ulong (void)
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;
@@ -500,7 +500,7 @@ test_bit_string_encode_decode (void)
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);
@@ -508,24 +508,24 @@ test_bit_string_encode_decode (void)
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;
@@ -542,7 +542,7 @@ test_bit_string_encode_decode_ulong (void)
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 ();
@@ -556,27 +556,27 @@ test_bit_string_encode_decode_ulong (void)
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");
@@ -594,7 +594,7 @@ test_have (void)
g_assert (egg_asn1x_have (asn));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
@@ -610,10 +610,10 @@ test_is_freed (gpointer unused)
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";
@@ -625,11 +625,11 @@ test_any_set_raw (void)
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);
@@ -641,8 +641,8 @@ test_any_set_raw (void)
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);
}
@@ -650,10 +650,10 @@ test_any_set_raw (void)
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";
@@ -665,10 +665,10 @@ test_any_set_raw_explicit (void)
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);
@@ -680,8 +680,8 @@ test_any_set_raw_explicit (void)
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);
}
@@ -689,9 +689,9 @@ test_any_set_raw_explicit (void)
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);
@@ -701,10 +701,10 @@ test_choice_not_chosen (void)
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);
@@ -718,10 +718,10 @@ test_choice_not_chosen (void)
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);
@@ -735,10 +735,10 @@ perform_asn1_any_choice_set_raw (const gchar *choice, const gchar *encoding, gsi
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) {
@@ -754,8 +754,8 @@ perform_asn1_any_choice_set_raw (const gchar *choice, const gchar *encoding, gsi
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);
}
@@ -777,10 +777,10 @@ test_any_choice_set_raw_long_tag (void)
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";
@@ -788,10 +788,10 @@ test_append (void)
/* 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));
@@ -807,14 +807,14 @@ test_append (void)
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");
@@ -838,15 +838,15 @@ test_append_and_clear (void)
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";
@@ -854,10 +854,10 @@ test_setof (void)
/* 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));
@@ -877,14 +877,14 @@ test_setof (void)
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 */
@@ -901,22 +901,22 @@ test_setof_empty (void)
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));
@@ -932,7 +932,7 @@ test_enumerated (void)
egg_assert_cmpbytes (data, ==, ENUM_THREE, XL (ENUM_THREE));
- egg_bytes_unref (data);
+ g_bytes_unref (data);
egg_asn1x_destroy (asn);
}
@@ -945,7 +945,7 @@ typedef struct {
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))
@@ -954,10 +954,10 @@ setup (Test *test, gconstpointer unused)
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
@@ -976,7 +976,7 @@ test_node_name (Test* test, gconstpointer unused)
static void
test_asn1_integers (Test* test, gconstpointer unused)
{
- EggBytes *data;
+ GBytes *data;
GNode *asn;
gboolean ret;
gulong val;
@@ -1017,13 +1017,13 @@ test_asn1_integers (Test* test, gconstpointer unused)
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;
@@ -1049,7 +1049,7 @@ test_boolean_seq (Test* test, gconstpointer unused)
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);
@@ -1057,14 +1057,14 @@ test_boolean_seq (Test* test, gconstpointer unused)
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;
@@ -1084,14 +1084,14 @@ test_write_value (Test* test, gconstpointer unused)
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;
@@ -1107,11 +1107,11 @@ test_element_length_content (Test* test, gconstpointer unused)
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);
@@ -1130,15 +1130,15 @@ test_element_length_content (Test* test, gconstpointer unused)
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);
@@ -1152,22 +1152,22 @@ test_read_element (Test* test, gconstpointer unused)
/* 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;
@@ -1195,7 +1195,7 @@ test_oid (Test* test, gconstpointer unused)
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);
@@ -1203,7 +1203,7 @@ test_oid (Test* test, gconstpointer unused)
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);
}
diff --git a/egg/tests/test-asn1x.c b/egg/tests/test-asn1x.c
index 720d62a..4581756 100644
--- a/egg/tests/test-asn1x.c
+++ b/egg/tests/test-asn1x.c
@@ -69,14 +69,14 @@ test_some_asn1_stuff (const EggAsn1xDef *defs,
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);
@@ -93,8 +93,8 @@ test_some_asn1_stuff (const EggAsn1xDef *defs,
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
diff --git a/egg/tests/test-dn.c b/egg/tests/test-dn.c
index 929cec2..cf83dcb 100644
--- a/egg/tests/test-dn.c
+++ b/egg/tests/test-dn.c
@@ -45,7 +45,7 @@ typedef struct {
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))
@@ -54,10 +54,10 @@ setup (Test *test, gconstpointer unused)
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
@@ -84,23 +84,23 @@ test_dn_value (Test* test, gconstpointer unused)
{
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);
}
@@ -110,7 +110,7 @@ static int last_index = 0;
static void
concatenate_dn (guint index,
GQuark oid,
- EggBytes *value,
+ GBytes *value,
gpointer user_data)
{
GString *dn = user_data;
@@ -118,7 +118,7 @@ concatenate_dn (guint index,
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;
@@ -180,8 +180,8 @@ static void
test_add_dn_part (Test *test,
gconstpointer unused)
{
- EggBytes *check;
- EggBytes *dn;
+ GBytes *check;
+ GBytes *dn;
GNode *check_dn;
GNode *asn;
GNode *node;
@@ -207,10 +207,10 @@ test_add_dn_part (Test *test,
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
diff --git a/egg/tests/test-openssl.c b/egg/tests/test-openssl.c
index 87596fd..562f200 100644
--- a/egg/tests/test-openssl.c
+++ b/egg/tests/test-openssl.c
@@ -36,12 +36,10 @@
#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;
@@ -59,13 +57,13 @@ setup (Test *test, gconstpointer unused)
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);
@@ -79,8 +77,8 @@ copy_each_key_value (gpointer key, gpointer value, gpointer user_data)
static void
parse_reference (GQuark type,
- EggBytes *data,
- EggBytes *outer,
+ GBytes *data,
+ GBytes *outer,
GHashTable *headers,
gpointer user_data)
{
@@ -91,9 +89,9 @@ parse_reference (GQuark type,
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);
@@ -104,7 +102,7 @@ parse_reference (GQuark type,
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
@@ -124,7 +122,7 @@ test_write_reference (Test *test, gconstpointer unused)
const gchar *dekinfo;
guchar *encrypted;
gsize n_encrypted;
- EggBytes *data;
+ GBytes *data;
guint num;
num = egg_armor_parse (test->input, parse_reference, test);
@@ -133,9 +131,9 @@ test_write_reference (Test *test, gconstpointer unused)
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);
@@ -179,7 +177,7 @@ test_openssl_roundtrip (Test *test, gconstpointer unused)
const gchar *dekinfo;
guchar *encrypted, *decrypted;
gsize n_encrypted, n_decrypted;
- EggBytes *data;
+ GBytes *data;
int i;
guint num;
@@ -188,16 +186,16 @@ test_openssl_roundtrip (Test *test, gconstpointer unused)
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);