using System;
using System.Collections.Generic;
using System.Text;
namespace FastReport.Messaging.Authentication.Sasl
{
///
/// The base abstarct class for all SASL mechanisms.
///
public abstract class SaslMechanism
{
#region Fields
private string name;
private string username;
private string password;
#endregion // Fields
#region Properties
///
/// Gets or sets the name of mechanism.
///
public string Name
{
get { return name; }
protected set { name = value; }
}
///
/// Gets or sets the username.
///
public string Username
{
get { return username; }
set { username = value; }
}
///
/// Gets or sets the user's password.
///
public string Password
{
get { return password; }
set { password = value; }
}
#endregion // Properties
#region Constructors
///
/// Initializes a new instance of the class.
///
public SaslMechanism()
{
name = "";
username = "";
password = "";
}
///
/// Initializes a new instance of the class with specified parameters.
///
/// The username.
/// The user's password.
public SaslMechanism(string username, string password)
{
this.name = "";
this.username = username;
this.password = password;
}
#endregion // Constructors
#region Protected Methods
///
/// Computes client response for server challenge.
///
/// The server challenge.
/// The client response.
protected abstract byte[] ComputeResponse(byte[] challenge);
#endregion // Protected Methods
#region Public Methods
///
/// Gets the base64-encoded client response fo the server challenge.
///
/// The base64-string containing server challenge.
/// The base64-string containing client response.
public string GetResponse(string challenge)
{
byte[] data = Convert.FromBase64String(challenge);
byte[] response = ComputeResponse(data);
return Convert.ToBase64String(response);
}
///
/// Gets the client response for the server challenge.
///
/// Byte array containing server challenge.
/// Byte array containing client response.
public byte[] GetResponse(byte[] challenge)
{
return ComputeResponse(challenge);
}
#endregion // Public Methods
}
}