From 6c46e0b463fdbe60af0363a8bff2c16f022dab82 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Thu, 18 Jun 2020 16:31:57 +0200 Subject: [PATCH] Scaffold for Envelope and EnvelopeEntity --- libsignal-service/src/envelope.rs | 29 +++++++++++++++++++++++++++++ libsignal-service/src/lib.rs | 1 + libsignal-service/src/receiver.rs | 10 +++++++++- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 libsignal-service/src/envelope.rs diff --git a/libsignal-service/src/envelope.rs b/libsignal-service/src/envelope.rs new file mode 100644 index 000000000..41ac3d62a --- /dev/null +++ b/libsignal-service/src/envelope.rs @@ -0,0 +1,29 @@ +pub struct Envelope { + inner: crate::proto::Envelope, +} + +#[derive(serde::Serialize, serde::Deserialize)] +#[serde(rename_all = "camelCase")] +pub(crate) struct EnvelopeEntity { + pub r#type: i32, + pub relay: String, + pub timestamp: i64, + pub source: String, + pub source_uuid: String, + pub source_device: i32, + pub message: Vec, + pub content: Vec, + pub server_timestamp: i64, + pub guid: String, +} + +const SUPPORTED_VERSION: usize = 1; +const CIPHER_KEY_SIZE: usize = 32; +const MAC_KEY_SIZE: usize = 20; +const MAC_SIZE: usize = 10; + +const VERSION_OFFSET: usize = 0; +const VERSION_LENGTH: usize = 1; +const IV_OFFSET: usize = VERSION_OFFSET + VERSION_LENGTH; +const IV_LENGTH: usize = 16; +const CIPHERTEXT_OFFSET: usize = IV_OFFSET + IV_LENGTH; diff --git a/libsignal-service/src/lib.rs b/libsignal-service/src/lib.rs index c53925476..50be735fd 100644 --- a/libsignal-service/src/lib.rs +++ b/libsignal-service/src/lib.rs @@ -1,5 +1,6 @@ mod account_manager; pub mod configuration; +pub mod envelope; pub mod push_service; pub mod receiver; diff --git a/libsignal-service/src/receiver.rs b/libsignal-service/src/receiver.rs index b7332b633..87e01b267 100644 --- a/libsignal-service/src/receiver.rs +++ b/libsignal-service/src/receiver.rs @@ -1,4 +1,4 @@ -use crate::{configuration::*, push_service::PushService}; +use crate::{configuration::*, envelope::Envelope, push_service::PushService}; use libsignal_protocol::StoreContext; @@ -12,4 +12,12 @@ impl MessageReceiver { pub fn new(service: Service, context: StoreContext) -> Self { MessageReceiver { service, context } } + + /// One-off method to receive all pending messages. + /// + /// For streaming messages, use a `MessagePipe` through + /// [`MessageReceiver::create_message_pipe()`]. + pub async fn receive_messages(&mut self) -> Vec { vec![] } + + pub async fn create_message_pipe(&self) -> () { unimplemented!() } }