diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2018-07-10 09:20:25 +0200 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2018-07-10 14:58:50 +0300 |
commit | 16b63f8cdf5b488ab2f4b0e029478b01a2d6b8a8 (patch) | |
tree | 78509ede9ae2652e8c82f01ec91b35eba3c3c7e4 /libbutl/sha1.cxx | |
parent | 681ca375fd5af01501a91a78214ab7a26ad67ac7 (diff) |
Add support for hashing ifdstream
Diffstat (limited to 'libbutl/sha1.cxx')
-rw-r--r-- | libbutl/sha1.cxx | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/libbutl/sha1.cxx b/libbutl/sha1.cxx index 8fdb833..af1f260 100644 --- a/libbutl/sha1.cxx +++ b/libbutl/sha1.cxx @@ -42,6 +42,8 @@ extern "C" #define SHA1_Update(x, y, z) sha1_loop((x), (const uint8_t *)(y), (z)) #define SHA1_Final(x, y) sha1_result((y), (char(&)[20])(x)) +#include <cassert> + #ifndef __cpp_lib_modules #include <string> #include <cstddef> @@ -53,12 +55,16 @@ extern "C" #ifdef __cpp_modules module butl.sha1; +// Only imports additional to interface. #ifdef __clang__ #ifdef __cpp_lib_modules import std.core; #endif #endif +import butl.fdstream; +#else +#include <libbutl/fdstream.mxx> #endif using namespace std; @@ -78,6 +84,20 @@ namespace butl SHA1_Update (reinterpret_cast<SHA1_CTX*> (buf_), b, n); } + void sha1:: + 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 sha1::digest_type& sha1:: binary () const { |