diff options
author | Werner Koch <wk@gnupg.org> | 2013-11-11 11:07:56 +0100 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-11-11 19:15:20 +0100 |
commit | 8b3eecee2d89179297e43de7d650f74759c61a58 (patch) | |
tree | d66c4c6bd224b74c107dbb1ae475fc179c59d39f /src/sexp.c | |
parent | 7b26586e35a6d407ca31b41528b0810b1408fd4b (diff) | |
download | libgcrypt-8b3eecee2d89179297e43de7d650f74759c61a58.tar.gz |
mpi: Add special format GCRYMPI_FMT_OPAQUE.
* src/gcrypt.h.in (GCRYMPI_FMT_OPAQUE): New.
(_gcry_sexp_nth_opaque_mpi): Remove.
* src/sexp.c (gcry_sexp_nth_mpi): Add support for GCRYMPI_FMT_OPAQUE.
(_gcry_sexp_vextract_param): Replace removed function by
GCRYMPI_FMT_OPAQUE.
--
Using a new formatting mode is easier than to add a dedicated
extraction function for opaque MPIs.
Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src/sexp.c')
-rw-r--r-- | src/sexp.c | 54 |
1 files changed, 24 insertions, 30 deletions
@@ -765,43 +765,37 @@ gcry_sexp_nth_string (const gcry_sexp_t list, int number) gcry_mpi_t gcry_sexp_nth_mpi (gcry_sexp_t list, int number, int mpifmt) { - const char *s; size_t n; gcry_mpi_t a; - if ( !mpifmt ) - mpifmt = GCRYMPI_FMT_STD; - - s = sexp_nth_data (list, number, &n); - if (!s) - return NULL; - - if ( gcry_mpi_scan ( &a, mpifmt, s, n, NULL ) ) - return NULL; + if (mpifmt == GCRYMPI_FMT_OPAQUE) + { + char *p; - return a; -} + p = gcry_sexp_nth_buffer (list, number, &n); + if (!p) + return NULL; + a = gcry_is_secure (list)? _gcry_mpi_snew (0) : _gcry_mpi_new (0); + if (a) + gcry_mpi_set_opaque (a, p, n*8); + else + gcry_free (p); + } + else + { + const char *s; -/* - * Get data from the car and store return it as an opaque MPI. - */ -gcry_mpi_t -_gcry_sexp_nth_opaque_mpi (gcry_sexp_t list, int number) -{ - char *p; - size_t n; - gcry_mpi_t a; + if (!mpifmt) + mpifmt = GCRYMPI_FMT_STD; - p = gcry_sexp_nth_buffer (list, number, &n); - if (!p) - return NULL; + s = sexp_nth_data (list, number, &n); + if (!s) + return NULL; - a = gcry_is_secure (list)? _gcry_mpi_snew (0) : _gcry_mpi_new (0); - if (a) - gcry_mpi_set_opaque (a, p, n*8); - else - gcry_free (p); + if (gcry_mpi_scan (&a, mpifmt, s, n, NULL)) + return NULL; + } return a; } @@ -2293,7 +2287,7 @@ _gcry_sexp_vextract_param (gcry_sexp_t sexp, const char *path, } } else if (mode == '/') - *array[idx] = _gcry_sexp_nth_opaque_mpi (l1, 1); + *array[idx] = gcry_sexp_nth_mpi (l1, 1, GCRYMPI_FMT_OPAQUE); else if (mode == '-') *array[idx] = gcry_sexp_nth_mpi (l1, 1, GCRYMPI_FMT_STD); else |