Remove uneeded traits and warnings

This commit is contained in:
Jazz Turner-Baggs 2026-02-05 07:35:56 -08:00
parent 989035a431
commit 2834099828
No known key found for this signature in database
4 changed files with 34 additions and 83 deletions

View File

@ -22,7 +22,6 @@ pub struct Context {
_identity: Rc<Identity>,
store: ConversationStore,
inbox: Inbox,
buf_size: usize,
convo_handle_map: HashMap<u32, Arc<str>>,
next_convo_handle: ConvoHandle,
}
@ -35,20 +34,11 @@ impl Context {
_identity: identity,
store: ConversationStore::new(),
inbox,
buf_size: 0,
convo_handle_map: HashMap::new(),
next_convo_handle: INITIAL_CONVO_HANDLE,
}
}
pub fn buffer_size(&self) -> usize {
self.buf_size
}
pub fn set_buffer_size(&mut self, size: usize) {
self.buf_size = size
}
pub fn create_private_convo(
&mut self,
remote_bundle: &Introduction,

View File

@ -3,7 +3,7 @@ use std::fmt::Debug;
use std::sync::Arc;
pub use crate::errors::ChatError;
use crate::types::{AddressedEncryptedPayload, ContentData};
use crate::types::AddressedEncryptedPayload;
pub type ConversationId<'a> = &'a str;
pub type ConversationIdOwned = Arc<str>;
@ -12,13 +12,6 @@ pub trait Id: Debug {
fn id(&self) -> ConversationId;
}
pub trait ConvoFactory: Id + Debug {
fn handle_frame(
&mut self,
encoded_payload: &[u8],
) -> Result<(Box<dyn Convo>, Vec<ContentData>), ChatError>;
}
pub trait Convo: Id + Debug {
fn send_message(&mut self, content: &[u8])
-> Result<Vec<AddressedEncryptedPayload>, ChatError>;
@ -28,14 +21,12 @@ pub trait Convo: Id + Debug {
pub struct ConversationStore {
conversations: HashMap<Arc<str>, Box<dyn Convo>>,
factories: HashMap<Arc<str>, Box<dyn ConvoFactory>>,
}
impl ConversationStore {
pub fn new() -> Self {
Self {
conversations: HashMap::new(),
factories: HashMap::new(),
}
}
@ -46,15 +37,6 @@ impl ConversationStore {
key
}
pub fn register_factory(
&mut self,
handler: impl ConvoFactory + Id + 'static,
) -> ConversationIdOwned {
let key: ConversationIdOwned = Arc::from(handler.id());
self.factories.insert(key.clone(), Box::new(handler));
key
}
pub fn get(&self, id: ConversationId) -> Option<&(dyn Convo + '_)> {
self.conversations.get(id).map(|c| c.as_ref())
}
@ -63,17 +45,9 @@ impl ConversationStore {
Some(self.conversations.get_mut(id)?.as_mut())
}
pub fn get_factory(&mut self, id: ConversationId) -> Option<&mut (dyn ConvoFactory + '_)> {
Some(self.factories.get_mut(id)?.as_mut())
}
pub fn conversation_ids(&self) -> impl Iterator<Item = ConversationIdOwned> + '_ {
self.conversations.keys().cloned()
}
pub fn factory_ids(&self) -> impl Iterator<Item = ConversationIdOwned> + '_ {
self.factories.keys().cloned()
}
}
mod group_test;

View File

@ -1,5 +1,3 @@
pub use blake2::Digest;
use blake2::{Blake2b, digest};
use prost::bytes::Bytes;
pub use x25519_dalek::{PublicKey, StaticSecret};
@ -12,6 +10,3 @@ impl CopyBytes for PublicKey {
Bytes::copy_from_slice(self.as_bytes())
}
}
#[allow(dead_code)]
pub type Blake2b128 = Blake2b<digest::consts::U16>;

View File

@ -1,4 +1,3 @@
use double_ratchets::InstallationKeyPair;
use hex;
use prost::Message;
use prost::bytes::Bytes;
@ -9,8 +8,8 @@ use std::rc::Rc;
use crypto::{PrekeyBundle, SecretKey};
use crate::context::Introduction;
use crate::conversation::{ChatError, ConversationId, Convo, ConvoFactory, Id, PrivateV1Convo};
use crate::crypto::{Blake2b128, CopyBytes, Digest, PublicKey, StaticSecret};
use crate::conversation::{ChatError, ConversationId, Convo, Id, PrivateV1Convo};
use crate::crypto::{CopyBytes, PublicKey, StaticSecret};
use crate::identity::Identity;
use crate::inbox::handshake::InboxHandshake;
use crate::proto;
@ -51,11 +50,6 @@ impl Inbox {
}
}
fn compute_local_convo_id(addr: &str) -> String {
let hash = Blake2b128::digest(format!("{}:{}:{}", "logoschat", "inboxV1", addr));
hex::encode(hash)
}
pub fn create_bundle(&mut self) -> PrekeyBundle {
let ephemeral = StaticSecret::random();
@ -125,6 +119,37 @@ impl Inbox {
Ok((convo, payloads))
}
fn handle_frame(
&mut self,
message: &[u8],
) -> Result<(Box<dyn Convo>, Vec<ContentData>), ChatError> {
if message.len() == 0 {
return Err(ChatError::Protocol("Example error".into()));
}
let handshake = Self::extract_payload(proto::EncryptedPayload::decode(message)?)?;
let header = handshake
.header
.ok_or(ChatError::UnexpectedPayload("InboxV1Header".into()))?;
// Get Ephemeral key used by the initator
let key_index = hex::encode(header.responder_ephemeral.as_ref());
let ephemeral_key = self.lookup_ephemeral_key(&key_index)?;
// Perform handshake and decrypt frame
let (seed_key, frame) = self.perform_handshake(ephemeral_key, header, handshake.payload)?;
match frame.frame_type.unwrap() {
proto::inbox_v1_frame::FrameType::InvitePrivateV1(_invite_private_v1) => {
let convo = PrivateV1Convo::new_responder(seed_key, ephemeral_key.clone().into());
// TODO: Update PrivateV1 Constructor with DR, initial_message
Ok((Box::new(convo), vec![]))
}
}
}
fn wrap_in_invite(payload: proto::EncryptedPayload) -> proto::InboxV1Frame {
let invite = proto::InvitePrivateV1 {
discriminator: "default".into(),
@ -202,39 +227,6 @@ impl Id for Inbox {
}
}
impl ConvoFactory for Inbox {
fn handle_frame(
&mut self,
message: &[u8],
) -> Result<(Box<dyn Convo>, Vec<ContentData>), ChatError> {
if message.len() == 0 {
return Err(ChatError::Protocol("Example error".into()));
}
let handshake = Self::extract_payload(proto::EncryptedPayload::decode(message)?)?;
let header = handshake
.header
.ok_or(ChatError::UnexpectedPayload("InboxV1Header".into()))?;
// Get Ephemeral key used by the initator
let key_index = hex::encode(header.responder_ephemeral.as_ref());
let ephemeral_key = self.lookup_ephemeral_key(&key_index)?;
// Perform handshake and decrypt frame
let (seed_key, frame) = self.perform_handshake(ephemeral_key, header, handshake.payload)?;
match frame.frame_type.unwrap() {
proto::inbox_v1_frame::FrameType::InvitePrivateV1(_invite_private_v1) => {
let convo = PrivateV1Convo::new_responder(seed_key, ephemeral_key.clone().into());
// TODO: Update PrivateV1 Constructor with DR, initial_message
Ok((Box::new(convo), vec![]))
}
}
}
}
#[cfg(test)]
mod tests {
use super::*;