Skip to main content

pim_messaging/
lib.rs

1//! User-to-user encrypted messaging — `pim-daemon` plugin.
2//!
3//! This crate is loaded by `pim-daemon` only when the `messaging`
4//! Cargo feature is enabled. It provides:
5//!
6//! - On-disk persistence of message history + conversation summaries
7//!   ([`storage::MessagingStorage`]), separate from the daemon-owned
8//!   peer keystore.
9//! - End-to-end encryption of message bodies via `pim-crypto`'s ECIES
10//!   helpers.
11//! - On-wire encoding of `messaging.msg` and `messaging.ack` payloads
12//!   carried inside [`pim_protocol::ControlFrame::PluginPayload`]
13//!   (see [`wire`]).
14//! - A [`pim_plugin::DaemonPlugin`] implementation
15//!   ([`plugin::MessagingPlugin`]) that the daemon registers in its
16//!   plugin list when the `messaging` feature is on.
17
18#![warn(missing_docs)]
19
20pub mod plugin;
21pub mod service;
22pub mod storage;
23pub mod wire;
24
25pub use plugin::MessagingPlugin;
26pub use service::{HistoryScope, MessageEvent, MessagingService, MAX_BODY_BYTES};
27pub use storage::{
28    AckKind, ConversationSummary, MessageDirection, MessageRecord, MessageStatus, MessagingStorage,
29};
30pub use wire::{KIND_ACK, KIND_MESSAGE};
31
32use pim_core::NodeId;
33
34/// Format a [`NodeId`] as a 32-char lowercase hex string.
35pub fn hex_node_id(id: &NodeId) -> String {
36    let mut out = String::with_capacity(32);
37    for b in id.as_bytes() {
38        out.push_str(&format!("{:02x}", b));
39    }
40    out
41}
42
43/// Format a 16-byte UUID as a 32-char lowercase hex string.
44pub fn hex16(bytes: &[u8; 16]) -> String {
45    let mut out = String::with_capacity(32);
46    for b in bytes {
47        out.push_str(&format!("{:02x}", b));
48    }
49    out
50}