fn prologue(&mut self) -> OckamResult<()> {
        let asymmetric_secret_info = self.get_secret_key_type_and_length();

        let mut attributes = SecretAttributes {
            stype: asymmetric_secret_info.0,
            persistence: SecretPersistence::Persistent,
            length: asymmetric_secret_info.1,
        };
        // 1. Generate a static key pair for this handshake and set it to `s`
        let mut vault = self.vault.lock().unwrap();
        let identity_key = self.identity_key.take();
        let identity_key = match identity_key {
            None => {
                let static_secret_handle = vault.secret_generate(attributes)?;
                self.identity_public_key =
                    Some(vault.secret_public_key_get(&static_secret_handle)?);
                Arc::new(static_secret_handle)
            }
            Some(ik) => {
                self.identity_public_key = Some(vault.secret_public_key_get(&ik)?);
                ik
            }
        };
        self.identity_key = Some(identity_key);

        attributes.persistence = SecretPersistence::Ephemeral;
        // 2. Generate an ephemeral key pair for this handshake and set it to e
        let ephemeral_secret_handle = vault.secret_generate(attributes)?;
        let ephemeral_public_key = vault.secret_public_key_get(&ephemeral_secret_handle)?;
        self.ephemeral_key_pair = Some(KeyPair {
            public_key: ephemeral_public_key,
            secret_handle: ephemeral_secret_handle,
        });

        // 3. Set k to empty, Set n to 0
        // let nonce = 0;
        self.key = None;
        self.nonce = 0;

        // 4. Set h and ck to protocol name
        // 5. h = SHA256(h || prologue),
        // prologue is empty
        // mix_hash(xx, NULL, 0);
        let mut h = [0u8; SHA256_SIZE];
        h[..self.get_protocol_name().len()].copy_from_slice(self.get_protocol_name());
        let attributes = SecretAttributes {
            stype: SecretType::Buffer,
            persistence: SecretPersistence::Ephemeral,
            length: SHA256_SIZE,
        };
        self.ck = Some(vault.secret_import(&h, attributes)?);
        self.h = Some(vault.sha256(&h)?);

        Ok(())
    }
/// Create a new `HandshakeState` starting with the prologue
Create a new `HandshakeState` starting with the prologue
Create a new ` HandshakeState ` starting with the prologue
fn prologue(&mut self) -> OckamResult<()> {
        let asymmetric_secret_info = self.get_secret_key_type_and_length();
        let mut attributes = SecretAttributes {
            stype: asymmetric_secret_info.0,
            persistence: SecretPersistence::Persistent,
            length: asymmetric_secret_info.1,
        };
        // 1. Generate a static key pair for this handshake and set it to `s`
        let mut vault = self.vault.lock().unwrap();
        let identity_key = self.identity_key.take();
        let identity_key = match identity_key {
            None => {
                let static_secret_handle = vault.secret_generate(attributes)?;
                self.identity_public_key =
                    Some(vault.secret_public_key_get(&static_secret_handle)?);
                Arc::new(static_secret_handle)
            }
            Some(ik) => {
                self.identity_public_key = Some(vault.secret_public_key_get(&ik)?);
                ik
            }
        };
        self.identity_key = Some(identity_key);
        attributes.persistence = SecretPersistence::Ephemeral;
        // 2. Generate an ephemeral key pair for this handshake and set it to e
        let ephemeral_secret_handle = vault.secret_generate(attributes)?;
        let ephemeral_public_key = vault.secret_public_key_get(&ephemeral_secret_handle)?;
        self.ephemeral_key_pair = Some(KeyPair {
            public_key: ephemeral_public_key,
            secret_handle: ephemeral_secret_handle,
        });
        // 3. Set k to empty, Set n to 0
        // let nonce = 0;
        self.key = None;
        self.nonce = 0;
        // 4. Set h and ck to protocol name
        // 5. h = SHA256(h || prologue),
        // prologue is empty
        // mix_hash(xx, NULL, 0);
        let mut h = [0u8; SHA256_SIZE];
        h[..self.get_protocol_name().len()].copy_from_slice(self.get_protocol_name());
        let attributes = SecretAttributes {
            stype: SecretType::Buffer,
            persistence: SecretPersistence::Ephemeral,
            length: SHA256_SIZE,
        };
        self.ck = Some(vault.secret_import(&h, attributes)?);
        self.h = Some(vault.sha256(&h)?);
        Ok(())
    }
fn prologue ( & mut self ) -> OckamResult < ( ) > { let asymmetric_secret_info = self . get_secret_key_type_and_length ( ) ; let mut attributes = SecretAttributes { stype : asymmetric_secret_info . 0 , persistence : SecretPersistence :: Persistent , length : asymmetric_secret_info . 1 , } ; // 1. Generate a static key pair for this handshake and set it to `s` let mut vault = self . vault . lock ( ) . unwrap ( ) ; let identity_key = self . identity_key . take ( ) ; let identity_key = match identity_key { None => { let static_secret_handle = vault . secret_generate ( attributes ) ? ; self . identity_public_key = Some ( vault . secret_public_key_get ( & static_secret_handle ) ? ) ; Arc :: new ( static_secret_handle ) } Some ( ik ) => { self . identity_public_key = Some ( vault . secret_public_key_get ( & ik ) ? ) ; ik } } ; self . identity_key = Some ( identity_key ) ; attributes . persistence = SecretPersistence :: Ephemeral ; // 2. Generate an ephemeral key pair for this handshake and set it to e let ephemeral_secret_handle = vault . secret_generate ( attributes ) ? ; let ephemeral_public_key = vault . secret_public_key_get ( & ephemeral_secret_handle ) ? ; self . ephemeral_key_pair = Some ( KeyPair { public_key : ephemeral_public_key , secret_handle : ephemeral_secret_handle , } ) ; // 3. Set k to empty, Set n to 0 // let nonce = 0; self . key = None ; self . nonce = 0 ; // 4. Set h and ck to protocol name // 5. h = SHA256(h || prologue), // prologue is empty // mix_hash(xx, NULL, 0); let mut h = [ 0u8 ; SHA256_SIZE ] ; h [ .. self . get_protocol_name ( ) . len ( ) ] . copy_from_slice ( self . get_protocol_name ( ) ) ; let attributes = SecretAttributes { stype : SecretType :: Buffer , persistence : SecretPersistence :: Ephemeral , length : SHA256_SIZE , } ; self . ck = Some ( vault . secret_import ( & h , attributes ) ? ) ; self . h = Some ( vault . sha256 ( & h ) ? ) ; Ok ( ( ) ) }
Create a new `HandshakeState` starting with the prologue
Create a new ` HandshakeState ` starting with the prologue
&mut self
&mut self