Replace UUID with DocumentElementId across the codebase
Updated `PdfSignOptionsDto` and `PdfSignatureCheckItemDto` to use `DocumentElementId` (long) instead of `UUID` (string). Modified `PdfDigitalSignatureService` to reflect this change, including updates to `SignatureReasonMetaRegex`, `BuildReasonWithMeta`, and `ParseReasonMeta`. Adjusted method signatures, return values, and property assignments to ensure consistent use of `DocumentElementId`. These changes align with a shift in the application's data model to use numeric identifiers for document elements.
This commit is contained in:
@@ -18,7 +18,7 @@ namespace EnvelopeGenerator.Infrastructure.Crypt.Services;
|
||||
|
||||
public sealed class PdfDigitalSignatureService(IOptions<Pkcs11Options> options) : IPdfDigitalSignatureService
|
||||
{
|
||||
private static readonly Regex SignatureReasonMetaRegex = new(@"\|\s*SFMETA:v1;doc=(?<doc>[0-9a-fA-F-]{36});sha256=(?<sha>[A-Fa-f0-9]{64})$", RegexOptions.CultureInvariant | RegexOptions.Compiled);
|
||||
private static readonly Regex SignatureReasonMetaRegex = new(@"\|\s*SFMETA:v1;deid=(?<deid>\d+);sha256=(?<sha>[A-Fa-f0-9]{64})$", RegexOptions.CultureInvariant | RegexOptions.Compiled);
|
||||
|
||||
public async Task SignPdfAsync(Stream inputPdf, Stream outputPdf, PdfSignOptionsDto request, Stream? image = null, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -34,7 +34,7 @@ public sealed class PdfDigitalSignatureService(IOptions<Pkcs11Options> options)
|
||||
|
||||
var pkcs11Options = options.Value;
|
||||
|
||||
var reasonWithMeta = BuildReasonWithMeta(request.Reason ?? pkcs11Options.DefaultReason, request.UUID, sourceHashHex);
|
||||
var reasonWithMeta = BuildReasonWithMeta(request.Reason ?? pkcs11Options.DefaultReason, request.DocumentElementId, sourceHashHex);
|
||||
|
||||
using var signer = new PdfDocumentSigner(workingInput);
|
||||
|
||||
@@ -166,7 +166,7 @@ public sealed class PdfDigitalSignatureService(IOptions<Pkcs11Options> options)
|
||||
Filter: signature.Filter,
|
||||
SubFilter: signature.SubFilter,
|
||||
ApplicationName: null,
|
||||
UUID: reasonMeta.UUID,
|
||||
DocumentElementId: reasonMeta.DocumentElementId,
|
||||
OriginalDocumentSha256: reasonMeta.OriginalDocumentSha256,
|
||||
MessageDigestHex: TryExtractMessageDigestHex(signature.Contents),
|
||||
Error: null));
|
||||
@@ -201,7 +201,7 @@ public sealed class PdfDigitalSignatureService(IOptions<Pkcs11Options> options)
|
||||
Filter: signature.Filter,
|
||||
SubFilter: signature.SubFilter,
|
||||
ApplicationName: null,
|
||||
UUID: reasonMeta.UUID,
|
||||
DocumentElementId: reasonMeta.DocumentElementId,
|
||||
OriginalDocumentSha256: reasonMeta.OriginalDocumentSha256,
|
||||
MessageDigestHex: null,
|
||||
Error: ex.Message));
|
||||
@@ -492,11 +492,11 @@ public sealed class PdfDigitalSignatureService(IOptions<Pkcs11Options> options)
|
||||
return start + length;
|
||||
}
|
||||
|
||||
private static string BuildReasonWithMeta(string? businessReason, string uuid, string sourceHashHex)
|
||||
private static string BuildReasonWithMeta(string? businessReason, long documentElementId, string sourceHashHex)
|
||||
{
|
||||
var trimmedReason = string.IsNullOrWhiteSpace(businessReason) ? null : businessReason.Trim();
|
||||
var prefix = string.IsNullOrWhiteSpace(trimmedReason) ? string.Empty : trimmedReason + " ";
|
||||
return $"{prefix}| SFMETA:v1;doc={uuid};sha256={sourceHashHex}";
|
||||
return $"{prefix}| SFMETA:v1;deid={documentElementId};sha256={sourceHashHex}";
|
||||
}
|
||||
|
||||
private static string? BuildContactInfo(string? email, string? phone)
|
||||
@@ -553,7 +553,7 @@ public sealed class PdfDigitalSignatureService(IOptions<Pkcs11Options> options)
|
||||
string.IsNullOrWhiteSpace(phone) ? null : phone);
|
||||
}
|
||||
|
||||
private static (string? BusinessReason, string? UUID, string? OriginalDocumentSha256) ParseReasonMeta(string? reason)
|
||||
private static (string? BusinessReason, long? DocumentElementId, string? OriginalDocumentSha256) ParseReasonMeta(string? reason)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(reason))
|
||||
return (reason, null, null);
|
||||
@@ -566,9 +566,11 @@ public sealed class PdfDigitalSignatureService(IOptions<Pkcs11Options> options)
|
||||
if (string.IsNullOrWhiteSpace(businessReason))
|
||||
businessReason = null;
|
||||
|
||||
long? parsedDocumentElementId = long.TryParse(match.Groups["deid"].Value, out var deid) ? deid : null;
|
||||
|
||||
return (
|
||||
businessReason,
|
||||
match.Groups["doc"].Value,
|
||||
parsedDocumentElementId,
|
||||
match.Groups["sha"].Value.ToUpperInvariant());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user