diff options
Diffstat (limited to 'butl')
-rw-r--r-- | butl/sha256 | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/butl/sha256 b/butl/sha256 index 3fc9e63..d583701 100644 --- a/butl/sha256 +++ b/butl/sha256 @@ -23,27 +23,35 @@ namespace butl { public: sha256 (); - explicit sha256 (const std::string& s): sha256 () {append (s);} - explicit sha256 (const char* s): sha256 () {append (s);} - sha256 (const void* b, std::size_t n): sha256 () {append (b, n);} - // Append string (without the traling '\0'). + // Append binary data. // void - append (const std::string& s) {append (s.c_str (), s.size ());} + append (const void*, std::size_t); - // Append C-string (without the traling '\0'). + sha256 (const void* b, std::size_t n): sha256 () {append (b, n);} + + // Append string. + // + // Note that the hash includes the '\0' terminator. Failed that, a call + // with an empty string will be indistinguishable from no call at all. // void - append (const char* s) {append (s, std::strlen (s));} + append (const std::string& s) {append (s.c_str (), s.size () + 1);} - // Append binary data. - // void - append (const void*, std::size_t); + append (const char* s) {append (s, std::strlen (s) + 1);} - // Extract result. It can be obtained as either a 32-byte binary digest or - // as a 64- character hex-encoded C-string. + explicit + sha256 (const std::string& s): sha256 () {append (s);} + + explicit + sha256 (const char* s): sha256 () {append (s);} + + // Extract result. + // + // It can be obtained as either a 32-byte binary digest or as a 64- + // character hex-encoded C-string. // using digest_type = std::uint8_t[32]; |