[svn] GnuPG - r4792 - trunk/sm
svn author wk
cvs at cvs.gnupg.org
Mon Jun 23 16:43:16 CEST 2008
Author: wk
Date: 2008-06-23 16:43:14 +0200 (Mon, 23 Jun 2008)
New Revision: 4792
Modified:
trunk/sm/ChangeLog
trunk/sm/encrypt.c
Log:
Code cleanup.
Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog 2008-06-23 08:49:04 UTC (rev 4791)
+++ trunk/sm/ChangeLog 2008-06-23 14:43:14 UTC (rev 4792)
@@ -1,3 +1,9 @@
+2008-06-23 Werner Koch <wk at g10code.com>
+
+ * encrypt.c (encode_session_key): Replace xmalloc by xtrymalloc.
+ Use bin2hex instead of open coding the conversion.
+ (encrypt_dek): Init S_DATA.
+
2008-06-13 Marcus Brinkmann <marcus at ulysses.g10code.com>
* call-dirmngr.c (prepare_dirmngr): Fix error code to ignore.
Modified: trunk/sm/encrypt.c
===================================================================
--- trunk/sm/encrypt.c 2008-06-23 08:49:04 UTC (rev 4791)
+++ trunk/sm/encrypt.c 2008-06-23 14:43:14 UTC (rev 4792)
@@ -1,5 +1,5 @@
/* encrypt.c - Encrypt a message
- * Copyright (C) 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2001, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
*
* This file is part of GnuPG.
*
@@ -144,17 +144,14 @@
encode_session_key (DEK dek, gcry_sexp_t * r_data)
{
gcry_sexp_t data;
- char * p, tmp[3];
- int i;
+ char *p;
int rc;
- p = xmalloc (64 + 2 * dek->keylen);
+ p = xtrymalloc (64 + 2 * dek->keylen);
+ if (!p)
+ return gpg_error_from_syserror ();
strcpy (p, "(data\n (flags pkcs1)\n (value #");
- for (i=0; i < dek->keylen; i++)
- {
- sprintf (tmp, "%02x", (unsigned char) dek->key[i]);
- strcat (p, tmp);
- }
+ bin2hex (dek->key, dek->keylen, p + strlen (p));
strcat (p, "#))\n");
rc = gcry_sexp_sscan (&data, NULL, p, strlen (p));
xfree (p);
@@ -196,13 +193,14 @@
return rc;
}
- /* put the encoded cleartext into a simple list */
+ /* Put the encoded cleartext into a simple list. */
+ s_data = NULL; /* (avoid compiler warning) */
rc = encode_session_key (dek, &s_data);
if (rc)
- {
- log_error ("encode_session_key failed: %s\n", gpg_strerror (rc));
- return rc;
- }
+ {
+ log_error ("encode_session_key failed: %s\n", gpg_strerror (rc));
+ return rc;
+ }
/* pass it to libgcrypt */
rc = gcry_pk_encrypt (&s_ciph, s_data, s_pkey);
More information about the Gnupg-commits
mailing list