diff options
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 |