Path: redb-route/redb.Route.As2/Mdn/ReceiptRequest.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.As2/Mdn/ReceiptRequest.cs
----
using Microsoft.AspNetCore.Http;
using redb.Route.As2.Crypto;
namespace redb.Route.As2.Mdn;
///
/// The receipt a received message asks for (RFC 4130 §7.3): whether any (Disposition-Notification-To), whether
/// signed and with which MIC algorithm (Disposition-Notification-Options:
/// signed-receipt-protocol=importance, pkcs7-signature; signed-receipt-micalg=importance, alg[, alg...]).
///
/// The sender asked for an MDN.
/// The sender asked for a signed MDN (pkcs7-signature).
/// The algorithm of the MIC and of the MDN signature: the first requested one usable here, else the agreement's.
/// The algorithms the sender listed, in its order; empty when it listed none.
///
/// A required option this receiver cannot honour, as the failure of the MDN (RFC 4130 §7.5.3):
/// or ; null when
/// every required option is met. An optional one is never a failure.
///
internal sealed record ReceiptRequest(bool Requested, bool Signed, string MicAlg, IReadOnlyList RequestedMicAlgs, string? Failure = null)
{
public static ReceiptRequest Of(HttpRequest request, As2Profile profile)
{
var requested = !string.IsNullOrWhiteSpace(request.Headers[As2Headers.DispositionNotificationTo].ToString());
var options = request.Headers[As2Headers.DispositionNotificationOptions].ToString();
var signed = false;
var protocolRequired = false;
var protocolListed = false;
var micAlgRequired = false;
IReadOnlyList algs = [];
foreach (var parameter in options.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
{
var eq = parameter.IndexOf('=');
if (eq < 0) continue;
var name = parameter[..eq].Trim();
// The first value is the importance (required | optional); the rest are the values.
var all = parameter[(eq + 1)..].Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
var required = all.Length > 0 && all[0].Equals("required", StringComparison.OrdinalIgnoreCase);
var values = all.Skip(1).ToList();
if (name.Equals("signed-receipt-protocol", StringComparison.OrdinalIgnoreCase))
{
protocolListed = true;
protocolRequired = required;
signed = values.Any(v => v.Equals("pkcs7-signature", StringComparison.OrdinalIgnoreCase));
}
else if (name.Equals("signed-receipt-micalg", StringComparison.OrdinalIgnoreCase))
{
micAlgRequired = required;
algs = values;
}
}
var usable = algs.FirstOrDefault(a => As2CryptoEngine.IsSupportedDigest(a) && (!As2Profile.IsLegacy(a) || profile.AllowLegacyAlgorithms));
string? failure = null;
// Required and not producible here: a protocol other than pkcs7-signature, or pkcs7-signature while the agreement
// has no certificate of ours to sign with.
if (protocolListed && protocolRequired && (!signed || profile.OurCertificate is null))
failure = As2Disposition.UnsupportedFormat;
else if (micAlgRequired && usable is null)
failure = As2Disposition.UnsupportedMicAlgorithms;
return new ReceiptRequest(requested, signed, usable ?? profile.SignAlg, algs, failure);
}
}