From 5a1f76f164bf73c17200fa1b5c94a5e0aff26ce1 Mon Sep 17 00:00:00 2001 From: Nguyen Van Nguyen Date: Wed, 11 Dec 2024 10:03:59 +0700 Subject: [PATCH] WIP Signed-off-by: Nguyen Van Nguyen --- lib/src/message/literal_message.dart | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/src/message/literal_message.dart b/lib/src/message/literal_message.dart index 30d6c17b..28413a45 100644 --- a/lib/src/message/literal_message.dart +++ b/lib/src/message/literal_message.dart @@ -61,15 +61,20 @@ final class LiteralMessage extends BaseMessage final Iterable encryptionKeys, [ final SymmetricAlgorithm defaultSymmetric = SymmetricAlgorithm.aes128, ]) { - var preferredSymmetrics = SymmetricAlgorithm.preferredSymmetrics; - for (final key in encryptionKeys) { - preferredSymmetrics = preferredSymmetrics - .where( - (symmetric) => key.preferredSymmetrics.contains(symmetric), - ) - .toList(); + final SymmetricAlgorithm symmetric; + if (encryptionKeys.isNotEmpty) { + var preferredSymmetrics = SymmetricAlgorithm.preferredSymmetrics; + for (final key in encryptionKeys) { + preferredSymmetrics = preferredSymmetrics + .where( + (symmetric) => key.preferredSymmetrics.contains(symmetric), + ) + .toList(); + } + symmetric = preferredSymmetrics.firstOrNull ?? defaultSymmetric; + } else { + symmetric = defaultSymmetric; } - final symmetric = preferredSymmetrics.firstOrNull ?? defaultSymmetric; var preferredAeads = [ AeadAlgorithm.ocb,