summaryrefslogtreecommitdiffstats
path: root/src/libomemo-test.c
blob: ef1cbc7c74d553a6a16bb52c5e5ea6db3cb8399a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// This file is part of MXE. See LICENSE.md for licensing information.

#include <libomemo.h>
#include <libomemo_crypto.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    char * msg_p = "<message xmlns='jabber:client' type='chat' to='alice@example.com'>"
                   "<body>hello</body>"
                   "</message>";

    printf("Original message:\n%s\n\n", msg_p);
    fflush(stdout);

    omemo_crypto_provider crypto = {
        .random_bytes_func = omemo_default_crypto_random_bytes,
        .aes_gcm_encrypt_func = omemo_default_crypto_aes_gcm_encrypt,
        .aes_gcm_decrypt_func = omemo_default_crypto_aes_gcm_decrypt,
        (void *) 0
    };

    uint32_t sid = 9178;

    omemo_message * msg_out_p;
    if (omemo_message_prepare_encryption(msg_p, sid, &crypto, &msg_out_p) != 0)
        return 1;

    char * xml_out_p;
    if (omemo_message_export_encrypted(msg_out_p, &xml_out_p) != 0)
        return 1;

    printf("Encrypted message:\n%s\n\n", xml_out_p);
    fflush(stdout);

    return 0;
}