Add Identity name

This commit is contained in:
Jazz Turner-Baggs 2026-02-18 09:55:12 -08:00
parent a9ca4ffb7d
commit 705236f85c
No known key found for this signature in database

View File

@ -3,6 +3,7 @@ use std::fmt;
use crate::crypto::{PrivateKey, PublicKey}; use crate::crypto::{PrivateKey, PublicKey};
pub struct Identity { pub struct Identity {
name: String,
secret: PrivateKey, secret: PrivateKey,
} }
@ -16,8 +17,9 @@ impl fmt::Debug for Identity {
} }
impl Identity { impl Identity {
pub fn new() -> Self { pub fn new(name: impl Into<String>) -> Self {
Self { Self {
name: name.into(),
secret: PrivateKey::random(), secret: PrivateKey::random(),
} }
} }
@ -29,10 +31,17 @@ impl Identity {
pub fn secret(&self) -> &PrivateKey { pub fn secret(&self) -> &PrivateKey {
&self.secret &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 {
return &self.name;
}
} }
impl Default for Identity { impl Default for Identity {
fn default() -> Self { fn default() -> Self {
Self::new() Self::new("default")
} }
} }