Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <[email protected]>
  • Loading branch information
nguyennv committed May 11, 2023
1 parent f78eb27 commit 27cafa5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@

## 1.1.1 (2023-04-24)
- Fix s2k iterated produce key

## 1.1.2 (2023-05-11)
- Pass ParametersWithIV to cipher in SKESK packet
- Refactor session key encryption
4 changes: 3 additions & 1 deletion lib/src/packet/key/session_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class SessionKey {

SessionKey(this.key, [this.symmetric = SymmetricAlgorithm.aes256]);

factory SessionKey.produceKey([SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256]) {
factory SessionKey.produceKey([
SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
]) {
return SessionKey(Helper.generateEncryptionKey(symmetric), symmetric);
}

Expand Down
27 changes: 18 additions & 9 deletions lib/src/type/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ class Message {

final List<Verification> verifications;

Message(this.packetList, [final Iterable<Verification> verifications = const []])
: verifications = verifications.toList(growable: false);
Message(
this.packetList, [
final Iterable<Verification> verifications = const [],
]) : verifications = verifications.toList(growable: false);

factory Message.fromArmored(final String armored) {
final armor = Armor.decode(armored);
Expand Down Expand Up @@ -87,7 +89,8 @@ class Message {
]));

LiteralDataPacket? get literalData {
final packets = unwrapCompressed().packetList.whereType<LiteralDataPacket>();
final packets =
unwrapCompressed().packetList.whereType<LiteralDataPacket>();
return packets.isNotEmpty ? packets.elementAt(0) : null;
}

Expand All @@ -104,10 +107,13 @@ class Message {
}

/// Gets the key IDs of the keys to which the session key is encrypted
Iterable<KeyID> get encryptionKeyIDs =>
unwrapCompressed().packetList.whereType<PublicKeyEncryptedSessionKeyPacket>().map((packet) => packet.publicKeyID);
Iterable<KeyID> get encryptionKeyIDs => unwrapCompressed()
.packetList
.whereType<PublicKeyEncryptedSessionKeyPacket>()
.map((packet) => packet.publicKeyID);

Iterable<SignaturePacket> get signaturePackets => unwrapCompressed().packetList.whereType<SignaturePacket>();
Iterable<SignaturePacket> get signaturePackets =>
unwrapCompressed().packetList.whereType<SignaturePacket>();

/// Returns ASCII armored text of message
String armor() => Armor.encode(ArmorType.message, packetList.encode());
Expand Down Expand Up @@ -220,7 +226,8 @@ class Message {
final List<PublicKey> verificationKeys, {
final DateTime? date,
}) async {
final literalDataPackets = unwrapCompressed().packetList.whereType<LiteralDataPacket>();
final literalDataPackets =
unwrapCompressed().packetList.whereType<LiteralDataPacket>();
if (literalDataPackets.isEmpty) {
throw StateError('No literal data packet to verify.');
}
Expand Down Expand Up @@ -251,7 +258,8 @@ class Message {
final pkeskPackets = await Future.wait(
encryptionKeys.map(
(key) async => PublicKeyEncryptedSessionKeyPacket.encryptSessionKey(
await key.getEncryptionKeyPacket(), sessionKey
await key.getEncryptionKeyPacket(),
sessionKey,
),
),
);
Expand Down Expand Up @@ -366,7 +374,8 @@ class Message {
}) async {
final sessionKeys = <SessionKey>[];
if (decryptionKeys.isNotEmpty) {
final pkeskPackets = packetList.whereType<PublicKeyEncryptedSessionKeyPacket>();
final pkeskPackets =
packetList.whereType<PublicKeyEncryptedSessionKeyPacket>();
for (final pkesk in pkeskPackets) {
for (final key in decryptionKeys) {
final keyPacket = await key.getDecryptionKeyPacket();
Expand Down
6 changes: 3 additions & 3 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: dart_pg
description: Dart PG (Dart Privacy Guard) - The OpenPGP implementation in Dart language.
version: 1.1.1
version: 1.1.2
homepage: https://github.com/nguyennv/dart_pg

environment:
sdk: '>=2.18.4 <3.0.0'
sdk: '>=2.19.0 <3.0.0'

dependencies:
crypto: ^3.0.2
crypto: ^3.0.3
fixnum: ^1.1.0
pinenacl: ^0.5.1
pointycastle: ^3.7.3
Expand Down

0 comments on commit 27cafa5

Please sign in to comment.