diff --git a/lib/encryption/encryption.dart b/lib/encryption/encryption.dart index e9245d33..754d36d5 100644 --- a/lib/encryption/encryption.dart +++ b/lib/encryption/encryption.dart @@ -135,7 +135,7 @@ class Encryption { Map decryptedPayload; var canRequestSession = false; try { - if (event.content['algorithm'] != 'm.megolm.v1.aes-sha2') { + if (event.content['algorithm'] != AlgorithmTypes.megolmV1AesSha2) { throw (DecryptError.UNKNOWN_ALGORITHM); } final String sessionId = event.content['session_id']; @@ -277,7 +277,7 @@ class Encryption { if (room == null || !room.encrypted || !enabled) { return payload; } - if (room.encryptionAlgorithm != 'm.megolm.v1.aes-sha2') { + if (room.encryptionAlgorithm != AlgorithmTypes.megolmV1AesSha2) { throw ('Unknown encryption algorithm'); } if (keyManager.getOutboundGroupSession(roomId) == null) { @@ -301,7 +301,7 @@ class Encryption { 'room_id': roomId, }; var encryptedPayload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'ciphertext': sess.outboundGroupSession.encrypt(json.encode(payloadContent)), 'device_id': client.deviceID, diff --git a/lib/encryption/key_manager.dart b/lib/encryption/key_manager.dart index 352196a9..c63892de 100644 --- a/lib/encryption/key_manager.dart +++ b/lib/encryption/key_manager.dart @@ -98,7 +98,7 @@ class KeyManager { } final oldSession = getInboundGroupSession(roomId, sessionId, senderKey, otherRooms: false); - if (content['algorithm'] != 'm.megolm.v1.aes-sha2') { + if (content['algorithm'] != AlgorithmTypes.megolmV1AesSha2) { return; } olm.InboundGroupSession inboundGroupSession; @@ -344,7 +344,7 @@ class KeyManager { sess.sentMessages++; sess.devices = newDeviceKeyIds; final rawSession = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': room.id, 'session_id': sess.outboundGroupSession.session_id(), 'session_key': sess.outboundGroupSession.session_key(), @@ -403,7 +403,7 @@ class KeyManager { return null; } final rawSession = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': room.id, 'session_id': outboundGroupSession.session_id(), 'session_key': outboundGroupSession.session_key(), @@ -607,7 +607,7 @@ class KeyManager { { 'action': 'request', 'body': { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': room.id, 'sender_key': senderKey, 'session_id': sessionId, @@ -949,7 +949,7 @@ RoomKeys _generateUploadKeys(_GenerateUploadKeysArgs args) { } // generate the encrypted content final payload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'forwarding_curve25519_key_chain': sess.forwardingCurve25519KeyChain, 'sender_key': sess.senderKey, 'sender_clencaimed_keys': sess.senderClaimedKeys, diff --git a/lib/encryption/olm_manager.dart b/lib/encryption/olm_manager.dart index 9c8bd49e..e98032ad 100644 --- a/lib/encryption/olm_manager.dart +++ b/lib/encryption/olm_manager.dart @@ -177,8 +177,8 @@ class OlmManager { 'user_id': client.userID, 'device_id': client.deviceID, 'algorithms': [ - 'm.olm.v1.curve25519-aes-sha2', - 'm.megolm.v1.aes-sha2' + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 ], 'keys': {}, }, @@ -251,7 +251,7 @@ class OlmManager { if (event.type != EventTypes.Encrypted) { return event; } - if (event.content['algorithm'] != 'm.olm.v1.curve25519-aes-sha2') { + if (event.content['algorithm'] != AlgorithmTypes.olmV1Curve25519AesSha2) { throw ('Unknown algorithm: ${event.content['algorithm']}'); } if (!event.content['ciphertext'].containsKey(identityKey)) { @@ -476,7 +476,7 @@ class OlmManager { final encryptResult = sess.first.session.encrypt(json.encode(fullPayload)); storeOlmSession(sess.first); final encryptedBody = { - 'algorithm': 'm.olm.v1.curve25519-aes-sha2', + 'algorithm': AlgorithmTypes.olmV1Curve25519AesSha2, 'sender_key': identityKey, 'ciphertext': {}, }; diff --git a/lib/encryption/ssss.dart b/lib/encryption/ssss.dart index 382a9430..fa9d7f39 100644 --- a/lib/encryption/ssss.dart +++ b/lib/encryption/ssss.dart @@ -169,7 +169,7 @@ class SSSS { bool checkKey(Uint8List key, BasicEvent keyData) { final info = keyData.content; - if (info['algorithm'] == 'm.secret_storage.v1.aes-hmac-sha2') { + if (info['algorithm'] == AlgorithmTypes.secretStorageV1AesHmcSha2) { if ((info['mac'] is String) && (info['iv'] is String)) { final encrypted = encryptAes(ZERO_STR, key, '', info['iv']); return info['mac'].replaceAll(RegExp(r'=+$'), '') == diff --git a/lib/matrix_api.dart b/lib/matrix_api.dart index b6e19ec9..d24abfee 100644 --- a/lib/matrix_api.dart +++ b/lib/matrix_api.dart @@ -19,6 +19,7 @@ library matrix_api; export 'matrix_api/matrix_api.dart'; +export 'matrix_api/model/algorithm_types.dart'; export 'matrix_api/model/basic_event.dart'; export 'matrix_api/model/basic_event_with_sender.dart'; export 'matrix_api/model/basic_room_event.dart'; diff --git a/lib/matrix_api/model/algorithm_types.dart b/lib/matrix_api/model/algorithm_types.dart new file mode 100644 index 00000000..457b4799 --- /dev/null +++ b/lib/matrix_api/model/algorithm_types.dart @@ -0,0 +1,26 @@ +/* + * Famedly Matrix SDK + * Copyright (C) 2019, 2020 Famedly GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +abstract class AlgorithmTypes { + static const String olmV1Curve25519AesSha2 = 'm.olm.v1.curve25519-aes-sha2'; + static const String megolmV1AesSha2 = 'm.megolm.v1.aes-sha2'; + static const String secretStorageV1AesHmcSha2 = + 'm.secret_storage.v1.aes-hmac-sha2'; + static const String megolmBackupV1Curve25519AesSha2 = + 'm.megolm_backup.v1.curve25519-aes-sha2'; +} diff --git a/lib/matrix_api/model/room_keys_info.dart b/lib/matrix_api/model/room_keys_info.dart index f7a2cfe1..3f55f8cc 100644 --- a/lib/matrix_api/model/room_keys_info.dart +++ b/lib/matrix_api/model/room_keys_info.dart @@ -16,13 +16,15 @@ * along with this program. If not, see . */ +import '../../matrix_api.dart'; + enum RoomKeysAlgorithmType { v1Curve25519AesSha2 } extension RoomKeysAlgorithmTypeExtension on RoomKeysAlgorithmType { String get algorithmString { switch (this) { case RoomKeysAlgorithmType.v1Curve25519AesSha2: - return 'm.megolm_backup.v1.curve25519-aes-sha2'; + return AlgorithmTypes.megolmBackupV1Curve25519AesSha2; default: return null; } @@ -30,7 +32,7 @@ extension RoomKeysAlgorithmTypeExtension on RoomKeysAlgorithmType { static RoomKeysAlgorithmType fromAlgorithmString(String s) { switch (s) { - case 'm.megolm_backup.v1.curve25519-aes-sha2': + case AlgorithmTypes.megolmBackupV1Curve25519AesSha2: return RoomKeysAlgorithmType.v1Curve25519AesSha2; default: return null; diff --git a/lib/src/client.dart b/lib/src/client.dart index 4c3f2710..aba61d1f 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -523,10 +523,10 @@ class Client extends MatrixApi { '{"room":{"state":{"lazy_load_members":true}}}'; static const String messagesFilters = '{"lazy_load_members":true}'; static const List supportedDirectEncryptionAlgorithms = [ - 'm.olm.v1.curve25519-aes-sha2' + AlgorithmTypes.olmV1Curve25519AesSha2 ]; static const List supportedGroupEncryptionAlgorithms = [ - 'm.megolm.v1.aes-sha2' + AlgorithmTypes.megolmV1AesSha2 ]; static const int defaultThumbnailSize = 256; diff --git a/test/client_test.dart b/test/client_test.dart index ad6f3c70..dc6e1475 100644 --- a/test/client_test.dart +++ b/test/client_test.dart @@ -357,7 +357,10 @@ void main() { var deviceKeys = DeviceKeys.fromJson({ 'user_id': '@alice:example.com', 'device_id': 'JLAFKJWSCS', - 'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], + 'algorithms': [ + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 + ], 'keys': { 'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', 'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI' diff --git a/test/device_keys_list_test.dart b/test/device_keys_list_test.dart index 4b870d3e..1621bee9 100644 --- a/test/device_keys_list_test.dart +++ b/test/device_keys_list_test.dart @@ -33,7 +33,10 @@ void main() { var rawJson = { 'user_id': '@alice:example.com', 'device_id': 'JLAFKJWSCS', - 'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], + 'algorithms': [ + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 + ], 'keys': { 'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', diff --git a/test/encryption/encrypt_decrypt_room_message_test.dart b/test/encryption/encrypt_decrypt_room_message_test.dart index 711a4a4a..484d211f 100644 --- a/test/encryption/encrypt_decrypt_room_message_test.dart +++ b/test/encryption/encrypt_decrypt_room_message_test.dart @@ -53,7 +53,7 @@ void main() { 'msgtype': 'm.text', 'text': 'Hello foxies!', }); - expect(payload['algorithm'], 'm.megolm.v1.aes-sha2'); + expect(payload['algorithm'], AlgorithmTypes.megolmV1AesSha2); expect(payload['ciphertext'] is String, true); expect(payload['device_id'], client.deviceID); expect(payload['sender_key'], client.identityKey); diff --git a/test/encryption/encrypt_decrypt_to_device_test.dart b/test/encryption/encrypt_decrypt_to_device_test.dart index 45c6122c..afdbc7c1 100644 --- a/test/encryption/encrypt_decrypt_to_device_test.dart +++ b/test/encryption/encrypt_decrypt_to_device_test.dart @@ -65,7 +65,10 @@ void main() { device = DeviceKeys.fromJson({ 'user_id': client.userID, 'device_id': client.deviceID, - 'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], + 'algorithms': [ + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 + ], 'keys': { 'curve25519:${client.deviceID}': client.identityKey, 'ed25519:${client.deviceID}': client.fingerprintKey, diff --git a/test/encryption/key_manager_test.dart b/test/encryption/key_manager_test.dart index 6d3783b6..19eaf10c 100644 --- a/test/encryption/key_manager_test.dart +++ b/test/encryption/key_manager_test.dart @@ -56,7 +56,7 @@ void main() { sender: '@alice:example.com', type: 'm.room_key', content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'session_id': validSessionId, 'session_key': sessionKey, @@ -79,7 +79,7 @@ void main() { sender: '@alice:example.com', type: 'm.room_key', content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'session_id': validSessionId, 'session_key': sessionKey, @@ -161,7 +161,10 @@ void main() { DeviceKeys.fromJson({ 'user_id': '@alice:example.com', 'device_id': 'NEWDEVICE', - 'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], + 'algorithms': [ + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 + ], 'keys': { 'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', @@ -212,7 +215,7 @@ void main() { final sessionId = 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU'; final senderKey = 'JBG7ZaPn54OBC7TuIEiylW3BZ+7WcGQhFBPB9pogbAg'; final sessionContent = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'session_id': 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU', 'session_key': @@ -307,7 +310,7 @@ void main() { eventId: '12345', originServerTs: DateTime.now(), content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'ciphertext': session.encrypt(json.encode({ 'type': 'm.room.message', 'content': {'msgtype': 'm.text', 'body': 'foxies'}, @@ -322,7 +325,7 @@ void main() { expect(room.lastEvent.type, 'm.room.encrypted'); // set a payload... var sessionPayload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': roomId, 'forwarding_curve25519_key_chain': [client.identityKey], 'session_id': sessionId, @@ -348,7 +351,7 @@ void main() { // not set one with a higher first known index sessionPayload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': roomId, 'forwarding_curve25519_key_chain': [client.identityKey], 'session_id': sessionId, @@ -374,7 +377,7 @@ void main() { // set one with a lower first known index sessionPayload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': roomId, 'forwarding_curve25519_key_chain': [client.identityKey], 'session_id': sessionId, @@ -400,7 +403,7 @@ void main() { // not set one with a longer forwarding chain sessionPayload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': roomId, 'forwarding_curve25519_key_chain': [client.identityKey, 'beep'], 'session_id': sessionId, @@ -426,7 +429,7 @@ void main() { // set one with a shorter forwarding chain sessionPayload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': roomId, 'forwarding_curve25519_key_chain': [], 'session_id': sessionId, diff --git a/test/encryption/key_request_test.dart b/test/encryption/key_request_test.dart index b6747e35..2bf1a60b 100644 --- a/test/encryption/key_request_test.dart +++ b/test/encryption/key_request_test.dart @@ -98,7 +98,7 @@ void main() { content: { 'action': 'request', 'body': { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'sender_key': validSenderKey, 'session_id': validSessionId, @@ -139,7 +139,7 @@ void main() { content: { 'action': 'request', 'body': { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'sender_key': validSenderKey, 'session_id': validSessionId, @@ -161,7 +161,7 @@ void main() { content: { 'action': 'request', 'body': { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'sender_key': validSenderKey, 'session_id': validSessionId, @@ -183,7 +183,7 @@ void main() { content: { 'action': 'request', 'body': { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!invalid:example.com', 'sender_key': validSenderKey, 'session_id': validSessionId, @@ -205,7 +205,7 @@ void main() { content: { 'action': 'request', 'body': { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'sender_key': validSenderKey, 'session_id': 'invalid', @@ -239,7 +239,7 @@ void main() { sender: '@alice:example.com', type: 'm.forwarded_room_key', content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'session_id': validSessionId, 'session_key': sessionKey, @@ -264,7 +264,7 @@ void main() { sender: '@alice:example.com', type: 'm.forwarded_room_key', content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'session_id': validSessionId, 'session_key': sessionKey, @@ -290,7 +290,7 @@ void main() { sender: '@alice:example.com', type: 'm.forwarded_room_key', content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'session_id': validSessionId, 'session_key': sessionKey, @@ -316,7 +316,7 @@ void main() { sender: '@alice:example.com', type: 'm.forwarded_room_key', content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': '!726s6s6q:example.com', 'session_id': validSessionId, 'session_key': sessionKey, diff --git a/test/encryption/online_key_backup_test.dart b/test/encryption/online_key_backup_test.dart index 92184660..1e81535f 100644 --- a/test/encryption/online_key_backup_test.dart +++ b/test/encryption/online_key_backup_test.dart @@ -81,7 +81,7 @@ void main() { final sessionId = inbound.session_id(); // set a payload... var sessionPayload = { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'room_id': roomId, 'forwarding_curve25519_key_chain': [client.identityKey], 'session_id': sessionId, diff --git a/test/event_test.dart b/test/event_test.dart index 85ccf87d..6d5bff85 100644 --- a/test/event_test.dart +++ b/test/event_test.dart @@ -304,7 +304,7 @@ void main() { 'msgtype': 'm.bad.encrypted', 'body': DecryptError.UNKNOWN_SESSION, 'can_request_session': true, - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'ciphertext': 'AwgAEnACgAkLmt6qF84IK++J7UDH2Za1YVchHyprqTqsg...', 'device_id': 'RJYKSTBOIE', 'sender_key': 'IlRMeOPX2e0MurIyfWEucYBRVOEEUMrOHqn/8mLqMjA', @@ -691,7 +691,7 @@ void main() { event = Event.fromJson({ 'content': { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'rotation_period_ms': 604800000, 'rotation_period_msgs': 100 }, diff --git a/test/fake_matrix_api.dart b/test/fake_matrix_api.dart index edb3c49a..795bf9f0 100644 --- a/test/fake_matrix_api.dart +++ b/test/fake_matrix_api.dart @@ -20,6 +20,7 @@ import 'dart:convert'; import 'dart:core'; import 'dart:math'; +import 'package:famedlysdk/matrix_api.dart'; import 'package:http/http.dart'; import 'package:http/testing.dart'; @@ -198,7 +199,7 @@ class FakeMatrixApi extends MockClient { 'sender': '@alice:example.com', 'type': 'm.room.encryption', 'state_key': '', - 'content': {'algorithm': 'm.megolm.v1.aes-sha2'}, + 'content': {'algorithm': AlgorithmTypes.megolmV1AesSha2}, 'origin_server_ts': 1417731086795, 'event_id': '666972737430353:example.com' }, @@ -543,7 +544,7 @@ class FakeMatrixApi extends MockClient { { 'type': 'm.secret_storage.key.0FajDWYaM6wQ4O60OZnLvwZfsBNu4Bu3', 'content': { - 'algorithm': 'm.secret_storage.v1.aes-hmac-sha2', + 'algorithm': AlgorithmTypes.secretStorageV1AesHmcSha2, 'passphrase': { 'algorithm': 'm.pbkdf2', 'iterations': 500000, @@ -620,7 +621,7 @@ class FakeMatrixApi extends MockClient { // { // 'sender': '@othertest:fakeServer.notExisting', // 'content': { -// 'algorithm': 'm.megolm.v1.aes-sha2', +// 'algorithm': AlgorithmTypes.megolmV1AesSha2, // 'room_id': '!726s6s6q:example.com', // 'session_id': 'ciM/JWTPrmiWPPZNkRLDPQYf9AW/I46bxyLSr+Bx5oU', // 'session_key': @@ -632,7 +633,7 @@ class FakeMatrixApi extends MockClient { // this is the commented out m.room_key event - only encrypted 'sender': '@othertest:fakeServer.notExisting', 'content': { - 'algorithm': 'm.olm.v1.curve25519-aes-sha2', + 'algorithm': AlgorithmTypes.olmV1Curve25519AesSha2, 'sender_key': 'JBG7ZaPn54OBC7TuIEiylW3BZ+7WcGQhFBPB9pogbAg', 'ciphertext': { '7rvl3jORJkBiK4XX1e5TnGnqz068XfYJ0W++Ml63rgk': { @@ -1551,7 +1552,7 @@ class FakeMatrixApi extends MockClient { 'event_fields': ['type', 'content', 'sender'] }, '/client/unstable/room_keys/version': (var req) => { - 'algorithm': 'm.megolm_backup.v1.curve25519-aes-sha2', + 'algorithm': AlgorithmTypes.megolmBackupV1Curve25519AesSha2, 'auth_data': { 'public_key': 'GXYaxqhNhUK28zUdxOmEsFRguz+PzBsDlTLlF0O0RkM', 'signatures': {}, @@ -1774,8 +1775,8 @@ class FakeMatrixApi extends MockClient { 'user_id': '@alice:example.com', 'device_id': 'JLAFKJWSCS', 'algorithms': [ - 'm.olm.v1.curve25519-aes-sha2', - 'm.megolm.v1.aes-sha2' + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 ], 'keys': { 'curve25519:JLAFKJWSCS': @@ -1795,8 +1796,8 @@ class FakeMatrixApi extends MockClient { 'user_id': '@alice:example.com', 'device_id': 'OTHERDEVICE', 'algorithms': [ - 'm.olm.v1.curve25519-aes-sha2', - 'm.megolm.v1.aes-sha2' + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 ], 'keys': { 'curve25519:OTHERDEVICE': 'blah', @@ -1810,8 +1811,8 @@ class FakeMatrixApi extends MockClient { 'user_id': '@test:fakeServer.notExisting', 'device_id': 'GHTYAJCE', 'algorithms': [ - 'm.olm.v1.curve25519-aes-sha2', - 'm.megolm.v1.aes-sha2' + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 ], 'keys': { 'curve25519:GHTYAJCE': @@ -1830,8 +1831,8 @@ class FakeMatrixApi extends MockClient { 'user_id': '@test:fakeServer.notExisting', 'device_id': 'OTHERDEVICE', 'algorithms': [ - 'm.olm.v1.curve25519-aes-sha2', - 'm.megolm.v1.aes-sha2' + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 ], 'keys': { 'curve25519:OTHERDEVICE': 'blah', @@ -1850,8 +1851,8 @@ class FakeMatrixApi extends MockClient { 'user_id': '@othertest:fakeServer.notExisting', 'device_id': 'FOXDEVICE', 'algorithms': [ - 'm.olm.v1.curve25519-aes-sha2', - 'm.megolm.v1.aes-sha2' + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 ], 'keys': { 'curve25519:FOXDEVICE': diff --git a/test/matrix_api_test.dart b/test/matrix_api_test.dart index 0f8f2aa6..c9dab61b 100644 --- a/test/matrix_api_test.dart +++ b/test/matrix_api_test.dart @@ -1158,7 +1158,10 @@ void main() { final key1 = MatrixDeviceKeys.fromJson({ 'user_id': '@alice:example.com', 'device_id': 'JLAFKJWSCS', - 'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], + 'algorithms': [ + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 + ], 'keys': { 'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', @@ -1175,7 +1178,10 @@ void main() { final key2 = MatrixDeviceKeys.fromJson({ 'user_id': '@alice:example.com', 'device_id': 'JLAFKJWSCS', - 'algorithms': ['m.olm.v1.curve25519-aes-sha2', 'm.megolm.v1.aes-sha2'], + 'algorithms': [ + AlgorithmTypes.olmV1Curve25519AesSha2, + AlgorithmTypes.megolmV1AesSha2 + ], 'keys': { 'curve25519:JLAFKJWSCS': '3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI', diff --git a/test/room_test.dart b/test/room_test.dart index 79679cf1..499cf239 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -516,14 +516,14 @@ void main() { eventId: '12345', originServerTs: DateTime.now(), content: { - 'algorithm': 'm.megolm.v1.aes-sha2', + 'algorithm': AlgorithmTypes.megolmV1AesSha2, 'rotation_period_ms': 604800000, 'rotation_period_msgs': 100 }, stateKey: ''), ); expect(room.encrypted, true); - expect(room.encryptionAlgorithm, 'm.megolm.v1.aes-sha2'); + expect(room.encryptionAlgorithm, AlgorithmTypes.megolmV1AesSha2); }); test('setPushRuleState', () async {