X-Git-Url: https://git.stg.codes/stg.git/blobdiff_plain/9eb47dfb9f56b63394bdab6e94d8a3ea0ca1685a..c949afc4f9940c71c63ce6dda771eb32e6fd8c65:/stglibs/crypto.lib/bfstream.cpp diff --git a/stglibs/crypto.lib/bfstream.cpp b/stglibs/crypto.lib/bfstream.cpp index 21a0d55d..3325bd1a 100644 --- a/stglibs/crypto.lib/bfstream.cpp +++ b/stglibs/crypto.lib/bfstream.cpp @@ -33,7 +33,7 @@ class COMMON void Put(const void * data, size_t size, bool last) { size_t dataSize = m_ptr - m_buffer; - if (dataSize + size > sizeof(m_buffer)) + while (dataSize + size > sizeof(m_buffer)) { memcpy(m_ptr, data, sizeof(m_buffer) - dataSize); // Fill buffer size -= sizeof(m_buffer) - dataSize; // Adjust size @@ -41,6 +41,7 @@ class COMMON m_proc(m_buffer, m_buffer, sizeof(m_buffer), &m_ctx); // Process m_ok = m_ok && m_callback(m_buffer, sizeof(m_buffer), m_data); // Consume m_ptr = m_buffer; + dataSize = 0; } if (!m_ok) return; @@ -49,7 +50,7 @@ class COMMON m_tryConsume(last); } - bool isOk() const { return m_ok; } + bool IsOk() const { return m_ok; } private: char m_buffer[BUFFER_SIZE]; @@ -69,7 +70,7 @@ class COMMON dataSize += 8; remainder = 0; } - if (dataSize == 0) + if (!last && dataSize == 0) // Allow to call callback with 0 data on last call. return; m_proc(m_buffer, m_buffer, dataSize, &m_ctx); m_ok = m_ok && m_callback(m_buffer, dataSize, m_data); @@ -116,9 +117,9 @@ void ENCRYPT_STREAM::Put(const void * data, size_t size, bool last) m_impl->Put(data, size, last); } -bool ENCRYPT_STREAM::isOk() const +bool ENCRYPT_STREAM::IsOk() const { -return m_impl->isOk(); +return m_impl->IsOk(); } DECRYPT_STREAM::DECRYPT_STREAM(const std::string & key, CALLBACK callback, void * data) @@ -135,7 +136,7 @@ void DECRYPT_STREAM::Put(const void * data, size_t size, bool last) m_impl->Put(data, size, last); } -bool DECRYPT_STREAM::isOk() const +bool DECRYPT_STREAM::IsOk() const { -return m_impl->isOk(); +return m_impl->IsOk(); }