summaryrefslogtreecommitdiffstats
path: root/kbx
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2019-08-06 14:59:37 +0200
committerWerner Koch <wk@gnupg.org>2019-08-06 15:01:21 +0200
commit1f980d23af8b818ed8246ec6bf13b9c61b963ec0 (patch)
treecc6d66cf92be79457c63a7fb5734a4802e2457da /kbx
parenttools: New option --keyboxd for gpg-connect-agent. (diff)
downloadgnupg2-1f980d23af8b818ed8246ec6bf13b9c61b963ec0.tar.xz
gnupg2-1f980d23af8b818ed8246ec6bf13b9c61b963ec0.zip
kbx: Allow writing using a estream.
* kbx/keybox-file.c (_keybox_write_header_blob): New optional arg stream. Change callers. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'kbx')
-rw-r--r--kbx/keybox-file.c18
-rw-r--r--kbx/keybox-update.c4
-rw-r--r--kbx/keybox.h3
3 files changed, 17 insertions, 8 deletions
diff --git a/kbx/keybox-file.c b/kbx/keybox-file.c
index 046e32123..7a1b43aa7 100644
--- a/kbx/keybox-file.c
+++ b/kbx/keybox-file.c
@@ -146,9 +146,9 @@ _keybox_write_blob (KEYBOXBLOB blob, FILE *fp)
}
-/* Write a fresh header type blob. */
-int
-_keybox_write_header_blob (FILE *fp, int for_openpgp)
+/* Write a fresh header type blob. Either FP or STREAM must be used. */
+gpg_error_t
+_keybox_write_header_blob (FILE *fp, estream_t stream, int for_openpgp)
{
unsigned char image[32];
u32 val;
@@ -174,7 +174,15 @@ _keybox_write_header_blob (FILE *fp, int for_openpgp)
image[20+2] = (val >> 8);
image[20+3] = (val );
- if (fwrite (image, 32, 1, fp) != 1)
- return gpg_error_from_syserror ();
+ if (fp)
+ {
+ if (fwrite (image, 32, 1, fp) != 1)
+ return gpg_error_from_syserror ();
+ }
+ else
+ {
+ if (es_fwrite (image, 32, 1, stream) != 1)
+ return gpg_error_from_syserror ();
+ }
return 0;
}
diff --git a/kbx/keybox-update.c b/kbx/keybox-update.c
index e09fefc41..d22da1bf8 100644
--- a/kbx/keybox-update.c
+++ b/kbx/keybox-update.c
@@ -182,7 +182,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
if (!newfp )
return gpg_error_from_syserror ();
- rc = _keybox_write_header_blob (newfp, for_openpgp);
+ rc = _keybox_write_header_blob (newfp, NULL, for_openpgp);
if (rc)
{
fclose (newfp);
@@ -730,7 +730,7 @@ keybox_compress (KEYBOX_HANDLE hd)
}
/* The header blob is missing. Insert it. */
- rc = _keybox_write_header_blob (newfp, hd->for_openpgp);
+ rc = _keybox_write_header_blob (newfp, NULL, hd->for_openpgp);
if (rc)
break;
any_changes = 1;
diff --git a/kbx/keybox.h b/kbx/keybox.h
index 4d941571e..d614c32d1 100644
--- a/kbx/keybox.h
+++ b/kbx/keybox.h
@@ -81,7 +81,8 @@ gpg_error_t keybox_lock (KEYBOX_HANDLE hd, int yes, long timeout);
/*-- keybox-file.c --*/
/* Fixme: This function does not belong here: Provide a better
interface to create a new keybox file. */
-int _keybox_write_header_blob (FILE *fp, int openpgp_flag);
+gpg_error_t _keybox_write_header_blob (FILE *fp, estream_t stream,
+ int openpgp_flag);
/*-- keybox-search.c --*/
gpg_error_t keybox_get_keyblock (KEYBOX_HANDLE hd, iobuf_t *r_iobuf,