1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Use shield status codes from Rust rather than string matching (#4529)

This commit is contained in:
Hubert Chathi
2024-11-26 10:06:57 -05:00
committed by GitHub
parent 006929ac0c
commit 69647a33b6
3 changed files with 58 additions and 23 deletions

View File

@@ -1157,6 +1157,16 @@ export enum EventShieldReason {
* decryption keys.
*/
MISMATCHED_SENDER_KEY,
/**
* The event was sent unencrypted in an encrypted room.
*/
SENT_IN_CLEAR,
/**
* The sender was previously verified but changed their identity.
*/
VERIFICATION_VIOLATION,
}
/** The result of a call to {@link CryptoApi.getOwnDeviceKeys} */

View File

@@ -2180,22 +2180,29 @@ function rustEncryptionInfoToJsEncryptionInfo(
}
let shieldReason: EventShieldReason | null;
if (shieldState.message === undefined) {
shieldReason = null;
} else if (shieldState.message === "Encrypted by an unverified user.") {
// this case isn't actually used with lax shield semantics.
shieldReason = EventShieldReason.UNVERIFIED_IDENTITY;
} else if (shieldState.message === "Encrypted by a device not verified by its owner.") {
shieldReason = EventShieldReason.UNSIGNED_DEVICE;
} else if (
shieldState.message === "The authenticity of this encrypted message can't be guaranteed on this device."
) {
shieldReason = EventShieldReason.AUTHENTICITY_NOT_GUARANTEED;
} else if (shieldState.message === "Encrypted by an unknown or deleted device.") {
shieldReason = EventShieldReason.UNKNOWN_DEVICE;
} else {
logger.warn(`Unknown shield state message '${shieldState.message}'`);
shieldReason = EventShieldReason.UNKNOWN;
switch (shieldState.code) {
case undefined:
case null:
shieldReason = null;
break;
case RustSdkCryptoJs.ShieldStateCode.AuthenticityNotGuaranteed:
shieldReason = EventShieldReason.AUTHENTICITY_NOT_GUARANTEED;
break;
case RustSdkCryptoJs.ShieldStateCode.UnknownDevice:
shieldReason = EventShieldReason.UNKNOWN_DEVICE;
break;
case RustSdkCryptoJs.ShieldStateCode.UnsignedDevice:
shieldReason = EventShieldReason.UNSIGNED_DEVICE;
break;
case RustSdkCryptoJs.ShieldStateCode.UnverifiedIdentity:
shieldReason = EventShieldReason.UNVERIFIED_IDENTITY;
break;
case RustSdkCryptoJs.ShieldStateCode.SentInClear:
shieldReason = EventShieldReason.SENT_IN_CLEAR;
break;
case RustSdkCryptoJs.ShieldStateCode.PreviouslyVerified:
shieldReason = EventShieldReason.VERIFICATION_VIOLATION;
break;
}
return { shieldColour, shieldReason };