1
0
mirror of git://git.gnupg.org/gnupg.git synced 2025-01-22 14:57:02 +01:00

* build-packet.c (write_header2): Remove call to start old gpg partial

length mode and change all callers. (do_plaintext): Turn off partial
length encoding now that we're done writing the packet. (do_comment,
do_user_id): Try for a headerlen of 2 since that's the smallest and most
likely encoding for these packets.

* parse-packet.c (parse): Remove call to start old gpg partial length
mode.
This commit is contained in:
David Shaw 2004-03-03 16:38:34 +00:00
parent 2d7fe1d3a1
commit 56a6945261
3 changed files with 88 additions and 76 deletions

View File

@ -1,3 +1,15 @@
2004-03-03 David Shaw <dshaw@jabberwocky.com>
* build-packet.c (write_header2): Remove call to start old gpg
partial length mode and change all callers.
(do_plaintext): Turn off partial length encoding now that we're
done writing the packet.
(do_comment, do_user_id): Try for a headerlen of 2 since that's
the smallest and most likely encoding for these packets.
* parse-packet.c (parse): Remove call to start old gpg partial
length mode.
2004-03-02 David Shaw <dshaw@jabberwocky.com>
* options.h, g10.c (main): Add a more flexible --keyid-format

View File

@ -54,7 +54,7 @@ static int write_16(IOBUF inp, u16 a);
static int write_32(IOBUF inp, u32 a);
static int write_header( IOBUF out, int ctb, u32 len );
static int write_sign_packet_header( IOBUF out, int ctb, u32 len );
static int write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode );
static int write_header2( IOBUF out, int ctb, u32 len, int hdrlen );
static int write_new_header( IOBUF out, int ctb, u32 len, int hdrlen );
static int write_version( IOBUF out, int ctb );
@ -196,7 +196,7 @@ do_comment( IOBUF out, int ctb, PKT_comment *rem )
{
if( opt.sk_comments )
{
write_header2(out, ctb, rem->len, 1, 1);
write_header2(out, ctb, rem->len, 2);
if( iobuf_write( out, rem->data, rem->len ) )
return G10ERR_WRITE_FILE;
}
@ -214,7 +214,7 @@ do_user_id( IOBUF out, int ctb, PKT_user_id *uid )
}
else
{
write_header2( out, ctb, uid->len, 1, 1 );
write_header2( out, ctb, uid->len, 2 );
if( iobuf_write( out, uid->name, uid->len ) )
return G10ERR_WRITE_FILE;
}
@ -248,7 +248,7 @@ do_public_key( IOBUF out, int ctb, PKT_public_key *pk )
for(i=0; i < n; i++ )
mpi_write(a, pk->pkey[i] );
write_header2(out, ctb, iobuf_get_temp_length(a), pk->hdrbytes, 1 );
write_header2(out, ctb, iobuf_get_temp_length(a), pk->hdrbytes);
if( iobuf_write_temp( out, a ) )
rc = G10ERR_WRITE_FILE;
@ -384,7 +384,7 @@ do_secret_key( IOBUF out, int ctb, PKT_secret_key *sk )
leave:
/* Build the header of the packet - which we must do after writing all
the other stuff, so that we know the length of the packet */
write_header2(out, ctb, iobuf_get_temp_length(a), sk->hdrbytes, 1 );
write_header2(out, ctb, iobuf_get_temp_length(a), sk->hdrbytes);
/* And finally write it out the real stream */
if( iobuf_write_temp( out, a ) )
rc = G10ERR_WRITE_FILE;
@ -494,9 +494,9 @@ do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
n += nbytes;
}
wipememory(buf,1000); /* burn the buffer */
if( !pt->len )
iobuf_set_block_mode(out, 0 ); /* write end marker */
else if( n != pt->len )
if( (ctb&0x40) && !pt->len )
iobuf_set_partial_block_mode(out, 0 ); /* turn off partial */
if( pt->len && n != pt->len )
log_error("do_plaintext(): wrote %lu bytes but expected %lu bytes\n",
(ulong)n, (ulong)pt->len );
@ -548,7 +548,7 @@ do_compressed( IOBUF out, int ctb, PKT_compressed *cd )
set, CTB is already formatted as new style and write_header2
does create a partial length encoding using new the new
style. */
write_header2(out, ctb, 0, 0, 0 );
write_header2(out, ctb, 0, 0);
iobuf_put(out, cd->algorithm );
/* This is all. The caller has to write the real data */
@ -1018,7 +1018,7 @@ calc_header_length( u32 len, int new_ctb )
static int
write_header( IOBUF out, int ctb, u32 len )
{
return write_header2( out, ctb, len, 0, 1 );
return write_header2( out, ctb, len, 0 );
}
@ -1041,12 +1041,13 @@ write_sign_packet_header( IOBUF out, int ctb, u32 len )
* (using the specified hdrlen).
*/
static int
write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode )
write_header2( IOBUF out, int ctb, u32 len, int hdrlen )
{
if( ctb & 0x40 )
return write_new_header( out, ctb, len, hdrlen );
if( hdrlen ) {
if( hdrlen )
{
if( hdrlen == 2 && len < 256 )
;
else if( hdrlen == 3 && len < 65536 )
@ -1054,7 +1055,8 @@ write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode )
else
ctb |= 2;
}
else {
else
{
if( !len )
ctb |= 3;
else if( len < 256 )
@ -1064,22 +1066,28 @@ write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode )
else
ctb |= 2;
}
if( iobuf_put(out, ctb ) )
return -1;
if( !len && !hdrlen ) {
if( blkmode )
iobuf_set_block_mode(out, 8196 );
}
else {
if( ctb & 2 ) {
iobuf_put(out, len >> 24 );
iobuf_put(out, len >> 16 );
if( len || hdrlen )
{
if( ctb & 2 )
{
if(iobuf_put(out, len >> 24 ))
return -1;
if(iobuf_put(out, len >> 16 ))
return -1;
}
if( ctb & 3 )
iobuf_put(out, len >> 8 );
if(iobuf_put(out, len >> 8 ))
return -1;
if( iobuf_put(out, len ) )
return -1;
}
return 0;
}

View File

@ -383,37 +383,29 @@ parse( IOBUF inp, PACKET *pkt, int onlykeypkts, off_t *retpos,
}
}
}
else {
else
{
pkttype = (ctb>>2)&0xf;
lenbytes = ((ctb&3)==3)? 0 : (1<<(ctb & 3));
if( !lenbytes ) {
if( !lenbytes )
{
pktlen = 0; /* don't know the value */
/* This isn't really partial, but we can treat it the same
in a "read until the end" sort of way. */
partial=1;
switch (pkttype) {
case PKT_ENCRYPTED:
case PKT_PLAINTEXT:
/* These partial length encodings are from an very
early GnuPG release and deprecated. However we
still support them read-wise. Note, that we should
not allow them for any key related packets, because
this might render a keyring unusable if an errenous
packet indicated this mode but not complying to it
gets imported. */
iobuf_set_block_mode(inp, 1);
break;
case PKT_COMPRESSED:
break; /* the orginal pgp 2 way. */
default:
log_error ("%s: old style partial length for invalid"
if(pkttype!=PKT_ENCRYPTED && pkttype!=PKT_PLAINTEXT
&& pkttype!=PKT_COMPRESSED)
{
log_error ("%s: indeterminate length for invalid"
" packet type %d\n", iobuf_where(inp), pkttype );
rc = G10ERR_INVALID_PACKET;
goto leave;
}
}
else {
for( ; lenbytes; lenbytes-- ) {
else
{
for( ; lenbytes; lenbytes-- )
{
pktlen <<= 8;
pktlen |= hdr[hdrlen++] = iobuf_get_noeof(inp);
}