libchat/conversations/src/identity.rs
Jazz Turner-Baggs eb941387df
Add Installation name (#58)
* Add Identity name

* Update Context to accept a name

* Change constructor in bindings

* Add name retrieval to bindings

* Update constructor string type

* Remove uneeded files

* rename functions for symmetry
2026-02-19 17:25:42 -08:00

48 lines
1.0 KiB
Rust

use std::fmt;
use crate::crypto::{PrivateKey, PublicKey};
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 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")
}
}