aboutsummaryrefslogtreecommitdiffstats
path: root/g10/build-packet.c
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 /g10/build-packet.c
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]>
Diffstat (limited to 'g10/build-packet.c')
-rw-r--r--g10/build-packet.c43
1 files changed, 43 insertions, 0 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