pub(crate) async fn create_outbound_session(
        &self,
        device: ReadOnlyDevice,
        key_map: &BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>,
    ) -> Result<Session, SessionCreationError> {
        let one_time_key = key_map.values().next().ok_or_else(|| {
            SessionCreationError::OneTimeKeyMissing(
                device.user_id().to_owned(),
                device.device_id().into(),
            )
        })?;

        let one_time_key: SignedKey = match one_time_key.deserialize() {
            Ok(OneTimeKey::SignedKey(k)) => k,
            Ok(OneTimeKey::Key(_)) => {
                return Err(SessionCreationError::OneTimeKeyNotSigned(
                    device.user_id().to_owned(),
                    device.device_id().into(),
                ));
            }
            Ok(_) => {
                return Err(SessionCreationError::OneTimeKeyUnknown(
                    device.user_id().to_owned(),
                    device.device_id().into(),
                ));
            }
            Err(e) => return Err(SessionCreationError::InvalidJson(e)),
        };

        device.verify_one_time_key(&one_time_key).map_err(|e| {
            SessionCreationError::InvalidSignature(
                device.user_id().to_owned(),
                device.device_id().into(),
                e,
            )
        })?;

        let curve_key = device.get_key(DeviceKeyAlgorithm::Curve25519).ok_or_else(|| {
            SessionCreationError::DeviceMissingCurveKey(
                device.user_id().to_owned(),
                device.device_id().into(),
            )
        })?;

        self.create_outbound_session_helper(curve_key, &one_time_key).await.map_err(|e| {
            SessionCreationError::OlmError(
                device.user_id().to_owned(),
                device.device_id().into(),
                e,
            )
        })
    }
/// Create a new session with another account given a one-time key and a
/// device.
///
/// Returns the newly created session or a `OlmSessionError` if creating a
/// session failed.
///
/// # Arguments
/// * `device` - The other account's device.
///
/// * `key_map` - A map from the algorithm and device id to the one-time key
///   that the other account created and shared with us.
Create a new session with another account given a one-time key and a
device.

Returns the newly created session or a `OlmSessionError` if creating a
session failed.
Create a new session with another account given a one - time key and a device . Returns the newly created session or a ` OlmSessionError ` if creating a session failed .
pub(crate) async fn create_outbound_session(
        &self,
        device: ReadOnlyDevice,
        key_map: &BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>,
    ) -> Result<Session, SessionCreationError> {
        let one_time_key = key_map.values().next().ok_or_else(|| {
            SessionCreationError::OneTimeKeyMissing(
                device.user_id().to_owned(),
                device.device_id().into(),
            )
        })?;
        let one_time_key: SignedKey = match one_time_key.deserialize() {
            Ok(OneTimeKey::SignedKey(k)) => k,
            Ok(OneTimeKey::Key(_)) => {
                return Err(SessionCreationError::OneTimeKeyNotSigned(
                    device.user_id().to_owned(),
                    device.device_id().into(),
                ));
            }
            Ok(_) => {
                return Err(SessionCreationError::OneTimeKeyUnknown(
                    device.user_id().to_owned(),
                    device.device_id().into(),
                ));
            }
            Err(e) => return Err(SessionCreationError::InvalidJson(e)),
        };
        device.verify_one_time_key(&one_time_key).map_err(|e| {
            SessionCreationError::InvalidSignature(
                device.user_id().to_owned(),
                device.device_id().into(),
                e,
            )
        })?;
        let curve_key = device.get_key(DeviceKeyAlgorithm::Curve25519).ok_or_else(|| {
            SessionCreationError::DeviceMissingCurveKey(
                device.user_id().to_owned(),
                device.device_id().into(),
            )
        })?;
        self.create_outbound_session_helper(curve_key, &one_time_key).await.map_err(|e| {
            SessionCreationError::OlmError(
                device.user_id().to_owned(),
                device.device_id().into(),
                e,
            )
        })
    }
pub ( crate ) async fn create_outbound_session ( & self , device : ReadOnlyDevice , key_map : & BTreeMap < Box < DeviceKeyId > , Raw < OneTimeKey > > , ) -> Result < Session , SessionCreationError > { let one_time_key = key_map . values ( ) . next ( ) . ok_or_else ( | | { SessionCreationError :: OneTimeKeyMissing ( device . user_id ( ) . to_owned ( ) , device . device_id ( ) . into ( ) , ) } ) ? ; let one_time_key : SignedKey = match one_time_key . deserialize ( ) { Ok ( OneTimeKey :: SignedKey ( k ) ) => k , Ok ( OneTimeKey :: Key ( _ ) ) => { return Err ( SessionCreationError :: OneTimeKeyNotSigned ( device . user_id ( ) . to_owned ( ) , device . device_id ( ) . into ( ) , ) ) ; } Ok ( _ ) => { return Err ( SessionCreationError :: OneTimeKeyUnknown ( device . user_id ( ) . to_owned ( ) , device . device_id ( ) . into ( ) , ) ) ; } Err ( e ) => return Err ( SessionCreationError :: InvalidJson ( e ) ) , } ; device . verify_one_time_key ( & one_time_key ) . map_err ( | e | { SessionCreationError :: InvalidSignature ( device . user_id ( ) . to_owned ( ) , device . device_id ( ) . into ( ) , e , ) } ) ? ; let curve_key = device . get_key ( DeviceKeyAlgorithm :: Curve25519 ) . ok_or_else ( | | { SessionCreationError :: DeviceMissingCurveKey ( device . user_id ( ) . to_owned ( ) , device . device_id ( ) . into ( ) , ) } ) ? ; self . create_outbound_session_helper ( curve_key , & one_time_key ) . await . map_err ( | e | { SessionCreationError :: OlmError ( device . user_id ( ) . to_owned ( ) , device . device_id ( ) . into ( ) , e , ) } ) }
Create a new session with another account given a one-time key and a
device.
Create a new session with another account given a one - time key and a device .
&self
device
ReadOnlyDevice
key_map
&BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>
&self
device
ReadOnlyDevice
key_map
&BTreeMap<Box<DeviceKeyId>, Raw<OneTimeKey>>