コード例 #1
0
ファイル: textfilter.c プロジェクト: cuidi/gnupg
static int
standard( text_filter_context_t *tfx, IOBUF a,
	  byte *buf, size_t size, size_t *ret_len)
{
    int rc=0;
    size_t len = 0;
    unsigned maxlen;

    log_assert( size > 10 );
    size -= 2;	/* reserve 2 bytes to append CR,LF */
    while( !rc && len < size ) {
	int lf_seen;

	while( len < size && tfx->buffer_pos < tfx->buffer_len )
	    buf[len++] = tfx->buffer[tfx->buffer_pos++];
	if( len >= size )
	    continue;

	/* read the next line */
	maxlen = MAX_LINELEN;
	tfx->buffer_pos = 0;
	tfx->buffer_len = iobuf_read_line( a, &tfx->buffer,
					   &tfx->buffer_size, &maxlen );
	if( !maxlen )
	    tfx->truncated++;
	if( !tfx->buffer_len ) {
	    if( !len )
		rc = -1; /* eof */
	    break;
	}
	lf_seen = tfx->buffer[tfx->buffer_len-1] == '\n';

	/* The story behind this is that 2440 says that textmode
	   hashes should canonicalize line endings to CRLF and remove
	   spaces and tabs.  2440bis-12 says to just canonicalize to
	   CRLF.  1.4.0 was released using the bis-12 behavior, but it
	   was discovered that many mail clients do not canonicalize
	   PGP/MIME signature text appropriately (and were relying on
	   GnuPG to handle trailing spaces).  So, we default to the
	   2440 behavior, but use the 2440bis-12 behavior if the user
	   specifies --no-rfc2440-text.  The default will be changed
	   at some point in the future when the mail clients have been
	   upgraded.  Aside from PGP/MIME and broken mail clients,
	   this makes no difference to any signatures in the real
	   world except for a textmode detached signature.  PGP always
	   used the 2440bis-12 behavior (ignoring 2440 itself), so
	   this actually makes us compatible with PGP textmode
	   detached signatures for the first time. */
	if(opt.rfc2440_text)
	  tfx->buffer_len=trim_trailing_chars(tfx->buffer,tfx->buffer_len,
					      " \t\r\n");
	else
	  tfx->buffer_len=trim_trailing_chars(tfx->buffer,tfx->buffer_len,
					      "\r\n");

	if( lf_seen ) {
	    tfx->buffer[tfx->buffer_len++] = '\r';
	    tfx->buffer[tfx->buffer_len++] = '\n';
	}
    }
    *ret_len = len;
    return rc;
}
コード例 #2
0
/****************
 * Remove trailing white spaces and return the length of the buffer
 */
unsigned
trim_trailing_ws( byte *line, unsigned len )
{
    return trim_trailing_chars( line, len, " \t\r\n" );
}