From 6bd8d0f766a5911e927370bf4b1411df02ce62c4 Mon Sep 17 00:00:00 2001 From: Nguyen Van Nguyen Date: Thu, 21 Nov 2024 13:08:28 +0700 Subject: [PATCH] Use record for Key.readPacketList Signed-off-by: Nguyen Van Nguyen --- lib/src/type/key.dart | 22 ++++++++++++++-------- lib/src/type/private_key.dart | 14 +++++++------- lib/src/type/public_key.dart | 14 +++++++------- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/lib/src/type/key.dart b/lib/src/type/key.dart index 3e831a06..10bf0ec2 100644 --- a/lib/src/type/key.dart +++ b/lib/src/type/key.dart @@ -245,7 +245,13 @@ abstract class Key { ...subkeys.map((subkey) => subkey.toPacketList()).expand((packet) => packet), ]); - static Map readPacketList(final PacketList packetList) { + static ({ + KeyPacket? keyPacket, + List users, + List revocationSignatures, + List directSignatures, + List subkeys, + }) readPacketList(final PacketList packetList) { final revocationSignatures = []; final directSignatures = []; final users = []; @@ -351,12 +357,12 @@ abstract class Key { throw StateError('Key packet not found in packet list'); } - return { - 'keyPacket': keyPacket, - 'users': users, - 'revocationSignatures': revocationSignatures, - 'directSignatures': directSignatures, - 'subkeys': subkeys, - }; + return ( + keyPacket: keyPacket, + users: users, + revocationSignatures: revocationSignatures, + directSignatures: directSignatures, + subkeys: subkeys, + ); } } diff --git a/lib/src/type/private_key.dart b/lib/src/type/private_key.dart index 9fb7ce29..31b255f9 100644 --- a/lib/src/type/private_key.dart +++ b/lib/src/type/private_key.dart @@ -46,16 +46,16 @@ class PrivateKey extends Key { } factory PrivateKey.fromPacketList(final PacketList packetList) { - final keyMap = Key.readPacketList(packetList); - if (keyMap['keyPacket'] is! SecretKeyPacket) { + final keyRecord = Key.readPacketList(packetList); + if (keyRecord.keyPacket is! SecretKeyPacket) { throw StateError('Key packet not of secret key type'); } return PrivateKey( - keyMap['keyPacket'] as SecretKeyPacket, - revocationSignatures: keyMap['revocationSignatures'], - directSignatures: keyMap['directSignatures'], - users: keyMap['users'], - subkeys: keyMap['subkeys'], + keyRecord.keyPacket as SecretKeyPacket, + revocationSignatures: keyRecord.revocationSignatures, + directSignatures: keyRecord.directSignatures, + users: keyRecord.users, + subkeys: keyRecord.subkeys, ); } diff --git a/lib/src/type/public_key.dart b/lib/src/type/public_key.dart index 279c136b..4ea17c36 100644 --- a/lib/src/type/public_key.dart +++ b/lib/src/type/public_key.dart @@ -29,16 +29,16 @@ class PublicKey extends Key { } factory PublicKey.fromPacketList(final PacketList packetList) { - final keyMap = Key.readPacketList(packetList); - if (keyMap['keyPacket'] is! PublicKeyPacket) { + final keyRecord = Key.readPacketList(packetList); + if (keyRecord.keyPacket is! PublicKeyPacket) { throw StateError('Key packet not of secret key type'); } return PublicKey( - keyMap['keyPacket'] as PublicKeyPacket, - revocationSignatures: keyMap['revocationSignatures'], - directSignatures: keyMap['directSignatures'], - users: keyMap['users'], - subkeys: keyMap['subkeys'], + keyRecord.keyPacket as PublicKeyPacket, + revocationSignatures: keyRecord.revocationSignatures, + directSignatures: keyRecord.directSignatures, + users: keyRecord.users, + subkeys: keyRecord.subkeys, ); }