• R/O
  • HTTP
  • SSH
  • HTTPS

mhash384: Commit

MHash-384 development repository


Commit MetaInfo

Revisionca62a298e22add11690b2f9f0fb156d79d2870ae (tree)
Time2020-01-08 06:45:30
AuthorLoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

C++ wrapper: Added more convenience overloads of the update() function.

Change Summary

Incremental Difference

--- a/README.md
+++ b/README.md
@@ -297,6 +297,19 @@ Process next chunk of input data. This function performs the actual MHash-384 ha
297297
298298 ### MHash384::update() [2]
299299
300+ template<size_t size>
301+ inline void update(const std::array<std::uint8_t, size> &data)
302+
303+A convenience overload of the [`MHash384::update()`](#mhash384update-1) function, which processes an `std::array<uint8_t, N>` as input.
304+
305+*Parameters:*
306+
307+* `const std::array<uint8_t, N> &data`
308+ Read-only reference to the `std::array<uint8_t, N>` containing the input data to be processed.
309+ *Note:* All bytes in the range from `data[0]` up to and including `data[data.size()-1]` will be processed as input.
310+
311+### MHash384::update() [3]
312+
300313 void MHash384::update(const std::vector<std::uint8_t> &data)
301314
302315 A convenience overload of the [`MHash384::update()`](#mhash384update-1) function, which processes an `std::vector<uint8_t>` as input.
@@ -305,9 +318,9 @@ A convenience overload of the [`MHash384::update()`](#mhash384update-1) function
305318
306319 * `const std::vector<std::uint8_t> &data`
307320 Read-only reference to the `std::vector<uint8_t>` containing the input data to be processed.
308- *Note:* All bytes in the range from `vector[0]` up to and including `vector[vector.size()-1]` will be processed as input.
321+ *Note:* All bytes in the range from `data[0]` up to and including `data[data.size()-1]` will be processed as input.
309322
310-### MHash384::update() [3]
323+### MHash384::update() [4]
311324
312325 void MHash384::update(const std::string &text)
313326
@@ -315,14 +328,52 @@ A convenience overload of the [`MHash384::update()`](#mhash384update-1) function
315328
316329 *Parameters:*
317330
318-* `const std::vector<std::uint8_t> &data`
331+* `const std::string &text`
319332 Read-only reference to the `std::string` containing the input data to be processed.
320- *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.
333+ *Note:* All characters in the range from `text[0]` up to and including `text[text.length()-1]` will be processed as input. Each character in the `std::string` is processed as a *byte* value, disregarding any specific character encoding.
321334
322-### MHash384::update() [4]
335+### MHash384::update() [5]
336+
337+ void MHash384::update(const char *const text)
338+
339+A convenience overload of the [`MHash384::update()`](#mhash384update-1) function, which processes a NULL-terminated C string as input.
340+
341+*Parameters:*
342+
343+* `const char *const text`
344+ Read-only pointer to the first character of the NULL-terminated string to be processed.
345+ *Note:* All characters in the range from `text[0]` up to and including `text[strlen(text)-1]` will be processed as input. Each character in the C string is processed as a *byte* value, disregarding any specific character encoding.
346+
347+### MHash384::update() [6]
348+
349+ template<typename element_type>
350+ inline void update(const element_type *const address);
351+
352+A convenience overload of the [`MHash384::update()`](#mhash384update-1) function, which processes an object designated by a pointer.
353+
354+*Parameters:*
355+
356+* `const element_type *const address`
357+ Read-only pointer to the target object to be processed.
358+ *Note:* The given object is processed as a byte-sequence, like a POD; all bytes in the range from `address[0]` up to and including `address[sizeof(element_type)-1]` will be processed as input.
359+
360+### MHash384::update() [7]
361+
362+ template<typename element_type>
363+ inline void update(const element_type &element);
364+
365+A convenience overload of the [`MHash384::update()`](#mhash384update-1) function, which processes an object designated by a reference.
366+
367+*Parameters:*
368+
369+* `const element_type &element`
370+ Read-only reference to the target object to be processed.
371+ *Note:* The given object is processed as a byte-sequence, like a POD; all bytes in the range from `addr[0]` up to and including `addr[sizeof(element_type)-1]` with `addr = std::addressof(element)` will be processed as input.
372+
373+### MHash384::update() [8]
323374
324375 template<typename iterator_type>
325- void update(const iterator_type &first, const iterator_type &last)
376+ void MHash384::update(const iterator_type &first, const iterator_type &last)
326377
327378 A convenience overload of the [`MHash384::update()`](#mhash384update-1) function, which processes a sequence of elements via iterators.
328379
@@ -330,11 +381,11 @@ A convenience overload of the [`MHash384::update()`](#mhash384update-1) function
330381
331382 * `const iterator_type &first`
332383 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)`.
384+ *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, like a POD, assuming a size of `sizeof(iterator_type::value_type)`.
334385
335386 * `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)`.
387+ Read-only reference to the iterator designating the element just after the *last* element to be processed.
388+ *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, like a POD, assuming a size of `sizeof(iterator_type::value_type)`.
338389
339390 ### MHash384::finish()
340391
--- a/libmhash384/include/mhash384.h
+++ b/libmhash384/include/mhash384.h
@@ -26,6 +26,8 @@
2626 #include <cstdint>
2727 #include <stdexcept>
2828 #include <vector>
29+#include <array>
30+#include <cstring>
2931 #include <string>
3032 #else
3133 #include <stdlib.h>
@@ -81,7 +83,7 @@ public:
8183 ::mhash384_init(&ctx);
8284 }
8385
84- void update(const std::uint8_t *const data, const size_t len)
86+ inline void update(const std::uint8_t *const data, const size_t len)
8587 {
8688 if(finished)
8789 {
@@ -90,27 +92,55 @@ public:
9092 ::mhash384_update(&ctx, data, len);
9193 }
9294
93- void update(const std::vector<std::uint8_t> &data)
95+ template<size_t size>
96+ inline void update(const std::array<std::uint8_t, size> &data)
97+ {
98+ update(data.data(), size);
99+ }
100+
101+ inline void update(const std::vector<std::uint8_t> &data)
94102 {
95103 update(data.data(), data.size());
96104 }
97105
98- void update(const std::string &text)
106+ inline void update(const std::string &text)
99107 {
100108 update(reinterpret_cast<const std::uint8_t*>(text.c_str()), text.length());
101109 }
102110
111+ inline void update(const char *const text)
112+ {
113+ update(reinterpret_cast<const std::uint8_t*>(text), std::strlen(text));
114+ }
115+
116+ template<typename element_type>
117+ inline void update(element_type *const address)
118+ {
119+ update(reinterpret_cast<const std::uint8_t*>(address), sizeof(element_type));
120+ }
121+
122+ template<typename element_type>
123+ inline void update(const element_type *const address)
124+ {
125+ update(reinterpret_cast<const std::uint8_t*>(address), sizeof(element_type));
126+ }
127+
128+ template<typename element_type>
129+ inline void update(const element_type &element)
130+ {
131+ update(reinterpret_cast<const std::uint8_t*>(std::addressof(element)), sizeof(element_type));
132+ }
133+
103134 template<typename iterator_type>
104- void update(const iterator_type &first, const iterator_type &last)
135+ inline void update(const iterator_type &first, const iterator_type &last)
105136 {
106- typedef typename std::iterator_traits<iterator_type>::value_type value_type;
107137 for (iterator_type iter = first; iter != last; ++iter)
108138 {
109- update(reinterpret_cast<const std::uint8_t*>(std::addressof(*iter)), sizeof(value_type));
139+ update(*iter);
110140 }
111141 }
112142
113- const std::uint8_t *finish(void)
143+ inline const std::uint8_t *finish(void)
114144 {
115145 if(!finished)
116146 {
@@ -120,7 +150,7 @@ public:
120150 return digest;
121151 }
122152
123- void reset(void)
153+ inline void reset(void)
124154 {
125155 ::mhash384_init(&ctx);
126156 finished = false;
Show on old repository browser