2026-01-22 06:39:09 +07:00
|
|
|
use std::fmt;
|
|
|
|
|
|
2026-02-18 09:29:33 -08:00
|
|
|
use crate::crypto::{PrivateKey, PublicKey};
|
2026-01-22 06:39:09 +07:00
|
|
|
|
|
|
|
|
pub struct Identity {
|
2026-02-18 09:29:33 -08:00
|
|
|
secret: PrivateKey,
|
2026-01-22 06:39:09 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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() -> Self {
|
|
|
|
|
Self {
|
2026-02-18 09:29:33 -08:00
|
|
|
secret: PrivateKey::random(),
|
2026-01-22 06:39:09 +07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn public_key(&self) -> PublicKey {
|
|
|
|
|
PublicKey::from(&self.secret)
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-18 09:29:33 -08:00
|
|
|
pub fn secret(&self) -> &PrivateKey {
|
2026-01-22 06:39:09 +07:00
|
|
|
&self.secret
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Default for Identity {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self::new()
|
|
|
|
|
}
|
|
|
|
|
}
|