summaryrefslogtreecommitdiff
path: root/utils/mir_signal.h
blob: f8fd9a01c29ae2c098845af0e68433b61375d5ca (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#ifndef __MIR_SIGNAL_H__
#define __MIR_SIGNAL_H__

#include <m_system.h>
#include <m_utils.h>

extern "C"
{
	#include "../libs/libsignal/src/curve.h"
	#include "../libs/libsignal/src/hkdf.h"
	#include "../libs/libsignal/src/group_cipher.h"
	#include "../libs/libsignal/src/group_session_builder.h"
	#include "../libs/libsignal/src/key_helper.h"
	#include "../libs/libsignal/src/protocol.h"
	#include "../libs/libsignal/src/session_builder.h"
	#include "../libs/libsignal/src/session_cipher.h"
	#include "../libs/libsignal/src/signal_protocol.h"
	#include "../libs/libsignal/src/signal_protocol_types.h"
	#include "../libs/libsignal/src/curve25519/curve25519-donna.h"
}

struct signal_buffer
{
	size_t len;
	uint8_t data[1];
};

struct signal_type_base
{
	unsigned int ref_count = 0;
	void (*destroy)(signal_type_base *instance) = 0;
};

struct ec_public_key : public signal_type_base
{
	uint8_t data[32];
};

struct ec_private_key : public signal_type_base
{
	uint8_t data[32];
};

class SignalBuffer
{
	signal_buffer *m_buf;

public:
	SignalBuffer() : m_buf(nullptr) {}
	SignalBuffer(signal_buffer *buf) : m_buf(buf) {}
	SignalBuffer(const class MBinBuffer &buf);
	SignalBuffer(const ec_public_key *key);
	SignalBuffer(const ec_private_key *key);
	SignalBuffer(const session_pre_key *pre_key);
	SignalBuffer(const session_signed_pre_key *pre_key);
	~SignalBuffer();

	void operator=(signal_buffer *buf);

	__forceinline operator bool() const { return m_buf != nullptr; }
	__forceinline uint8_t* data() const { return m_buf->data; }
	__forceinline unsigned len() const { return unsigned(m_buf->len); }
	__forceinline void reset(size_t len) { m_buf->len = len; }

	CMStringA toBase64() const;
};

#endif // __MIR_SMILEYS_H__