diff --git a/include/base/baseN.hpp b/include/base/baseN.hpp index c3f37cc..73aba9a 100644 --- a/include/base/baseN.hpp +++ b/include/base/baseN.hpp @@ -7,7 +7,7 @@ namespace baseN { - bool isValid(const char *str, const int8_t *map) noexcept; + bool isValid(const char *str, size_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 9703997..e2b3f98 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, uint64_t data_size, uint8_t *hash) noexcept; + void sha256(const uint8_t *data, size_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 0b18cae..ae90df2 100644 --- a/include/base/hex.hpp +++ b/include/base/hex.hpp @@ -9,8 +9,8 @@ namespace hex { bool isValid(const char *str) noexcept; bool isValid(std::string_view str) noexcept; - void encode(const uint8_t *data, uint64_t data_size, char *str) noexcept; + void encode(const uint8_t *data, size_t data_size, char *str, size_t str_size) noexcept; std::string encode(std::span data) noexcept; - void decode(const char *str, uint8_t *data, uint64_t data_size); + void decode(const char *str, size_t str_size, uint8_t *data, size_t data_size); std::vector decode(std::string_view str); } \ No newline at end of file diff --git a/src/baseN.cpp b/src/baseN.cpp index e280f1a..dc2233e 100644 --- a/src/baseN.cpp +++ b/src/baseN.cpp @@ -6,15 +6,15 @@ namespace baseN { - bool isValid(const char *str, const int8_t *map) noexcept + bool isValid(const char *str, size_t str_size, const int8_t *map) noexcept { - std::string_view sv(str); + std::string_view sv(str, str_size); return std::all_of(sv.begin(), sv.end(), [map](char ch) { return map[(int8_t)ch] != -1; }); } bool isValid(std::string_view str, const int8_t *map) noexcept { - return baseN::isValid(str.data(), map); + return baseN::isValid(str.data(), str.size(), map); } 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/src/hash/sha256.cpp b/src/hash/sha256.cpp index 92e5641..c176c3b 100644 --- a/src/hash/sha256.cpp +++ b/src/hash/sha256.cpp @@ -163,7 +163,7 @@ static void sha256_final(SHA256_CTX *ctx, uint8_t *hash) namespace hash { - void sha256(const uint8_t *data, uint64_t data_size, uint8_t *hash) noexcept + void sha256(const uint8_t *data, size_t data_size, uint8_t *hash) noexcept { SHA256_CTX ctx; sha256_init(&ctx); diff --git a/src/hex.cpp b/src/hex.cpp index f784548..45d6009 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -35,9 +35,9 @@ namespace hex { return baseN::isValid(str, hexmap); } - void encode(const uint8_t *data, uint64_t data_size, char *str) noexcept + void encode(const uint8_t *data, size_t data_size, char *str, size_t str_size) noexcept { - std::string_view sv(str); + std::string_view sv(str, str_size); std::span dv(data, data_size); for (size_t i = 0; i < dv.size() && i * 2 + 1 < sv.size(); i++) @@ -49,16 +49,16 @@ namespace hex std::string encode(std::span data) noexcept { std::string str(data.size() * 2, ' '); - hex::encode(data.data(), data.size(), str.data()); + hex::encode(data.data(), data.size(), str.data(), str.size()); return str; } - void decode(const char *str, uint8_t *data, uint64_t data_size) + void decode(const char *str, size_t str_size, uint8_t *data, size_t data_size) { if (!hex::isValid(str)) { throw std::logic_error("hex::decode: out of digits map"); } - std::string_view sv(str); + std::string_view sv(str, str_size); std::span dv(data, data_size); if (sv.size() % 2 != 0) { @@ -73,7 +73,7 @@ namespace hex std::vector decode(std::string_view str) { std::vector data(str.size() / 2); - hex::decode(str.data(), data.data(), data.size()); + hex::decode(str.data(), str.size(), data.data(), data.size()); return data; } } \ No newline at end of file