Files
letro-ios/ElementX/Sources/Services/Timeline/TimelineItemContent/EncryptionAuthenticity.swift
Valere 6b8d440be6 Show Encryption Authenticity warnings on messages in the timeline. (#3051)
* Initial implementation.

* Add developer option for showing timeline item authenticity.

* Refactor code to use new SendInfo.Status.

---------

Co-authored-by: Doug <douglase@element.io>
2024-08-05 11:15:38 +00:00

75 lines
2.4 KiB
Swift

//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import Foundation
import MatrixRustSDK
/// Represents and issue with a timeline item's authenticity such as coming from an
/// unsigned session or being sent unencrypted in an encrypted room. See Rust's
/// `ShieldStateCode` for more information about the meaning of the cases.
enum EncryptionAuthenticity: Hashable {
enum Color { case red, gray }
case notGuaranteed(color: Color)
case unknownDevice(color: Color)
case unsignedDevice(color: Color)
case unverifiedIdentity(color: Color)
case sentInClear(color: Color)
var message: String {
switch self {
case .notGuaranteed:
L10n.eventShieldReasonAuthenticityNotGuaranteed
case .unknownDevice:
L10n.eventShieldReasonUnknownDevice
case .unsignedDevice:
L10n.eventShieldReasonUnsignedDevice
case .unverifiedIdentity:
L10n.eventShieldReasonUnverifiedIdentity
case .sentInClear:
L10n.eventShieldReasonSentInClear
}
}
}
extension EncryptionAuthenticity {
init?(shieldState: ShieldState) {
switch shieldState {
case .red(let code, _):
self.init(shieldStateCode: code, color: .red)
case .grey(let code, _):
self.init(shieldStateCode: code, color: .gray)
case .none:
return nil
}
}
init(shieldStateCode: ShieldStateCode, color: EncryptionAuthenticity.Color) {
switch shieldStateCode {
case .authenticityNotGuaranteed:
self = .notGuaranteed(color: color)
case .unknownDevice:
self = .unknownDevice(color: color)
case .unsignedDevice:
self = .unsignedDevice(color: color)
case .unverifiedIdentity:
self = .unverifiedIdentity(color: color)
case .sentInClear:
self = .sentInClear(color: color)
}
}
}