[gnome-keyring: 4/6] egg: Add support for encoding NULL in ASN.1
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring: 4/6] egg: Add support for encoding NULL in ASN.1
- Date: Tue, 24 May 2011 07:38:15 +0000 (UTC)
commit 0c68a6f28958d21d5f76815217e343842dc96766
Author: Stef Walter <stefw collabora co uk>
Date: Sat Apr 9 08:52:29 2011 +0200
egg: Add support for encoding NULL in ASN.1
egg/egg-asn1x.c | 13 +++++++++++++
egg/egg-asn1x.h | 2 ++
egg/tests/test-asn1.c | 25 +++++++++++++++++++++++++
egg/tests/test.asn | 2 ++
4 files changed, 42 insertions(+), 0 deletions(-)
---
diff --git a/egg/egg-asn1x.c b/egg/egg-asn1x.c
index 550dae2..aae8ddd 100644
--- a/egg/egg-asn1x.c
+++ b/egg/egg-asn1x.c
@@ -1263,6 +1263,7 @@ anode_encode_tlv_and_enc (GNode *node, gsize n_data, EggAsn1xEncoder encoder,
case TYPE_TIME:
case TYPE_ENUMERATED:
case TYPE_GENERALSTRING:
+ case TYPE_NULL:
tlv.cls = ASN1_CLASS_UNIVERSAL;
break;
/* Container types */
@@ -1656,6 +1657,7 @@ anode_encode_prepare (GNode *node, gboolean want)
case TYPE_ENUMERATED:
case TYPE_GENERALSTRING:
case TYPE_ANY:
+ case TYPE_NULL:
return anode_encode_prepare_simple (node, want);
break;
case TYPE_SEQUENCE:
@@ -2451,6 +2453,17 @@ egg_asn1x_set_boolean (GNode *node, gboolean value)
return TRUE;
}
+gboolean
+egg_asn1x_set_null (GNode *node)
+{
+ g_return_val_if_fail (node, FALSE);
+ g_return_val_if_fail (anode_def_type (node) == TYPE_NULL, FALSE);
+
+ /* Encode zero characters */
+ anode_encode_tlv_and_enc (node, 0, anode_encoder_simple, "", NULL);
+ return TRUE;
+}
+
GQuark
egg_asn1x_get_enumerated (GNode *node)
{
diff --git a/egg/egg-asn1x.h b/egg/egg-asn1x.h
index 66ccd31..06e94e3 100644
--- a/egg/egg-asn1x.h
+++ b/egg/egg-asn1x.h
@@ -84,6 +84,8 @@ gboolean egg_asn1x_get_boolean (GNode *node,
gboolean egg_asn1x_set_boolean (GNode *node,
gboolean value);
+gboolean egg_asn1x_set_null (GNode *node);
+
GQuark egg_asn1x_get_enumerated (GNode *node);
gboolean egg_asn1x_set_enumerated (GNode *node,
diff --git a/egg/tests/test-asn1.c b/egg/tests/test-asn1.c
index cf855da..c155b42 100644
--- a/egg/tests/test-asn1.c
+++ b/egg/tests/test-asn1.c
@@ -46,6 +46,7 @@ const gchar TGENERALIZED[] = "\x18\x0F""20070725130528Z";
const gchar BITS_TEST[] = "\x03\x04\x06\x6e\x5d\xc0";
const gchar BITS_BAD[] = "\x03\x04\x06\x6e\x5d\xc1";
const gchar BITS_ZERO[] = "\x03\x01\x00";
+const gchar NULL_TEST[] = "\x05\x00";
/* ENUM with value = 2 */
const gchar ENUM_TWO[] = "\x0A\x01\x02";
@@ -94,6 +95,29 @@ test_boolean (void)
}
static void
+test_null (void)
+{
+ GNode *asn;
+ gpointer data;
+ gsize n_data;
+
+ asn = egg_asn1x_create (test_asn1_tab, "TestNull");
+ g_assert (asn);
+
+ if (!egg_asn1x_set_null (asn))
+ g_assert_not_reached ();
+
+ data = egg_asn1x_encode (asn, g_realloc, &n_data);
+ egg_assert_cmpmem (NULL_TEST, XL (NULL_TEST), ==, data, n_data);
+
+ if (!egg_asn1x_decode (asn, data, n_data))
+ g_assert_not_reached ();
+
+ egg_asn1x_destroy (asn);
+ g_free (data);
+}
+
+static void
test_integer (void)
{
GNode *asn;
@@ -1130,6 +1154,7 @@ main (int argc, char **argv)
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/asn1/boolean", test_boolean);
+ g_test_add_func ("/asn1/null", test_null);
g_test_add_func ("/asn1/integer", test_integer);
g_test_add_func ("/asn1/octet_string", test_octet_string);
g_test_add_func ("/asn1/generalized_time", test_generalized_time);
diff --git a/egg/tests/test.asn b/egg/tests/test.asn
index 9779b37..28cb176 100644
--- a/egg/tests/test.asn
+++ b/egg/tests/test.asn
@@ -8,6 +8,8 @@ TestInteger ::= INTEGER
TestBoolean ::= BOOLEAN
+TestNull ::= NULL
+
TestOctetString ::= OCTET STRING
TestGeneralized ::= GeneralizedTime
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]