diff --git a/include/basen/base64.hpp b/include/basen/base64.hpp index fcd480b..41b380f 100644 --- a/include/basen/base64.hpp +++ b/include/basen/base64.hpp @@ -13,12 +13,23 @@ namespace base64 bool isValid(const char *str, uint64_t str_size) noexcept; bool isValid(std::string_view str) noexcept; + /** + * @throw std::overflow_error if if there is an overflow + */ uint64_t sizeEncoded(std::span data); uint64_t sizeDecoded(std::string_view str) noexcept; + /** + * @throw std::length_error if not enough allocated length + */ void encode(const uint8_t *data, uint64_t data_size, char *str, uint64_t str_size); std::string encode(std::span data) noexcept; + /** + * @throw std::length_error if not enough allocated length + * @throw std::logic_error if out of digits map + * @throw std::logic_error if incorrect padding + */ 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/basen/baseN.hpp b/include/basen/baseN.hpp index 56abb92..fe8a9d3 100644 --- a/include/basen/baseN.hpp +++ b/include/basen/baseN.hpp @@ -32,6 +32,7 @@ namespace baseN * @param base from 1 to 255 * @param digits char[base] array of digits * @return estimated size after decoding + * @throw std::overflow_error if if there is an overflow */ uint64_t sizeDecoded(std::string_view str, uint8_t base, const char *digits) noexcept; diff --git a/src/base64.cpp b/src/base64.cpp index 17200d3..8976085 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -64,7 +64,7 @@ namespace base64 { if (str_size < base64::sizeEncoded(std::span(data, data_size))) { - throw std::logic_error("base64::encode: not enough allocated length"); + throw std::length_error("base64::encode: not enough allocated length"); } for (uint64_t i = 0; i < data_size / 3; i++) { @@ -106,7 +106,7 @@ namespace base64 std::string_view sv(str, str_size); if (data_size < base64::sizeDecoded(sv)) { - throw std::logic_error("base64::decode: not enough allocated length"); + throw std::length_error("base64::decode: not enough allocated length"); } if (!base64::isValid(sv)) { diff --git a/src/hex.cpp b/src/hex.cpp index 29b67f8..a5e4286 100644 --- a/src/hex.cpp +++ b/src/hex.cpp @@ -50,7 +50,7 @@ namespace hex { if (str_size < hex::sizeEncoded(std::span(data, data_size))) { - throw std::logic_error("hex::encode: not enough allocated length"); + throw std::length_error("hex::encode: not enough allocated length"); } for (uint64_t i = 0; i < data_size; i++) { @@ -72,7 +72,7 @@ namespace hex } if (data_size < hex::sizeDecoded(std::string_view(str, str_size))) { - throw std::logic_error("hex::decode: not enough allocated length"); + throw std::length_error("hex::decode: not enough allocated length"); } if (!hex::isValid(str, str_size)) {