From 243f90afba87e99ca42e2451ac5cc59d00a044ac Mon Sep 17 00:00:00 2001 From: "Neal H. Walfield" Date: Wed, 21 Oct 2015 12:52:56 +0200 Subject: [PATCH] gpg: Factor out code into a standalone function. * g10/trustdb.c (tdb_keyid_is_utk): New function. (add_utk): Use it. -- Signed-off-by: Neal H. Walfield --- g10/trustdb.c | 21 ++++++++++++++------- g10/trustdb.h | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/g10/trustdb.c b/g10/trustdb.c index cadc7e96b..1be98b5f5 100644 --- a/g10/trustdb.c +++ b/g10/trustdb.c @@ -229,13 +229,8 @@ add_utk (u32 *kid) { struct key_item *k; - for (k = utk_list; k; k = k->next) - { - if (k->kid[0] == kid[0] && k->kid[1] == kid[1]) - { - return 0; - } - } + if (tdb_keyid_is_utk (kid)) + return 0; k = new_key_item (); k->kid[0] = kid[0]; @@ -317,6 +312,18 @@ verify_own_keys(void) return; } +/* Returns whether KID is on the list of ultimately trusted keys. */ +int +tdb_keyid_is_utk (u32 *kid) +{ + struct key_item *k; + + for (k = utk_list; k; k = k->next) + if (k->kid[0] == kid[0] && k->kid[1] == kid[1]) + return 1; + + return 0; +} /********************************************* *********** TrustDB stuff ******************* diff --git a/g10/trustdb.h b/g10/trustdb.h index adb75d72c..718f7791c 100644 --- a/g10/trustdb.h +++ b/g10/trustdb.h @@ -111,6 +111,8 @@ void clean_key (kbnode_t keyblock, int noisy, int self_only, /*-- trustdb.c --*/ void tdb_register_trusted_keyid (u32 *keyid); void tdb_register_trusted_key (const char *string); +/* Returns whether KID is on the list of ultimately trusted keys. */ +int tdb_keyid_is_utk (u32 *kid); void check_trustdb (void); void update_trustdb (void); int setup_trustdb( int level, const char *dbname );