keybox_insert_keyblock (KEYBOX_HANDLE hd, const void *image, size_t imagelen,
                        u32 *sigstatus)
{
  gpg_error_t err;
  const char *fname;
  KEYBOXBLOB blob;
  size_t nparsed;
  struct _keybox_openpgp_info info;

  if (!hd)
    return gpg_error (GPG_ERR_INV_HANDLE);
  if (!hd->kb)
    return gpg_error (GPG_ERR_INV_HANDLE);
  fname = hd->kb->fname;
  if (!fname)
    return gpg_error (GPG_ERR_INV_HANDLE);


  /* Close this one otherwise we will mess up the position for a next
     search.  Fixme: it would be better to adjust the position after
     the write operation.  */
  _keybox_close_file (hd);

  err = _keybox_parse_openpgp (image, imagelen, &nparsed, &info);
  if (err)
    return err;
  assert (nparsed <= imagelen);
  err = _keybox_create_openpgp_blob (&blob, &info, image, imagelen,
                                     sigstatus, hd->ephemeral);
  _keybox_destroy_openpgp_info (&info);
  if (!err)
    {
      err = blob_filecopy (FILECOPY_INSERT, fname, blob, hd->secret, 1, 0);
      _keybox_release_blob (blob);
      /*    if (!rc && !hd->secret && kb_offtbl) */
      /*      { */
      /*        update_offset_hash_table_from_kb (kb_offtbl, kb, 0); */
      /*      } */
    }
  return err;
}
keybox_insert_keyblock (KEYBOX_HANDLE hd, const void *image, size_t imagelen,
                        u32 *sigstatus)
{
  gpg_error_t err;
  const char *fname;
  KEYBOXBLOB blob;
  size_t nparsed;
  struct _keybox_openpgp_info info;

  if (!hd)
    return gpg_error (GPG_ERR_INV_HANDLE);
  if (!hd->kb)
    return gpg_error (GPG_ERR_INV_HANDLE);
  fname = hd->kb->fname;
  if (!fname)
    return gpg_error (GPG_ERR_INV_HANDLE);


   
  _keybox_close_file (hd);

  err = _keybox_parse_openpgp (image, imagelen, &nparsed, &info);
  if (err)
    return err;
  assert (nparsed <= imagelen);
  err = _keybox_create_openpgp_blob (&blob, &info, image, imagelen,
                                     sigstatus, hd->ephemeral);
  _keybox_destroy_openpgp_info (&info);
  if (!err)
    {
      err = blob_filecopy (FILECOPY_INSERT, fname, blob, hd->secret, 1, 0);
      _keybox_release_blob (blob);
       
       
       
       
    }
  return err;
}