/// Start the first act of the handshake as a responder (reading e, es, ss and doing wizardry with it)
Start the first act of the handshake as a responder (reading e, es, ss and doing wizardry with it)
Start the first act of the handshake as a responder ( reading e es ss and doing wizardry with it )
pub fn responder(
        my_privkey: &NoisePrivKey,
        their_possible_pubkeys: &[NoisePubKey],
        message: &KKMessageActOne,
    ) -> Result<KKHandshakeActOne, Error> {
        // TODO: estimate how inefficient it is.
        for their_pubkey in their_possible_pubkeys {
            // Build the initial responder state
            let builder = Builder::with_resolver(
                "Noise_KK_25519_ChaChaPoly_SHA256"
                    .parse()
                    .expect("Valid params"),
                Box::new(SodiumResolver::default()),
            );
            let mut state = builder
                .local_private_key(&my_privkey.0)
                .remote_public_key(&their_pubkey.0)
                .build_responder()
                .map_err(|e| {
                    Error::Noise(format!("Failed to build state for responder: {:?}", e))
                })?;
            let mut msg = [0u8; KK_MSG_1_SIZE];
            if state.read_message(&message.0, &mut msg).is_err() {
                continue;
            }
            if &msg[..HANDSHAKE_MESSAGE.len()] != HANDSHAKE_MESSAGE {
                return Err(Error::Noise(format!(
                    "Wrong handshake message. Expected '{:x?}' got '{:x?}'.",
                    HANDSHAKE_MESSAGE,
                    &msg[..HANDSHAKE_MESSAGE.len()]
                )));
            }
            return Ok(KKHandshakeActOne { state });
        }
        Err(Error::Noise("No matching pubkey".to_string()))
    }
pub fn responder ( my_privkey : & NoisePrivKey , their_possible_pubkeys : & [ NoisePubKey ] , message : & KKMessageActOne , ) -> Result < KKHandshakeActOne , Error > { // TODO: estimate how inefficient it is. for their_pubkey in their_possible_pubkeys { // Build the initial responder state let builder = Builder :: with_resolver ( " " . parse ( ) . expect ( " " ) , Box :: new ( SodiumResolver :: default ( ) ) , ) ; let mut state = builder . local_private_key ( & my_privkey . 0 ) . remote_public_key ( & their_pubkey . 0 ) . build_responder ( ) . map_err ( | e | { Error :: Noise ( format ! ( " " e ) ) } ) ? ; let mut msg = [ 0u8 ; KK_MSG_1_SIZE ] ; if state . read_message ( & message . 0 , & mut msg ) . is_err ( ) { continue ; } if & msg [ .. HANDSHAKE_MESSAGE . len ( ) ] != HANDSHAKE_MESSAGE { return Err ( Error :: Noise ( format ! ( " " HANDSHAKE_MESSAGE msg [ HANDSHAKE_MESSAGE len ( ) ] ) ) ) ; } return Ok ( KKHandshakeActOne { state } ) ; } Err ( Error :: Noise ( " " . to_string ( ) ) ) }
Start the first act of the handshake as a responder (reading e, es, ss and doing wizardry with it)
Start the first act of the handshake as a responder ( reading e es ss and doing wizardry with it )
my_privkey
&NoisePrivKey
their_possible_pubkeys
&[NoisePubKey]
message
&KKMessageActOne