Skip to content

Commit

Permalink
move decrypted copying into the while loop
Browse files Browse the repository at this point in the history
  • Loading branch information
Aidan63 committed Nov 23, 2024
1 parent e529a1d commit 9b6f41d
Showing 1 changed file with 9 additions and 30 deletions.
39 changes: 9 additions & 30 deletions src/hx/libs/ssl/windows/SSL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,26 +452,21 @@ int _hx_ssl_recv(Dynamic hssl, Array<unsigned char> buf, int p, int l)
auto buffers = std::array<SecBuffer, 4>();
auto bufferDescription = SecBufferDesc();

if (ctx->decrypted->length > 0)
while (true)
{
auto taking = std::min(l, ctx->decrypted->length);

printf("taking %i cached bytes\n", taking);

for (auto i = 0; i < taking; i++)
if (ctx->decrypted->length > 0)
{
auto src = ctx->decrypted[i];
auto taking = std::min(l, ctx->decrypted->length);

buf[p + i] = src;
}
printf("taking %i cached bytes\n", taking);

ctx->decrypted->removeRange(0, taking);
buf->memcpy(p, &ctx->decrypted[0], taking);

return taking;
}
ctx->decrypted->removeRange(0, taking);

return taking;
}

while (true)
{
if (ctx->received > 0)
{
auto result = SECURITY_STATUS{ SEC_E_OK };
Expand Down Expand Up @@ -524,22 +519,6 @@ int _hx_ssl_recv(Dynamic hssl, Array<unsigned char> buf, int p, int l)
}
case SEC_E_INCOMPLETE_MESSAGE:
{
if (ctx->decrypted->length > 0)
{
auto taking = std::min(l, ctx->decrypted->length);

printf("taking %i cached bytes\n", taking);

for (auto i = 0; i < taking; i++)
{
buf[p + i] = ctx->decrypted[i];
}

ctx->decrypted->removeRange(0, taking);

return taking;
}

assert(buffers[0].BufferType == SECBUFFER_MISSING);
assert(buffers[0].cbBuffer > 0);

Expand Down

0 comments on commit 9b6f41d

Please sign in to comment.