reverted [3945], proper fix for zero value ASN1 integer

This commit is contained in:
Martin Willi
2008-05-13 14:15:12 +00:00
parent cb1c54c93e
commit f3884f6da6
@@ -374,9 +374,13 @@ static bool belongs_to(private_gmp_rsa_private_key_t *this, public_key_t *public
chunk_t gmp_mpz_to_asn1(const mpz_t value)
{
chunk_t n;
n.ptr = mpz_export(NULL, &n.len, 1, 1, 1, 0, value);
n.len = 1 + mpz_sizeinbase(value, 2) / 8; /* size in bytes */
n.ptr = mpz_export(NULL, NULL, 1, n.len, 1, 0, value);
if (n.ptr == NULL)
{ /* if we have zero in "value", gmp returns NULL */
n.len = 0;
}
return asn1_wrap(ASN1_INTEGER, "m", n);
}