fn dh(&mut self, secret_handle: &Box<dyn Secret>, public_key: &[u8]) -> OckamResult<()> {
        let ck = self.ck.take().ok_or_else(|| Error::InvalidState.into())?;

        let mut vault = self.vault.lock().unwrap();

        let attributes_ck = SecretAttributes {
            stype: SecretType::Buffer,
            persistence: SecretPersistence::Ephemeral,
            length: SHA256_SIZE,
        };

        let symmetric_secret_info = self.get_symmetric_key_type_and_length();

        let attributes_k = SecretAttributes {
            stype: symmetric_secret_info.0,
            persistence: SecretPersistence::Ephemeral,
            length: symmetric_secret_info.1,
        };

        let ecdh = vault.ec_diffie_hellman(secret_handle, public_key)?;

        let mut hkdf_output =
            vault.hkdf_sha256(&ck, b"", Some(&ecdh), vec![attributes_ck, attributes_k])?;

        if hkdf_output.len() != 2 {
            return Err(Error::InternalVaultError.into());
        }

        let key = self.key.take();
        if key.is_some() {
            vault.secret_destroy(key.unwrap())?;
        }

        self.key = Some(hkdf_output.pop().unwrap());

        vault.secret_destroy(ck)?;
        self.ck = Some(hkdf_output.pop().unwrap());

        self.nonce = 0;

        Ok(())
    }
/// Perform the diffie-hellman computation
Perform the diffie-hellman computation
Perform the diffie - hellman computation
fn dh(&mut self, secret_handle: &Box<dyn Secret>, public_key: &[u8]) -> OckamResult<()> {
        let ck = self.ck.take().ok_or_else(|| Error::InvalidState.into())?;
        let mut vault = self.vault.lock().unwrap();
        let attributes_ck = SecretAttributes {
            stype: SecretType::Buffer,
            persistence: SecretPersistence::Ephemeral,
            length: SHA256_SIZE,
        };
        let symmetric_secret_info = self.get_symmetric_key_type_and_length();
        let attributes_k = SecretAttributes {
            stype: symmetric_secret_info.0,
            persistence: SecretPersistence::Ephemeral,
            length: symmetric_secret_info.1,
        };
        let ecdh = vault.ec_diffie_hellman(secret_handle, public_key)?;
        let mut hkdf_output =
            vault.hkdf_sha256(&ck, b"", Some(&ecdh), vec![attributes_ck, attributes_k])?;
        if hkdf_output.len() != 2 {
            return Err(Error::InternalVaultError.into());
        }
        let key = self.key.take();
        if key.is_some() {
            vault.secret_destroy(key.unwrap())?;
        }
        self.key = Some(hkdf_output.pop().unwrap());
        vault.secret_destroy(ck)?;
        self.ck = Some(hkdf_output.pop().unwrap());
        self.nonce = 0;
        Ok(())
    }
fn dh ( & mut self , secret_handle : & Box < dyn Secret > , public_key : & [ u8 ] ) -> OckamResult < ( ) > { let ck = self . ck . take ( ) . ok_or_else ( | | Error :: InvalidState . into ( ) ) ? ; let mut vault = self . vault . lock ( ) . unwrap ( ) ; let attributes_ck = SecretAttributes { stype : SecretType :: Buffer , persistence : SecretPersistence :: Ephemeral , length : SHA256_SIZE , } ; let symmetric_secret_info = self . get_symmetric_key_type_and_length ( ) ; let attributes_k = SecretAttributes { stype : symmetric_secret_info . 0 , persistence : SecretPersistence :: Ephemeral , length : symmetric_secret_info . 1 , } ; let ecdh = vault . ec_diffie_hellman ( secret_handle , public_key ) ? ; let mut hkdf_output = vault . hkdf_sha256 ( & ck , b" " , Some ( & ecdh ) , vec ! [ attributes_ck attributes_k ] ) ? ; if hkdf_output . len ( ) != 2 { return Err ( Error :: InternalVaultError . into ( ) ) ; } let key = self . key . take ( ) ; if key . is_some ( ) { vault . secret_destroy ( key . unwrap ( ) ) ? ; } self . key = Some ( hkdf_output . pop ( ) . unwrap ( ) ) ; vault . secret_destroy ( ck ) ? ; self . ck = Some ( hkdf_output . pop ( ) . unwrap ( ) ) ; self . nonce = 0 ; Ok ( ( ) ) }
Perform the diffie-hellman computation
Perform the diffie - hellman computation
&mut self
secret_handle
&Box<dyn Secret>
public_key
&[u8]
&mut self
secret_handle
&Box<dyn Secret>
public_key
&[u8]