namespace Renci.SshNet.Messages.Authentication
{
///
/// Represents "publickey" SSH_MSG_USERAUTH_REQUEST message.
///
public class RequestMessagePublicKey : RequestMessage
{
///
/// Gets the name of the public key algorithm as ASCII encoded byte array.
///
///
/// The name of the public key algorithm.
///
public byte[] PublicKeyAlgorithmName { get; private set; }
///
/// Gets the public key data.
///
public byte[] PublicKeyData { get; private set; }
///
/// Gets or sets public key signature.
///
///
/// The signature.
///
public byte[] Signature { get; set; }
///
/// 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 += 1; // Signature flag
capacity += 4; // PublicKeyAlgorithmName length
capacity += PublicKeyAlgorithmName.Length; // PublicKeyAlgorithmName
capacity += 4; // PublicKeyData length
capacity += PublicKeyData.Length; // PublicKeyData
if (Signature != null)
{
capacity += 4; // Signature length
capacity += Signature.Length; // Signature
}
return capacity;
}
}
///
/// Initializes a new instance of the class.
///
/// Name of the service.
/// Authentication username.
/// Name of private key algorithm.
/// Private key data.
public RequestMessagePublicKey(ServiceName serviceName, string username, string keyAlgorithmName, byte[] keyData)
: base(serviceName, username, "publickey")
{
PublicKeyAlgorithmName = Ascii.GetBytes(keyAlgorithmName);
PublicKeyData = keyData;
}
///
/// Initializes a new instance of the class.
///
/// Name of the service.
/// Authentication username.
/// Name of private key algorithm.
/// Private key data.
/// Private key signature.
public RequestMessagePublicKey(ServiceName serviceName, string username, string keyAlgorithmName, byte[] keyData, byte[] signature)
: this(serviceName, username, keyAlgorithmName, keyData)
{
Signature = signature;
}
///
/// Called when type specific data need to be saved.
///
protected override void SaveData()
{
base.SaveData();
Write(Signature != null);
WriteBinaryString(PublicKeyAlgorithmName);
WriteBinaryString(PublicKeyData);
if (Signature != null)
{
WriteBinaryString(Signature);
}
}
}
}