diff options
Diffstat (limited to 'src/sexp.c')
-rw-r--r-- | src/sexp.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -1,6 +1,7 @@ /* sexp.c - S-Expression handling * Copyright (C) 1999, 2000, 2001, 2002, 2003, * 2004, 2006, 2007, 2008, 2011 Free Software Foundation, Inc. + * Copyright (C) 2013 g10 Code GmbH * * This file is part of Libgcrypt. * @@ -713,6 +714,30 @@ gcry_sexp_nth_data (const gcry_sexp_t list, int number, size_t *datalen ) } +/* Get the nth element of a list which needs to be a simple object. + The returned value is a malloced buffer and needs to be freed by + the caller. This is basically the same as gcry_sexp_nth_data but + with an allocated result. */ +void * +gcry_sexp_nth_buffer (const gcry_sexp_t list, int number, size_t *rlength) +{ + const char *s; + size_t n; + char *buf; + + *rlength = 0; + s = sexp_nth_data (list, number, &n); + if (!s || !n) + return NULL; + buf = gcry_malloc (n); + if (!buf) + return NULL; + memcpy (buf, s, n); + *rlength = n; + return buf; +} + + /* Get a string from the car. The returned value is a malloced string and needs to be freed by the caller. */ char * @@ -733,6 +758,7 @@ gcry_sexp_nth_string (const gcry_sexp_t list, int number) return buf; } + /* * Get a MPI from the car */ |