diff --git a/internal/api/client.go b/internal/api/client.go index 9aa4986..b04ee54 100644 --- a/internal/api/client.go +++ b/internal/api/client.go @@ -369,10 +369,49 @@ type Event struct { } type EventShield struct { - Colour string // "Red" or "Grey" - Code string // "VerificationViolation" or similar + Colour EventShieldColour + Code EventShieldCode } +type EventShieldColour string + +var ( + EventShieldColourRed EventShieldColour = "Red" + EventShieldColourGrey EventShieldColour = "Grey" +) + +type EventShieldCode string + +var ( + // "An unknown reason from the crypto library (if you see this, it is a bug in matrix-js-sdk)." + EventShieldCodeUnknown EventShieldCode = "Unknown" + + // "Encrypted by an unverified user." + EventShieldCodeUnverifiedIdentity EventShieldCode = "UnverifiedIdentity" + + // "Encrypted by a device not verified by its owner." + EventShieldCodeUnsignedDevice EventShieldCode = "UnsignedDevice" + + // "Encrypted by an unknown or deleted device." + EventShieldCodeUnknownDevice EventShieldCode = "UnknownDevice" + + // "The authenticity of this encrypted message can't be guaranteed on this device." + // + // i.e.: the key has been forwarded, or retrieved from an insecure backup. + EventShieldCodeAuthenticityNotGuaranteed EventShieldCode = "AuthenticityNotGuaranteed" + + // "The (deprecated) sender_key field in the event does not match the Ed25519 key of the device that sent us the decryption keys. + // + // No longer used with rust crypto stack, since it doesn't check the sender_key field. + EventShieldCodeMismatchedSenderKey EventShieldCode = "MismatchedSenderKey" + + // "The event was sent unencrypted in an encrypted room." + EventShieldCodeSentInClear EventShieldCode = "SentInClear" + + // "The sender was previously verified but changed their identity." + EventShieldCodeVerificationViolation EventShieldCode = "VerificationViolation" +) + type Waiter interface { // Wait for something to happen, up until the timeout s. If nothing happens, // fail the test with the formatted string provided. diff --git a/internal/api/js/js.go b/internal/api/js/js.go index 2216d1a..5a9a288 100644 --- a/internal/api/js/js.go +++ b/internal/api/js/js.go @@ -587,58 +587,37 @@ func (c *JSClient) GetEventShield(t ct.TestLike, roomID, eventID string) (*api.E var eventShield api.EventShield switch encryptionInfo.ShieldColour { case 1: - eventShield.Colour = "grey" + eventShield.Colour = api.EventShieldColourGrey case 2: - eventShield.Colour = "red" + eventShield.Colour = api.EventShieldColourRed default: return nil, fmt.Errorf("unknown shield colour: %d", encryptionInfo.ShieldColour) } switch encryptionInfo.ShieldReason { case 0: - /** An unknown reason from the crypto library (if you see this, it is a bug in matrix-js-sdk). */ - eventShield.Code = "Unknown" + eventShield.Code = api.EventShieldCodeUnknown case 1: - /** "Encrypted by an unverified user." */ - eventShield.Code = "UnverifiedIdentity" + eventShield.Code = api.EventShieldCodeUnverifiedIdentity case 2: - /** "Encrypted by a device not verified by its owner." */ - eventShield.Code = "UnsignedDevice" + eventShield.Code = api.EventShieldCodeUnsignedDevice case 3: - /** "Encrypted by an unknown or deleted device." */ - eventShield.Code = "UnknownDevice" + eventShield.Code = api.EventShieldCodeUnknownDevice case 4: - /** - * "The authenticity of this encrypted message can't be guaranteed on this device." - * - * i.e.: the key has been forwarded, or retrieved from an insecure backup. - */ - eventShield.Code = "AuthenticityNotGuaranteed" + eventShield.Code = api.EventShieldCodeAuthenticityNotGuaranteed case 5: - /** - * The (deprecated) sender_key field in the event does not match the Ed25519 key of the device that sent us the - * decryption keys. - * - * No longer used with rust crypto stack, since it doesn't check the sender_key field. - */ - eventShield.Code = "MismatchedSenderKey" + eventShield.Code = api.EventShieldCodeMismatchedSenderKey case 6: - /** - * The event was sent unencrypted in an encrypted room. - */ - eventShield.Code = "SentInClear" + eventShield.Code = api.EventShieldCodeSentInClear case 7: - /** - * The sender was previously verified but changed their identity. - */ - eventShield.Code = "VerificationViolation" + eventShield.Code = api.EventShieldCodeVerificationViolation default: return nil, fmt.Errorf("unknown shield reason code: %d", encryptionInfo.ShieldReason) diff --git a/internal/api/rust/rust.go b/internal/api/rust/rust.go index 7c17401..207f9d7 100644 --- a/internal/api/rust/rust.go +++ b/internal/api/rust/rust.go @@ -350,21 +350,21 @@ func (c *RustClient) GetEventShield(t ct.TestLike, roomID, eventID string) (*api } shieldState := timelineItem.LazyProvider.GetShields(false) - codeToString := func(code matrix_sdk_common.ShieldStateCode) string { - var result string + codeToString := func(code matrix_sdk_common.ShieldStateCode) api.EventShieldCode { + var result api.EventShieldCode switch code { case matrix_sdk_common.ShieldStateCodeAuthenticityNotGuaranteed: - result = "AuthenticityNotGuaranteed" + result = api.EventShieldCodeAuthenticityNotGuaranteed case matrix_sdk_common.ShieldStateCodeUnknownDevice: - result = "UnknownDevice" + result = api.EventShieldCodeUnknownDevice case matrix_sdk_common.ShieldStateCodeUnsignedDevice: - result = "UnsignedDevice" + result = api.EventShieldCodeUnsignedDevice case matrix_sdk_common.ShieldStateCodeUnverifiedIdentity: - result = "UnverifiedIdentity" + result = api.EventShieldCodeUnverifiedIdentity case matrix_sdk_common.ShieldStateCodeSentInClear: - result = "SentInClear" + result = api.EventShieldCodeSentInClear case matrix_sdk_common.ShieldStateCodeVerificationViolation: - result = "VerificationViolation" + result = api.EventShieldCodeVerificationViolation default: log.Panicf("Unknown shield code %d", code) } @@ -381,13 +381,13 @@ func (c *RustClient) GetEventShield(t ct.TestLike, roomID, eventID string) (*api case matrix_sdk_ffi.ShieldStateGrey: eventShield = &api.EventShield{ - Colour: "grey", + Colour: api.EventShieldColourGrey, Code: codeToString(shield.(matrix_sdk_ffi.ShieldStateGrey).Code), } case matrix_sdk_ffi.ShieldStateRed: eventShield = &api.EventShield{ - Colour: "red", + Colour: api.EventShieldColourRed, Code: codeToString(shield.(matrix_sdk_ffi.ShieldStateRed).Code), } }