Skip to content

Commit

Permalink
Support signature salt notation
Browse files Browse the repository at this point in the history
Signed-off-by: Nguyen Van Nguyen <[email protected]>
  • Loading branch information
nguyennv committed Oct 15, 2024
1 parent 532d58e commit ee3fbb8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/src/enum/hash_algorithm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
10 changes: 10 additions & 0 deletions lib/src/packet/signature_packet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -31,6 +32,8 @@ import 'user_id.dart';
/// See RFC 4880, section 5.2.
/// Author Nguyen Van Nguyen <[email protected]>
class SignaturePacket extends ContainedPacket {
static const saltNotation = "[email protected]";

final int version;

final SignatureType signatureType;
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit ee3fbb8

Please sign in to comment.