88
99#include < array> // TODO: When we use C++20, change this to <span>
1010#include < cstdint>
11+ #include < string_view>
1112
1213namespace OpenShock {
1314 class MD5 {
@@ -20,6 +21,7 @@ namespace OpenShock {
2021
2122 inline bool begin () { return mbedtls_md5_starts_ret (&ctx) == 0 ; }
2223 inline bool update (const uint8_t * data, std::size_t dataLen) { return mbedtls_md5_update_ret (&ctx, data, dataLen) == 0 ; }
24+ inline bool update (std::string_view data) { return update (reinterpret_cast <const uint8_t *>(data.data ()), data.length ()); }
2325 inline bool finish (std::array<uint8_t , 16 >& hash) { return mbedtls_md5_finish_ret (&ctx, hash.data ()) == 0 ; }
2426
2527 private:
@@ -35,6 +37,7 @@ namespace OpenShock {
3537
3638 inline bool begin () { return mbedtls_sha1_starts_ret (&ctx) == 0 ; }
3739 inline bool update (const uint8_t * data, std::size_t dataLen) { return mbedtls_sha1_update_ret (&ctx, data, dataLen) == 0 ; }
40+ inline bool update (std::string_view data) { return update (reinterpret_cast <const uint8_t *>(data.data ()), data.length ()); }
3841 inline bool finish (std::array<uint8_t , 20 >& hash) { return mbedtls_sha1_finish_ret (&ctx, hash.data ()) == 0 ; }
3942
4043 private:
@@ -50,6 +53,7 @@ namespace OpenShock {
5053
5154 inline bool begin () { return mbedtls_sha256_starts_ret (&ctx, 0 ) == 0 ; }
5255 inline bool update (const uint8_t * data, std::size_t dataLen) { return mbedtls_sha256_update_ret (&ctx, data, dataLen) == 0 ; }
56+ inline bool update (std::string_view data) { return update (reinterpret_cast <const uint8_t *>(data.data ()), data.length ()); }
5357 inline bool finish (std::array<uint8_t , 32 >& hash) { return mbedtls_sha256_finish_ret (&ctx, hash.data ()) == 0 ; }
5458
5559 private:
0 commit comments