Commit 42d08b36 authored by Niels Möller's avatar Niels Möller

(nettle_mpz_set_sexp): Call sexp_iterator_next on

success. That means the iterator argument can't be const.

Rev: src/nettle/bignum.h:1.7
Rev: src/nettle/sexp2bignum.c:1.4
parent 0991e9a6
...@@ -80,8 +80,9 @@ nettle_mpz_random(mpz_t x, ...@@ -80,8 +80,9 @@ nettle_mpz_random(mpz_t x,
struct sexp_iterator; struct sexp_iterator;
/* If LIMIT is non-zero, the number must be at most LIMIT bits. */ /* If LIMIT is non-zero, the number must be at most LIMIT bits.
* Implies sexp_iterator_next. */
int int
nettle_mpz_set_sexp(mpz_t x, unsigned limit, const struct sexp_iterator *i); nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i);
#endif /* NETTLE_BIGNUM_H_INCLUDED */ #endif /* NETTLE_BIGNUM_H_INCLUDED */
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "bignum.h" #include "bignum.h"
int int
nettle_mpz_set_sexp(mpz_t x, unsigned limit, const struct sexp_iterator *i) nettle_mpz_set_sexp(mpz_t x, unsigned limit, struct sexp_iterator *i)
{ {
if (i->type == SEXP_ATOM if (i->type == SEXP_ATOM
&& i->atom_length && i->atom_length
...@@ -43,8 +43,12 @@ nettle_mpz_set_sexp(mpz_t x, unsigned limit, const struct sexp_iterator *i) ...@@ -43,8 +43,12 @@ nettle_mpz_set_sexp(mpz_t x, unsigned limit, const struct sexp_iterator *i)
return 0; return 0;
nettle_mpz_set_str_256_s(x, i->atom_length, i->atom); nettle_mpz_set_str_256_s(x, i->atom_length, i->atom);
/* FIXME: How to interpret a limit for negative numbers? */ /* FIXME: How to interpret a limit for negative numbers? */
return !limit || mpz_sizeinbase(x, 2) <= limit; if (limit && mpz_sizeinbase(x, 2) > limit)
return 0;
return sexp_iterator_next(i);
} }
else else
return 0; return 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment