aboutsummaryrefslogtreecommitdiffstats
path: root/g10/objcache.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <[email protected]>2019-07-11 03:32:44 +0000
committerNIIBE Yutaka <[email protected]>2019-07-11 03:32:44 +0000
commit29c7fb4053d207c163802642babbdbb6f885727e (patch)
treee755afaf29e3dae9de9d855d943a95c6839ff005 /g10/objcache.c
parentgpg: Improve import slowness. (diff)
downloadgnupg-29c7fb4053d207c163802642babbdbb6f885727e.tar.gz
gnupg-29c7fb4053d207c163802642babbdbb6f885727e.zip
gpg: Fix getting User ID.
* g10/getkey.c (user_id_db): Remove, as no use anymore. (get_user_id_string): Use cache_get_uid_bykid. (get_user_id_byfpr): Use cache_get_uid_byfpr. * g10/objcache.c (cache_get_uid_byfpr): New. * g10/objcache.h (cache_get_uid_byfpr): New. Fixes-commit: 64a5fd37271a3e454c0d59ac3500e1a1b232e4f7 Signed-off-by: NIIBE Yutaka <[email protected]>
Diffstat (limited to 'g10/objcache.c')
-rw-r--r--g10/objcache.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/g10/objcache.c b/g10/objcache.c
index 7eb92cd0d..adb0717d7 100644
--- a/g10/objcache.c
+++ b/g10/objcache.c
@@ -640,3 +640,50 @@ cache_get_uid_bykid (u32 *keyid, unsigned int *r_length)
return p;
}
+
+
+/* Return the user id string for FPR with FPRLEN. If a user id is not
+ * found (or on malloc error) NULL is returned. If R_LENGTH is not
+ * NULL the length of the user id is stored there; this does not
+ * included the always appended nul. Note that a user id may include
+ * an internal nul which can be detected by the caller by comparing to
+ * the returned length. */
+char *
+cache_get_uid_byfpr (const byte *fpr, size_t fprlen, size_t *r_length)
+{
+ char *p;
+ unsigned int hash;
+ u32 keyid[2];
+ key_item_t ki;
+
+ if (r_length)
+ *r_length = 0;
+
+ if (!key_table)
+ return NULL;
+
+ keyid_from_fingerprint (NULL, fpr, fprlen, keyid);
+ hash = key_table_hasher (keyid);
+ for (ki = key_table[hash]; ki; ki = ki->next)
+ if (ki->fprlen == fprlen && !memcmp (ki->fpr, fpr, fprlen))
+ break; /* Found */
+
+ if (!ki)
+ return NULL; /* Not found. */
+
+ if (!ki->ui)
+ p = NULL; /* No user id known for key. */
+ else
+ {
+ p = xtrymalloc (ki->ui->namelen + 1);
+ if (p)
+ {
+ memcpy (p, ki->ui->name, ki->ui->namelen + 1);
+ if (r_length)
+ *r_length = ki->ui->namelen;
+ ki->usecount++;
+ }
+ }
+
+ return p;
+}