mirror of
https://github.com/sshnet/SSH.NET.git
synced 2026-09-10 09:15:47 +00:00
5b8382de26
A byte array is allocated to hold each plaintext packet. This removes that by adding a buffer for that purpose.
47 lines
1.3 KiB
C#
47 lines
1.3 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
using Renci.SshNet.Common;
|
|
using Renci.SshNet.Compression;
|
|
using Renci.SshNet.Messages;
|
|
|
|
namespace Renci.SshNet.Tests.Common
|
|
{
|
|
internal static class Extensions
|
|
{
|
|
public static string AsString(this IList<ExceptionEventArgs> exceptionEvents)
|
|
{
|
|
if (exceptionEvents.Count == 0)
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
var reportedExceptions = string.Empty;
|
|
foreach (var exceptionEvent in exceptionEvents)
|
|
{
|
|
reportedExceptions += exceptionEvent.Exception.ToString();
|
|
}
|
|
|
|
return reportedExceptions;
|
|
}
|
|
|
|
/// <returns>[4 bytes] || packet_len || padding_len || payload || padding.</returns>
|
|
public static byte[] GetPacket(this Message message, byte paddingMultiplier, Compressor? compressor)
|
|
{
|
|
var buffer = Array.Empty<byte>();
|
|
|
|
var byteCount = message.GetPacket(
|
|
ref buffer,
|
|
paddingMultiplier,
|
|
compressor,
|
|
excludePacketLengthFieldWhenPadding: false,
|
|
macLength: 0);
|
|
|
|
Array.Resize(ref buffer, byteCount);
|
|
|
|
return buffer;
|
|
}
|
|
}
|
|
}
|