aboutsummaryrefslogtreecommitdiffstats
path: root/g10/build-packet.c
diff options
context:
space:
mode:
authorNeal H. Walfield <[email protected]>2016-02-23 20:07:09 +0000
committerNeal H. Walfield <[email protected]>2016-02-23 20:10:51 +0000
commit33ac735a781325c4d47cdf6216813866ab93562e (patch)
tree7841f5eb29dd962c372a5d4f9bd5d158a06b3a95 /g10/build-packet.c
parentcommon: Check for an error before reading. (diff)
downloadgnupg-33ac735a781325c4d47cdf6216813866ab93562e.tar.gz
gnupg-33ac735a781325c4d47cdf6216813866ab93562e.zip
gpg: Use higher-level functions.
* g10/build-packet.c (do_symkey_enc): Use iobuf_write instead of iobuf_put in a loop. Use iobuf_copy instead of iobuf_read and iobuf_write in a loop. Move the memory wiping from here... * common/iobuf.c (iobuf_copy): ... to here. -- Signed-off-by: Neal H. Walfield <[email protected]>
Diffstat (limited to 'g10/build-packet.c')
-rw-r--r--g10/build-packet.c22
1 files changed, 6 insertions, 16 deletions
diff --git a/g10/build-packet.c b/g10/build-packet.c
index 4dec5b94f..a6d588115 100644
--- a/g10/build-packet.c
+++ b/g10/build-packet.c
@@ -528,33 +528,23 @@ calc_plaintext( PKT_plaintext *pt )
static int
do_plaintext( IOBUF out, int ctb, PKT_plaintext *pt )
{
- int i, rc = 0;
- u32 n;
- byte buf[1000]; /* this buffer has the plaintext! */
- int nbytes;
+ int rc = 0;
+ size_t nbytes;
write_header(out, ctb, calc_plaintext( pt ) );
iobuf_put(out, pt->mode );
iobuf_put(out, pt->namelen );
- for(i=0; i < pt->namelen; i++ )
- iobuf_put(out, pt->name[i] );
+ iobuf_write (out, pt->name, pt->namelen);
rc = write_32(out, pt->timestamp );
if (rc)
return rc;
- n = 0;
- while( (nbytes=iobuf_read(pt->buf, buf, 1000)) != -1 ) {
- rc = iobuf_write (out, buf, nbytes);
- if (rc)
- break;
- n += nbytes;
- }
- wipememory(buf,1000); /* burn the buffer */
+ nbytes = iobuf_copy (out, pt->buf);
if( (ctb&0x40) && !pt->len )
iobuf_set_partial_body_length_mode(out, 0 ); /* turn off partial */
- if( pt->len && n != pt->len )
+ if( pt->len && nbytes != pt->len )
log_error("do_plaintext(): wrote %lu bytes but expected %lu bytes\n",
- (ulong)n, (ulong)pt->len );
+ (ulong)nbytes, (ulong)pt->len );
return rc;
}