1pub use sodiumoxide::crypto::box_::curve25519xsalsa20poly1305 as naclbox;
7
8use std::convert::TryInto;
9
10pub mod import;
12
13pub mod directory_api;
15
16pub mod blob_api;
18
19mod threema_id;
20pub use threema_id::{ThreemaID, InvalidID};
21
22pub mod pltypes{
24 pub const ECHO_REQUEST : u32 = 0x00;
26 pub const ECHO_REPLY : u32 = 0x80;
27 pub const OUTGOING_MESSAGE : u32 = 0x01;
28 pub const OUTGOING_MESSAGE_ACK : u32 = 0x81;
29 pub const INCOMING_MESSAGE : u32 = 0x02;
30 pub const INCOMING_MESSAGE_ACK : u32 = 0x82;
31 pub const PUSH_NOTIFICATION_TOKEN : u32 = 0x20;
32 pub const PUSH_ALLOWED_IDENTITIES : u32 = 0x21;
33 pub const VOIP_PUSH_NOTIFICATION_TOKEN : u32 = 0x24;
34 pub const QUEUE_SEND_COMPLETE : u32 = 0xd0;
35 pub const ERROR : u32 = 0xe0;
36 pub const ALERT : u32 = 0xe1;
37}
38
39pub mod transport;
41
42pub mod messaging_client;
45
46#[derive(Clone, Debug)]
48pub struct Credentials{
49 pub id: ThreemaID,
50 pub sk: naclbox::SecretKey,
51}
52
53impl Credentials{
54 pub fn new(id: &str, sk: naclbox::SecretKey) -> Result<Self, InvalidID>{
55 Ok(Credentials{id: id.try_into()?, sk})
56 }
57}
58
59#[derive(Clone, Debug)]
61pub struct Peer{
62 pub id: ThreemaID,
63 pub pk: naclbox::PublicKey,
64}
65
66impl Peer{
67 pub fn new(id: &str, pk: naclbox::PublicKey) -> Result<Self, InvalidID>{
68 Ok(Peer{id: id.try_into()?, pk})
69 }
70}
71
72
73pub mod msg_types{
75 pub const TEXT: u8 = 0x01;
76 pub const IMAGE: u8 = 0x02;
77 pub const LOCATION: u8 = 0x10;
78 pub const VIDEO: u8 = 0x13;
79 pub const AUDIO: u8 = 0x14;
80 pub const BALLOT_CREATE: u8 = 0x15;
81 pub const BALLOT_VOTE: u8 = 0x16;
82 pub const FILE: u8 = 0x17;
83 pub const CONTACT_SET_PHOTO: u8 = 0x18;
84 pub const CONTACT_DELETE_PHOTO: u8 = 0x19;
85 pub const CONTACT_REQUEST_PHOTO: u8 = 0x1a;
86 pub const GROUP_TEXT: u8 = 0x41;
87 pub const GROUP_LOCATION: u8 = 0x42;
88 pub const GROUP_IMAGE: u8 = 0x43;
89 pub const GROUP_VIDEO: u8 = 0x44;
90 pub const GROUP_AUDIO: u8 = 0x45;
91 pub const GROUP_FILE: u8 = 0x46;
92 pub const GROUP_CREATE: u8 = 0x4a;
93 pub const GROUP_RENAME: u8 = 0x4b;
94 pub const GROUP_LEAVE: u8 = 0x4c;
95 pub const GROUP_ADD_MEMBER: u8 = 0x4d;
96 pub const GROUP_REMOVE_MEMBER: u8 = 0x4e;
97 pub const GROUP_DESTROY: u8 = 0x4f;
98 pub const GROUP_SET_PHOTO: u8 = 0x50;
99 pub const GROUP_REQUEST_SYNC: u8 = 0x51;
100 pub const GROUP_BALLOT_CREATE: u8 = 0x52;
101 pub const GROUP_BALLOT_VOTE: u8 = 0x53;
102 pub const GROUP_DELETE_PHOTO: u8 = 0x54;
103 pub const VOIP_CALL_OFFER: u8 = 0x60;
104 pub const VOIP_CALL_ANSWER: u8 = 0x61;
105 pub const VOIP_ICE_CANDIDATES: u8 = 0x62;
106 pub const VOIP_CALL_HANGUP: u8 = 0x63;
107 pub const VOIP_CALL_RINGING: u8 = 0x64;
108 pub const DELIVERY_RECEIPT: u8 = 0x80;
109 pub const TYPING_INDICATOR: u8 = 0x90;
110}
111
112#[derive(thiserror::Error, Debug)]
114pub enum ParseError {
115 #[error("Packet to short for packet type: expected {expected}, got {got} bytes")]
116 ToShort{expected:usize, got:usize},
117 #[error("Could not decode UTF8 - invalid encoding")]
118 InvalidUTF8,
119 #[error("Decryption or verification failed")]
120 DecryptionError,
121 #[error("Invalid padding")]
122 InvalidPadding,
123}