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