Skip to content

Commit

Permalink
chore: add require trailing comma lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rmoradi88 committed Nov 7, 2024
1 parent 989dbd8 commit 9c32193
Show file tree
Hide file tree
Showing 135 changed files with 13,207 additions and 8,964 deletions.
1 change: 1 addition & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ linter:
prefer_single_quotes: true
sort_child_properties_last: true
sort_pub_dependencies: true
require_trailing_commas: true

# Be nice to our users and allow them to configure what gets logged.
avoid_print: true
Expand Down
46 changes: 28 additions & 18 deletions lib/encryption/cross_signing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ class CrossSigning {
null;
}

Future<void> selfSign(
{String? passphrase,
String? recoveryKey,
String? keyOrPassphrase,
OpenSSSS? openSsss}) async {
Future<void> selfSign({
String? passphrase,
String? recoveryKey,
String? keyOrPassphrase,
OpenSSSS? openSsss,
}) async {
var handle = openSsss;
if (handle == null) {
handle = encryption.ssss.open(EventTypes.CrossSigningMasterKey);
Expand All @@ -89,7 +90,8 @@ class CrossSigning {
await handle.maybeCacheAll();
}
final masterPrivateKey = base64decodeUnpadded(
await handle.getStored(EventTypes.CrossSigningMasterKey));
await handle.getStored(EventTypes.CrossSigningMasterKey),
);
final keyObj = olm.PkSigning();
String? masterPubkey;
try {
Expand Down Expand Up @@ -117,11 +119,13 @@ class CrossSigning {
]);
}

bool signable(List<SignableKey> keys) => keys.any((key) =>
key is CrossSigningKey && key.usage.contains('master') ||
key is DeviceKeys &&
key.userId == client.userID &&
key.identifier != client.deviceID);
bool signable(List<SignableKey> keys) => keys.any(
(key) =>
key is CrossSigningKey && key.usage.contains('master') ||
key is DeviceKeys &&
key.userId == client.userID &&
key.identifier != client.deviceID,
);

Future<void> sign(List<SignableKey> keys) async {
final signedKeys = <MatrixSignableKey>[];
Expand All @@ -133,7 +137,10 @@ class CrossSigning {
}

void addSignature(
SignableKey key, SignableKey signedWith, String signature) {
SignableKey key,
SignableKey signedWith,
String signature,
) {
final signedKey = key.cloneForSigning();
((signedKey.signatures ??=
<String, Map<String, String>>{})[signedWith.userId] ??=
Expand All @@ -154,19 +161,22 @@ class CrossSigning {
// we don't care about signing other cross-signing keys
} else {
// okay, we'll sign a device key with our self signing key
selfSigningKey ??= base64decodeUnpadded(await encryption.ssss
.getCached(EventTypes.CrossSigningSelfSigning) ??
'');
selfSigningKey ??= base64decodeUnpadded(
await encryption.ssss
.getCached(EventTypes.CrossSigningSelfSigning) ??
'',
);
if (selfSigningKey.isNotEmpty) {
final signature = _sign(key.signingContent, selfSigningKey);
addSignature(key, userKeys.selfSigningKey!, signature);
}
}
} else if (key is CrossSigningKey && key.usage.contains('master')) {
// we are signing someone elses master key
userSigningKey ??= base64decodeUnpadded(await encryption.ssss
.getCached(EventTypes.CrossSigningUserSigning) ??
'');
userSigningKey ??= base64decodeUnpadded(
await encryption.ssss.getCached(EventTypes.CrossSigningUserSigning) ??
'',
);
if (userSigningKey.isNotEmpty) {
final signature = _sign(key.signingContent, userSigningKey);
addSignature(key, userKeys.userSigningKey!, signature);
Expand Down
52 changes: 35 additions & 17 deletions lib/encryption/encryption.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@ class Encryption {
);

void handleDeviceOneTimeKeysCount(
Map<String, int>? countJson, List<String>? unusedFallbackKeyTypes) {
runInRoot(() async => olmManager.handleDeviceOneTimeKeysCount(
countJson, unusedFallbackKeyTypes));
Map<String, int>? countJson,
List<String>? unusedFallbackKeyTypes,
) {
runInRoot(
() async => olmManager.handleDeviceOneTimeKeysCount(
countJson,
unusedFallbackKeyTypes,
),
);
}

void onSync() {
Expand Down Expand Up @@ -173,9 +179,10 @@ class Encryption {
return await olmManager.decryptToDeviceEvent(event);
} catch (e, s) {
Logs().w(
'[LibOlm] Could not decrypt to device event from ${event.sender} with content: ${event.content}',
e,
s);
'[LibOlm] Could not decrypt to device event from ${event.sender} with content: ${event.content}',
e,
s,
);
client.onEncryptionError.add(
SdkError(
exception: e is Exception ? e : Exception(e),
Expand Down Expand Up @@ -241,7 +248,10 @@ class Encryption {
client.database
// ignore: discarded_futures
?.updateInboundGroupSessionIndexes(
json.encode(inboundGroupSession.indexes), roomId, sessionId)
json.encode(inboundGroupSession.indexes),
roomId,
sessionId,
)
// ignore: discarded_futures
.onError((e, _) => Logs().e('Ignoring error for updating indexes'));
}
Expand All @@ -255,8 +265,10 @@ class Encryption {
?.session_id() ??
'') ==
content.sessionId) {
runInRoot(() async =>
keyManager.clearOrUseOutboundGroupSession(roomId, wipe: true));
runInRoot(
() async =>
keyManager.clearOrUseOutboundGroupSession(roomId, wipe: true),
);
}
if (canRequestSession) {
decryptedPayload = {
Expand Down Expand Up @@ -295,9 +307,12 @@ class Encryption {
);
}

Future<Event> decryptRoomEvent(String roomId, Event event,
{bool store = false,
EventUpdateType updateType = EventUpdateType.timeline}) async {
Future<Event> decryptRoomEvent(
String roomId,
Event event, {
bool store = false,
EventUpdateType updateType = EventUpdateType.timeline,
}) async {
if (event.type != EventTypes.Encrypted || event.redacted) {
return event;
}
Expand Down Expand Up @@ -351,8 +366,10 @@ class Encryption {
/// Encrypts the given json payload and creates a send-ready m.room.encrypted
/// payload. This will create a new outgoingGroupSession if necessary.
Future<Map<String, dynamic>> encryptGroupMessagePayload(
String roomId, Map<String, dynamic> payload,
{String type = EventTypes.Message}) async {
String roomId,
Map<String, dynamic> payload, {
String type = EventTypes.Message,
}) async {
payload = copyMap(payload);
final Map<String, dynamic>? mRelatesTo = payload.remove('m.relates_to');

Expand Down Expand Up @@ -403,9 +420,10 @@ class Encryption {
}

Future<Map<String, Map<String, Map<String, dynamic>>>> encryptToDeviceMessage(
List<DeviceKeys> deviceKeys,
String type,
Map<String, dynamic> payload) async {
List<DeviceKeys> deviceKeys,
String type,
Map<String, dynamic> payload,
) async {
return await olmManager.encryptToDeviceMessage(deviceKeys, type, payload);
}

Expand Down
Loading

0 comments on commit 9c32193

Please sign in to comment.