use alloc::vec::Vec; use crate::crypto::{Keys, PublicKey}; use crate::res::IFResult; use crate::tunnel::TunnelPublic; /// A serialized message pub(crate) type MessageBytes = Vec; pub enum Signature { /// The message is signed. Author is unknown NotSigned, /// The message is signed with the sender's key visible to everyone Signed { sender: PublicKey, signature: Vec, }, /// Sender's key is encrypted for the recipient SignedPrivately { sender_encrypted: Vec, signature: Vec, } } pub enum MessageType { SingleCast, Broadcast, Service(ServiceMessageType), } pub enum ServiceMessageType { TunnelBuilding(TunnelPublic) } pub enum MessageContent { /// Just plaintext message content Plain(Vec), /// Message content bytes encrypted for the recipient Encrypted(Vec), } pub struct Message { /// Content of the message (not to be confused with the bytes that we are sending through interfaces) content: MessageContent, /// The type of this message message_type: MessageType, /// Sender's signature signature: Signature, /// A random number that is used in hash together with the content salt: u64, /// Hash of message content and the salt hash: Vec, /// Optional: hash of the message encrypted for the recipient, so that the recipient can know that this message is for them, but nobody else recipient_verification: Option>, /// ID of the tunnel that is used tunnel_id: u64, } impl Message { /// Verify message's hash pub fn verify(&self) -> bool { todo!() } /// Check if this message is for this set of keys pub fn check_recipient(&self, _keys: Keys) -> bool { todo!() } /// Get decrypted content of the message pub fn get_decrypted(&self, _keys: Keys) -> IFResult> { todo!() } pub fn calculate_hash(_content: MessageContent, _message_type: MessageType, _sender: Option) -> Vec { todo!() } }