Skip to content

Commit

Permalink
Use record for Key.readPacketList
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <[email protected]>
  • Loading branch information
nguyennv committed Nov 21, 2024
1 parent 1feeb8a commit 6bd8d0f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
22 changes: 14 additions & 8 deletions lib/src/type/key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,13 @@ abstract class Key {
...subkeys.map((subkey) => subkey.toPacketList()).expand((packet) => packet),
]);

static Map<String, dynamic> readPacketList(final PacketList packetList) {
static ({
KeyPacket? keyPacket,
List<User> users,
List<SignaturePacket> revocationSignatures,
List<SignaturePacket> directSignatures,
List<Subkey> subkeys,
}) readPacketList(final PacketList packetList) {
final revocationSignatures = <SignaturePacket>[];
final directSignatures = <SignaturePacket>[];
final users = <User>[];
Expand Down Expand Up @@ -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,
);
}
}
14 changes: 7 additions & 7 deletions lib/src/type/private_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down
14 changes: 7 additions & 7 deletions lib/src/type/public_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}

Expand Down

0 comments on commit 6bd8d0f

Please sign in to comment.