mirror of git://git.gnupg.org/gnupg.git
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>
This commit is contained in:
parent
0611f548bc
commit
1f980d23af
|
@ -448,7 +448,7 @@ maybe_create_keyring_or_box (char *filename, int is_box, int force_create)
|
||||||
rc = gpg_error_from_syserror ();
|
rc = gpg_error_from_syserror ();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rc = _keybox_write_header_blob (fp, 1);
|
rc = _keybox_write_header_blob (fp, NULL, 1);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
}
|
}
|
||||||
if (rc)
|
if (rc)
|
||||||
|
|
|
@ -146,9 +146,9 @@ _keybox_write_blob (KEYBOXBLOB blob, FILE *fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Write a fresh header type blob. */
|
/* Write a fresh header type blob. Either FP or STREAM must be used. */
|
||||||
int
|
gpg_error_t
|
||||||
_keybox_write_header_blob (FILE *fp, int for_openpgp)
|
_keybox_write_header_blob (FILE *fp, estream_t stream, int for_openpgp)
|
||||||
{
|
{
|
||||||
unsigned char image[32];
|
unsigned char image[32];
|
||||||
u32 val;
|
u32 val;
|
||||||
|
@ -174,7 +174,15 @@ _keybox_write_header_blob (FILE *fp, int for_openpgp)
|
||||||
image[20+2] = (val >> 8);
|
image[20+2] = (val >> 8);
|
||||||
image[20+3] = (val );
|
image[20+3] = (val );
|
||||||
|
|
||||||
if (fwrite (image, 32, 1, fp) != 1)
|
if (fp)
|
||||||
return gpg_error_from_syserror ();
|
{
|
||||||
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ blob_filecopy (int mode, const char *fname, KEYBOXBLOB blob,
|
||||||
if (!newfp )
|
if (!newfp )
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
|
|
||||||
rc = _keybox_write_header_blob (newfp, for_openpgp);
|
rc = _keybox_write_header_blob (newfp, NULL, for_openpgp);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
fclose (newfp);
|
fclose (newfp);
|
||||||
|
@ -730,7 +730,7 @@ keybox_compress (KEYBOX_HANDLE hd)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The header blob is missing. Insert it. */
|
/* 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)
|
if (rc)
|
||||||
break;
|
break;
|
||||||
any_changes = 1;
|
any_changes = 1;
|
||||||
|
|
|
@ -81,7 +81,8 @@ gpg_error_t keybox_lock (KEYBOX_HANDLE hd, int yes, long timeout);
|
||||||
/*-- keybox-file.c --*/
|
/*-- keybox-file.c --*/
|
||||||
/* Fixme: This function does not belong here: Provide a better
|
/* Fixme: This function does not belong here: Provide a better
|
||||||
interface to create a new keybox file. */
|
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 --*/
|
/*-- keybox-search.c --*/
|
||||||
gpg_error_t keybox_get_keyblock (KEYBOX_HANDLE hd, iobuf_t *r_iobuf,
|
gpg_error_t keybox_get_keyblock (KEYBOX_HANDLE hd, iobuf_t *r_iobuf,
|
||||||
|
|
|
@ -224,7 +224,7 @@ maybe_create_keybox (char *filename, int force, int *r_created)
|
||||||
/* Make sure that at least one record is in a new keybox file, so
|
/* Make sure that at least one record is in a new keybox file, so
|
||||||
that the detection magic for OpenPGP keyboxes works the next time
|
that the detection magic for OpenPGP keyboxes works the next time
|
||||||
it is used. */
|
it is used. */
|
||||||
rc = _keybox_write_header_blob (fp, 0);
|
rc = _keybox_write_header_blob (fp, NULL, 0);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
Loading…
Reference in New Issue