imitating the coax structure a little, adding the protos api + part of the JSON API definiton
This commit is contained in:
2
src/net/mod.rs
Normal file
2
src/net/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub(crate) mod protos;
|
||||
pub(crate) mod model;
|
||||
97
src/net/model/client.rs
Normal file
97
src/net/model/client.rs
Normal file
@@ -0,0 +1,97 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::net::model::prekeys::{PreKey, LastPreKey};
|
||||
// Client
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct Client {
|
||||
pub id: String,
|
||||
pub class: Option<Class>,
|
||||
pub time: Option<DateTime<Utc>>,
|
||||
pub r#type: Option<ClientType>,
|
||||
pub cookie_label: Option<String>,
|
||||
pub label: Option<String>,
|
||||
pub model: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
|
||||
pub enum Class {
|
||||
phone,
|
||||
tablet,
|
||||
desktop
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Copy, Clone, Debug)]
|
||||
pub enum ClientType {
|
||||
permanent,
|
||||
temporary
|
||||
}
|
||||
|
||||
// PubClientView
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PubClientView {
|
||||
pub id: String,
|
||||
pub class: Class
|
||||
}
|
||||
|
||||
// SignalingKeys
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct SignalingKeys {
|
||||
#[serde(serialize_with = "b64_encode", deserialize_with = "b64_decode")]
|
||||
pub enc: Vec<u8>,
|
||||
#[serde(serialize_with = "b64_encode", deserialize_with = "b64_decode")]
|
||||
pub mac: Vec<u8>
|
||||
}
|
||||
|
||||
fn b64_encode<'a, S>(bytes: &'a Vec<u8>, serialzer: S) -> Result<S::Ok, S::Error>
|
||||
where S: Serializer
|
||||
{
|
||||
serialzer.serialize_str(&base64::encode(&bytes))
|
||||
}
|
||||
|
||||
fn b64_decode<'de, D>(deserialzer: D) -> Result<Vec<u8>, D::Error>
|
||||
where D: Deserializer<'de>
|
||||
{
|
||||
use serde::de::Error;
|
||||
|
||||
String::deserialize(deserialzer)
|
||||
.and_then(|string|
|
||||
base64::decode(&string)
|
||||
.map_err(|e| Error::custom(e.to_string()))
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct User2Clients {
|
||||
pub value: HashMap<Uuid, HashSet<String>>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ClientMismatch {
|
||||
pub time: DateTime<Utc>,
|
||||
pub redundant: User2Clients,
|
||||
pub missing: User2Clients,
|
||||
pub deleted: User2Clients
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct RegisterParams{
|
||||
pub prekeys: Vec<PreKey>,
|
||||
pub last_prekey: LastPreKey,
|
||||
pub sig_keys: SignalingKeys,
|
||||
pub ctype: ClientType,
|
||||
pub class: Class,
|
||||
pub cookie_label: String,
|
||||
pub label: Option<String>,
|
||||
pub password: Option<String>,
|
||||
pub model: Option<String>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
struct DeleteParams {
|
||||
password: String
|
||||
}
|
||||
0
src/net/model/conversation.rs
Normal file
0
src/net/model/conversation.rs
Normal file
0
src/net/model/events.rs
Normal file
0
src/net/model/events.rs
Normal file
0
src/net/model/messages.rs
Normal file
0
src/net/model/messages.rs
Normal file
2
src/net/model/mod.rs
Normal file
2
src/net/model/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod client;
|
||||
pub mod prekeys;
|
||||
28
src/net/model/prekeys.rs
Normal file
28
src/net/model/prekeys.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
use std::collections::HashMap;
|
||||
|
||||
use proteus::keys::PreKeyBundle;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PreKeyMap {
|
||||
pub value: HashMap<Uuid, HashMap<String, Option<PreKey>>>
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct PreKey {
|
||||
pub key: PreKeyBundle
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct LastPreKey(PreKey);
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ClientPreKey {
|
||||
pub id: String,
|
||||
pub key: PreKey
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||
pub struct ClientPreKeys(Vec<ClientPreKey>);
|
||||
0
src/net/model/token.rs
Normal file
0
src/net/model/token.rs
Normal file
0
src/net/model/user.rs
Normal file
0
src/net/model/user.rs
Normal file
1
src/net/protos/mod.rs
Normal file
1
src/net/protos/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod wire_api;
|
||||
10758
src/net/protos/wire_api.rs
Normal file
10758
src/net/protos/wire_api.rs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user