fix: Crypto buffered hexadecimal encoding
This commit is contained in:
parent
d468893bb0
commit
285b79f31e
@ -396,14 +396,14 @@ namespace hex::crypt {
|
|||||||
|
|
||||||
ON_SCOPE_EXIT { mbedtls_mpi_free(&ctx); };
|
ON_SCOPE_EXIT { mbedtls_mpi_free(&ctx); };
|
||||||
|
|
||||||
|
// read buffered
|
||||||
constexpr static auto BufferSize = 0x100;
|
constexpr static auto BufferSize = 0x100;
|
||||||
for (size_t offset = 0; offset < input.size(); offset += BufferSize) {
|
for (size_t offset = 0; offset < input.size(); offset += BufferSize) {
|
||||||
std::string inputPart = input.substr(offset, std::min<size_t>(BufferSize, input.size() - offset));
|
std::string inputPart = input.substr(offset, std::min<size_t>(BufferSize, input.size() - offset));
|
||||||
if (mbedtls_mpi_read_string(&ctx, 16, inputPart.c_str()))
|
if (mbedtls_mpi_read_string(&ctx, 16, inputPart.c_str()))
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
auto size = std::min<size_t>(BufferSize / 2, input.size() - offset);
|
if (mbedtls_mpi_write_binary(&ctx, output.data() + offset / 2, inputPart.size() / 2))
|
||||||
if (mbedtls_mpi_write_binary(&ctx, output.data() + offset / 2, size) != 0)
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user