diff --git a/include/base/base64.hpp b/include/base/base64.hpp index 2e37b71..2b90a4f 100644 --- a/include/base/base64.hpp +++ b/include/base/base64.hpp @@ -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 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 decode(std::string_view str) noexcept; } \ No newline at end of file diff --git a/include/base/baseN.hpp b/include/base/baseN.hpp index 73aba9a..12e1a22 100644 --- a/include/base/baseN.hpp +++ b/include/base/baseN.hpp @@ -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; diff --git a/include/base/hash/sha256.hpp b/include/base/hash/sha256.hpp index e2b3f98..9703997 100644 --- a/include/base/hash/sha256.hpp +++ b/include/base/hash/sha256.hpp @@ -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 sha256(std::span data) noexcept; } \ No newline at end of file diff --git a/include/base/hex.hpp b/include/base/hex.hpp index 861e424..d7dcb2f 100644 --- a/include/base/hex.hpp +++ b/include/base/hex.hpp @@ -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 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 decode(std::string_view str) noexcept; } \ No newline at end of file diff --git a/src/base64.cpp b/src/base64.cpp index 784cc55..1845277 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -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]; diff --git a/src/baseN.cpp b/src/baseN.cpp index dc2233e..dfe9337 100644 --- a/src/baseN.cpp +++ b/src/baseN.cpp @@ -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) diff --git a/src/hash/sha256.cpp b/src/hash/sha256.cpp index c176c3b..b4ac8cd 100644 --- a/src/hash/sha256.cpp +++ b/src/hash/sha256.cpp @@ -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); diff --git a/src/hex.cpp b/src/hex.cpp index 8bae1e3..011d92d 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -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]]; }