using System; namespace Renci.SshNet.Messages.Authentication { /// /// Represents SSH_MSG_USERAUTH_REQUEST message. Server as a base message for other user authentication requests. /// [Message("SSH_MSG_USERAUTH_REQUEST", AuthenticationMessageCode)] public abstract class RequestMessage : Message { /// /// Returns the authentication message code for SSH_MSG_USERAUTH_REQUEST. /// internal const int AuthenticationMessageCode = 50; private readonly byte[] _serviceName; private readonly byte[] _userName; private readonly byte[] _methodNameBytes; private readonly string _methodName; /// /// Gets authentication username as UTF-8 encoded byte array. /// public byte[] Username { get { return _userName; } } /// /// Gets the name of the service as ASCII encoded byte array. /// /// /// The name of the service. /// public byte[] ServiceName { get { return _serviceName; } } /// /// Gets the name of the authentication method. /// /// /// The name of the method. /// public virtual string MethodName { get { return _methodName; } } /// /// 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; // Username length capacity += Username.Length; // Username capacity += 4; // ServiceName length capacity += ServiceName.Length; // ServiceName capacity += 4; // MethodName length capacity += _methodNameBytes.Length; // MethodName return capacity; } } /// /// Initializes a new instance of the class. /// /// Name of the service. /// Authentication username. /// The name of the authentication method. protected RequestMessage(ServiceName serviceName, string username, string methodName) { _serviceName = serviceName.ToArray(); _userName = Utf8.GetBytes(username); _methodNameBytes = Ascii.GetBytes(methodName); _methodName = methodName; } /// /// Called when type specific data need to be loaded. /// protected override void LoadData() { throw new InvalidOperationException("Load data is not supported."); } /// /// Called when type specific data need to be saved. /// protected override void SaveData() { WriteBinaryString(_userName); WriteBinaryString(_serviceName); WriteBinaryString(_methodNameBytes); } internal override void Process(Session session) { throw new NotImplementedException(); } } }