summaryrefslogtreecommitdiffabout
path: root/src/eyetil.cc
Side-by-side diff
Diffstat (limited to 'src/eyetil.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--src/eyetil.cc17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/eyetil.cc b/src/eyetil.cc
index fe816a6..7669cb6 100644
--- a/src/eyetil.cc
+++ b/src/eyetil.cc
@@ -9,6 +9,11 @@
#include <openssl/md5.h>
#include "eyetil.h"
+#include "config.h"
+#ifdef HAVE_LIBUUID
+# include <uuid/uuid.h>
+#endif
+
binary_t& binary_t::from_hex(const std::string& h) {
std::string::size_type hs = h.length();
if(hs&1)
@@ -32,6 +37,18 @@ binary_t& binary_t::from_data(const void *d,size_t s) {
return *this;
}
+binary_t& binary_t::make_nonce() {
+#ifdef HAVE_LIBUUID
+ uuid_t uuid;
+ uuid_generate(uuid);
+ from_data((unsigned char*)uuid,sizeof(uuid));
+#else
+ resize(16);
+ std::generate_n(begin(),16,rand);
+#endif /* HAVE_LIBUUID */
+ return *this;
+}
+
std::string binary_t::hex() const {
std::string rv;
rv.reserve((size()<<1)+1);