]> git.meshlink.io Git - meshlink/blob - test/encrypted.c
a97e0eec1e1f63604808e553ab268a667db036a5
[meshlink] / test / encrypted.c
1 #ifdef NDEBUG
2 #undef NDEBUG
3 #endif
4
5 #include <stdio.h>
6 #include <string.h>
7 #include <unistd.h>
8 #include <errno.h>
9 #include <sys/time.h>
10 #include <assert.h>
11
12 #include "meshlink.h"
13 #include "utils.h"
14
15 int main() {
16         meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
17
18         // Open a new meshlink instance.
19
20         assert(meshlink_destroy("encrypted_conf"));
21         meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
22         assert(mesh);
23
24         // Close the mesh and open it again, now with a different key.
25
26         meshlink_close(mesh);
27
28         mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "wrong", 5);
29         assert(!mesh);
30
31         // Open it again, now with the right key.
32
33         mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
34         assert(mesh);
35
36         // That's it.
37
38         meshlink_close(mesh);
39
40         // Destroy the mesh.
41
42         assert(meshlink_destroy("encrypted_conf"));
43         assert(access("encrypted_conf", F_OK) == -1 && errno == ENOENT);
44 }