Secure channel: seal symmetric chunks in place

SealSymmetricMessage copied the encoded chunks into a second
BufferCollection. The chunks are now replaced in place by the segments
to send, which are over the same buffers, so the encoded collection is
the one sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Roman Ettlinger
2026-10-19 14:19:46 +02:00
co-authored by Claude Opus 5.5
parent 730cec1985
commit 2135f7d7f9
@@ -939,7 +939,8 @@ namespace Opc.Ua.Bindings
const int headerSize = TcpMessageLimits.SymmetricHeaderSize +
TcpMessageLimits.SequenceHeaderSize;
var chunksToSend = new BufferCollection(chunksToProcess.Count);
// the chunks are secured in place: each body segment is replaced by the
// segment to send, which covers the headers in the same buffer.
int lastChunk = chunksToProcess.Count - 1;
for (int ii = 0; ii < chunksToProcess.Count; ii++)
@@ -1028,13 +1029,12 @@ namespace Opc.Ua.Bindings
position);
}
// add the header into chunk.
chunksToSend.Add(dataToSend);
chunksToProcess[ii] = dataToSend;
}
// ensure the buffers don't get cleaned up on exit.
success = true;
return chunksToSend;
return chunksToProcess;
}
finally
{