summaryrefslogtreecommitdiffstats
path: root/kbx
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-08-10 11:14:08 +0200
committerWerner Koch <wk@gnupg.org>2002-08-10 11:14:08 +0200
commit69f389096d7386293ef243d98124a55e3a52b8e9 (patch)
tree15f3d2e5e7f159b68813fc84e73b4926a2be908c /kbx
parent* decrypt.c (prepare_decryption): Hack to detected already (diff)
downloadgnupg2-69f389096d7386293ef243d98124a55e3a52b8e9.tar.xz
gnupg2-69f389096d7386293ef243d98124a55e3a52b8e9.zip
* keybox-search.c (blob_cmp_fpr_part): New.
(has_short_kid, has_long_kid): Implemented.
Diffstat (limited to 'kbx')
-rw-r--r--kbx/ChangeLog5
-rw-r--r--kbx/keybox-search.c50
2 files changed, 45 insertions, 10 deletions
diff --git a/kbx/ChangeLog b/kbx/ChangeLog
index c53d48a84..351ec5d13 100644
--- a/kbx/ChangeLog
+++ b/kbx/ChangeLog
@@ -1,3 +1,8 @@
+2002-08-10 Werner Koch <wk@gnupg.org>
+
+ * keybox-search.c (blob_cmp_fpr_part): New.
+ (has_short_kid, has_long_kid): Implemented.
+
2002-07-22 Werner Koch <wk@gnupg.org>
* keybox-defs.h: New BLOBTYPTE_EMPTY.
diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c
index e57754344..126364f5b 100644
--- a/kbx/keybox-search.c
+++ b/kbx/keybox-search.c
@@ -150,6 +150,38 @@ blob_cmp_fpr (KEYBOXBLOB blob, const unsigned char *fpr)
return 0; /* not found */
}
+static int
+blob_cmp_fpr_part (KEYBOXBLOB blob, const unsigned char *fpr,
+ int fproff, int fprlen)
+{
+ const unsigned char *buffer;
+ size_t length;
+ size_t pos, off;
+ size_t nkeys, keyinfolen;
+ int idx;
+
+ buffer = _keybox_get_blob_image (blob, &length);
+ if (length < 40)
+ return 0; /* blob too short */
+
+ /*keys*/
+ nkeys = get16 (buffer + 16);
+ keyinfolen = get16 (buffer + 18 );
+ if (keyinfolen < 28)
+ return 0; /* invalid blob */
+ pos = 20;
+ if (pos + keyinfolen*nkeys > length)
+ return 0; /* out of bounds */
+
+ for (idx=0; idx < nkeys; idx++)
+ {
+ off = pos + idx*keyinfolen;
+ if (!memcmp (buffer + off + fproff, fpr, fprlen))
+ return 1; /* found */
+ }
+ return 0; /* not found */
+}
+
static int
blob_cmp_name (KEYBOXBLOB blob, int idx,
@@ -321,19 +353,17 @@ blob_cmp_mail (KEYBOXBLOB blob, const char *name, size_t namelen, int substr)
/*
The has_foo functions are used as helpers for search
*/
-#if 0
static int
-has_short_kid (KEYBOXBLOB blob, u32 kid)
+has_short_kid (KEYBOXBLOB blob, const unsigned char *kid)
{
- return 0;
+ return blob_cmp_fpr_part (blob, kid+4, 16, 4);
}
static int
-has_long_kid (KEYBOXBLOB blob, u32 *kid)
+has_long_kid (KEYBOXBLOB blob, const unsigned char *kid)
{
- return 0;
+ return blob_cmp_fpr_part (blob, kid, 12, 8);
}
-#endif
static int
has_fingerprint (KEYBOXBLOB blob, const unsigned char *fpr)
@@ -652,12 +682,12 @@ keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc)
goto found;
break;
case KEYDB_SEARCH_MODE_SHORT_KID:
-/* if (has_short_kid (blob, desc[n].u.kid[1])) */
-/* goto found; */
+ if (has_short_kid (blob, desc[n].u.kid))
+ goto found;
break;
case KEYDB_SEARCH_MODE_LONG_KID:
-/* if (has_long_kid (blob, desc[n].u.kid)) */
-/* goto found; */
+ if (has_long_kid (blob, desc[n].u.kid))
+ goto found;
break;
case KEYDB_SEARCH_MODE_FPR:
case KEYDB_SEARCH_MODE_FPR20: