@@ -62,17 +62,14 @@ pub struct SecretAddress {
6262}
6363
6464impl SecretAddress {
65- pub fn from_string ( peer_node_id : String , peer_passphrase : String ) -> Result < Self > {
66- if peer_node_id. is_empty ( ) {
67- bail ! ( "peer_node_id is empty!" )
65+ pub fn from_string ( peer_secret_address : String ) -> Result < Self > {
66+ let parts: Vec < & str > = peer_secret_address. split ( '#' ) . collect ( ) ;
67+ if parts. len ( ) != 2 {
68+ bail ! ( "peer_secret_address does not have the format <node_id>#<passphrase>" )
6869 }
6970
70- if peer_passphrase. is_empty ( ) {
71- bail ! ( "peer_passphrase is empty!" )
72- }
73-
74- let peer_node_id = NodeId :: from_str ( & peer_node_id) ?;
75- let peer_passphrase = SecretKey :: from_str ( & peer_passphrase) ?;
71+ let peer_node_id = NodeId :: from_str ( & parts[ 0 ] ) ?;
72+ let peer_passphrase = SecretKey :: from_str ( & parts[ 1 ] ) ?;
7673
7774 Ok ( Self {
7875 peer_node_id,
@@ -173,14 +170,8 @@ pub async fn get_secret_address_from_wormhole(code: &str) -> Result<SecretAddres
173170 MailboxConnection :: connect ( config, Code :: from_str ( code) ?, false ) . await ?;
174171 let mut wormhole = Wormhole :: connect ( mailbox_connection) . await ?;
175172 let bytes = wormhole. receive ( ) . await ?;
176- let fragments: Vec < String > = String :: from_utf8 ( bytes) ?
177- . clone ( )
178- . split ( "#" )
179- . map ( |value| value. to_string ( ) )
180- . collect ( ) ;
181- let peer_node_id = fragments[ 0 ] . to_string ( ) ;
182- let peer_passphrase = fragments[ 1 ] . to_string ( ) ;
183- SecretAddress :: from_string ( peer_node_id, peer_passphrase)
173+ let secret_address = String :: from_utf8 ( bytes) ?;
174+ SecretAddress :: from_string ( secret_address)
184175}
185176
186177async fn handle_node_command (
0 commit comments