diff options
author | Daiki Ueno <dueno@redhat.com> | 2017-05-18 14:27:36 +0200 |
---|---|---|
committer | Daiki Ueno <ueno@gnu.org> | 2017-05-18 14:42:15 +0200 |
commit | 723dfeb3dd9b8426c4c1d6236f4b22354c122dae (patch) | |
tree | 22f37958dbc361709c8d6f3b92fad67dca3cd256 /trust/persist.c | |
parent | 66c6a7e912d39d66cd4cc91375ac7be418bf7176 (diff) |
trust: Simplify the check for the magic
Instead of reusing the CKA_X_GENERATED attribute, check the file
contents directly in the caller side.
Diffstat (limited to 'trust/persist.c')
-rw-r--r-- | trust/persist.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/trust/persist.c b/trust/persist.c index 928260e..887b316 100644 --- a/trust/persist.c +++ b/trust/persist.c @@ -70,6 +70,16 @@ p11_persist_magic (const unsigned char *data, return (strnstr ((char *)data, "[" PERSIST_HEADER "]", length) != NULL); } +bool +p11_persist_is_generated (const unsigned char *data, + size_t length) +{ + static const char comment[] = + "# This file has been auto-generated and written by p11-kit."; + return length >= sizeof (comment) - 1 && + memcmp ((const char *)data, comment, sizeof (comment) - 1) == 0; +} + p11_persist * p11_persist_new (void) { @@ -631,9 +641,6 @@ p11_persist_read (p11_persist *persist, CK_ATTRIBUTE *attrs; bool failed; bool skip; - CK_BBOOL generatedv = CK_FALSE; - CK_ATTRIBUTE generated = { CKA_X_GENERATED, &generatedv, sizeof (generatedv) }; - static const char comment[] = "# This file has been auto-generated and written by p11-kit."; return_val_if_fail (persist != NULL, false); return_val_if_fail (objects != NULL, false); @@ -642,10 +649,6 @@ p11_persist_read (p11_persist *persist, attrs = NULL; failed = false; - if (length >= sizeof (comment) - 1 && - memcmp ((const char *)data, comment, sizeof (comment) - 1) == 0) - generatedv = CK_TRUE; - p11_lexer_init (&lexer, filename, (const char *)data, length); while (p11_lexer_next (&lexer, &failed)) { switch (lexer.tok_type) { @@ -657,7 +660,7 @@ p11_persist_read (p11_persist *persist, p11_lexer_msg (&lexer, "unrecognized or invalid section header"); skip = true; } else { - attrs = p11_attrs_build (NULL, &generated, NULL); + attrs = p11_attrs_build (NULL, NULL); return_val_if_fail (attrs != NULL, false); skip = false; } |