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 | |
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')
-rw-r--r-- | src/g10lib.h | 1 | ||||
-rw-r--r-- | src/gcrypt.h.in | 3 | ||||
-rw-r--r-- | src/sexp.c | 54 |
3 files changed, 26 insertions, 32 deletions
diff --git a/src/g10lib.h b/src/g10lib.h index 80c73ee3..ae4502cd 100644 --- a/src/g10lib.h +++ b/src/g10lib.h @@ -338,7 +338,6 @@ gcry_err_code_t _gcry_mpi_init (void); /*-- sexp.c --*/ gcry_err_code_t _gcry_sexp_vbuild (gcry_sexp_t *retsexp, size_t *erroff, const char *format, va_list arg_ptr); -gcry_mpi_t _gcry_sexp_nth_opaque_mpi (gcry_sexp_t list, int number); char *_gcry_sexp_nth_string (const gcry_sexp_t list, int number); gpg_err_code_t _gcry_sexp_vextract_param (gcry_sexp_t sexp, const char *path, const char *list, va_list arg_ptr); diff --git a/src/gcrypt.h.in b/src/gcrypt.h.in index 234e8a4a..fffc15ca 100644 --- a/src/gcrypt.h.in +++ b/src/gcrypt.h.in @@ -489,7 +489,8 @@ enum gcry_mpi_format GCRYMPI_FMT_PGP = 2, /* As used by OpenPGP (unsigned only). */ GCRYMPI_FMT_SSH = 3, /* As used by SSH (like STD but with length). */ GCRYMPI_FMT_HEX = 4, /* Hex format. */ - GCRYMPI_FMT_USG = 5 /* Like STD but unsigned. */ + GCRYMPI_FMT_USG = 5, /* Like STD but unsigned. */ + GCRYMPI_FMT_OPAQUE = 8 /* Opaque format (some functions only). */ }; /* Flags used for creating big integers. */ @@ -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 |