Skip to content

Commit 4e6b25a

Browse files
committed
Replace unwrapping public keys with handleable errors in handshake module.
1 parent eda13bf commit 4e6b25a

File tree

1 file changed

+10
-4
lines changed
  • lightning/src/ln/peers/handshake

1 file changed

+10
-4
lines changed

lightning/src/ln/peers/handshake/mod.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,11 @@ impl PeerHandshake {
310310
let remote_pubkey_vec = chacha::decrypt(&act_three_expectation.temporary_key, 1, &hash.value, &tagged_encrypted_pubkey)?;
311311
let mut remote_pubkey_bytes = [0u8; 33];
312312
remote_pubkey_bytes.copy_from_slice(remote_pubkey_vec.as_slice());
313-
// todo: replace unwrap with handleable error type
314-
let remote_pubkey = PublicKey::from_slice(&remote_pubkey_bytes).unwrap();
313+
let remote_pubkey = if let Ok(public_key) = PublicKey::from_slice(&remote_pubkey_bytes) {
314+
public_key
315+
} else {
316+
return Err("invalid remote public key".to_string());
317+
};
315318

316319
hash.update(&tagged_encrypted_pubkey);
317320

@@ -360,8 +363,11 @@ impl PeerHandshake {
360363

361364
let mut ephemeral_public_key_bytes = [0u8; 33];
362365
ephemeral_public_key_bytes.copy_from_slice(&act_bytes[1..34]);
363-
// todo: replace unwrap with handleable error type
364-
let ephemeral_public_key = PublicKey::from_slice(&ephemeral_public_key_bytes).unwrap();
366+
let ephemeral_public_key = if let Ok(public_key) = PublicKey::from_slice(&ephemeral_public_key_bytes) {
367+
public_key
368+
} else {
369+
return Err("invalid remote ephemeral public key".to_string());
370+
};
365371

366372
let mut chacha_tag = [0u8; 16];
367373
chacha_tag.copy_from_slice(&act_bytes[34..50]);

0 commit comments

Comments
 (0)