summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--doc/gcrypt.texi24
-rw-r--r--src/gcrypt.h.in7
-rw-r--r--src/libgcrypt.def5
-rw-r--r--src/libgcrypt.vers2
-rw-r--r--src/sexp.c26
-rw-r--r--src/visibility.c6
-rw-r--r--src/visibility.h9
8 files changed, 76 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index b1ad7ac6..508b943d 100644
--- a/NEWS
+++ b/NEWS
@@ -73,6 +73,7 @@ Noteworthy changes in version 1.6.0 (unreleased)
GCRYCTL_DISABLE_LOCKED_SECMEM NEW.
GCRYCTL_DISABLE_PRIV_DROP NEW.
GCRY_CIPHER_SALSA20 NEW.
+ gcry_sexp_nth_buffer NEW.
Noteworthy changes in version 1.5.0 (2011-06-29)
diff --git a/doc/gcrypt.texi b/doc/gcrypt.texi
index cfc01741..770a2451 100644
--- a/doc/gcrypt.texi
+++ b/doc/gcrypt.texi
@@ -3596,6 +3596,30 @@ printf ("my name is %.*s\n", (int)len, name);
@end example
@end deftypefun
+@deftypefun {void *} gcry_sexp_nth_buffer (@w{const gcry_sexp_t @var{list}}, @w{int @var{number}}, @w{size_t *@var{rlength}})
+
+This function is used to get data from a @var{list}. A malloced
+buffer with the actual data at list index @var{number} is returned and
+the length of this buffer will be stored to @var{rlength}. If there
+is no data at the given index or the index represents another list,
+@code{NULL} is returned. The caller must release the result using
+@code{gcry_free}.
+
+@noindent
+Here is an example on how to extract and print the CRC value from the
+S-expression @samp{(hash crc32 #23ed00d7)}:
+
+@example
+size_t len;
+char *value;
+
+value = gcry_sexp_nth_buffer (list, 2, &len);
+if (value)
+ fwrite (value, len, 1, stdout);
+gcry_free (value);
+@end example
+@end deftypefun
+
@deftypefun {char *} gcry_sexp_nth_string (@w{gcry_sexp_t @var{list}}, @w{int @var{number}})
This function is used to get and convert data from a @var{list}. The
diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in
index 6bd615d1..06d66639 100644
--- a/src/gcrypt.h.in
+++ b/src/gcrypt.h.in
@@ -423,6 +423,13 @@ gcry_sexp_t gcry_sexp_cadr (const gcry_sexp_t list);
const char *gcry_sexp_nth_data (const gcry_sexp_t list, int number,
size_t *datalen);
+/* This function is used to get data from a LIST. A malloced buffer to the
+ data with index NUMBER is returned and the length of this
+ data will be stored to RLENGTH. If there is no data at the given
+ index or the index represents another list, `NULL' is returned. */
+void *gcry_sexp_nth_buffer (const gcry_sexp_t list, int number,
+ size_t *rlength);
+
/* This function is used to get and convert data from a LIST. The
data is assumed to be a Nul terminated string. The caller must
release the returned value using `gcry_free'. If there is no data
diff --git a/src/libgcrypt.def b/src/libgcrypt.def
index 9eaf8a7a..bbc8f437 100644
--- a/src/libgcrypt.def
+++ b/src/libgcrypt.def
@@ -236,3 +236,8 @@ EXPORTS
gcry_pubkey_get_sexp @212
_gcry_mpi_get_const @213
+
+ gcry_sexp_get_buffer @214
+
+
+;; end of file with public symbols for Windows.
diff --git a/src/libgcrypt.vers b/src/libgcrypt.vers
index 6aaf0f13..473ee68d 100644
--- a/src/libgcrypt.vers
+++ b/src/libgcrypt.vers
@@ -72,7 +72,7 @@ GCRYPT_1.6 {
gcry_sexp_build_array; gcry_sexp_cadr; gcry_sexp_canon_len;
gcry_sexp_car; gcry_sexp_cdr; gcry_sexp_cons; gcry_sexp_create;
gcry_sexp_dump; gcry_sexp_find_token; gcry_sexp_length;
- gcry_sexp_new; gcry_sexp_nth; gcry_sexp_nth_data;
+ gcry_sexp_new; gcry_sexp_nth; gcry_sexp_nth_buffer; gcry_sexp_nth_data;
gcry_sexp_nth_mpi; gcry_sexp_prepend; gcry_sexp_release;
gcry_sexp_sprint; gcry_sexp_sscan; gcry_sexp_vlist;
gcry_sexp_nth_string;
diff --git a/src/sexp.c b/src/sexp.c
index 62126d33..6dedf4e8 100644
--- a/src/sexp.c
+++ b/src/sexp.c
@@ -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
*/
diff --git a/src/visibility.c b/src/visibility.c
index c86d31b2..bb51d58e 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -226,6 +226,12 @@ gcry_sexp_nth_data (const gcry_sexp_t list, int number, size_t *datalen)
return _gcry_sexp_nth_data (list, number, datalen);
}
+void *
+gcry_sexp_nth_buffer (const gcry_sexp_t list, int number, size_t *rlength)
+{
+ return _gcry_sexp_nth_buffer (list, number, rlength);
+}
+
char *
gcry_sexp_nth_string (gcry_sexp_t list, int number)
{
diff --git a/src/visibility.h b/src/visibility.h
index 4837ed65..54da016f 100644
--- a/src/visibility.h
+++ b/src/visibility.h
@@ -133,14 +133,15 @@
#define gcry_sexp_length _gcry_sexp_length
#define gcry_sexp_new _gcry_sexp_new
#define gcry_sexp_nth _gcry_sexp_nth
+#define gcry_sexp_nth_buffer _gcry_sexp_nth_buffer
#define gcry_sexp_nth_data _gcry_sexp_nth_data
#define gcry_sexp_nth_mpi _gcry_sexp_nth_mpi
+#define gcry_sexp_nth_string _gcry_sexp_nth_string
#define gcry_sexp_prepend _gcry_sexp_prepend
#define gcry_sexp_release _gcry_sexp_release
#define gcry_sexp_sprint _gcry_sexp_sprint
#define gcry_sexp_sscan _gcry_sexp_sscan
#define gcry_sexp_vlist _gcry_sexp_vlist
-#define gcry_sexp_nth_string _gcry_sexp_nth_string
#define gcry_mpi_add _gcry_mpi_add
#define gcry_mpi_add_ui _gcry_mpi_add_ui
@@ -348,14 +349,15 @@ gcry_err_code_t gcry_md_get (gcry_md_hd_t hd, int algo,
#undef gcry_sexp_length
#undef gcry_sexp_new
#undef gcry_sexp_nth
+#undef gcry_sexp_nth_buffer
#undef gcry_sexp_nth_data
#undef gcry_sexp_nth_mpi
+#undef gcry_sexp_nth_string
#undef gcry_sexp_prepend
#undef gcry_sexp_release
#undef gcry_sexp_sprint
#undef gcry_sexp_sscan
#undef gcry_sexp_vlist
-#undef gcry_sexp_nth_string
#undef gcry_mpi_add
#undef gcry_mpi_add_ui
@@ -524,14 +526,15 @@ MARK_VISIBLE (gcry_sexp_find_token)
MARK_VISIBLE (gcry_sexp_length)
MARK_VISIBLE (gcry_sexp_new)
MARK_VISIBLE (gcry_sexp_nth)
+MARK_VISIBLE (gcry_sexp_nth_buffer)
MARK_VISIBLE (gcry_sexp_nth_data)
MARK_VISIBLE (gcry_sexp_nth_mpi)
+MARK_VISIBLE (gcry_sexp_nth_string)
MARK_VISIBLE (gcry_sexp_prepend)
MARK_VISIBLE (gcry_sexp_release)
MARK_VISIBLE (gcry_sexp_sprint)
MARK_VISIBLE (gcry_sexp_sscan)
MARK_VISIBLE (gcry_sexp_vlist)
-MARK_VISIBLE (gcry_sexp_nth_string)
MARK_VISIBLE (gcry_mpi_add)
MARK_VISIBLE (gcry_mpi_add_ui)