aboutsummaryrefslogtreecommitdiff
path: root/butl
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-02-29 08:10:16 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-02-29 08:10:16 +0200
commit104de2e0872d37cf4291d92aa9bee191a01f9c15 (patch)
tree106dd25f11444c070995799b4950357175658a9a /butl
parentd928de165f8bb896ee77f5668f35611f57429c93 (diff)
Add '\0' string terminator to sha256 calculation
Failed that, an empty string will be indistinguishable from no string.
Diffstat (limited to 'butl')
-rw-r--r--butl/sha25632
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];