Skip to content

Commit

Permalink
refactor: Reorder structs and impls into a sensible order.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkasak committed Feb 9, 2024
1 parent bc32d46 commit e513c32
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions src/olm/messages/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ impl Debug for InterolmMessage {
}
}

#[derive(ProstMessage, PartialEq, Eq)]
#[derive(Eq, PartialEq, ProstMessage)]
struct ProtoBufMessage {
#[prost(bytes, tag = "1")]
ratchet_key: Vec<u8>,
Expand All @@ -385,41 +385,23 @@ struct ProtoBufMessage {
ciphertext: Vec<u8>,
}

#[cfg(feature = "interolm")]
#[derive(PartialEq, Eq, ProstMessage)]
struct InterolmProtoBufMessage {
#[prost(bytes, tag = "1")]
ratchet_key: Vec<u8>,
#[prost(uint32, tag = "2")]
index: u32,
#[prost(uint32, tag = "3")]
previous_index: u32,
#[prost(bytes, tag = "4")]
ciphertext: Vec<u8>,
}

#[cfg(feature = "interolm")]
impl InterolmProtoBufMessage {
impl ProtoBufMessage {
const RATCHET_TAG: &'static [u8; 1] = b"\x0A";
const INDEX_TAG: &'static [u8; 1] = b"\x10";
const PREVIOUS_INDEX_TAG: &'static [u8; 1] = b"\x18";
const CIPHER_TAG: &'static [u8; 1] = b"\x22";

fn encode_manual(&self) -> Vec<u8> {
let index = self.index.to_var_int();
let previous_index = self.previous_index.to_var_int();
fn encode_manual(&self, version: u8) -> Vec<u8> {
let index = self.chain_index.to_var_int();
let ratchet_len = self.ratchet_key.len().to_var_int();
let ciphertext_len = self.ciphertext.len().to_var_int();

[
[InterolmMessage::VERSION].as_ref(),
[version].as_ref(),
Self::RATCHET_TAG.as_ref(),
&ratchet_len,
&self.ratchet_key,
Self::INDEX_TAG.as_ref(),
&index,
Self::PREVIOUS_INDEX_TAG.as_ref(),
&previous_index,
Self::CIPHER_TAG.as_ref(),
&ciphertext_len,
&self.ciphertext,
Expand All @@ -428,23 +410,41 @@ impl InterolmProtoBufMessage {
}
}

impl ProtoBufMessage {
#[cfg(feature = "interolm")]
#[derive(Eq, PartialEq, ProstMessage)]
struct InterolmProtoBufMessage {
#[prost(bytes, tag = "1")]
ratchet_key: Vec<u8>,
#[prost(uint32, tag = "2")]
index: u32,
#[prost(uint32, tag = "3")]
previous_index: u32,
#[prost(bytes, tag = "4")]
ciphertext: Vec<u8>,
}

#[cfg(feature = "interolm")]
impl InterolmProtoBufMessage {
const RATCHET_TAG: &'static [u8; 1] = b"\x0A";
const INDEX_TAG: &'static [u8; 1] = b"\x10";
const PREVIOUS_INDEX_TAG: &'static [u8; 1] = b"\x18";
const CIPHER_TAG: &'static [u8; 1] = b"\x22";

fn encode_manual(&self, version: u8) -> Vec<u8> {
let index = self.chain_index.to_var_int();
fn encode_manual(&self) -> Vec<u8> {
let index = self.index.to_var_int();
let previous_index = self.previous_index.to_var_int();
let ratchet_len = self.ratchet_key.len().to_var_int();
let ciphertext_len = self.ciphertext.len().to_var_int();

[
[version].as_ref(),
[InterolmMessage::VERSION].as_ref(),
Self::RATCHET_TAG.as_ref(),
&ratchet_len,
&self.ratchet_key,
Self::INDEX_TAG.as_ref(),
&index,
Self::PREVIOUS_INDEX_TAG.as_ref(),
&previous_index,
Self::CIPHER_TAG.as_ref(),
&ciphertext_len,
&self.ciphertext,
Expand Down

0 comments on commit e513c32

Please sign in to comment.