Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RIOT
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cm-projects
RIOT
Commits
db4ce5ef
Commit
db4ce5ef
authored
6 years ago
by
Vincent Dupont
Browse files
Options
Downloads
Patches
Plain Diff
uuid: add uuid_to_string()
parent
71455b69
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile.dep
+1
-0
1 addition, 0 deletions
Makefile.dep
sys/include/uuid.h
+10
-0
10 additions, 0 deletions
sys/include/uuid.h
sys/uuid/uuid.c
+18
-0
18 additions, 0 deletions
sys/uuid/uuid.c
tests/unittests/tests-uuid/tests-uuid.c
+21
-0
21 additions, 0 deletions
tests/unittests/tests-uuid/tests-uuid.c
with
50 additions
and
0 deletions
Makefile.dep
+
1
−
0
View file @
db4ce5ef
...
@@ -780,6 +780,7 @@ endif
...
@@ -780,6 +780,7 @@ endif
ifneq
(,$(filter uuid,$(USEMODULE)))
ifneq
(,$(filter uuid,$(USEMODULE)))
USEMODULE
+=
hashes
USEMODULE
+=
hashes
USEMODULE
+=
random
USEMODULE
+=
random
USEMODULE
+=
fmt
endif
endif
# Enable periph_gpio when periph_gpio_irq is enabled
# Enable periph_gpio when periph_gpio_irq is enabled
...
...
This diff is collapsed.
Click to expand it.
sys/include/uuid.h
+
10
−
0
View file @
db4ce5ef
...
@@ -38,6 +38,8 @@ extern "C" {
...
@@ -38,6 +38,8 @@ extern "C" {
#define UUID_NODE_LEN (6U)
/**< Size of the node identifier in bytes */
#define UUID_NODE_LEN (6U)
/**< Size of the node identifier in bytes */
#define UUID_STR_LEN (36U)
/**< Size of a string UUID without null character */
/**
/**
* @name UUID version identifiers
* @name UUID version identifiers
* @{
* @{
...
@@ -140,6 +142,14 @@ static inline bool uuid_equal(uuid_t *uuid1, uuid_t *uuid2)
...
@@ -140,6 +142,14 @@ static inline bool uuid_equal(uuid_t *uuid1, uuid_t *uuid2)
return
(
memcmp
(
uuid1
,
uuid2
,
sizeof
(
uuid_t
))
==
0
);
return
(
memcmp
(
uuid1
,
uuid2
,
sizeof
(
uuid_t
))
==
0
);
}
}
/**
* @brief Generate an UUID string from an UUID structure
*
* @param[in] uuid UUID
* @param[out] str null-terminated UUID string, must be at least UUID_STR_LEN + 1 bytes
*/
void
uuid_to_string
(
const
uuid_t
*
uuid
,
char
*
str
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
#endif
#endif
...
...
This diff is collapsed.
Click to expand it.
sys/uuid/uuid.c
+
18
−
0
View file @
db4ce5ef
...
@@ -23,6 +23,7 @@
...
@@ -23,6 +23,7 @@
#include
"hashes/sha1.h"
#include
"hashes/sha1.h"
#include
"random.h"
#include
"random.h"
#include
"uuid.h"
#include
"uuid.h"
#include
"fmt.h"
const
uuid_t
uuid_namespace_dns
=
{
/* 6ba7b810-9dad-11d1-80b4-00c04fd430c8 */
const
uuid_t
uuid_namespace_dns
=
{
/* 6ba7b810-9dad-11d1-80b4-00c04fd430c8 */
.
time_low
.
u8
=
{
0x6b
,
0xa7
,
0xb8
,
0x10
},
.
time_low
.
u8
=
{
0x6b
,
0xa7
,
0xb8
,
0x10
},
...
@@ -110,3 +111,20 @@ void uuid_v5(uuid_t *uuid, const uuid_t *ns, const uint8_t *name, size_t len)
...
@@ -110,3 +111,20 @@ void uuid_v5(uuid_t *uuid, const uuid_t *ns, const uint8_t *name, size_t len)
_set_version
(
uuid
,
UUID_V5
);
_set_version
(
uuid
,
UUID_V5
);
_set_reserved
(
uuid
);
_set_reserved
(
uuid
);
}
}
void
uuid_to_string
(
const
uuid_t
*
uuid
,
char
*
str
)
{
char
*
p
=
str
;
p
+=
fmt_u32_hex
(
p
,
byteorder_ntohl
(
uuid
->
time_low
));
p
+=
fmt_char
(
p
,
'-'
);
p
+=
fmt_u16_hex
(
p
,
byteorder_ntohs
(
uuid
->
time_mid
));
p
+=
fmt_char
(
p
,
'-'
);
p
+=
fmt_u16_hex
(
p
,
byteorder_ntohs
(
uuid
->
time_hi
));
p
+=
fmt_char
(
p
,
'-'
);
p
+=
fmt_byte_hex
(
p
,
uuid
->
clk_seq_hi_res
);
p
+=
fmt_byte_hex
(
p
,
uuid
->
clk_seq_low
);
p
+=
fmt_char
(
p
,
'-'
);
p
+=
fmt_bytes_hex
(
p
,
uuid
->
node
,
UUID_NODE_LEN
);
*
p
=
'\0'
;
fmt_to_lower
(
str
,
str
);
}
This diff is collapsed.
Click to expand it.
tests/unittests/tests-uuid/tests-uuid.c
+
21
−
0
View file @
db4ce5ef
...
@@ -95,12 +95,33 @@ void test_uuid_v5(void)
...
@@ -95,12 +95,33 @@ void test_uuid_v5(void)
TEST_ASSERT_EQUAL_INT
(
uuid_version
(
&
uuid_next
),
UUID_V5
);
TEST_ASSERT_EQUAL_INT
(
uuid_version
(
&
uuid_next
),
UUID_V5
);
}
}
void
test_uuid_str
(
void
)
{
char
str
[
40
];
const
char
dns
[]
=
"6ba7b810-9dad-11d1-80b4-00c04fd430c8"
;
uuid_to_string
(
&
uuid_namespace_dns
,
str
);
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
dns
,
str
,
sizeof
(
dns
)));
const
char
url
[]
=
"6ba7b811-9dad-11d1-80b4-00c04fd430c8"
;
uuid_to_string
(
&
uuid_namespace_url
,
str
);
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
url
,
str
,
sizeof
(
dns
)));
const
char
iso
[]
=
"6ba7b812-9dad-11d1-80b4-00c04fd430c8"
;
uuid_to_string
(
&
uuid_namespace_iso
,
str
);
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
iso
,
str
,
sizeof
(
dns
)));
const
char
x500
[]
=
"6ba7b814-9dad-11d1-80b4-00c04fd430c8"
;
uuid_to_string
(
&
uuid_namespace_x500
,
str
);
TEST_ASSERT_EQUAL_INT
(
0
,
memcmp
(
x500
,
str
,
sizeof
(
dns
)));
}
Test
*
tests_uuid_all
(
void
)
Test
*
tests_uuid_all
(
void
)
{
{
EMB_UNIT_TESTFIXTURES
(
fixtures
)
{
EMB_UNIT_TESTFIXTURES
(
fixtures
)
{
new_TestFixture
(
test_uuid_v3
),
new_TestFixture
(
test_uuid_v3
),
new_TestFixture
(
test_uuid_v4
),
new_TestFixture
(
test_uuid_v4
),
new_TestFixture
(
test_uuid_v5
),
new_TestFixture
(
test_uuid_v5
),
new_TestFixture
(
test_uuid_str
),
};
};
EMB_UNIT_TESTCALLER
(
uuid_tests
,
NULL
,
NULL
,
fixtures
);
EMB_UNIT_TESTCALLER
(
uuid_tests
,
NULL
,
NULL
,
fixtures
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment