1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-02-01 16:33:02 +01:00

gpg: Minor rework for better readibility of get_best_pubkey_byname.

* g10/getkey.c (get_best_pubkey_byname): Change return type to
gpg_error_t.  Use var name err instead of rc.  Move a
gpg_error_from_syserror closer to the call.
--

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2017-07-28 11:08:32 +02:00
parent 6496dc1f9d
commit 1c35e29af9
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
2 changed files with 17 additions and 17 deletions

View File

@ -1583,24 +1583,23 @@ pubkey_cmp (ctrl_t ctrl, const char *name, struct pubkey_cmp_cookie *old,
/* This function works like get_pubkey_byname, but if the name /* This function works like get_pubkey_byname, but if the name
* resembles a mail address, the results are ranked and only the best * resembles a mail address, the results are ranked and only the best
* result is returned. */ * result is returned. */
int gpg_error_t
get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk, get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
const char *name, KBNODE *ret_keyblock, const char *name, KBNODE *ret_keyblock,
int include_unusable, int no_akl) int include_unusable, int no_akl)
{ {
int rc; gpg_error_t err;
struct getkey_ctx_s *ctx = NULL; struct getkey_ctx_s *ctx = NULL;
if (retctx) if (retctx)
*retctx = NULL; *retctx = NULL;
rc = get_pubkey_byname (ctrl, &ctx, pk, name, ret_keyblock, err = get_pubkey_byname (ctrl, &ctx, pk, name, ret_keyblock,
NULL, include_unusable, no_akl); NULL, include_unusable, no_akl);
if (rc) if (err)
{ {
if (ctx) getkey_end (ctrl, ctx);
getkey_end (ctrl, ctx); return err;
return rc;
} }
if (is_valid_mailbox (name) && ctx) if (is_valid_mailbox (name) && ctx)
@ -1647,16 +1646,17 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
{ {
ctx = xtrycalloc (1, sizeof **retctx); ctx = xtrycalloc (1, sizeof **retctx);
if (! ctx) if (! ctx)
rc = gpg_error_from_syserror (); err = gpg_error_from_syserror ();
else else
{ {
ctx->kr_handle = keydb_new (); ctx->kr_handle = keydb_new ();
if (! ctx->kr_handle) if (! ctx->kr_handle)
{ {
err = gpg_error_from_syserror ();
xfree (ctx); xfree (ctx);
ctx = NULL;
if (retctx) if (retctx)
*retctx = NULL; *retctx = NULL;
rc = gpg_error_from_syserror ();
} }
else else
{ {
@ -1671,7 +1671,7 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
{ {
release_kbnode (*ret_keyblock); release_kbnode (*ret_keyblock);
*ret_keyblock = NULL; *ret_keyblock = NULL;
rc = getkey_next (ctrl, ctx, NULL, ret_keyblock); err = getkey_next (ctrl, ctx, NULL, ret_keyblock);
} }
} }
} }
@ -1684,7 +1684,7 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
} }
} }
if (rc && ctx) if (err && ctx)
{ {
getkey_end (ctrl, ctx); getkey_end (ctrl, ctx);
ctx = NULL; ctx = NULL;
@ -1695,7 +1695,7 @@ get_best_pubkey_byname (ctrl_t ctrl, GETKEY_CTX *retctx, PKT_public_key *pk,
else else
getkey_end (ctrl, ctx); getkey_end (ctrl, ctx);
return rc; return err;
} }

View File

@ -319,10 +319,10 @@ int get_pubkey_byname (ctrl_t ctrl,
/* Likewise, but only return the best match if NAME resembles a mail /* Likewise, but only return the best match if NAME resembles a mail
* address. */ * address. */
int get_best_pubkey_byname (ctrl_t ctrl, gpg_error_t get_best_pubkey_byname (ctrl_t ctrl,
GETKEY_CTX *retctx, PKT_public_key *pk, GETKEY_CTX *retctx, PKT_public_key *pk,
const char *name, KBNODE *ret_keyblock, const char *name, KBNODE *ret_keyblock,
int include_unusable, int no_akl); int include_unusable, int no_akl);
/* Get a public key directly from file FNAME. */ /* Get a public key directly from file FNAME. */
gpg_error_t get_pubkey_fromfile (ctrl_t ctrl, gpg_error_t get_pubkey_fromfile (ctrl_t ctrl,