aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2019-11-27 10:58:47 +0000
committerWerner Koch <[email protected]>2019-11-27 10:58:47 +0000
commit61f41cdce5b60b9df05d6531ab1b7aab84ada659 (patch)
tree746f62b9932050dba10681bb38faee097ceaec73
parentdirmngr: Rework of the LDAP code, part 1. (diff)
downloadgnupg-61f41cdce5b60b9df05d6531ab1b7aab84ada659.tar.gz
gnupg-61f41cdce5b60b9df05d6531ab1b7aab84ada659.zip
gpg: Move a keydb function to another file.
* g10/keydb.c (build_keyblock_image): Move to ... * g10/build-packet.c (build_keyblock_image): here. Signed-off-by: Werner Koch <[email protected]>
-rw-r--r--g10/build-packet.c43
-rw-r--r--g10/keydb.c44
-rw-r--r--g10/packet.h1
3 files changed, 46 insertions, 42 deletions
diff --git a/g10/build-packet.c b/g10/build-packet.c
index 865f2b500..a1db0251d 100644
--- a/g10/build-packet.c
+++ b/g10/build-packet.c
@@ -79,6 +79,49 @@ ctb_pkttype (int ctb)
}
+/* Build a keyblock image from KEYBLOCK. Returns 0 on success and
+ * only then stores a new iobuf object at R_IOBUF; the returned iobuf
+ * can be access with the iobuf_get_temp_buffer and
+ * iobuf_get_temp_length macros. */
+gpg_error_t
+build_keyblock_image (kbnode_t keyblock, iobuf_t *r_iobuf)
+{
+ gpg_error_t err;
+ iobuf_t iobuf;
+ kbnode_t kbctx, node;
+
+ *r_iobuf = NULL;
+
+ iobuf = iobuf_temp ();
+ for (kbctx = NULL; (node = walk_kbnode (keyblock, &kbctx, 0));)
+ {
+ /* Make sure to use only packets valid on a keyblock. */
+ switch (node->pkt->pkttype)
+ {
+ case PKT_PUBLIC_KEY:
+ case PKT_PUBLIC_SUBKEY:
+ case PKT_SIGNATURE:
+ case PKT_USER_ID:
+ case PKT_ATTRIBUTE:
+ case PKT_RING_TRUST:
+ break;
+ default:
+ continue;
+ }
+
+ err = build_packet_and_meta (iobuf, node->pkt);
+ if (err)
+ {
+ iobuf_close (iobuf);
+ return err;
+ }
+ }
+
+ *r_iobuf = iobuf;
+ return 0;
+}
+
+
/* Build a packet and write it to the stream OUT.
* Returns: 0 on success or on an error code. */
int
diff --git a/g10/keydb.c b/g10/keydb.c
index aeb62abfc..57d51e7b7 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -1359,48 +1359,6 @@ internal_keydb_get_keyblock (KEYDB_HANDLE hd, KBNODE *ret_kb)
}
-/* Build a keyblock image from KEYBLOCK. Returns 0 on success and
- * only then stores a new iobuf object at R_IOBUF. */
-static gpg_error_t
-build_keyblock_image (kbnode_t keyblock, iobuf_t *r_iobuf)
-{
- gpg_error_t err;
- iobuf_t iobuf;
- kbnode_t kbctx, node;
-
- *r_iobuf = NULL;
-
- iobuf = iobuf_temp ();
- for (kbctx = NULL; (node = walk_kbnode (keyblock, &kbctx, 0));)
- {
- /* Make sure to use only packets valid on a keyblock. */
- switch (node->pkt->pkttype)
- {
- case PKT_PUBLIC_KEY:
- case PKT_PUBLIC_SUBKEY:
- case PKT_SIGNATURE:
- case PKT_USER_ID:
- case PKT_ATTRIBUTE:
- case PKT_RING_TRUST:
- break;
- default:
- continue;
- }
-
- err = build_packet_and_meta (iobuf, node->pkt);
- if (err)
- {
- iobuf_close (iobuf);
- return err;
- }
- }
-
- keydb_stats.build_keyblocks++;
- *r_iobuf = iobuf;
- return 0;
-}
-
-
/* Update the keyblock KB (i.e., extract the fingerprint and find the
* corresponding keyblock in the keyring).
* keydb_update_keyblock diverts to here in the non-keyboxd mode.
@@ -1473,6 +1431,7 @@ internal_keydb_update_keyblock (ctrl_t ctrl, KEYDB_HANDLE hd, kbnode_t kb)
err = build_keyblock_image (kb, &iobuf);
if (!err)
{
+ keydb_stats.build_keyblocks++;
err = keybox_update_keyblock (hd->active[hd->found].u.kb,
iobuf_get_temp_buffer (iobuf),
iobuf_get_temp_length (iobuf));
@@ -1543,6 +1502,7 @@ internal_keydb_insert_keyblock (KEYDB_HANDLE hd, kbnode_t kb)
err = build_keyblock_image (kb, &iobuf);
if (!err)
{
+ keydb_stats.build_keyblocks++;
err = keybox_insert_keyblock (hd->active[idx].u.kb,
iobuf_get_temp_buffer (iobuf),
iobuf_get_temp_length (iobuf));
diff --git a/g10/packet.h b/g10/packet.h
index 5023903d2..db4945237 100644
--- a/g10/packet.h
+++ b/g10/packet.h
@@ -862,6 +862,7 @@ PACKET *create_gpg_control ( ctrlpkttype_t type,
size_t datalen );
/*-- build-packet.c --*/
+gpg_error_t build_keyblock_image (kbnode_t keyblock, iobuf_t *r_iobuf);
int build_packet (iobuf_t out, PACKET *pkt);
gpg_error_t build_packet_and_meta (iobuf_t out, PACKET *pkt);
gpg_error_t gpg_mpi_write (iobuf_t out, gcry_mpi_t a, unsigned int *t_nwritten);