Skip to content

Commit

Permalink
Scaffold for Envelope and EnvelopeEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
rubdos committed Jun 18, 2020
1 parent e70c850 commit 6c46e0b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
29 changes: 29 additions & 0 deletions libsignal-service/src/envelope.rs
Original file line number Diff line number Diff line change
@@ -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<u8>,
pub content: Vec<u8>,
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;
1 change: 1 addition & 0 deletions libsignal-service/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod account_manager;
pub mod configuration;
pub mod envelope;
pub mod push_service;
pub mod receiver;

Expand Down
10 changes: 9 additions & 1 deletion libsignal-service/src/receiver.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{configuration::*, push_service::PushService};
use crate::{configuration::*, envelope::Envelope, push_service::PushService};

use libsignal_protocol::StoreContext;

Expand All @@ -12,4 +12,12 @@ impl<Service: PushService> MessageReceiver<Service> {
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<Envelope> { vec![] }

pub async fn create_message_pipe(&self) -> () { unimplemented!() }
}

0 comments on commit 6c46e0b

Please sign in to comment.