• R/O
  • HTTP
  • SSH
  • HTTPS

mhash384: Commit

MHash-384 development repository


Commit MetaInfo

Revision539ea422f8c6db5962437e636d2720a242946b3d (tree)
Time2020-01-05 07:44:13
AuthorLoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

C++ wrapper: Add overload of update() that processes a sequence of elements specified via iterators.

Change Summary

Incremental Difference

--- a/README.md
+++ b/README.md
@@ -319,11 +319,30 @@ A convenience overload of the [`MHash384::update()`](#mhash384update-1) function
319319 Read-only reference to the `std::string` containing the input data to be processed.
320320 *Note:* All characters in the range from `str[0]` up to and including `str[str.length()-1]` will be processed as input. Each character in the `std::string` is processed as a *byte* value, disregarding any specific character encoding.
321321
322+### MHash384::update() [4]
323+
324+ template<typename iterator_type>
325+ void update(const iterator_type &first, const iterator_type &last)
326+
327+A convenience overload of the [`MHash384::update()`](#mhash384update-1) function, which processes a sequence of elements via iterators.
328+
329+*Parameters:*
330+
331+* `const iterator_type &first`
332+ Read-only reference to the iterator designating the *first* element to be processed.
333+ *Note:* All elements in the range from `*first` up to but excluding `*last` will be processed as input. Each element in this range is processed as a byte-sequence; the size of an element is `sizeof(iterator_type::value_type)`.
334+
335+* `const iterator_type &last`
336+ Read-only reference to the iterator designating the *last* element to be processed.
337+ *Note:* All elements in the range from `*first` up to but excluding `*last` will be processed as input. Each element in this range is processed as a byte-sequence; the size of an element is `sizeof(iterator_type::value_type)`.
338+
322339 ### MHash384::finish()
323340
324341 const std::uint8_t *MHash384::finish(void)
325342
326-Retrieve final hash value. This function completes the MHash-384 hash computation and returns the computed hash value. The function finalizes the internal MHash-384 context and returns a pointer to the buffer containing the resulting hash value. Once this function has been called, the `MHash384` instance is in an *finalized* state, until it is [reset](#mhash384reset)!
343+Retrieve final hash value. This function completes the MHash-384 hash computation. The function finalizes the internal MHash-384 context, if it was not finalized yet, and returns a pointer to the buffer containing the resulting hash value. Once this function has been called, the `MHash384` instance remains in the *finalized* state, until it is [reset](#mhash384reset).
344+
345+***Warning:*** Trying to process more input data while the `MHash384` instance is in *finalized* state will throw an exception!
327346
328347 *Return value:*
329348
--- a/libmhash384/include/mhash384.h
+++ b/libmhash384/include/mhash384.h
@@ -100,6 +100,16 @@ public:
100100 update(reinterpret_cast<const std::uint8_t*>(text.c_str()), text.length());
101101 }
102102
103+ template<typename iterator_type>
104+ void update(const iterator_type &first, const iterator_type &last)
105+ {
106+ typedef typename std::iterator_traits<iterator_type>::value_type value_type;
107+ for (iterator_type iter = first; iter != last; ++iter)
108+ {
109+ update(reinterpret_cast<const std::uint8_t*>(&(*iter)), sizeof(value_type));
110+ }
111+ }
112+
103113 const std::uint8_t *finish(void)
104114 {
105115 if(!finished)
Show on old repository browser