aboutsummaryrefslogtreecommitdiff
path: root/libbutl/sha256.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-07-10 09:20:25 +0200
committerKaren Arutyunov <karen@codesynthesis.com>2018-07-10 14:58:50 +0300
commit16b63f8cdf5b488ab2f4b0e029478b01a2d6b8a8 (patch)
tree78509ede9ae2652e8c82f01ec91b35eba3c3c7e4 /libbutl/sha256.cxx
parent681ca375fd5af01501a91a78214ab7a26ad67ac7 (diff)
Add support for hashing ifdstream
Diffstat (limited to 'libbutl/sha256.cxx')
-rw-r--r--libbutl/sha256.cxx18
1 files changed, 18 insertions, 0 deletions
diff --git a/libbutl/sha256.cxx b/libbutl/sha256.cxx
index a688a15..c4556e7 100644
--- a/libbutl/sha256.cxx
+++ b/libbutl/sha256.cxx
@@ -27,6 +27,8 @@ extern "C"
#include "sha256c.c"
}
+#include <cassert>
+
#ifndef __cpp_lib_modules
#include <string>
#include <cstddef>
@@ -53,8 +55,10 @@ import std.core;
#endif
import butl.utility; // *case()
+import butl.fdstream;
#else
#include <libbutl/utility.mxx>
+#include <libbutl/fdstream.mxx>
#endif
using namespace std;
@@ -74,6 +78,20 @@ namespace butl
SHA256_Update (reinterpret_cast<SHA256_CTX*> (buf_), b, n);
}
+ void sha256::
+ append (ifdstream& is)
+ {
+ fdbuf* buf (dynamic_cast<fdbuf*> (is.rdbuf ()));
+ assert (buf != nullptr);
+
+ while (is.peek () != ifdstream::traits_type::eof () && is.good ())
+ {
+ size_t n (buf->egptr () - buf->gptr ());
+ append (buf->gptr (), n);
+ buf->gbump (static_cast<int> (n));
+ }
+ }
+
const sha256::digest_type& sha256::
binary () const
{