fix(*): size_t -> uint64_t

This commit is contained in:
2024-09-17 14:38:27 +03:00
parent 0c28595bbf
commit 961b5f6b0c
8 changed files with 26 additions and 24 deletions

View File

@ -7,12 +7,12 @@
namespace base64
{
bool isValid(const char *str, size_t str_size) noexcept;
bool isValid(const char *str, uint64_t str_size) noexcept;
bool isValid(std::string_view str) noexcept;
void encode(const uint8_t *data, size_t data_size, char *str, size_t str_size);
void encode(const uint8_t *data, uint64_t data_size, char *str, uint64_t str_size);
std::string encode(std::span<const uint8_t> data) noexcept;
void decode(const char *str, size_t str_size, uint8_t *data, size_t data_size);
void decode(const char *str, uint64_t str_size, uint8_t *data, uint64_t data_size);
std::vector<uint8_t> decode(std::string_view str) noexcept;
}

View File

@ -7,7 +7,7 @@
namespace baseN
{
bool isValid(const char *str, size_t str_size, const int8_t *map) noexcept;
bool isValid(const char *str, uint64_t str_size, const int8_t *map) noexcept;
bool isValid(std::string_view str, const int8_t *map) noexcept;
void encode(const uint8_t *data, uint64_t data_size, char *str, uint8_t base, const char *digits, uint64_t enc_size) noexcept;

View File

@ -7,6 +7,6 @@
#define SHA256_DIGEST_LENGTH 32
namespace hash {
void sha256(const uint8_t *data, size_t data_size, uint8_t *hash) noexcept;
void sha256(const uint8_t *data, uint64_t data_size, uint8_t *hash) noexcept;
std::vector<uint8_t> sha256(std::span<const uint8_t> data) noexcept;
}

View File

@ -7,12 +7,12 @@
namespace hex
{
bool isValid(const char *str, size_t str_size) noexcept;
bool isValid(const char *str, uint64_t str_size) noexcept;
bool isValid(std::string_view str) noexcept;
void encode(const uint8_t *data, size_t data_size, char *str, size_t str_size);
void encode(const uint8_t *data, uint64_t data_size, char *str, uint64_t str_size);
std::string encode(std::span<const uint8_t> data) noexcept;
void decode(const char *str, size_t str_size, uint8_t *data, size_t data_size);
void decode(const char *str, uint64_t str_size, uint8_t *data, uint64_t data_size);
std::vector<uint8_t> decode(std::string_view str) noexcept;
}

View File

@ -29,7 +29,7 @@ static const int8_t b64map[] = {
namespace base64
{
bool isValid(const char *str, size_t str_size) noexcept
bool isValid(const char *str, uint64_t str_size) noexcept
{
return base64::isValid(std::string_view(str, str_size));
}
@ -44,13 +44,13 @@ namespace base64
}
return baseN::isValid(sv, b64map);
}
void encode(const uint8_t *data, size_t data_size, char *str, size_t str_size)
void encode(const uint8_t *data, uint64_t data_size, char *str, uint64_t str_size)
{
if (str_size < data_size / 3 * 4 + (data_size % 3 ? 4 : 0))
{
throw std::logic_error("base64::encode: not enough allocated length");
}
for (size_t i = 0; i < data_size / 3; i++)
for (uint64_t i = 0; i < data_size / 3; i++)
{
str[i * 4] = b64digits[data[i * 3] >> 2];
str[i * 4 + 1] = b64digits[(data[i * 3] << 4 | data[i * 3 + 1] >> 4) & 0x3F];

View File

@ -6,7 +6,7 @@
namespace baseN
{
bool isValid(const char *str, size_t str_size, const int8_t *map) noexcept
bool isValid(const char *str, uint64_t str_size, const int8_t *map) noexcept
{
std::string_view sv(str, str_size);
return std::all_of(sv.begin(), sv.end(), [map](char ch)

View File

@ -27,12 +27,14 @@
#define SIG0(x) (ROTRIGHT(x,7) ^ ROTRIGHT(x,18) ^ ((x) >> 3))
#define SIG1(x) (ROTRIGHT(x,17) ^ ROTRIGHT(x,19) ^ ((x) >> 10))
struct SHA256_CTX{
uint8_t data[64];
uint32_t datalen;
unsigned long long bitlen;
uint32_t state[8];
};
namespace {
struct SHA256_CTX{
uint8_t data[64];
uint32_t datalen;
unsigned long long bitlen;
uint32_t state[8];
};
}
static const uint32_t k[64] = {
0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5,0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5,
@ -163,7 +165,7 @@ static void sha256_final(SHA256_CTX *ctx, uint8_t *hash)
namespace hash
{
void sha256(const uint8_t *data, size_t data_size, uint8_t *hash) noexcept
void sha256(const uint8_t *data, uint64_t data_size, uint8_t *hash) noexcept
{
SHA256_CTX ctx;
sha256_init(&ctx);

View File

@ -27,7 +27,7 @@ static const int8_t hexmap[] = {
namespace hex
{
bool isValid(const char *str, size_t str_size) noexcept
bool isValid(const char *str, uint64_t str_size) noexcept
{
return baseN::isValid(str, str_size, hexmap);
}
@ -35,13 +35,13 @@ namespace hex
{
return baseN::isValid(str, hexmap);
}
void encode(const uint8_t *data, size_t data_size, char *str, size_t str_size)
void encode(const uint8_t *data, uint64_t data_size, char *str, uint64_t str_size)
{
if (str_size < data_size * 2)
{
throw std::logic_error("hex::encode: not enough allocated length");
}
for (size_t i = 0; i < data_size; i++)
for (uint64_t i = 0; i < data_size; i++)
{
str[i * 2] = hexdigits[data[i] >> 4];
str[i * 2 + 1] = hexdigits[data[i] & 0x0F];
@ -53,7 +53,7 @@ namespace hex
hex::encode(data.data(), data.size(), str.data(), str.size());
return str;
}
void decode(const char *str, size_t str_size, uint8_t *data, size_t data_size)
void decode(const char *str, uint64_t str_size, uint8_t *data, uint64_t data_size)
{
if (str_size % 2 != 0)
{
@ -67,7 +67,7 @@ namespace hex
{
throw std::logic_error("hex::decode: out of digits map");
}
for (size_t i = 0; i * 2 < str_size; i++)
for (uint64_t i = 0; i * 2 < str_size; i++)
{
data[i] = hexmap[(int8_t)str[i * 2]] << 4 | hexmap[(int8_t)str[i * 2 + 1]];
}