diff options
Diffstat (limited to 'randpool.cpp')
-rw-r--r-- | randpool.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/randpool.cpp b/randpool.cpp index d28f7a9..c2b44fa 100644 --- a/randpool.cpp +++ b/randpool.cpp @@ -40,9 +40,9 @@ void RandomPool::Stir() getPos = key.size(); } -unsigned int RandomPool::Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking) +size_t RandomPool::Put2(const byte *inString, size_t length, int messageEnd, bool blocking) { - unsigned t; + size_t t; while (length > (t = pool.size() - addPos)) { @@ -62,25 +62,21 @@ unsigned int RandomPool::Put2(const byte *inString, unsigned int length, int mes return 0; } -unsigned int RandomPool::TransferTo2(BufferedTransformation &target, unsigned long &transferBytes, const std::string &channel, bool blocking) +size_t RandomPool::TransferTo2(BufferedTransformation &target, lword &transferBytes, const std::string &channel, bool blocking) { if (!blocking) throw NotImplemented("RandomPool: nonblocking transfer is not implemented by this object"); - unsigned int t; - unsigned long size = transferBytes; + lword size = transferBytes; - while (size > (t = pool.size() - getPos)) + while (size > 0) { + if (getPos == pool.size()) + Stir(); + size_t t = UnsignedMin(pool.size() - getPos, size); target.ChannelPut(channel, pool+getPos, t); size -= t; - Stir(); - } - - if (size) - { - target.ChannelPut(channel, pool+getPos, size); - getPos += size; + getPos += t; } return 0; @@ -94,7 +90,7 @@ byte RandomPool::GenerateByte() return pool[getPos++]; } -void RandomPool::GenerateBlock(byte *outString, unsigned int size) +void RandomPool::GenerateBlock(byte *outString, size_t size) { ArraySink sink(outString, size); TransferTo(sink, size); |