aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/hash.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-12-02 14:00:43 +0100
committerEelco Dolstra <edolstra@gmail.com>2020-12-02 14:17:27 +0100
commitfaa31f40846f7a4dbc2487d000b112a6aef69d1b (patch)
tree37f34b2378c81d9f2bb8fc79046d12b4e0592647 /src/libutil/hash.cc
parentaa684861127eabc18a0d7386a66c5b75d4962897 (diff)
Sink: Use std::string_view
Diffstat (limited to 'src/libutil/hash.cc')
-rw-r--r--src/libutil/hash.cc18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/libutil/hash.cc b/src/libutil/hash.cc
index 8efff190a..4df8b4ecb 100644
--- a/src/libutil/hash.cc
+++ b/src/libutil/hash.cc
@@ -291,12 +291,12 @@ static void start(HashType ht, Ctx & ctx)
static void update(HashType ht, Ctx & ctx,
- const unsigned char * bytes, size_t len)
+ std::string_view data)
{
- if (ht == htMD5) MD5_Update(&ctx.md5, bytes, len);
- else if (ht == htSHA1) SHA1_Update(&ctx.sha1, bytes, len);
- else if (ht == htSHA256) SHA256_Update(&ctx.sha256, bytes, len);
- else if (ht == htSHA512) SHA512_Update(&ctx.sha512, bytes, len);
+ if (ht == htMD5) MD5_Update(&ctx.md5, data.data(), data.size());
+ else if (ht == htSHA1) SHA1_Update(&ctx.sha1, data.data(), data.size());
+ else if (ht == htSHA256) SHA256_Update(&ctx.sha256, data.data(), data.size());
+ else if (ht == htSHA512) SHA512_Update(&ctx.sha512, data.data(), data.size());
}
@@ -314,7 +314,7 @@ Hash hashString(HashType ht, std::string_view s)
Ctx ctx;
Hash hash(ht);
start(ht, ctx);
- update(ht, ctx, (const unsigned char *) s.data(), s.length());
+ update(ht, ctx, s);
finish(ht, ctx, hash.hash);
return hash;
}
@@ -341,10 +341,10 @@ HashSink::~HashSink()
delete ctx;
}
-void HashSink::write(const unsigned char * data, size_t len)
+void HashSink::write(std::string_view data)
{
- bytes += len;
- update(ht, *ctx, data, len);
+ bytes += data.size();
+ update(ht, *ctx, data);
}
HashResult HashSink::finish()