summaryrefslogtreecommitdiff
path: root/mpi.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mpi.cpp')
-rw-r--r--mpi.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/mpi.cpp b/mpi.cpp
index b8a4b6c..6a94f3e 100644
--- a/mpi.cpp
+++ b/mpi.cpp
@@ -127,14 +127,17 @@ void Mpi::clearHighBit(u_int32_t n)
gcry_mpi_clear_highbit( val_, n );
}
-Buffer Mpi::getBuf() const
+Buffer Mpi::getBuf(u_int32_t min_len) const
{
u_int32_t len = 0, written = 0;
len = gcry_mpi_get_nbits( val_ );
Buffer res(static_cast<u_int32_t>(len/8)+1);
- gcry_mpi_print( GCRYMPI_FMT_STD, res, len, &written, val_ );
+ if(res.getLength() < min_len)
+ res.resizeBack(min_len);
+
+ gcry_mpi_print( GCRYMPI_FMT_STD, res, res.getLength(), &written, val_ );
return res;
}