Path: redb-route/redb.Route.As4/Signals/Responses.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.As4/Signals/Responses.cs ---- using System.Security.Cryptography.X509Certificates; using System.Text; using System.Xml; using redb.Route.As4.Messaging; using redb.Route.As4.Mime; using redb.Route.As4.Security; namespace redb.Route.As4.Signals; /// /// What a receiver answers in the HTTP response (eDelivery AS4 1.16: receipts and errors only as responses): /// a signed non-repudiation receipt, an ebMS error, or — for a message that is not ebMS at all — a SOAP fault. /// Statuses follow what Holodeck B2B answers: an ebMS signal with 200; a SOAP fault per the SOAP 1.2 HTTP /// binding, 400 for a Sender fault, 500 for MustUnderstand. /// internal static class Responses { /// The signed receipt for , echoing . public static (string ContentType, byte[] Body) Receipt(string receivedMessageId, IReadOnlyList receivedReferences, string host, X509Certificate2 signer, As4KeyReference keyReference, TimeSpan? timestampTtl, IReadOnlyList? signingPath = null) { var signal = new SignalMessage( new MessageInfo(DateTimeOffset.UtcNow, MessageIdFactory.New(host), receivedMessageId), Receipts.NonRepudiation(receivedReferences), [], null); var message = SwaMessage.Create(MessagingWriter.CreateEnvelope(signal)); As4SecurityEngine.Sign(message, signer, keyReference, timestampTtl, DateTimeOffset.UtcNow, signingPath); return message.Write(); } /// /// An ebMS error signal for (null when the message could not be read far /// enough to know it). The texts are the code's fixed partner text and a reference to quote — never the text of /// one of our exceptions (BR-4); is the one exception: a description of the caller's /// own bytes. Signed when a signer is given (the agreement is known), unsigned otherwise. /// public static (string ContentType, byte[] Body) Error(As4ErrorCode code, string? refToMessageId, string host, string reference, string? callerText = null, X509Certificate2? signer = null, As4KeyReference keyReference = As4KeyReference.BinarySecurityToken, IReadOnlyList? signingPath = null) { var error = new EbmsError(code.Code, code.Severity, code.Category, "ebms", refToMessageId, code.ShortDescription, callerText ?? code.PartnerText, $"ref: {reference}"); var signal = new SignalMessage(new MessageInfo(DateTimeOffset.UtcNow, MessageIdFactory.New(host), refToMessageId), null, [error], null); var message = SwaMessage.Create(MessagingWriter.CreateEnvelope(signal)); if (signer is not null) As4SecurityEngine.Sign(message, signer, keyReference, timestampTtl: null, DateTimeOffset.UtcNow, signingPath); return message.Write(); } /// A SOAP 1.2 fault with code soapenv:Sender or soapenv:MustUnderstand. public static (int Status, string ContentType, byte[] Body) SoapFault(bool mustUnderstand, string reason) { var code = mustUnderstand ? "MustUnderstand" : "Sender"; var xml = $"" + $"soapenv:{code}" + $"{System.Security.SecurityElement.Escape(reason)}" + ""; return (mustUnderstand ? 500 : 400, "application/soap+xml; charset=UTF-8", Encoding.UTF8.GetBytes(xml)); } }