diff options
author | Stef Walter <stef@thewalter.net> | 2013-07-08 16:36:50 +0200 |
---|---|---|
committer | Stef Walter <stef@thewalter.net> | 2013-07-08 16:43:41 +0200 |
commit | 03787ae83b1911118a7a689c4817bbce1e74dabd (patch) | |
tree | c7c83e748d6c4f935e7a4269fde0880f42c29f4d /trust | |
parent | 9f7c426d5a6bfb0e60895a690ed835c47e04cb4e (diff) |
trust: Support using the parser without an asn1_cache
Diffstat (limited to 'trust')
-rw-r--r-- | trust/asn1.c | 11 | ||||
-rw-r--r-- | trust/parser.c | 15 | ||||
-rw-r--r-- | trust/tests/test-parser.c | 22 |
3 files changed, 41 insertions, 7 deletions
diff --git a/trust/asn1.c b/trust/asn1.c index 653d816..7ed3b01 100644 --- a/trust/asn1.c +++ b/trust/asn1.c @@ -302,7 +302,9 @@ p11_asn1_cache_get (p11_asn1_cache *cache, { asn1_item *item; - return_val_if_fail (cache != NULL, NULL); + if (cache == NULL) + return NULL; + return_val_if_fail (struct_name != NULL, NULL); return_val_if_fail (der != NULL, NULL); @@ -325,7 +327,9 @@ p11_asn1_cache_take (p11_asn1_cache *cache, { asn1_item *item; - return_if_fail (cache != NULL); + if (cache == NULL) + return; + return_if_fail (struct_name != NULL); return_if_fail (der != NULL); return_if_fail (der_len != 0); @@ -345,7 +349,8 @@ p11_asn1_cache_take (p11_asn1_cache *cache, void p11_asn1_cache_flush (p11_asn1_cache *cache) { - return_if_fail (cache != NULL); + if (cache == NULL) + return; p11_dict_clear (cache->items); } diff --git a/trust/parser.c b/trust/parser.c index 26d911b..0d250fc 100644 --- a/trust/parser.c +++ b/trust/parser.c @@ -66,6 +66,7 @@ struct _p11_parser { p11_asn1_cache *asn1_cache; p11_dict *asn1_defs; + bool asn1_owned; p11_persist *persist; char *basename; p11_array *parsed; @@ -659,10 +660,14 @@ p11_parser_new (p11_asn1_cache *asn1_cache) { p11_parser parser = { 0, }; - return_val_if_fail (asn1_cache != NULL, NULL); - - parser.asn1_defs = p11_asn1_cache_defs (asn1_cache); - parser.asn1_cache = asn1_cache; + if (asn1_cache == NULL) { + parser.asn1_owned = true; + parser.asn1_defs = p11_asn1_defs_load (); + } else { + parser.asn1_defs = p11_asn1_cache_defs (asn1_cache); + parser.asn1_cache = asn1_cache; + parser.asn1_owned = false; + } parser.parsed = p11_array_new (p11_attrs_free); return_val_if_fail (parser.parsed != NULL, NULL); @@ -676,6 +681,8 @@ p11_parser_free (p11_parser *parser) return_if_fail (parser != NULL); p11_persist_free (parser->persist); p11_array_free (parser->parsed); + if (parser->asn1_owned) + p11_dict_free (parser->asn1_defs); free (parser); } diff --git a/trust/tests/test-parser.c b/trust/tests/test-parser.c index cc71d1d..c8cac03 100644 --- a/trust/tests/test-parser.c +++ b/trust/tests/test-parser.c @@ -414,6 +414,24 @@ test_parse_unrecognized (void) p11_message_loud (); } +static void +test_parse_no_asn1_cache (void) +{ + p11_parser *parser; + int ret; + + parser = p11_parser_new (NULL); + assert_ptr_not_null (parser); + + ret = p11_parse_file (parser, SRCDIR "/files/cacert3.der", P11_PARSE_FLAG_NONE); + assert_num_eq (P11_PARSE_SUCCESS, ret); + + /* Should have gotten certificate */ + assert_num_eq (1, p11_parser_parsed (parser)->num); + + p11_parser_free (parser); +} + int main (int argc, char *argv[]) @@ -428,5 +446,9 @@ main (int argc, p11_test (test_parse_thawte, "/parser/parse_thawte"); p11_test (test_parse_invalid_file, "/parser/parse_invalid_file"); p11_test (test_parse_unrecognized, "/parser/parse_unrecognized"); + + p11_fixture (NULL, NULL); + p11_test (test_parse_no_asn1_cache, "/parser/null-asn1-cache"); + return p11_test_run (argc, argv); } |