IronForce is a decentralized network, Degeon is a messenger built on it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.7 KiB

use alloc::string::String;
use alloc::vec::Vec;
use crate::crypto::{Keys, PublicKey};
use crate::res::IFResult;
use crate::tunnel::TunnelPublic;
use serde::{Serialize, Deserialize};
/// A serialized message
pub(crate) type MessageBytes = Vec<u8>;
/// Signature of the message: optional and optionally encrypted sender's key and signed hash
#[derive(Serialize, Deserialize, Clone)]
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<u8>,
},
/// Sender's key is encrypted for the recipient
SignedPrivately {
sender_encrypted: Vec<u8>,
signature: Vec<u8>,
},
}
/// Network name and version
#[derive(Serialize, Deserialize, Clone)]
struct NetworkInfo {
network_name: String,
version: String,
}
impl Default for NetworkInfo {
fn default() -> Self {
Self { version: String::from("0.1.0"), network_name: String::from("test") }
}
}
#[derive(Serialize, Deserialize, Clone)]
pub enum MessageType {
SingleCast,
Broadcast,
Service(ServiceMessageType),
}
#[derive(Serialize, Deserialize, Clone)]
pub enum ServiceMessageType {
TunnelBuilding(TunnelPublic)
}
#[derive(Serialize, Deserialize, Clone)]
pub enum MessageContent {
/// Just plaintext message content
Plain(Vec<u8>),
/// Message content bytes encrypted for the recipient
Encrypted(Vec<u8>),
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Message {
/// Content of the message (not to be confused with the bytes that we are sending through interfaces)
pub content: MessageContent,
/// The type of this message
pub message_type: MessageType,
/// Sender's signature
pub 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<u8>,
/// 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<Vec<u8>>,
/// ID of the tunnel that is used
tunnel_id: u64,
/// Network info
network_info: NetworkInfo,
}
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<Vec<u8>> {
todo!()
}
pub fn calculate_hash(_content: MessageContent, _message_type: MessageType, _sender: Option<PublicKey>) -> Vec<u8> {
todo!()
}
}