using System;
using System.Globalization;
using Renci.SshNet.Abstractions;
using Renci.SshNet.Common;
namespace Renci.SshNet.Messages.Transport
{
///
/// Represents SSH_MSG_IGNORE message.
///
[Message("SSH_MSG_IGNORE", MessageNumber)]
public class IgnoreMessage : Message
{
internal const byte MessageNumber = 2;
///
/// Gets ignore message data if any.
///
public byte[] Data { get; private set; }
///
/// Initializes a new instance of the class
///
public IgnoreMessage()
{
Data = Array.Empty;
}
///
/// Gets the size of the message in bytes.
///
///
/// The size of the messages in bytes.
///
protected override int BufferCapacity
{
get
{
var capacity = base.BufferCapacity;
capacity += 4; // Data length
capacity += Data.Length; // Data
return capacity;
}
}
///
/// Initializes a new instance of the class.
///
/// The data.
public IgnoreMessage(byte[] data)
{
if (data == null)
throw new ArgumentNullException("data");
Data = data;
}
///
/// Called when type specific data need to be loaded.
///
protected override void LoadData()
{
var dataLength = ReadUInt32();
if (dataLength > int.MaxValue)
{
throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, "Data longer than {0} is not supported.", int.MaxValue));
}
if (dataLength > (DataStream.Length - DataStream.Position))
{
DiagnosticAbstraction.Log("SSH_MSG_IGNORE: Length exceeds data bytes, data ignored.");
Data = Array.Empty;
}
else
{
Data = ReadBytes((int) dataLength);
}
}
///
/// Called when type specific data need to be saved.
///
protected override void SaveData()
{
WriteBinaryString(Data);
}
internal override void Process(Session session)
{
session.OnIgnoreReceived(this);
}
}
}