~ubuntu-branches/ubuntu/maverick/strongswan/maverick

« back to all changes in this revision

Viewing changes to src/libstrongswan/chunk.c

  • Committer: Bazaar Package Importer
  • Author(s): Rene Mayrhofer
  • Date: 2008-12-05 17:21:42 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20081205172142-9g77wgyzcj0blq7p
* New upstream release, fixes a MOBIKE issue.
  Closes: #507542: strongswan: endless loop
* Explicitly enable compilation with libcurl for CRL fetching
  Closes: #497756: strongswan: not compiled with curl support; crl 
                   fetching not available
* Enable compilation with SSH agent support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14
14
 * for more details.
15
15
 *
16
 
 * $Id: chunk.c 3868 2008-04-24 13:26:22Z martin $
 
16
 * $Id: chunk.c 4276 2008-08-22 10:44:51Z martin $
17
17
 */
18
18
 
19
19
#include <stdio.h>
298
298
chunk_t chunk_from_hex(chunk_t hex, char *buf)
299
299
{
300
300
        int i, len;
 
301
        bool odd = FALSE;
301
302
        
302
 
        len = hex.len / 2;
 
303
        len = (hex.len / 2);
 
304
        if (hex.len % 2)
 
305
        {
 
306
                odd = TRUE;
 
307
                len++;
 
308
        }
303
309
        if (!buf)
304
310
        {
305
311
                buf = malloc(len);
306
312
        }
307
 
        for (i = 0; i < len; i++)
 
313
        /* buffer is filled from the right */
 
314
        memset(buf, 0, len);
 
315
        hex.ptr += hex.len;
 
316
        for (i = len - 1; i >= 0; i--)
308
317
        {
309
 
                buf[i] =  hex2bin(*hex.ptr++) << 4;
310
 
                buf[i] |= hex2bin(*hex.ptr++);
 
318
                buf[i] = hex2bin(*(--hex.ptr));
 
319
                if (i > 0 || !odd)
 
320
                {
 
321
                        buf[i] |= hex2bin(*(--hex.ptr)) << 4;
 
322
                }
311
323
        }
312
324
        return chunk_create(buf, len);
313
325
}