Skip to content

Commit

Permalink
refactor node_secrets & ephemeral secrets into single interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Lederstrumpf committed Dec 20, 2021
1 parent 4edf2ce commit efe92ec
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/peerd/opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,25 +118,25 @@ pub struct PeerSecrets {

impl PeerKeyOpts {
pub fn local_node(&self) -> LocalNode {
self.node_secrets().local_node
self.node_secrets(Some(
SecretKey::from_str(&self.peer_secret_key).expect("peer secret key"),
))
.local_node
}

pub fn internal_node(&self) -> LocalNode {
self.ephemeral_secrets().local_node
self.node_secrets(None).local_node
}

pub fn node_secrets(&self) -> PeerSecrets {
pub fn node_secrets(&self, opt_secret_key: Option<SecretKey>) -> PeerSecrets {
let mut rng = thread_rng();
let secret_key = SecretKey::from_str(&self.peer_secret_key).expect("peer secret key");
let ephemeral_secret_key = SecretKey::new(&mut rng);
let local_node = LocalNode::from_keys(secret_key, ephemeral_secret_key);
PeerSecrets { local_node }
}

pub fn ephemeral_secrets(&self) -> PeerSecrets {
let mut rng = thread_rng();
rng.next_u64();
let secret_key = SecretKey::new(&mut rng);
let secret_key = match opt_secret_key {
Some(secret_key) => secret_key,
None => {
rng.next_u64();
SecretKey::new(&mut rng)
}
};
let ephemeral_secret_key = SecretKey::new(&mut rng);
let local_node = LocalNode::from_keys(secret_key, ephemeral_secret_key);
PeerSecrets { local_node }
Expand Down

0 comments on commit efe92ec

Please sign in to comment.