summaryrefslogtreecommitdiff
path: root/common/tests
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-03-14 11:14:52 +0100
committerStef Walter <stefw@gnome.org>2013-03-15 17:51:04 +0100
commit5208fc8539aabc626c1699f181e1191d6bb1c787 (patch)
treedc740b45a209198959a5b14e45db22ee60bbaf4e /common/tests
parent07a53cecc3220b3811f9db7514e49235fff32b94 (diff)
asn1: Implement a parsed ASN.1 tree cache
In order to unmarry the parser from the future builder, but still retain efficiency, we need to be able to cache parsed ASN.1 trees. The ASN.1 cache provides this. In addition it carries around the loaded ASN.1 definitions. https://bugs.freedesktop.org/show_bug.cgi?id=62329
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/test-asn1.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/common/tests/test-asn1.c b/common/tests/test-asn1.c
index 0034623..0335fa6 100644
--- a/common/tests/test-asn1.c
+++ b/common/tests/test-asn1.c
@@ -89,6 +89,51 @@ test_tlv_length (CuTest *cu)
teardown (cu);
}
+static const unsigned char test_eku_server_and_client[] = {
+ 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06,
+ 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
+};
+
+static void
+test_asn1_cache (CuTest *cu)
+{
+ p11_asn1_cache *cache;
+ p11_dict *defs;
+ node_asn *asn;
+ node_asn *check;
+
+ cache = p11_asn1_cache_new ();
+ CuAssertPtrNotNull (cu, cache);
+
+ defs = p11_asn1_cache_defs (cache);
+ CuAssertPtrNotNull (cu, defs);
+
+ asn = p11_asn1_decode (defs, "PKIX1.ExtKeyUsageSyntax",
+ test_eku_server_and_client,
+ sizeof (test_eku_server_and_client), NULL);
+ CuAssertPtrNotNull (cu, defs);
+
+ /* Place the parsed data in the cache */
+ p11_asn1_cache_take (cache, asn, "PKIX1.ExtKeyUsageSyntax",
+ test_eku_server_and_client,
+ sizeof (test_eku_server_and_client));
+
+ /* Get it back out */
+ check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax",
+ test_eku_server_and_client,
+ sizeof (test_eku_server_and_client));
+ CuAssertPtrEquals (cu, asn, check);
+
+ /* Flush should remove it */
+ p11_asn1_cache_flush (cache);
+ check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax",
+ test_eku_server_and_client,
+ sizeof (test_eku_server_and_client));
+ CuAssertPtrEquals (cu, NULL, check);
+
+ p11_asn1_cache_free (cache);
+}
+
int
main (void)
{
@@ -100,6 +145,7 @@ main (void)
p11_debug_init ();
SUITE_ADD_TEST (suite, test_tlv_length);
+ SUITE_ADD_TEST (suite, test_asn1_cache);
CuSuiteRun (suite);
CuSuiteSummary (suite, output);