-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathFeature.MLS.swift
117 lines (84 loc) · 4.6 KB
/
Feature.MLS.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//
// Wire
// Copyright (C) 2024 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
import Foundation
public extension Feature {
struct MLS: Codable {
// MARK: - Properties
/// Whether MLS is availble to the user.
public let status: Status
/// The configuration used to control how the MLS behaves.
public let config: Config
// MARK: - Life cycle
public init(status: Feature.Status = .disabled, config: Config = .init()) {
self.status = status
self.config = config
}
// MARK: - Types
// WARNING: This config is encoded and stored in the database, so any changes
// to it will require some migration code.
public struct Config: Codable, Equatable {
/// The ids of users who have the option to create new MLS groups.
public let protocolToggleUsers: [UUID]
/// The default protocol to use when creating a conversation.
public let defaultProtocol: MessageProtocol
/// The list of cipher suites that are allowed to be used with mls.
public let allowedCipherSuites: [MLSCipherSuite]
/// The default cipher suite used when creating a new MLS group.
public let defaultCipherSuite: MLSCipherSuite
/// The list of supported message protocols.
public let supportedProtocols: Set<MessageProtocol>
public init(
protocolToggleUsers: [UUID] = [],
defaultProtocol: MessageProtocol = .proteus,
allowedCipherSuites: [MLSCipherSuite] = [.MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519],
defaultCipherSuite: MLSCipherSuite = .MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519,
supportedProtocols: Set<MessageProtocol> = []
) {
self.protocolToggleUsers = protocolToggleUsers
self.defaultProtocol = defaultProtocol
self.allowedCipherSuites = allowedCipherSuites
self.defaultCipherSuite = defaultCipherSuite
self.supportedProtocols = supportedProtocols
}
public init(from decoder: any Decoder) throws {
let container: KeyedDecodingContainer<Feature.MLS.Config.CodingKeys> = try decoder.container(keyedBy: Feature.MLS.Config.CodingKeys.self)
self.protocolToggleUsers = try container.decode([UUID].self, forKey: Feature.MLS.Config.CodingKeys.protocolToggleUsers)
self.defaultProtocol = try container.decode(Feature.MLS.Config.MessageProtocol.self, forKey: Feature.MLS.Config.CodingKeys.defaultProtocol)
self.allowedCipherSuites = try container.decode([Feature.MLS.Config.MLSCipherSuite].self, forKey: Feature.MLS.Config.CodingKeys.allowedCipherSuites)
self.defaultCipherSuite = try container.decode(Feature.MLS.Config.MLSCipherSuite.self, forKey: Feature.MLS.Config.CodingKeys.defaultCipherSuite)
// Supported protocols was added in v4 so we decode if present and provide a default if it's not there.
self.supportedProtocols = try container.decodeIfPresent(Set<Feature.MLS.Config.MessageProtocol>.self, forKey: Feature.MLS.Config.CodingKeys.supportedProtocols) ?? [.proteus]
}
public enum MessageProtocol: String, Codable {
case proteus
case mls
case mixed
}
@objc
public enum MLSCipherSuite: Int, Codable {
case MLS_128_DHKEMX25519_AES128GCM_SHA256_Ed25519 = 1
case MLS_128_DHKEMP256_AES128GCM_SHA256_P256 = 2
case MLS_128_DHKEMX25519_CHACHA20POLY1305_SHA256_Ed25519 = 3
case MLS_256_DHKEMX448_AES256GCM_SHA512_Ed448 = 4
case MLS_256_DHKEMP521_AES256GCM_SHA512_P521 = 5
case MLS_256_DHKEMX448_CHACHA20POLY1305_SHA512_Ed448 = 6
case MLS_256_DHKEMP384_AES256GCM_SHA384_P384 = 7
}
}
}
}