mirror of
https://github.com/logos-messaging/libchat.git
synced 2026-05-12 21:19:44 +00:00
* feat: storage for conversations * fix: db types conversion * feat: run migrations from sql files * feat: persist identity * fix: revert double ratchet storage refactor * fix: clean * refactor: use result wrapper for ffi * refactor: uniform storage error into chat error * fix: zeroize identity record * fix: zeroize for secret keys in db operations * fix: transactional sql migration * fix: remove destroy_string * feat: db storage for inbox ephermeral keys * chore: remove in memory hashmap for ephemeral keys * feat: persist conversation store * feat: wire with the double ratchet storage * feat: remove conversation store * chore: fix conversation type not used * feat: mock chat store implementation * chore: sqlite module * feat: sqlite crate * chore: sqlite rename * chore: more refactor * extract ratchet store trait * chore: clear error conversion * chore: remove customized db conn * chore: fix clippy * chore: refactor to use generics and enum * chore: further clean for review comments
56 lines
1.2 KiB
Rust
56 lines
1.2 KiB
Rust
use std::fmt;
|
|
|
|
use crate::{PrivateKey, PublicKey};
|
|
|
|
#[derive(Clone)]
|
|
pub struct Identity {
|
|
name: String,
|
|
secret: PrivateKey,
|
|
}
|
|
|
|
impl fmt::Debug for Identity {
|
|
// Manually implement debug to not reveal secret key material
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
f.debug_struct("Identity")
|
|
.field("public_key", &self.public_key())
|
|
.finish_non_exhaustive()
|
|
}
|
|
}
|
|
|
|
impl Identity {
|
|
pub fn new(name: impl Into<String>) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
secret: PrivateKey::random(),
|
|
}
|
|
}
|
|
|
|
pub fn from_secret(name: impl Into<String>, secret: PrivateKey) -> Self {
|
|
Self {
|
|
name: name.into(),
|
|
secret,
|
|
}
|
|
}
|
|
|
|
pub fn public_key(&self) -> PublicKey {
|
|
PublicKey::from(&self.secret)
|
|
}
|
|
|
|
pub fn secret(&self) -> &PrivateKey {
|
|
&self.secret
|
|
}
|
|
|
|
// Returns an associated name for this Identity.
|
|
// Names are a friendly developer chosen identifier for an Identity which
|
|
// can provide between logging.
|
|
pub fn get_name(&self) -> &str {
|
|
&self.name
|
|
}
|
|
}
|
|
|
|
impl Default for Identity {
|
|
fn default() -> Self {
|
|
Self::new("default")
|
|
}
|
|
}
|