mirror of
https://github.com/element-hq/element-android
synced 2024-12-20 00:13:12 +03:00
crypto: Use the new CancelInfo struct
This commit is contained in:
parent
7650e43362
commit
b33537fd6e
7 changed files with 50 additions and 33 deletions
|
@ -208,6 +208,7 @@ internal class QrCodeVerification(
|
|||
get() {
|
||||
refreshData()
|
||||
val inner = this.inner
|
||||
val cancelInfo = inner?.cancelInfo
|
||||
|
||||
return if (inner != null) {
|
||||
when {
|
||||
|
@ -215,9 +216,9 @@ internal class QrCodeVerification(
|
|||
inner.reciprocated -> VerificationTxState.Started
|
||||
inner.hasBeenConfirmed -> VerificationTxState.WaitingOtherReciprocateConfirm
|
||||
inner.otherSideScanned -> VerificationTxState.QrScannedByOther
|
||||
inner.isCancelled -> {
|
||||
val cancelCode = safeValueOf(inner.cancelCode)
|
||||
val byMe = inner.cancelledByUs ?: false
|
||||
cancelInfo != null -> {
|
||||
val cancelCode = safeValueOf(cancelInfo.cancelCode)
|
||||
val byMe = cancelInfo.cancelledByUs
|
||||
VerificationTxState.Cancelled(cancelCode, byMe)
|
||||
}
|
||||
else -> {
|
||||
|
|
|
@ -82,11 +82,11 @@ internal class SasVerification(
|
|||
override var state: VerificationTxState
|
||||
get() {
|
||||
refreshData()
|
||||
val cancelInfo = this.inner.cancelInfo
|
||||
return when {
|
||||
this.inner.isCancelled -> {
|
||||
val cancelCode = safeValueOf(this.inner.cancelCode)
|
||||
val byMe = this.inner.cancelledByUs ?: false
|
||||
VerificationTxState.Cancelled(cancelCode, byMe)
|
||||
cancelInfo != null -> {
|
||||
val cancelCode = safeValueOf(cancelInfo.cancelCode)
|
||||
VerificationTxState.Cancelled(cancelCode, cancelInfo.cancelledByUs)
|
||||
}
|
||||
this.inner.isDone -> VerificationTxState.Verified
|
||||
this.inner.haveWeConfirmed -> VerificationTxState.ShortCodeAccepted
|
||||
|
|
|
@ -180,11 +180,10 @@ internal class VerificationRequest(
|
|||
|
||||
fun toPendingVerificationRequest(): PendingVerificationRequest {
|
||||
refreshData()
|
||||
val code = this.inner.cancelCode
|
||||
|
||||
val cancelInfo = this.inner.cancelInfo
|
||||
val cancelCode =
|
||||
if (code != null) {
|
||||
safeValueOf(code)
|
||||
if (cancelInfo != null) {
|
||||
safeValueOf(cancelInfo.cancelCode)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ features = ["lax_deserialize"]
|
|||
|
||||
[dependencies.matrix-sdk-common]
|
||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||
rev = "b53518d1b8dd93ac447d1318c2e8aa4e2004dd2f"
|
||||
rev = "3a8ff2f6b43f312b7582146ed712ff245ef9d5aa"
|
||||
|
||||
[dependencies.matrix-sdk-crypto]
|
||||
git = "https://github.com/matrix-org/matrix-rust-sdk/"
|
||||
rev = "b53518d1b8dd93ac447d1318c2e8aa4e2004dd2f"
|
||||
rev = "3a8ff2f6b43f312b7582146ed712ff245ef9d5aa"
|
||||
features = ["sled_cryptostore"]
|
||||
|
||||
[dependencies.tokio]
|
||||
|
|
|
@ -8,8 +8,8 @@ pub use device::Device;
|
|||
pub use error::{CryptoStoreError, DecryptionError, KeyImportError, MachineCreationError};
|
||||
pub use logger::{set_logger, Logger};
|
||||
pub use machine::{
|
||||
KeyRequestPair, OlmMachine, QrCode, RequestVerificationResult, Sas, ScanResult, StartSasResult,
|
||||
Verification, VerificationRequest,
|
||||
CancelInfo, KeyRequestPair, OlmMachine, QrCode, RequestVerificationResult, Sas, ScanResult,
|
||||
StartSasResult, Verification, VerificationRequest,
|
||||
};
|
||||
pub use responses::{
|
||||
DeviceLists, KeysImportResult, OutgoingVerificationRequest, Request, RequestType,
|
||||
|
|
|
@ -30,9 +30,10 @@ use tokio::runtime::Runtime;
|
|||
|
||||
use matrix_sdk_common::{deserialized_responses::AlgorithmInfo, uuid::Uuid};
|
||||
use matrix_sdk_crypto::{
|
||||
decrypt_key_export, encrypt_key_export, matrix_qrcode::QrVerificationData, EncryptionSettings,
|
||||
LocalTrust, OlmMachine as InnerMachine, QrVerification as InnerQr, Sas as InnerSas,
|
||||
Verification as RustVerification, VerificationRequest as InnerVerificationRequest,
|
||||
decrypt_key_export, encrypt_key_export, matrix_qrcode::QrVerificationData,
|
||||
CancelInfo as RustCancelInfo, EncryptionSettings, LocalTrust, OlmMachine as InnerMachine,
|
||||
QrVerification as InnerQr, Sas as InnerSas, Verification as RustVerification,
|
||||
VerificationRequest as InnerVerificationRequest,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -61,8 +62,7 @@ pub struct Sas {
|
|||
pub have_we_confirmed: bool,
|
||||
pub is_cancelled: bool,
|
||||
pub is_done: bool,
|
||||
pub cancel_code: Option<String>,
|
||||
pub cancelled_by_us: Option<bool>,
|
||||
pub cancel_info: Option<CancelInfo>,
|
||||
pub has_been_accepted: bool,
|
||||
pub we_started: bool,
|
||||
pub can_be_presented: bool,
|
||||
|
@ -81,8 +81,7 @@ pub struct QrCode {
|
|||
pub other_side_scanned: bool,
|
||||
pub has_been_confirmed: bool,
|
||||
pub reciprocated: bool,
|
||||
pub cancel_code: Option<String>,
|
||||
pub cancelled_by_us: Option<bool>,
|
||||
pub cancel_info: Option<CancelInfo>,
|
||||
}
|
||||
|
||||
impl From<InnerQr> for QrCode {
|
||||
|
@ -92,8 +91,7 @@ impl From<InnerQr> for QrCode {
|
|||
flow_id: qr.flow_id().as_str().to_owned(),
|
||||
is_cancelled: qr.is_cancelled(),
|
||||
is_done: qr.is_done(),
|
||||
cancel_code: qr.cancel_code().map(|c| c.to_string()),
|
||||
cancelled_by_us: qr.cancelled_by_us(),
|
||||
cancel_info: qr.cancel_info().map(|c| c.into()),
|
||||
reciprocated: qr.reciprocated(),
|
||||
we_started: qr.we_started(),
|
||||
other_side_scanned: qr.has_been_scanned(),
|
||||
|
@ -104,6 +102,22 @@ impl From<InnerQr> for QrCode {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct CancelInfo {
|
||||
pub reason: String,
|
||||
pub cancel_code: String,
|
||||
pub cancelled_by_us: bool,
|
||||
}
|
||||
|
||||
impl From<RustCancelInfo> for CancelInfo {
|
||||
fn from(c: RustCancelInfo) -> Self {
|
||||
Self {
|
||||
reason: c.reason().to_owned(),
|
||||
cancel_code: c.cancel_code().to_string(),
|
||||
cancelled_by_us: c.cancelled_by_us(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StartSasResult {
|
||||
pub sas: Sas,
|
||||
pub request: OutgoingVerificationRequest,
|
||||
|
@ -126,11 +140,10 @@ impl From<InnerSas> for Sas {
|
|||
timed_out: sas.timed_out(),
|
||||
supports_emoji: sas.supports_emoji(),
|
||||
have_we_confirmed: sas.have_we_confirmed(),
|
||||
cancel_code: sas.cancel_code().map(|c| c.as_str().to_owned()),
|
||||
we_started: sas.we_started(),
|
||||
room_id: sas.room_id().map(|r| r.to_string()),
|
||||
cancelled_by_us: sas.cancelled_by_us(),
|
||||
has_been_accepted: sas.has_been_accepted(),
|
||||
cancel_info: sas.cancel_info().map(|c| c.into()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -148,11 +161,11 @@ pub struct VerificationRequest {
|
|||
pub is_done: bool,
|
||||
pub is_ready: bool,
|
||||
pub room_id: Option<String>,
|
||||
pub cancel_code: Option<String>,
|
||||
pub we_started: bool,
|
||||
pub is_passive: bool,
|
||||
pub their_methods: Option<Vec<String>>,
|
||||
pub our_methods: Option<Vec<String>>,
|
||||
pub cancel_info: Option<CancelInfo>,
|
||||
}
|
||||
|
||||
impl From<InnerVerificationRequest> for VerificationRequest {
|
||||
|
@ -165,9 +178,9 @@ impl From<InnerVerificationRequest> for VerificationRequest {
|
|||
is_done: v.is_done(),
|
||||
is_ready: v.is_ready(),
|
||||
room_id: v.room_id().map(|r| r.to_string()),
|
||||
cancel_code: v.cancel_code().map(|c| c.as_str().to_owned()),
|
||||
we_started: v.we_started(),
|
||||
is_passive: v.is_passive(),
|
||||
cancel_info: v.cancel_info().map(|c| c.into()),
|
||||
their_methods: v
|
||||
.their_supported_methods()
|
||||
.map(|v| v.into_iter().map(|m| m.to_string()).collect()),
|
||||
|
|
|
@ -65,6 +65,12 @@ dictionary Device {
|
|||
boolean cross_signing_trusted;
|
||||
};
|
||||
|
||||
dictionary CancelInfo {
|
||||
string cancel_code;
|
||||
string reason;
|
||||
boolean cancelled_by_us;
|
||||
};
|
||||
|
||||
dictionary StartSasResult {
|
||||
Sas sas;
|
||||
OutgoingVerificationRequest request;
|
||||
|
@ -74,10 +80,8 @@ dictionary Sas {
|
|||
string other_user_id;
|
||||
string other_device_id;
|
||||
string flow_id;
|
||||
string? cancel_code;
|
||||
string? room_id;
|
||||
boolean we_started;
|
||||
boolean? cancelled_by_us;
|
||||
boolean has_been_accepted;
|
||||
boolean have_we_confirmed;
|
||||
boolean is_done;
|
||||
|
@ -85,6 +89,7 @@ dictionary Sas {
|
|||
boolean can_be_presented;
|
||||
boolean timed_out;
|
||||
boolean supports_emoji;
|
||||
CancelInfo? cancel_info;
|
||||
};
|
||||
|
||||
dictionary ScanResult {
|
||||
|
@ -97,15 +102,14 @@ dictionary QrCode {
|
|||
string other_user_id;
|
||||
string other_device_id;
|
||||
string flow_id;
|
||||
string? cancel_code;
|
||||
string? room_id;
|
||||
boolean reciprocated;
|
||||
boolean we_started;
|
||||
boolean has_been_confirmed;
|
||||
boolean? cancelled_by_us;
|
||||
boolean is_done;
|
||||
boolean is_cancelled;
|
||||
boolean other_side_scanned;
|
||||
CancelInfo? cancel_info;
|
||||
};
|
||||
|
||||
dictionary VerificationRequest {
|
||||
|
@ -118,7 +122,7 @@ dictionary VerificationRequest {
|
|||
boolean we_started;
|
||||
boolean is_passive;
|
||||
string? room_id;
|
||||
string? cancel_code;
|
||||
CancelInfo? cancel_info;
|
||||
sequence<string>? their_methods;
|
||||
sequence<string>? our_methods;
|
||||
|
||||
|
|
Loading…
Reference in a new issue