예제 #1
0
static int
text_encode( void * opaque, FILE * in, FILE * out )
{
    const char * s;
    char buf[1024];

    if( !in || !out )
        return CDK_Inv_Value;
  
    while( !feof( in ) ) {
        s = fgets( buf, sizeof buf-1, in );
        if( !s )
            break;
        _cdk_trim_string( buf, 1 );
        fwrite( buf, 1, strlen( buf ), out );
    }
    
    return 0;
}
예제 #2
0
파일: literal.c 프로젝트: sqs/gnutls
static int
text_encode (void *data, FILE * in, FILE * out)
{
    const char *s;
    char buf[2048];

    if (!in || !out)
        return CDK_Inv_Value;

    /* FIXME: This code does not work for very long lines. */
    while (!feof (in))
    {
        s = fgets (buf, DIM (buf) - 1, in);
        if (!s)
            break;
        _cdk_trim_string (buf, 1);
        fwrite (buf, 1, strlen (buf), out);
    }

    return 0;
}
예제 #3
0
static int
text_decode( void * opaque, FILE * in, FILE * out )
{
    text_filter_t * tfx = opaque;
    const char * s;
    char buf[1024];

    if( !tfx || !in || !out )
        return CDK_Inv_Value;

    while( !feof( in ) ) {
        s = fgets( buf, sizeof buf-1, in );
        if( !s )
            break;
        _cdk_trim_string( buf, 0 );
        fwrite( buf, 1, strlen( buf ), out );
        fwrite( tfx->lf, 1, strlen( tfx->lf ), out );
    }
    
    return 0;
}
예제 #4
0
파일: literal.c 프로젝트: nobled/gnutls
static int
text_decode (void *data, FILE * in, FILE * out)
{
  text_filter_t *tfx = data;
  const char *s;
  char buf[2048];

  if (!tfx || !in || !out)
    return CDK_Inv_Value;

  while (!feof (in))
    {
      s = fgets (buf, DIM (buf) - 1, in);
      if (!s)
        break;
      _cdk_trim_string (buf);
      fwrite (buf, 1, strlen (buf), out);
      fwrite (tfx->lf, 1, strlen (tfx->lf), out);
    }

  return 0;
}
예제 #5
0
파일: literal.c 프로젝트: nobled/gnutls
static int
text_encode (void *data, FILE * in, FILE * out)
{
  const char *s;
  char buf[2048];

  if (!in || !out)
    return CDK_Inv_Value;

  /* FIXME: This code does not work for very long lines. */
  while (!feof (in))
    {
      /* give space for trim_string \r\n */
      s = fgets (buf, DIM (buf) - 3, in);
      if (!s)
        break;
      _cdk_trim_string (buf);
      _gnutls_str_cat (buf, sizeof(buf), "\r\n");
      fwrite (buf, 1, strlen (buf), out);
    }

  return 0;
}
예제 #6
0
파일: verify.c 프로젝트: Chronic-Dev/gnutls
static cdk_error_t
file_verify_clearsign (cdk_ctx_t hd, const char *file, const char *output)
{
  cdk_stream_t inp = NULL, out = NULL, tmp = NULL;
  digest_hd_st md;
  char buf[512], chk[512];
  const char *s;
  int i, is_signed = 0, nbytes;
  int digest_algo = 0;
  int err;
  cdk_error_t rc;

  memset(&md, 0, sizeof(md));

  if (output)
    {
      rc = cdk_stream_create (output, &out);
      if (rc)
	return rc;
    }

  rc = cdk_stream_open (file, &inp);
  if (rc)
    {
      if (output)
	cdk_stream_close (out);
      return rc;
    }

  s = "-----BEGIN PGP SIGNED MESSAGE-----";
  while (!cdk_stream_eof (inp))
    {
      nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1);
      if (!nbytes || nbytes == -1)
	break;
      if (!strncmp (buf, s, strlen (s)))
	{
	  is_signed = 1;
	  break;
	}
    }

  if (cdk_stream_eof (inp) && !is_signed)
    {
      rc = CDK_Armor_Error;
      goto leave;
    }

  while (!cdk_stream_eof (inp))
    {
      nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1);
      if (!nbytes || nbytes == -1)
	break;
      if (nbytes == 1)		/* Empty line */
	break;
      else if (!strncmp (buf, "Hash: ", 6))
	{
	  for (i = 0; digest_table[i].name; i++)
	    {
	      if (!strcmp (buf + 6, digest_table[i].name))
		{
		  digest_algo = digest_table[i].algo;
		  break;
		}
	    }
	}
    }

  if (digest_algo && _gnutls_hash_get_algo_len (digest_algo) <= 0)
    {
      rc = CDK_Inv_Algo;
      goto leave;
    }

  if (!digest_algo)
    digest_algo = GNUTLS_DIG_MD5;

  err = _gnutls_hash_init (&md, digest_algo);
  if (err < 0)
    {
      rc = map_gnutls_error (err);
      goto leave;
    }

  s = "-----BEGIN PGP SIGNATURE-----";
  while (!cdk_stream_eof (inp))
    {
      nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1);
      if (!nbytes || nbytes == -1)
	break;
      if (!strncmp (buf, s, strlen (s)))
	break;
      else
	{
	  cdk_stream_peek (inp, (byte *) chk, DIM (chk) - 1);
	  i = strncmp (chk, s, strlen (s));
	  if (strlen (buf) == 0 && i == 0)
	    continue;		/* skip last '\n' */
	  _cdk_trim_string (buf, i == 0 ? 0 : 1);
	  _gnutls_hash (&md, buf, strlen (buf));
	}
      if (!strncmp (buf, "- ", 2))	/* FIXME: handle it recursive. */
	memmove (buf, buf + 2, nbytes - 2);
      if (out)
	{
	  if (strstr (buf, "\r\n"))
	    buf[strlen (buf) - 2] = '\0';
	  cdk_stream_write (out, buf, strlen (buf));
	  _cdk_stream_puts (out, _cdk_armor_get_lineend ());
	}
    }

  /* We create a temporary stream object to store the
     signature data in there. */
  rc = cdk_stream_tmp_new (&tmp);
  if (rc)
    goto leave;

  s = "-----BEGIN PGP SIGNATURE-----\n";
  _cdk_stream_puts (tmp, s);
  while (!cdk_stream_eof (inp))
    {
      nbytes = _cdk_stream_gets (inp, buf, DIM (buf) - 1);
      if (!nbytes || nbytes == -1)
	break;
      if (nbytes < (int) (DIM (buf) - 3))
	{
	  buf[nbytes - 1] = '\n';
	  buf[nbytes] = '\0';
	}
      cdk_stream_write (tmp, buf, nbytes);
    }

  /* FIXME: This code is not very elegant. */
  cdk_stream_tmp_set_mode (tmp, STREAMCTL_READ);
  cdk_stream_seek (tmp, 0);
  cdk_stream_set_armor_flag (tmp, 0);
  cdk_stream_read (tmp, NULL, 0);

  /* the digest handle will be closed there. */
  rc = _cdk_proc_packets (hd, tmp, NULL, NULL, NULL, &md);

leave:
  _gnutls_hash_deinit (&md, NULL);
  cdk_stream_close (out);
  cdk_stream_close (tmp);
  cdk_stream_close (inp);
  return rc;
}