From ee3fbb8e349f096896bfbb6746f71305d99071cf Mon Sep 17 00:00:00 2001 From: Nguyen Van Nguyen Date: Tue, 15 Oct 2024 12:10:00 +0700 Subject: [PATCH] Support signature salt notation Signed-off-by: Nguyen Van Nguyen --- lib/src/enum/hash_algorithm.dart | 16 ++++++++++++++++ lib/src/packet/signature_packet.dart | 10 ++++++++++ 2 files changed, 26 insertions(+) diff --git a/lib/src/enum/hash_algorithm.dart b/lib/src/enum/hash_algorithm.dart index 2878a6a5..915b5ad6 100644 --- a/lib/src/enum/hash_algorithm.dart +++ b/lib/src/enum/hash_algorithm.dart @@ -56,4 +56,20 @@ enum HashAlgorithm { return 28; } } + + int get saltSize { + switch (this) { + case md5: + case sha1: + case ripemd160: + return 8; + case sha224: + case sha256: + return 16; + case sha384: + return 24; + case sha512: + return 32; + } + } } diff --git a/lib/src/packet/signature_packet.dart b/lib/src/packet/signature_packet.dart index a253968c..94a565e2 100644 --- a/lib/src/packet/signature_packet.dart +++ b/lib/src/packet/signature_packet.dart @@ -2,6 +2,7 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +import 'dart:convert'; import 'dart:typed_data'; import '../crypto/math/byte_ext.dart'; @@ -31,6 +32,8 @@ import 'user_id.dart'; /// See RFC 4880, section 5.2. /// Author Nguyen Van Nguyen class SignaturePacket extends ContainedPacket { + static const saltNotation = "salt@notations.dart-pg.org"; + final int version; final SignatureType signatureType; @@ -230,6 +233,13 @@ class SignaturePacket extends ContainedPacket { SignatureCreationTime.fromTime(date ?? DateTime.now()), IssuerFingerprint.fromKey(signKey), IssuerKeyID(signKey.keyID.bytes), + NotationData.fromNotation( + false, + saltNotation, + utf8.decode( + Helper.secureRandom().nextBytes(hashAlgorithm.saltSize), + ), + ), ...subpackets, ]; if (keyExpirationTime > 0) {