]> git.meshlink.io Git - meshlink/blob - test/encrypted.c
Allow meshlink_open() to be called with a NULL name.
[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 #include <dirent.h>
12
13 #include "meshlink.h"
14 #include "utils.h"
15
16 int main() {
17         meshlink_set_log_cb(NULL, MESHLINK_DEBUG, log_cb);
18
19         // Open a new meshlink instance.
20
21         assert(meshlink_destroy("encrypted_conf"));
22         meshlink_handle_t *mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
23         assert(mesh);
24
25         // Close the mesh and open it again, now with a different key.
26
27         meshlink_close(mesh);
28
29         mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "wrong", 5);
30         assert(!mesh);
31
32         // Open it again, now with the right key.
33
34         mesh = meshlink_open_encrypted("encrypted_conf", "foo", "encrypted", DEV_CLASS_BACKBONE, "right", 5);
35         assert(mesh);
36
37         // That's it.
38
39         meshlink_close(mesh);
40
41         // Destroy the mesh.
42
43         assert(meshlink_destroy("encrypted_conf"));
44
45         DIR *dir = opendir("encrypted_conf");
46         assert(dir);
47         struct dirent *ent;
48
49         while((ent = readdir(dir))) {
50                 fprintf(stderr, "%s\n", ent->d_name);
51                 assert(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."));
52         }
53
54         closedir(dir);
55 }