Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLAScommon
Commits
2439e56d
Commit
2439e56d
authored
Oct 15, 2020
by
Steffen Vogel
🎅🏼
Browse files
utils: add some helpers to generate UUIDs
parent
dfd8bb23
Changes
2
Show whitespace changes
Inline
Side-by-side
include/villas/utils.hpp
View file @
2439e56d
...
...
@@ -36,6 +36,8 @@
#include <sys/types.h>
#include <openssl/sha.h>
#include <jansson.h>
#include <uuid/uuid.h>
#include <villas/config.h>
#include <villas/log.h>
...
...
@@ -200,6 +202,12 @@ size_t strlenp(const char *str);
*/
int
sha1sum
(
FILE
*
f
,
unsigned
char
*
sha1
);
/** Generate an UUID by MD5 hashing the provided string */
void
uuid_generate_from_str
(
uuid_t
out
,
const
std
::
string
&
data
,
const
std
::
string
&
ns
=
""
);
/** Generate an UUID by MD5 hashing the serialized representation of the provided JSON object */
void
uuid_generate_from_json
(
uuid_t
out
,
json_t
*
json
,
const
std
::
string
&
ns
=
""
);
namespace
base64
{
using
byte
=
std
::
uint8_t
;
...
...
lib/utils.cpp
View file @
2439e56d
/** Utilities.
*
* @author Daniel Krebs <github@daniel-krebs.net>
* @author Steffen Vogel <svogel2@eonerc.rwth-aachen.de>
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
* @license GNU General Public License (version 3)
*
...
...
@@ -38,6 +39,9 @@
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/evp.h>
#include <openssl/md5.h>
#include <jansson.h>
#include <uuid/uuid.h>
#include <villas/config.h>
#include <villas/utils.hpp>
...
...
@@ -353,5 +357,26 @@ int sha1sum(FILE *f, unsigned char *sha1)
return
0
;
}
void
uuid_generate_from_str
(
uuid_t
out
,
const
std
::
string
&
data
,
const
std
::
string
&
ns
)
{
std
::
stringstream
ss
;
if
(
!
ns
.
empty
())
ss
<<
ns
<<
"|"
;
ss
<<
data
;
MD5
((
unsigned
char
*
)
ss
.
str
().
c_str
(),
ss
.
str
().
size
(),
(
unsigned
char
*
)
&
out
);
}
void
uuid_generate_from_json
(
uuid_t
out
,
json_t
*
json
,
const
std
::
string
&
ns
)
{
char
*
str
=
json_dumps
(
json
,
JSON_COMPACT
|
JSON_SORT_KEYS
);
uuid_generate_from_str
(
out
,
str
,
ns
);
free
(
str
);
}
}
/* namespace utils */
}
/* namespace villas */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment