write_keyblock (IOBUF fp, KBNODE keyblock)
{
  KBNODE kbctx = NULL, node;
  int rc;

  while ( (node = walk_kbnode (keyblock, &kbctx, 0)) )
    {
      if (node->pkt->pkttype == PKT_RING_TRUST)
        continue; /* we write it later on our own */

      if ( (rc = build_packet (fp, node->pkt) ))
        {
          log_error ("build_packet(%d) failed: %s\n",
                     node->pkt->pkttype, gpg_strerror (rc) );
          return rc;
        }
      if (node->pkt->pkttype == PKT_SIGNATURE)
        { /* always write a signature cache packet */
          PKT_signature *sig = node->pkt->pkt.signature;
          unsigned int cacheval = 0;

          if (sig->flags.checked)
            {
              cacheval |= 1;
              if (sig->flags.valid)
                cacheval |= 2;
            }
          iobuf_put (fp, 0xb0); /* old style packet 12, 1 byte len*/
          iobuf_put (fp, 2);    /* 2 bytes */
          iobuf_put (fp, 0);    /* unused */
          if (iobuf_put (fp, cacheval))
            {
              rc = gpg_error_from_syserror ();
              log_error ("writing sigcache packet failed\n");
              return rc;
            }
        }
    }
  return 0;
}
write_keyblock (IOBUF fp, KBNODE keyblock)
{
  KBNODE kbctx = NULL, node;
  int rc;

  while ( (node = walk_kbnode (keyblock, &kbctx, 0)) )
    {
      if (node->pkt->pkttype == PKT_RING_TRUST)
        continue;  

      if ( (rc = build_packet (fp, node->pkt) ))
        {
          log_error ("build_packet(%d) failed: %s\n",
                     node->pkt->pkttype, gpg_strerror (rc) );
          return rc;
        }
      if (node->pkt->pkttype == PKT_SIGNATURE)
        {  
          PKT_signature *sig = node->pkt->pkt.signature;
          unsigned int cacheval = 0;

          if (sig->flags.checked)
            {
              cacheval |= 1;
              if (sig->flags.valid)
                cacheval |= 2;
            }
          iobuf_put (fp, 0xb0);  
          iobuf_put (fp, 2);     
          iobuf_put (fp, 0);     
          if (iobuf_put (fp, cacheval))
            {
              rc = gpg_error_from_syserror ();
              log_error ("writing sigcache packet failed\n");
              return rc;
            }
        }
    }
  return 0;
}