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 11, 2024
1 parent 2bdba30 commit 5017477
Show file tree
Hide file tree
Showing 86 changed files with 110 additions and 100 deletions.
2 changes: 1 addition & 1 deletion lib/src/common/argon2_s2k.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'helpers.dart';

/// Implementation of the Argon2 string-to-key specifier
/// See https://www.rfc-editor.org/rfc/rfc9580#section-3.7
class Argon2S2k implements S2kInterface {
final class Argon2S2k implements S2kInterface {
/// Default salt length
static const saltLength = 16;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/armor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'helpers.dart';
/// encoding of the binary data and a checksum.
/// See https://www.rfc-editor.org/rfc/rfc9580#section-6
/// Author Nguyen Van Nguyen <[email protected]>
class Armor {
final class Armor {
static const version = 'Dart PG v2';
static const comment = 'The Dart OpenPGP library';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/common/generic_s2k.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'helpers.dart';

/// Implementation of the string-to-key specifier
/// See https://www.rfc-editor.org/rfc/rfc9580#section-3.7
class GenericS2k implements S2kInterface {
final class GenericS2k implements S2kInterface {
/// Default salt length
static const saltLength = 8;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/aead/eax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import '../../type/aead.dart';

/// EAX Authenticated-Encryption class
/// Author Nguyen Van Nguyen <[email protected]>
class Eax implements AeadInterface {
final class Eax implements AeadInterface {
final Uint8List key;
final SymmetricAlgorithm symmetric;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/aead/gcm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import '../../type/aead.dart';

/// GCM Authenticated-Encryption class
/// Author Nguyen Van Nguyen <[email protected]>
class Gcm implements AeadInterface {
final class Gcm implements AeadInterface {
final Uint8List key;
final SymmetricAlgorithm symmetric;

Expand Down
4 changes: 2 additions & 2 deletions lib/src/cryptor/aead/ocb.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import '../../type/aead.dart';

/// OCB Authenticated-Encryption class
/// Author Nguyen Van Nguyen <[email protected]>
class Ocb implements AeadInterface {
final class Ocb implements AeadInterface {
final Uint8List key;
final SymmetricAlgorithm symmetric;

Expand Down Expand Up @@ -81,7 +81,7 @@ class Ocb implements AeadInterface {
/// An implementation of RFC 7253 on The OCB Authenticated-Encryption Algorithm.
/// See https://tools.ietf.org/html/rfc7253
/// Author Nguyen Van Nguyen <[email protected]>
class OCBCipher implements AEADCipher {
final class OCBCipher implements AEADCipher {
static const _blockSize = 16;

final BlockCipher _hashCipher;
Expand Down
8 changes: 4 additions & 4 deletions lib/src/cryptor/asymmetric/dsa.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../../common/helpers.dart';

/// Implementation of DSA (digital signature algorithm)
/// Author Nguyen Van Nguyen <[email protected]>
class DSASigner implements Signer {
final class DSASigner implements Signer {
final Digest? _digest;

late DSAAsymmetricKey? _key;
Expand Down Expand Up @@ -150,7 +150,7 @@ class DSASigner implements Signer {
}
}

class DSASignature implements Signature {
final class DSASignature implements Signature {
final BigInt r;
final BigInt s;

Expand Down Expand Up @@ -191,14 +191,14 @@ abstract class DSAAsymmetricKey implements AsymmetricKey {
DSAAsymmetricKey(this.prime, this.order, this.generator);
}

class DSAPublicKey extends DSAAsymmetricKey implements PublicKey {
final class DSAPublicKey extends DSAAsymmetricKey implements PublicKey {
/// public exponent y = g ** x mod p
final BigInt y;

DSAPublicKey(this.y, super.prime, super.order, super.generator);
}

class DSAPrivateKey extends DSAAsymmetricKey implements PrivateKey {
final class DSAPrivateKey extends DSAAsymmetricKey implements PrivateKey {
/// secret exponent
final BigInt x;

Expand Down
7 changes: 4 additions & 3 deletions lib/src/cryptor/asymmetric/elgamal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../../common/helpers.dart';

/// Asymmetric block cipher using basic ElGamal algorithm.
/// Author Nguyen Van Nguyen <[email protected]>
class ElGamalEngine implements AsymmetricBlockCipher {
final class ElGamalEngine implements AsymmetricBlockCipher {
late ElGamalAsymmetricKey? _key;

late SecureRandom _random;
Expand Down Expand Up @@ -149,14 +149,15 @@ abstract class ElGamalAsymmetricKey implements AsymmetricKey {
ElGamalAsymmetricKey(this.prime, this.generator);
}

class ElGamalPublicKey extends ElGamalAsymmetricKey implements PublicKey {
final class ElGamalPublicKey extends ElGamalAsymmetricKey implements PublicKey {
/// public exponent y = g ** x mod p
final BigInt y;

ElGamalPublicKey(this.y, super.prime, super.generator);
}

class ElGamalPrivateKey extends ElGamalAsymmetricKey implements PrivateKey {
final class ElGamalPrivateKey extends ElGamalAsymmetricKey
implements PrivateKey {
/// secret exponent
final BigInt x;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/symmetric/blowfish.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'base_engine.dart';
/// All the algorithms herein are from Applied Cryptography
/// and implement a simplified cryptography interface.
/// Author Nguyen Van Nguyen <[email protected]>
class BlowfishEngine extends BaseEngine {
final class BlowfishEngine extends BaseEngine {
static const _kp = [
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, // 0 - 3
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/cryptor/symmetric/buffered_cipher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'package:pointycastle/api.dart';

/// Buffered cipher.
/// Author Nguyen Van Nguyen <[email protected]>
class BufferedCipher {
final class BufferedCipher {
final BlockCipher _underlyingCipher;

final Uint8List _buffer;
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 @@ -12,7 +12,7 @@ import '../../common/extensions.dart';

/// Camellia - based on RFC 3713.
/// Author Nguyen Van Nguyen <[email protected]>
class CamelliaEngine extends BaseEngine {
final class CamelliaEngine extends BaseEngine {
static const _blockSize = 16;

static const _mask8 = 0xff;
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 @@ -18,7 +18,7 @@ import '../../common/extensions.dart';
///
/// and implement a simplified cryptography interface.
/// Author Nguyen Van Nguyen <[email protected]>
class CAST5Engine extends BaseEngine {
final class CAST5Engine extends BaseEngine {
static const _sBox1 = [
0x30fb40d4, 0x9fa0ff0b, 0x6beccd2f, 0x3f258c7a, 0x1e213f2f, 0x9c004dd3,
0x6003e540, 0xcf9fc949, // 0 - 7
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 @@ -12,7 +12,7 @@ import '../../common/extensions.dart';

/// A class that provides a basic International Data Encryption Algorithm (IDEA) engine.
/// Author Nguyen Van Nguyen <[email protected]>
class IDEAEngine extends BaseEngine {
final class IDEAEngine extends BaseEngine {
static const _mask = 0xffff;
static const _base = 0x10001;

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 @@ -12,7 +12,7 @@ import '../../common/extensions.dart';

/// A class that provides Twofish encryption operations.
/// Author Nguyen Van Nguyen <[email protected]>
class TwofishEngine extends BaseEngine {
final class TwofishEngine extends BaseEngine {
/// Q-Table 0
static const _q0 = [
0xa9, 0x67, 0xb3, 0xe8, 0x04, 0xfd, 0xa3, 0x76, // 0 - 7
Expand Down
2 changes: 2 additions & 0 deletions lib/src/key/private_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import '../type/private_key.dart';
import '../type/secret_key_packet.dart';
import 'base_key.dart';

/// OpenPGP private key class
/// Author Nguyen Van Nguyen <[email protected]>
final class PrivateKey extends BaseKey implements PrivateKeyInterface {
PrivateKey(super.packetList);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/message/verification.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../type/verification.dart';

/// Verification class
/// Author Nguyen Van Nguyen <[email protected]>
class Verification implements VerificationInterface {
final class Verification implements VerificationInterface {
@override
final Uint8List keyID;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/aead_encrypted_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'base_packet.dart';
/// Implementation of the Symmetrically Encrypted Authenticated Encryption with
/// Additional Data (AEAD) Protected Data Packet - Type 20
/// Author Nguyen Van Nguyen <[email protected]>
class AeadEncryptedDataPacket extends BasePacket
final class AeadEncryptedDataPacket extends BasePacket
implements EncryptedDataPacketInterface {
static const version = 1;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/compressed_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'base_packet.dart';

/// Implementation of the Compressed Data (COMP) Packet - Type 11
/// Author Nguyen Van Nguyen <[email protected]>
class CompressedDataPacket extends BasePacket {
final class CompressedDataPacket extends BasePacket {
/// Default zip/zlib compression level, between 1 and 9
static const deflateLevel = 6;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/image_user_attribute.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'user_attribute_subpacket.dart';

/// Implementation of the Image User Attribute Subpacket
/// Author Nguyen Van Nguyen <[email protected]>
class ImageUserAttribute extends UserAttributeSubpacket {
final class ImageUserAttribute extends UserAttributeSubpacket {
static const jpeg = 1;

ImageUserAttribute(
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/aes_key_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import 'key_wrapper.dart';

/// An implementation of the AES Key Wrapper from the NIST Key Wrap Specification.
/// Author Nguyen Van Nguyen <[email protected]>
class AesKeyWrapper extends KeyWrapper {
final class AesKeyWrapper extends KeyWrapper {
AesKeyWrapper(final int keySize)
: super(
BlockCipher('AES/ECB'),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/camellia_key_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'key_wrapper.dart';

/// An implementation of the Camellia key wrapper based on RFC 3657/RFC 3394.
/// Author Nguyen Van Nguyen <[email protected]>
class CamelliaKeyWrapper extends KeyWrapper {
final class CamelliaKeyWrapper extends KeyWrapper {
CamelliaKeyWrapper(final int keySize)
: super(
ECBBlockCipher(CamelliaEngine()),
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/dsa_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import '../../type/verification_key_material.dart';

/// DSA public key material
/// Author Nguyen Van Nguyen <[email protected]>
class DSAPublicMaterial implements VerificationKeyMaterial {
final class DSAPublicMaterial implements VerificationKeyMaterial {
/// DSA prime p
final BigInt prime;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/dsa_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'dsa_public_material.dart';

/// DSA secret key material
/// Author Nguyen Van Nguyen <[email protected]>
class DSASecretMaterial implements SigningKeyMaterialInterface {
final class DSASecretMaterial implements SigningKeyMaterialInterface {
/// DSA secret exponent x
final BigInt exponent;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/ecdh_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'ec_public_material.dart';

/// ECDH public key material
/// Author Nguyen Van Nguyen <[email protected]>
class ECDHPublicMaterial extends ECPublicMaterial {
final class ECDHPublicMaterial extends ECPublicMaterial {
final int reserved;

/// Hash algorithm used with the KDF
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/ecdh_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'ecdh_public_material.dart';

/// ECDH secret key material
/// Author Nguyen Van Nguyen <[email protected]>
class ECDHSecretMaterial extends ECSecretMaterial
final class ECDHSecretMaterial extends ECSecretMaterial
implements SecretKeyMaterialInterface {
@override
final ECDHPublicMaterial publicMaterial;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/ecdh_session_key_cryptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import 'session_key_cryptor.dart';

/// ECDH session key cryptor class
/// Author Nguyen Van Nguyen <[email protected]>
class ECDHSessionKeyCryptor extends SessionKeyCryptor {
final class ECDHSessionKeyCryptor extends SessionKeyCryptor {
/// 20 octets representing the UTF-8 encoding of the string 'Anonymous Sender '
static const _anonymousSender = [
0x41, 0x6e, 0x6f, 0x6e, // 0 - 3
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/ecdsa_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import '../../type/verification_key_material.dart';

/// ECDSA public key material
/// Author Nguyen Van Nguyen <[email protected]>
class ECDSAPublicMaterial extends ECPublicMaterial
final class ECDSAPublicMaterial extends ECPublicMaterial
implements VerificationKeyMaterial {
ECDSAPublicMaterial(super.oid, super.q);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/ecdsa_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'ecdsa_public_material.dart';

/// ECDSA secret key material
/// Author Nguyen Van Nguyen <[email protected]>
class ECDSASecretMaterial extends ECSecretMaterial
final class ECDSASecretMaterial extends ECSecretMaterial
implements SigningKeyMaterialInterface {
@override
final ECDSAPublicMaterial publicMaterial;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/eddsa_legacy_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import 'ec_public_material.dart';

/// EdDSA legacy public key material
/// Author Nguyen Van Nguyen <[email protected]>
class EdDSALegacyPublicMaterial extends ECPublicMaterial
final class EdDSALegacyPublicMaterial extends ECPublicMaterial
implements VerificationKeyMaterial {
EdDSALegacyPublicMaterial(super.oid, super.q);

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/eddsa_legacy_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import 'eddsa_legacy_public_material.dart';

/// EdDSA legacy secret key material
/// Author Nguyen Van Nguyen <[email protected]>
class EdDSALegacySecretMaterial implements SigningKeyMaterialInterface {
final class EdDSALegacySecretMaterial implements SigningKeyMaterialInterface {
/// Ed's seed parameter
final BigInt seed;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/eddsa_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import '../../type/verification_key_material.dart';

/// EdDSA public key material
/// Author Nguyen Van Nguyen <[email protected]>
class EdDSAPublicMaterial implements VerificationKeyMaterial {
final class EdDSAPublicMaterial implements VerificationKeyMaterial {
final Uint8List publicKey;

final EdDSACurve curve;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/eddsa_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'eddsa_public_material.dart';

/// EdDSA secret key material
/// Author Nguyen Van Nguyen <[email protected]>
class EdDSASecretMaterial implements SigningKeyMaterialInterface {
final class EdDSASecretMaterial implements SigningKeyMaterialInterface {
final Uint8List secretKey;

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/elgamal_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import '../../type/key_material.dart';

/// ElGamal public key material
/// Author Nguyen Van Nguyen <[email protected]>
class ElGamalPublicMaterial implements KeyMaterialInterface {
final class ElGamalPublicMaterial implements KeyMaterialInterface {
/// Elgamal prime p
final BigInt prime;

Expand Down
4 changes: 3 additions & 1 deletion lib/src/packet/key/elgamal_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import '../../cryptor/asymmetric/elgamal.dart';
import '../../type/secret_key_material.dart';
import 'elgamal_public_material.dart';

class ElGamalSecretMaterial implements SecretKeyMaterialInterface {
/// ElGamal secret key material
/// Author Nguyen Van Nguyen <[email protected]>
final class ElGamalSecretMaterial implements SecretKeyMaterialInterface {
/// Elgamal secret exponent x.
final BigInt exponent;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/elgamal_session_key_cryptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'session_key_cryptor.dart';

/// ElGamal session key cryptor class
/// Author Nguyen Van Nguyen <[email protected]>
class ElGamalSessionKeyCryptor extends SessionKeyCryptor {
final class ElGamalSessionKeyCryptor extends SessionKeyCryptor {
/// MPI of ElGamal (Diffie-Hellman) value g**k mod p.
final BigInt gamma;

Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/montgomery_public_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import '../../enum/montgomery_curve.dart';

/// Montgomery public key material
/// Author Nguyen Van Nguyen <[email protected]>
class MontgomeryPublicMaterial implements KeyMaterialInterface {
final class MontgomeryPublicMaterial implements KeyMaterialInterface {
final Uint8List publicKey;

final MontgomeryCurve curve;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/packet/key/montgomery_secret_material.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import 'montgomery_public_material.dart';

/// Montgomery secret key material
/// Author Nguyen Van Nguyen <[email protected]>
class MontgomerySecretMaterial implements SecretKeyMaterialInterface {
final class MontgomerySecretMaterial implements SecretKeyMaterialInterface {
final Uint8List secretKey;

@override
Expand Down
4 changes: 3 additions & 1 deletion lib/src/packet/key/montgomery_session_key_cryptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import 'montgomery_public_material.dart';
import 'montgomery_secret_material.dart';
import 'session_key_cryptor.dart';

class MontgomerySessionKeyCryptor extends SessionKeyCryptor {
/// Montgomery session key cryptor
/// Author Nguyen Van Nguyen <[email protected]>
final class MontgomerySessionKeyCryptor extends SessionKeyCryptor {
/// The ephemeral key used to establish the shared secret
final Uint8List ephemeralKey;

Expand Down
Loading

0 comments on commit 5017477

Please sign in to comment.