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 Dec 20, 2024
1 parent 3dc51ba commit 7319b39
Show file tree
Hide file tree
Showing 22 changed files with 32 additions and 37 deletions.
2 changes: 1 addition & 1 deletion lib/src/common/config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class Config {

static HashAlgorithm preferredHash = HashAlgorithm.sha256;

static SymmetricAlgorithm preferredSymmetric = SymmetricAlgorithm.aes128;
static SymmetricAlgorithm preferredSymmetric = SymmetricAlgorithm.aes256;

static CompressionAlgorithm preferredCompression =
CompressionAlgorithm.uncompressed;
Expand Down
1 change: 0 additions & 1 deletion lib/src/cryptor/aead/eax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
library;

import 'dart:typed_data';

import 'package:pointycastle/export.dart';

import '../../enum/symmetric_algorithm.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/src/cryptor/aead/gcm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
library;

import 'dart:typed_data';

import 'package:pointycastle/export.dart';

import '../../enum/symmetric_algorithm.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/src/cryptor/symmetric/buffered_cipher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
library;

import 'dart:typed_data';

import 'package:pointycastle/api.dart';

/// Buffered cipher.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/symmetric/camellia.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ library;
import 'dart:typed_data';
import 'package:pointycastle/api.dart';

import 'base_engine.dart';
import '../../common/extensions.dart';
import 'base_engine.dart';

/// Camellia - based on RFC 3713.
/// Author Nguyen Van Nguyen <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/symmetric/cast5.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ library;
import 'dart:typed_data';
import 'package:pointycastle/api.dart';

import 'base_engine.dart';
import '../../common/extensions.dart';
import 'base_engine.dart';

/// A class that provides CAST key encryption operations, such as encoding data and generating keys.
/// All the algorithms herein are from the Internet RFC's
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/symmetric/idea.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ library;
import 'dart:typed_data';
import 'package:pointycastle/api.dart';

import 'base_engine.dart';
import '../../common/extensions.dart';
import 'base_engine.dart';

/// A class that provides a basic International Data Encryption Algorithm (IDEA) engine.
/// Author Nguyen Van Nguyen <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/symmetric/twofish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ library;
import 'dart:typed_data';
import 'package:pointycastle/api.dart';

import 'base_engine.dart';
import '../../common/extensions.dart';
import 'base_engine.dart';

/// A class that provides Twofish encryption operations.
/// Author Nguyen Van Nguyen <[email protected]>
Expand Down
6 changes: 3 additions & 3 deletions lib/src/enum/signature_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ library;

export 'aead_algorithm.dart';
export 'compression_algorithm.dart';
export 'hash_algorithm.dart';
export 'key_algorithm.dart';
export 'key_flag.dart';
export 'key_version.dart';
export 'literal_format.dart';
export 'signature_subpacket_type.dart';
export 'support_feature.dart';
export 'symmetric_algorithm.dart';
export 'hash_algorithm.dart';
export 'key_algorithm.dart';
export 'signature_subpacket_type.dart';

///Signature types enum
/// Author Nguyen Van Nguyen <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions lib/src/message/cleartext_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
library;

import '../common/helpers.dart';
import '../message/signature.dart';
import '../message/signed_message.dart';
import '../packet/base_packet.dart';
import '../type/cleartext_message.dart';
import '../type/key.dart';
import '../type/notation_data.dart';
import '../type/signature.dart';
import 'signature.dart';
import 'signed_message.dart';

/// Cleartext message class that represents an OpenPGP cleartext message.
/// See RFC 9580, section 7.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/message/encrypted_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ library;
import '../common/armor.dart';
import '../common/helpers.dart';
import '../enum/armor_type.dart';
import '../message/base_message.dart';
import '../packet/base_packet.dart';
import '../type/encrypted_data_packet.dart';
import '../type/encrypted_message.dart';
import '../type/packet_list.dart';
import '../type/private_key.dart';
import '../type/session_key.dart';
import 'base_message.dart';

/// OpenPGP encrypted message class
/// Author Nguyen Van Nguyen <[email protected]>
Expand Down
6 changes: 3 additions & 3 deletions lib/src/message/literal_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import '../enum/aead_algorithm.dart';
import '../enum/armor_type.dart';
import '../enum/compression_algorithm.dart';
import '../enum/symmetric_algorithm.dart';
import '../message/base_message.dart';
import '../packet/base_packet.dart';
import '../packet/key/session_key.dart';
import '../type/key.dart';
Expand All @@ -22,6 +21,7 @@ import '../type/literal_message.dart';
import '../type/packet_list.dart';
import '../type/session_key.dart';
import '../type/signature_packet.dart';
import 'base_message.dart';

/// OpenPGP literal message class
/// Author Nguyen Van Nguyen <[email protected]>
Expand Down Expand Up @@ -59,7 +59,7 @@ final class LiteralMessage extends BaseMessage
/// Taking the algorithm preferences of the passed encryption keys, if any.
static SessionKeyInterface generateSessionKey(
final Iterable<KeyInterface> encryptionKeys, [
final SymmetricAlgorithm defaultSymmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm defaultSymmetric = SymmetricAlgorithm.aes256,
]) {
final SymmetricAlgorithm symmetric;
if (encryptionKeys.isNotEmpty) {
Expand Down Expand Up @@ -163,7 +163,7 @@ final class LiteralMessage extends BaseMessage
encrypt({
final Iterable<KeyInterface> encryptionKeys = const [],
final Iterable<String> passwords = const [],
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
}) {
final sessionKey = generateSessionKey(
encryptionKeys,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/message/signature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import '../common/armor.dart';
import '../common/helpers.dart';
import '../enum/armor_type.dart';
import '../enum/hash_algorithm.dart';
import '../message/verification.dart';
import '../packet/base_packet.dart';
import '../type/cleartext_message.dart';
import '../type/key.dart';
import '../type/literal_data.dart';
import '../type/signature.dart';
import '../type/signature_packet.dart';
import '../type/verification.dart';
import 'verification.dart';

/// Signature class
/// Author Nguyen Van Nguyen <[email protected]>
Expand Down
2 changes: 1 addition & 1 deletion lib/src/message/signed_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ library;

import '../common/armor.dart';
import '../enum/armor_type.dart';
import '../message/signature.dart';
import '../packet/packet_list.dart';
import '../type/key.dart';
import '../type/signature.dart';
import '../type/signature_packet.dart';
import '../type/signed_cleartext_message.dart';
import 'cleartext_message.dart';
import 'signature.dart';

/// Signed message class that represents an OpenPGP cleartext signed message.
/// See RFC 9580, section 7.
Expand Down
6 changes: 3 additions & 3 deletions lib/src/packet/aead_encrypted_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ final class AeadEncryptedDataPacket extends BasePacket
factory AeadEncryptedDataPacket.encryptPackets(
final Uint8List key,
final PacketListInterface packets, {
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
final AeadAlgorithm aead = AeadAlgorithm.ocb,
final int chunkSize = 12,
}) {
Expand Down Expand Up @@ -117,7 +117,7 @@ final class AeadEncryptedDataPacket extends BasePacket
@override
decrypt(
final Uint8List key, [
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
]) {
final length = encrypted.length;
final data = encrypted.sublist(0, length - aead.tagLength);
Expand Down Expand Up @@ -147,7 +147,7 @@ final class AeadEncryptedDataPacket extends BasePacket
final Uint8List key,
final Uint8List data, {
final Uint8List? finalChunk,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
final AeadAlgorithm aead = AeadAlgorithm.ocb,
final chunkSizeByte = 0,
final Uint8List? iv,
Expand Down
1 change: 0 additions & 1 deletion lib/src/packet/key/dsa_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
library;

import 'dart:typed_data';

import 'package:pointycastle/export.dart';

import '../../common/helpers.dart';
Expand Down
1 change: 0 additions & 1 deletion lib/src/packet/key/rsa_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
library;

import 'dart:typed_data';

import 'package:pointycastle/pointycastle.dart';

import '../../common/helpers.dart';
Expand Down
14 changes: 7 additions & 7 deletions lib/src/packet/signature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,8 @@ final class SignaturePacket extends BasePacket
KeyFlag.certifyKeys.value | KeyFlag.signData.value,
),
PreferredSymmetricAlgorithms(Uint8List.fromList([
SymmetricAlgorithm.aes128.value,
SymmetricAlgorithm.aes256.value,
SymmetricAlgorithm.aes128.value,
])),
PreferredAeadAlgorithms(Uint8List.fromList([
AeadAlgorithm.ocb.value,
Expand All @@ -529,18 +529,18 @@ final class SignaturePacket extends BasePacket
if (version == KeyVersion.v6.value) {
subpackets.add(PreferredAeadCiphers(Uint8List.fromList([
...[
SymmetricAlgorithm.aes128.value,
SymmetricAlgorithm.aes256.value,
AeadAlgorithm.ocb.value,
SymmetricAlgorithm.aes128.value,
SymmetricAlgorithm.aes256.value,
AeadAlgorithm.gcm.value,
SymmetricAlgorithm.aes128.value,
AeadAlgorithm.eax.value,
],
...[
SymmetricAlgorithm.aes256.value,
SymmetricAlgorithm.aes128.value,
AeadAlgorithm.ocb.value,
SymmetricAlgorithm.aes256.value,
SymmetricAlgorithm.aes128.value,
AeadAlgorithm.gcm.value,
SymmetricAlgorithm.aes128.value,
AeadAlgorithm.eax.value,
],
])));
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/sym_encrypted_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class SymEncryptedDataPacket extends BasePacket
@override
decrypt(
final Uint8List key, [
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
]) {
if (!Config.allowUnauthenticated) {
throw AssertionError(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/sym_encrypted_integrity_protected_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ final class SymEncryptedIntegrityProtectedDataPacket extends BasePacket
factory SymEncryptedIntegrityProtectedDataPacket.encryptPackets(
final Uint8List key,
final PacketListInterface packets, {
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
final AeadAlgorithm? aead,
}) {
Helper.assertSymmetric(symmetric);
Expand Down
6 changes: 3 additions & 3 deletions lib/src/packet/sym_encrypted_session_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class SymEncryptedSessionKeyPacket extends BasePacket {
this.s2k,
this.iv,
this.encrypted, {
this.symmetric = SymmetricAlgorithm.aes128,
this.symmetric = SymmetricAlgorithm.aes256,
this.aead,
this.sessionKey,
}) : super(PacketType.symEncryptedSessionKey) {
Expand Down Expand Up @@ -126,9 +126,9 @@ final class SymEncryptedSessionKeyPacket extends BasePacket {

factory SymEncryptedSessionKeyPacket.encryptSessionKey(
final String password, {
final SessionKeyInterface? sessionKey,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes128,
final SymmetricAlgorithm symmetric = SymmetricAlgorithm.aes256,
final AeadAlgorithm? aead,
final SessionKeyInterface? sessionKey,
}) {
Helper.assertSymmetric(symmetric);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/user_attribute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ library;

import 'dart:typed_data';

import '../type/user_id_packet.dart';
import '../common/extensions.dart';
import '../type/user_id_packet.dart';
import 'base_packet.dart';
import 'image_user_attribute.dart';
import 'subpacket_reader.dart';
Expand Down

0 comments on commit 7319b39

Please sign in to comment.